| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Yajra\CMS\Http\Controllers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Http\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Yajra\CMS\Entities\Configuration; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * Class SiteConfigurationController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @package Yajra\CMS\Controllers | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | class ConfigurationsController extends Controller | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |      * Limit the config results based on given key. | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |      * @var array | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     protected $limits = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |         'site'     => ['name', 'version', 'keywords', 'author', 'description', 'admin_theme', 'registration'], | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |         'app'      => ['name', 'debug', 'debugbar', 'env', 'locale', 'log', 'timezone', 'url'], | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |         'database' => ['default', 'connections', 'migrations', 'redis'], | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |      * Site configuration setup page. | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |      * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     public function index() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $config = $this->setupConfig(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         return view('administrator.configuration.index', compact('config')); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 36 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |      * Get configuration setup. | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |      * @return \Illuminate\Support\Collection | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     protected function setupConfig() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         return collect([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                 'title' => 'Site Management', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                 'key'   => 'site', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                 'icon'  => 'fa-cog', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 'title' => 'Application Environment', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                 'key'   => 'app', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                 'icon'  => 'fa-laptop', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                 'title' => 'Database Connection', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                 'key'   => 'database', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |                 'icon'  => 'fa-database', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                 'title' => 'Mail Driver', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |                 'key'   => 'mail', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                 'icon'  => 'fa-envelope', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                 'title' => 'Cache Store', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                 'key'   => 'cache', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                 'icon'  => 'fa-cloud-download', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |                 'title' => 'Session Driver', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                 'key'   => 'session', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                 'icon'  => 'fa-comment-o', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |                 'title' => 'File System', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                 'key'   => 'filesystems', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |                 'icon'  => 'fa-briefcase', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         ]); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 82 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |      * Store submitted configurations. | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |      * @param \Illuminate\Http\Request $request | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     public function store(Request $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         $config = $request->input('config'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         foreach (array_dot($request->input('data')) as $key => $value) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             $path = $config . '.' . $key; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             $this->destroy($path); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             if (is_array($value)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |                 $value = implode(',', $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             Configuration::create(['key' => $path, 'value' => $value]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         return $this->notifySuccess("Configuation ($config) successfully saved! You may need to refresh the page to reflect some changes."); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 103 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |      * Remove configuration by key. | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |      * @param string $key | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |      * @return Configuration | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     public function destroy($key) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         return Configuration::where('key', $key)->delete(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 114 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |      * Show configuration by key. | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |      * @param string $key | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |      * @return array|mixed | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     public function show($key) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         $config = config($key) ?? []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         if (! isset($this->limits[$key])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |             return $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         return response()->json(array_only($config, $this->limits[$key])); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 131 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 132 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 133 |  |  |  | 
            
                        
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.