-
Notifications
You must be signed in to change notification settings - Fork 7
/
file_secretary.php
246 lines (223 loc) · 10.9 KB
/
file_secretary.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<?php return [
/*
|--------------------------------------------------------------------------
| File Name Generator
|--------------------------------------------------------------------------
|
| An instance of the presented file is passed to the "generate" method of
| this class,
| you can implement your own class which respects the interface.
|
*/
'file_name_generator' => \Reshadman\FileSecretary\Infrastructure\MillionOptimizedFileNameGenerator::class,
/*
|--------------------------------------------------------------------------
| Currently works only with rackspace
|--------------------------------------------------------------------------
|
| Allows to add custom config to your disk driver upon upload like headers etc.
|
*/
'default_store_config_array' => [
'headers' => [
'Cache-Control' => 'max-age=31536000'
]
],
/*
|--------------------------------------------------------------------------
| Database Tracking (Persistable Files)
|--------------------------------------------------------------------------
|
| You can use the following eloquent model for tracking files
| You can also extend it to have more flexibility.
|
*/
'eloquent' => [
'model' => \Reshadman\FileSecretary\Application\EloquentPersistedFile::class,
'table' => 'system__files'
],
/*
|--------------------------------------------------------------------------
| Image templates
|--------------------------------------------------------------------------
|
| You store your images with this package, it then handles the resizing and
| manipulating based on the following templates, Each Intervention, Image
| instance is passed to the template defined here.
| by default a dynamic template takes care of generic needs. You can
| implement your own template by extending the base template and
| implementing the proper interface.
| The package takes care of manipulating, storing and serving,
| by default images are generated once, after that they can be served
| without the participation of php with a simple nginx snippet included
| in the package
|
*/
'available_image_templates' => [
'companies_logo_200x200' => [
'class' => \Reshadman\FileSecretary\Infrastructure\Images\Templates\DynamicResizableTemplate::class,
'args' => [
'width' => 200,
'height' => 200,
'encodings' => null, // always needed, When null only parent file encoding is allowed.
'strip' => false, // removes the ICC profile when imagick is used.
],
],
'companies_logo_201xauto' => [
'class' => \Reshadman\FileSecretary\Infrastructure\Images\Templates\DynamicResizableTemplate::class,
'args' => [
'width' => 201,
'height' => null, // Height will be calculated automatically
'mode' => \Reshadman\FileSecretary\Infrastructure\Images\TemplateManager::MODE_FIT, // The image will fit
'encodings' => [
'png', // Ony png extension is served otherwise it throws 404 exception
]
],
],
],
/*
|--------------------------------------------------------------------------
| Contexts
|--------------------------------------------------------------------------
| Contexts are used to have different strategies for each one of your needs
| Basically there are three context category types:
| 1. Basic Files: A Simple File Store which stores files in this format:
| context_folder/xxx-unique-folder-name-xxxxxxx.ext
| 2. Images: This context category allows manipulating images, it stores
| images in this format:
| context_folder/xxxx-unique-folder-name-based-on-hash-xxx/main.(png|jpg|etc)
| Images are requested through the controller, the main file is found by the package
| It is passed to the proper template(based on file name) it is manipulated, it is
| It is then store beside the main image so it won't be regenerated again.
| 3. Assets: After each deploy for purging cache you can use the
| php artisan file-secretary:upload-assets --tags=backoffice,c2c_assets,b2c_assets
| to publish your assets to the cloud, each call creates a new folder for the entire
| assets, and puts the proper env key in the .env file so there is
| no runtime i/o needed for fetching the new folder's unique key, unlike
| Other packages that store the key in a .json file and read it in the runtime.
|
| The array key represents the "context name"
| Keys:
| "driver" : The laravel filesystem driver name.
| "context_folder" : The folder which files are stored in your driver.
| "driver_base_address" : For public files you can use the built in functions
| To address the relative URIs generated by this package.
| "category" : one of the "basic_file", "image" and "asset", "manipulated_image" Images will be manipulated
| By the defined templates.
| "privacy" : There are built in privacy strategies "public" and "no_access"
| If you want to handle the file serving differently you can implement
| Your own ones based on the proper interfaces of the package.
| "store_manipulated" : if FALSE, manipulated images won't be stored, if TRUE they will be stored beside the main image
| if STRING, the STRING would be considered as the context_name of category of type "manipulated_images",
| the image is stored
| there, this is useful when you want to store the main image in a reliable storage, and
| store the manipulated images in a less-reliable storage like your ftp server.
| also this is useful when you want to directly serve manipulated images from
| an nginx server exactly where the files are stored.
*/
'contexts' => [
'file_manager_private' => [
'context_folder' => 'file_manager',
'driver' => 'private',
'driver_based_address' => null,
'category' => \Reshadman\FileSecretary\Application\ContextCategoryTypes::TYPE_BASIC_FILE,
'privacy' => \Reshadman\FileSecretary\Application\Privacy\NotAllowedPrivacy::class
],
'file_manager_public' => [
'context_folder' => 'file_manager',
'driver' => 'public',
'driver_based_address' => 'https://files.jobinja.ir/',
'category' => \Reshadman\FileSecretary\Application\ContextCategoryTypes::TYPE_BASIC_FILE,
'privacy' => \Reshadman\FileSecretary\Application\Privacy\PublicPrivacy::class
],
'images_private' => [
'driver' => 'private',
'driver_base_address' => null,
'context_folder' => 'images1',
'store_manipulated' => true,
'category' => \Reshadman\FileSecretary\Application\ContextCategoryTypes::TYPE_IMAGE,
'privacy' => \Reshadman\FileSecretary\Application\Privacy\NotAllowedPrivacy::class
],
'images_public' => [
'driver' => 'public',
'context_folder' => 'images2',
'store_manipulated' => false, // false to not store manipulated images
'driver_base_address' => null,
'headers_mutator' => \Reshadman\FileSecretary\Presentation\Http\CacheContentHeadersMutator::class,
'category' => \Reshadman\FileSecretary\Application\ContextCategoryTypes::TYPE_IMAGE,
'privacy' => \Reshadman\FileSecretary\Application\Privacy\PublicPrivacy::class
],
'images_with_another_context_for_manipulated' => [
'driver' => 'public',
'driver_base_address' => null,
'context_folder' => 'images3',
'store_manipulated' => 'manipulated_images_context',
'category' => \Reshadman\FileSecretary\Application\ContextCategoryTypes::TYPE_IMAGE,
'privacy' => \Reshadman\FileSecretary\Application\Privacy\PublicPrivacy::class
],
'manipulated_images_context' => [
'driver' => 'public',
'driver_base_address' => null,
'context_folder' => 'images4',
'category' => \Reshadman\FileSecretary\Application\ContextCategoryTypes::TYPE_MANIPULATED_IMAGE,
],
'assets' => [
'driver' => 'public',
'context_folder' => 'assets',
'driver_base_address' => 'https://assets.jobinja.ir/',
'category' => \Reshadman\FileSecretary\Application\ContextCategoryTypes::TYPE_ASSET,
]
],
/*
|--------------------------------------------------------------------------
| Asset folders
|--------------------------------------------------------------------------
|
| You can use the same context for different assets
| You may have some backoffice assets + c2c_assets + b2c_assets
| You specify the proper folders for each of them they can be
| easily addressed by simple function calls when you need them.
|
*/
'asset_folders' => [
'asset_1' => [
'after_public_path' => 'asset_tags/asset_1',
'context' => 'assets',
// You should specify the name of the env variable which stores the unique id
'env_key' => 'ASSET_1_ID'
],
'asset_2' => [
'after_public_path' => 'asset_tags/asset_2',
'context' => 'assets',
'env_key' => 'ASSET_2_ID'
]
],
/*
|--------------------------------------------------------------------------
| Listeners
|--------------------------------------------------------------------------
|
| You can handle event handles here, you can use your own ones or remove them
| entirely.
|
*/
'listen' => [
// Triggered when an entire asset folder is uploaded to the cloud
// By default it will erase every asset before the previous version.
\Reshadman\FileSecretary\Application\Events\AfterAssetUpload::class => [
\Reshadman\FileSecretary\Application\AfterAssetUploadEventHandler::class
]
],
/*
|--------------------------------------------------------------------------
| Load routes
|--------------------------------------------------------------------------
|
| By default two routes are created by this package.
| One for serving basic files
| and Second one for serving manipulable images.
| If you don't want them you can implement your own.
|
*/
'load_routes' => true
];