/** * Decorate a given subject. * * @param object $subject * * @return object */ public function decorate($subject) { foreach ($subject as $key => $atom) { $subject[$key] = $this->autoPresenter->decorate($atom); } return $subject; }
/** * Decorate a given subject. * * @param object $subject * * @return object */ public function decorate($subject) { $items = $this->getItems($subject); foreach ($items->keys() as $key) { $items->put($key, $this->autoPresenter->decorate($items->get($key))); } return $subject; }
/** * Decorate a given subject. * * @param object $subject * * @return object */ public function decorate($subject) { if (is_object($subject)) { $subject = clone $subject; } if ($subject instanceof Model) { foreach ($subject->getRelations() as $relationName => $model) { $subject->setRelation($relationName, $this->autoPresenter->decorate($model)); } } if (!class_exists($presenterClass = $subject->getPresenterClass())) { throw new PresenterNotFoundException($presenterClass); } return $this->container->make($presenterClass, ['resource' => $subject]); }
/** * Register the presenter decorator. * * @param \Illuminate\Contracts\Container\Container $app * * @return void */ public function registerAutoPresenter(Container $app) { $app->singleton('autopresenter', function (Container $app) { $autoPresenter = new AutoPresenter(); $autoPresenter->register($app->make(AtomDecorator::class, ['autoPresenter' => $autoPresenter, 'app' => $app])); $autoPresenter->register($app->make(ArrayDecorator::class, ['autoPresenter' => $autoPresenter])); $autoPresenter->register($app->make(PaginatorDecorator::class, ['autoPresenter' => $autoPresenter])); return $autoPresenter; }); $app->alias('autopresenter', AutoPresenter::class); }
/** * Register the presenter decorator. * * @param \Illuminate\Contracts\Foundation\Application $app * * @return void */ public function registerAutoPresenter(Application $app) { $app->singleton('autopresenter', function (Application $app) { $autoPresenter = new AutoPresenter(); $autoPresenter->register(new AtomDecorator($autoPresenter, $app)); $autoPresenter->register(new ArrayDecorator($autoPresenter)); $autoPresenter->register(new PaginatorDecorator($autoPresenter)); return $autoPresenter; }); $app->alias('autopresenter', AutoPresenter::class); }