Skip to content
Permalink
Browse files

Only UI\Presenter is supported by PresenterStartup and PresenterShutd…

…own events
  • Loading branch information...
mabar authored and f3l1x committed Jul 5, 2019
1 parent 1e509d5 commit 455dddf9d1bf54f29c0c53acef2ec9cf6d34e3b6
@@ -12,6 +12,7 @@
use Contributte\Events\Extra\Event\Application\StartupEvent;
use LogicException;
use Nette\Application\Application;
use Nette\Application\UI\Presenter;
use Nette\DI\CompilerExtension;
use Nette\DI\ServiceDefinition;
use Nette\PhpGenerator\PhpLiteral;
@@ -58,14 +59,16 @@ public function beforeCompile(): void
new PhpLiteral(PresenterEvent::class),
]);
$application->addSetup('?->onPresenter[] = function($application, $presenter) {if(!property_exists($presenter, "onStartup")){return;} $presenter->onStartup[] = function() {?->dispatch(new ?(...func_get_args()));};}', [
$application->addSetup('?->onPresenter[] = function($application, $presenter) {if(!$presenter instanceof ?){return;} $presenter->onStartup[] = function() {?->dispatch(new ?(...func_get_args()));};}', [
'@self',
new PhpLiteral(Presenter::class),
$dispatcher,
new PhpLiteral(PresenterStartupEvent::class),
]);
$application->addSetup('?->onPresenter[] = function($application, $presenter) {if(!property_exists($presenter, "onShutdown")){return;} $presenter->onShutdown[] = function() {?->dispatch(new ?(...func_get_args()));};}', [
$application->addSetup('?->onPresenter[] = function($application, $presenter) {if(!$presenter instanceof ?){return;} $presenter->onShutdown[] = function() {?->dispatch(new ?(...func_get_args()));};}', [
'@self',
new PhpLiteral(Presenter::class),
$dispatcher,
new PhpLiteral(PresenterShutdownEvent::class),
]);
@@ -2,26 +2,26 @@
namespace Contributte\Events\Extra\Event\Application;
use Nette\Application\IPresenter;
use Nette\Application\IResponse;
use Nette\Application\UI\Presenter;
use Symfony\Component\EventDispatcher\Event;
class PresenterShutdownEvent extends Event
{
/** @var IPresenter */
/** @var Presenter */
private $presenter;
/** @var IResponse|null */
private $response;
public function __construct(IPresenter $presenter, ?IResponse $response = null)
public function __construct(Presenter $presenter, ?IResponse $response = null)
{
$this->presenter = $presenter;
$this->response = $response;
}
public function getPresenter(): IPresenter
public function getPresenter(): Presenter
{
return $this->presenter;
}
@@ -2,21 +2,21 @@
namespace Contributte\Events\Extra\Event\Application;
use Nette\Application\IPresenter;
use Nette\Application\UI\Presenter;
use Symfony\Component\EventDispatcher\Event;
class PresenterStartupEvent extends Event
{
/** @var IPresenter */
/** @var Presenter */
private $presenter;
public function __construct(IPresenter $presenter)
public function __construct(Presenter $presenter)
{
$this->presenter = $presenter;
}
public function getPresenter(): IPresenter
public function getPresenter(): Presenter
{
return $this->presenter;
}
@@ -5,21 +5,10 @@
use Nette\Application\IPresenter;
use Nette\Application\IResponse;
use Nette\Application\Request;
use Nette\Application\UI\Presenter;
use Nette\SmartObject;
class FakePresenter implements IPresenter
class FakePresenter extends Presenter
{
use SmartObject;
/** @var callable[] function (Presenter $sender); Occurs when the presenter is starting */
public $onStartup;
/** @var callable[] function (Presenter $sender, IResponse $response = null); Occurs when the presenter is shutting down */
public $onShutdown;
public function run(Request $request): IResponse
{
}
}

0 comments on commit 455dddf

Please sign in to comment.
You can’t perform that action at this time.