| 1 |  |  | <?php namespace Distilleries\Expendable\Layouts;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use Closure;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Distilleries\Expendable\Contracts\LayoutManagerContract;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Distilleries\Expendable\Contracts\StateDisplayerContract;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Contracts\View\Factory;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Illuminate\Filesystem\Filesystem;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | class LayoutManager implements LayoutManagerContract {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     protected $config;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     protected $view;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     protected $state;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     protected $filesystem;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     protected $items = [];
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     protected $layout = null;
 | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 18 |  |  | 
 | 
            
                                                                        
                            
            
                                    
            
            
                | 19 | 150 |  |     public function __construct(array $config, Factory $view, Filesystem $filesystem, StateDisplayerContract $state)
 | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     {
 | 
            
                                                                        
                            
            
                                    
            
            
                | 21 | 150 |  |         $this->config     = $config;
 | 
            
                                                                        
                            
            
                                    
            
            
                | 22 | 150 |  |         $this->view       = $view;
 | 
            
                                                                        
                            
            
                                    
            
            
                | 23 | 150 |  |         $this->filesystem = $filesystem;
 | 
            
                                                                        
                            
            
                                    
            
            
                | 24 | 150 |  |         $this->state      = $state;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 | 150 |  |     public function setupLayout($layout)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 150 |  |         $this->layout = $layout;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 150 |  |     public function initInterfaces(array $interfaces, $class)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 150 |  |         foreach ($interfaces as $interface)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 120 |  |             if (strpos($interface, 'StateContract') !== false)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 120 |  |                 $this->state->setState($interface);
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 150 |  |         $this->state->setClass($class);
 | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 150 |  |     public function initStaticPart(Closure $closure = null)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 150 |  |         if (!is_null($this->layout))
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 150 |  |             $header = $this->view->make('expendable::admin.part.header')->with([
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 75 |  |                 'title'   => ''
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 75 |  |             ]);
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 150 |  |             $footer = $this->view->make('expendable::admin.part.footer')->with([
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 75 |  |                 'title'   => ''
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 75 |  |             ]);
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 150 |  |             $this->add([
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 150 |  |                 'header' => $header,
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 150 |  |                 'footer' => $footer,
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             ]);
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 150 |  |             if (!empty($closure))
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 120 |  |                 $closure($this);
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 150 |  |     public function add(array $items)
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 150 |  |         $this->items = array_merge($this->items, $items);
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 46 |  |     public function render()
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 46 |  |         return $this->view->make($this->layout, $this->items);
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * @return array
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     public function getConfig()
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         return $this->config;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * @return Factory
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 | 120 |  |     public function getView()
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 120 |  |         return $this->view;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * @return StateDisplayerContract
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 | 120 |  |     public function getState()
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 | 120 |  |         return $this->state;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     /**
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      * @return Filesystem
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      */
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     public function getFilesystem()
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     {
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         return $this->filesystem;
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     }
 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 
 | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 113 |  |  | 
 | 
            
                                                        
            
                                    
            
            
                | 114 |  |  | } |