|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace UniSharp\LaravelFilemanager\Controllers; |
| 4 | + |
| 5 | +use UniSharp\LaravelFilemanager\Lfm; |
| 6 | +use UniSharp\LaravelFilemanager\LfmPath; |
| 7 | + |
| 8 | +class LfmController extends Controller |
| 9 | +{ |
| 10 | + protected static $success_response = 'OK'; |
| 11 | + |
| 12 | + public function __construct() |
| 13 | + { |
| 14 | + $this->applyIniOverrides(); |
| 15 | + } |
| 16 | + |
| 17 | + /** |
| 18 | + * Set up needed functions. |
| 19 | + * |
| 20 | + * @return object|null |
| 21 | + */ |
| 22 | + public function __get($var_name) |
| 23 | + { |
| 24 | + if ($var_name === 'lfm') { |
| 25 | + return app(LfmPath::class); |
| 26 | + } elseif ($var_name === 'helper') { |
| 27 | + return app(Lfm::class); |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * Show the filemanager. |
| 33 | + * |
| 34 | + * @return mixed |
| 35 | + */ |
| 36 | + public function show() |
| 37 | + { |
| 38 | + return view('laravel-filemanager::index') |
| 39 | + ->withHelper($this->helper); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Check if any extension or config is missing. |
| 44 | + * |
| 45 | + * @return array |
| 46 | + */ |
| 47 | + public function getErrors() |
| 48 | + { |
| 49 | + $arr_errors = []; |
| 50 | + |
| 51 | + if (! extension_loaded('gd') && ! extension_loaded('imagick')) { |
| 52 | + array_push($arr_errors, trans('laravel-filemanager::lfm.message-extension_not_found')); |
| 53 | + } |
| 54 | + |
| 55 | + if (! extension_loaded('exif')) { |
| 56 | + array_push($arr_errors, 'EXIF extension not found.'); |
| 57 | + } |
| 58 | + |
| 59 | + if (! extension_loaded('fileinfo')) { |
| 60 | + array_push($arr_errors, 'Fileinfo extension not found.'); |
| 61 | + } |
| 62 | + |
| 63 | + $mine_config_key = 'lfm.folder_categories.' |
| 64 | + . $this->helper->currentLfmType() |
| 65 | + . '.valid_mime'; |
| 66 | + |
| 67 | + if (! is_array(config($mine_config_key))) { |
| 68 | + array_push($arr_errors, 'Config : ' . $mine_config_key . ' is not a valid array.'); |
| 69 | + } |
| 70 | + |
| 71 | + return $arr_errors; |
| 72 | + } |
| 73 | + |
| 74 | + public function error($error_type, $variables = []) |
| 75 | + { |
| 76 | + return $this->helper->error($error_type, $variables); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Overrides settings in php.ini. |
| 81 | + * |
| 82 | + * @return null |
| 83 | + */ |
| 84 | + public function applyIniOverrides() |
| 85 | + { |
| 86 | + $overrides = config('lfm.php_ini_overrides'); |
| 87 | + if ($overrides && count($overrides) === 0) { |
| 88 | + return; |
| 89 | + } |
| 90 | + |
| 91 | + foreach ($overrides as $key => $value) { |
| 92 | + if ($value && $value != 'false') { |
| 93 | + ini_set($key, $value); |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | +} |
0 commit comments