robclancy / presenter

Decorate your objects using presenters. Primarily to keep presentation logic out of your models.
MIT License
345 stars 38 forks source link

How to use "Extending the Decorator" #35

Closed ghost closed 7 years ago

ghost commented 10 years ago

Hi,

I was able to get the PresentableInterface and getPresenter() plugin style working but I am not able to get the "Extending the Decorator" style working.

Here is what I am doing :

  1. class User extends Eloquent { .... public $presenter = 'Sampleapp\Presenters\UserPresenter'; // removed getPresenter() }
  2. Created the Decorator class
  3. Add to start/global.php

App::make('presenter.decorator', App::share(function($app) { $decorator = new (PATH TO DECORATOR CLASS)\Decorator; Robbo\Presenter\Presenter::setExtendedDecorator($decorator); return $decorator; }));

robclancy commented 10 years ago

I believe my readme is wrong. Because I set the decorator in the service provider it is overriding your global one since the providers are executed after it. So current solution would be to use your own service provider. Personally I have an ApplicationProvider.php which handles stuff like this. Just make sure it comes after the presenters one in the config/app.php.

Leave this open as I am classifying this as a bug. When I get around to it I plan to do a 2.0 update to add support for things like traits and make things easier in general.