@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | // When no files are uploaded, we still would like to sort our assets duh |
| 27 | 27 | if (empty($files_by_type)) { |
| 28 | - foreach($files_order_by_type as $type => $fileIdsCollection){ |
|
| 28 | + foreach ($files_order_by_type as $type => $fileIdsCollection) { |
|
| 29 | 29 | $this->sortFiles($model, $type, $fileIdsCollection); |
| 30 | 30 | } |
| 31 | 31 | |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | foreach ($files_by_type as $type => $files) { |
| 36 | 36 | |
| 37 | - foreach($files as $locale => $files) |
|
| 37 | + foreach ($files as $locale => $files) |
|
| 38 | 38 | { |
| 39 | 39 | $this->validateFileUploads($files); |
| 40 | 40 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | if (is_string($file)) { |
| 69 | 69 | $image_name = json_decode($file)->output->name; |
| 70 | 70 | $asset = $this->addAsset(json_decode($file)->output->image, $type, $locale, $image_name, $model); |
| 71 | - } else { |
|
| 71 | + }else { |
|
| 72 | 72 | $image_name = $file->getClientOriginalName(); |
| 73 | 73 | $asset = $this->addAsset($file, $type, $locale, $image_name, $model); |
| 74 | 74 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | if (is_string($file)) { |
| 93 | 93 | $asset = AssetUploader::uploadFromBase64($file, $filename); |
| 94 | - } else { |
|
| 94 | + }else { |
|
| 95 | 95 | $asset = AssetUploader::upload($file, $filename); |
| 96 | 96 | } |
| 97 | 97 | |
@@ -137,9 +137,9 @@ discard block |
||
| 137 | 137 | */ |
| 138 | 138 | private function sluggifyFilename($filename): string |
| 139 | 139 | { |
| 140 | - $extension = substr($filename, strrpos($filename, '.') + 1); |
|
| 140 | + $extension = substr($filename, strrpos($filename, '.')+1); |
|
| 141 | 141 | $filename = substr($filename, 0, strrpos($filename, '.')); |
| 142 | - $filename = str_slug($filename) . '.' . $extension; |
|
| 142 | + $filename = str_slug($filename).'.'.$extension; |
|
| 143 | 143 | |
| 144 | 144 | return $filename; |
| 145 | 145 | } |
@@ -155,9 +155,9 @@ discard block |
||
| 155 | 155 | if ($file instanceof UploadedFile && !$file->isValid()) { |
| 156 | 156 | if ($file->getError() == UPLOAD_ERR_INI_SIZE) { |
| 157 | 157 | throw new FileTooBigException( |
| 158 | - 'Cannot upload file because it exceeded the allowed upload_max_filesize: upload_max_filesize is smaller than post size. ' . |
|
| 159 | - 'upload_max_filesize: ' . (int)ini_get('upload_max_filesize') . 'MB, ' . |
|
| 160 | - 'post_max_size: ' . (int)(ini_get('post_max_size')) . 'MB' |
|
| 158 | + 'Cannot upload file because it exceeded the allowed upload_max_filesize: upload_max_filesize is smaller than post size. '. |
|
| 159 | + 'upload_max_filesize: '.(int)ini_get('upload_max_filesize').'MB, '. |
|
| 160 | + 'post_max_size: '.(int)(ini_get('post_max_size')).'MB' |
|
| 161 | 161 | ); |
| 162 | 162 | } |
| 163 | 163 | } |
@@ -169,31 +169,31 @@ discard block |
||
| 169 | 169 | { |
| 170 | 170 | $actions = ['new', 'replace', 'delete']; |
| 171 | 171 | |
| 172 | - foreach($files_by_type as $type => $files) |
|
| 172 | + foreach ($files_by_type as $type => $files) |
|
| 173 | 173 | { |
| 174 | - foreach($files as $locale => $_files){ |
|
| 175 | - if(!in_array($locale, config('translatable.locales'))) { |
|
| 176 | - throw new \InvalidArgumentException('Corrupt file payload. key is expected to be a valid locale [' . implode(',', config('translatable.locales', [])). ']. Instead [' . $locale . '] is given.'); |
|
| 174 | + foreach ($files as $locale => $_files) { |
|
| 175 | + if (!in_array($locale, config('translatable.locales'))) { |
|
| 176 | + throw new \InvalidArgumentException('Corrupt file payload. key is expected to be a valid locale ['.implode(',', config('translatable.locales', [])).']. Instead ['.$locale.'] is given.'); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - if(!is_array($_files)) { |
|
| 180 | - throw new \InvalidArgumentException('A valid files entry should be an array of files, key with either [new, replace or delete]. Instead a ' . gettype($_files) . ' is given.'); |
|
| 179 | + if (!is_array($_files)) { |
|
| 180 | + throw new \InvalidArgumentException('A valid files entry should be an array of files, key with either [new, replace or delete]. Instead a '.gettype($_files).' is given.'); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - foreach($_files as $action => $file) { |
|
| 184 | - if(!in_array($action, $actions)) { |
|
| 185 | - throw new \InvalidArgumentException('A valid files entry should have a key of either ['.implode(',', $actions).']. Instead ' . $action . ' is given.'); |
|
| 183 | + foreach ($_files as $action => $file) { |
|
| 184 | + if (!in_array($action, $actions)) { |
|
| 185 | + throw new \InvalidArgumentException('A valid files entry should have a key of either ['.implode(',', $actions).']. Instead '.$action.' is given.'); |
|
| 186 | 186 | } |
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - foreach($files_order_by_type as $type => $fileIdsCollection) |
|
| 191 | + foreach ($files_order_by_type as $type => $fileIdsCollection) |
|
| 192 | 192 | { |
| 193 | - foreach($fileIdsCollection as $locale => $commaSeparatedFileIds){ |
|
| 193 | + foreach ($fileIdsCollection as $locale => $commaSeparatedFileIds) { |
|
| 194 | 194 | |
| 195 | - if(!in_array($locale, config('translatable.locales'))) { |
|
| 196 | - throw new \InvalidArgumentException('Corrupt file payload. key for the file order is expected to be a valid locale [' . implode(',', config('translatable.locales', [])). ']. Instead [' . $locale . '] is given.'); |
|
| 195 | + if (!in_array($locale, config('translatable.locales'))) { |
|
| 196 | + throw new \InvalidArgumentException('Corrupt file payload. key for the file order is expected to be a valid locale ['.implode(',', config('translatable.locales', [])).']. Instead ['.$locale.'] is given.'); |
|
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | } |
@@ -203,13 +203,13 @@ discard block |
||
| 203 | 203 | { |
| 204 | 204 | $defaultLocale = config('app.fallback_locale'); |
| 205 | 205 | |
| 206 | - foreach($files_by_type as $type => $files) |
|
| 206 | + foreach ($files_by_type as $type => $files) |
|
| 207 | 207 | { |
| 208 | - foreach($files as $locale => $_files){ |
|
| 209 | - if(!in_array($locale, config('translatable.locales'))) { |
|
| 208 | + foreach ($files as $locale => $_files) { |
|
| 209 | + if (!in_array($locale, config('translatable.locales'))) { |
|
| 210 | 210 | unset($files_by_type[$type][$locale]); |
| 211 | 211 | |
| 212 | - if(!isset($files_by_type[$type][$defaultLocale])) { |
|
| 212 | + if (!isset($files_by_type[$type][$defaultLocale])) { |
|
| 213 | 213 | $files_by_type[$type][$defaultLocale] = []; |
| 214 | 214 | } |
| 215 | 215 | |
@@ -225,14 +225,14 @@ discard block |
||
| 225 | 225 | { |
| 226 | 226 | $defaultLocale = config('app.fallback_locale'); |
| 227 | 227 | |
| 228 | - foreach($files_order_by_type as $type => $fileIdsCollection) |
|
| 228 | + foreach ($files_order_by_type as $type => $fileIdsCollection) |
|
| 229 | 229 | { |
| 230 | - if(!is_array($fileIdsCollection)) { |
|
| 230 | + if (!is_array($fileIdsCollection)) { |
|
| 231 | 231 | $fileIdsCollection = [$defaultLocale => $fileIdsCollection]; |
| 232 | 232 | $files_order_by_type[$type] = $fileIdsCollection; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - foreach($fileIdsCollection as $locale => $commaSeparatedFileIds){ |
|
| 235 | + foreach ($fileIdsCollection as $locale => $commaSeparatedFileIds) { |
|
| 236 | 236 | $files_order_by_type[$type][$locale] = explode(',', $commaSeparatedFileIds); |
| 237 | 237 | } |
| 238 | 238 | } |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | { |
| 245 | 245 | $sortedFileIds = []; |
| 246 | 246 | |
| 247 | - foreach($fileIdsCollection as $locale => $fileIds) { |
|
| 247 | + foreach ($fileIdsCollection as $locale => $fileIds) { |
|
| 248 | 248 | $sortedFileIds = array_merge($sortedFileIds, $fileIds); |
| 249 | 249 | } |
| 250 | 250 | |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | { |
| 256 | 256 | $assets = $model->assets()->where('asset_pivots.type', $type)->get(); |
| 257 | 257 | |
| 258 | - foreach($assets as $asset) |
|
| 258 | + foreach ($assets as $asset) |
|
| 259 | 259 | { |
| 260 | 260 | $pivot = $asset->pivot; |
| 261 | 261 | $pivot->order = array_search($asset->id, $sortedAssetIds); |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Thinktomorrow\Chief\Fields\Types; |
| 6 | 6 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | $builder = $model->assets()->where('asset_pivots.type', $this->key()); |
| 45 | 45 | |
| 46 | - if($locale) { |
|
| 46 | + if ($locale) { |
|
| 47 | 47 | $builder = $builder->where('asset_pivots.locale', $locale); |
| 48 | 48 | } |
| 49 | 49 | |