/**
  * Perform post-registration booting of services.
  *
  * @return void
  */
 public function boot()
 {
     $app = $this->app;
     $app['view']->composer('*', function ($view) use($app) {
         $data = array_merge($view->getFactory()->getShared(), $view->getData());
         foreach ($data as $key => $item) {
             $view[$key] = Decorator::decorate($item);
         }
     });
 }
示例#2
0
 /**
  * Convert the entity instance to an array.
  *
  * @return array
  */
 public function toArray()
 {
     $presenter = $this->getPresenter();
     $items = $presenter->getPresentableItems(array_except(get_object_vars($this), '__presenter'));
     $array = [];
     foreach ($items as $name => $item) {
         $array[snake_case($name)] = Decorator::decorate($item, true);
     }
     return $array;
 }
示例#3
0
 /**
  * Handle dynamic method calls into the model.
  *
  * @param  string  $method
  * @param  array   $parameters
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     // magical getter
     if ($this->checkPresentable($method)) {
         $item = $this->model->{$method}();
         return Decorator::decorate($item);
     } else {
         throw new BadMethodCallException('Method ' . $method . ' is hidden for presentation');
     }
 }