コード例 #1
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::decorateArray($item);
     }
     return $array;
 }
コード例 #2
0
 /**
  * Perform post-registration booting of services.
  *
  * @return void
  */
 public function boot()
 {
     $app = $this->app;
     if (!empty($app['config']['datamapper.auto_present'])) {
         $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);
             }
         });
     }
 }
コード例 #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');
     }
 }