Created
May 31, 2018 14:00
-
-
Save dg/c4f323f8be94b2bf0ea47bcd4a42d899 to your computer and use it in GitHub Desktop.
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My solution would be marker interfaces or doctrine annotations on presenters and Symfony subscribers (using contributte dispatcher) to handle it.