Composing presenters without inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// composing presenters without inheritance | |
// (requires nette/application 2.4.11) | |
trait RequireLoggedUser | |
{ | |
public function injectRequireLoggedUser() | |
{ | |
$this->onStartup[] = function () { | |
if (!$this->getUser()->isLoggedIn()) { | |
$this->redirect('Sign:in', $this->storeRequest()); | |
} | |
}; | |
} | |
} | |
trait AdminLayout | |
{ | |
public function injectLayout(Model $model) | |
{ | |
$this->onStartup[] = function () use ($model) { | |
$this->layout = 'admin.layout'; | |
$this->template->menu = $model->getMenu(); | |
}; | |
} | |
} | |
class DashboardPresenter extends Nette\Application\UI\Presenter | |
{ | |
use RequireLoggedUser; | |
use AdminLayout; | |
} | |
class SignPresenter extends Nette\Application\UI\Presenter | |
{ | |
use AdminLayout; | |
} |
My solution would be marker interfaces or doctrine annotations on presenters and Symfony subscribers (using contributte dispatcher) to handle it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Myslím, že ani ty traity nejsou nutné: