/** * @return void */ public function init() { $this->addEventListener(Event\Type\System\SecurityPolicyApplication::toType(), function ($event) { $success = $this->onSecurityPolicyApplication($event); if (false === $success) { $event->discard(); } }); }
/** * @return void */ protected function getTargetPackage($event) { $success = false; foreach ($this->getExtensions(true) as $pkg) { foreach ($pkg->getRouters() as $router) { $success = $router->process($event); if ($event->getStatus() == Event\STATUS_DISCARDED) { return $this; } if ($success) { $package = $router->getPackage(); break; } } } // if discarded then event was designated to the current router but // routing by some reason failed if (!$success) { return $this; } $fcInstance = $router->getFrontController(); $ctrlInstance = $router->getController(); $actionInstance = $router->getAction(); // form a propagation path through which the event will be passed. // Package -> Front Controller -> Controller -> Action $package->dispatchChainAddElement($fcInstance)->dispatchChainAddElement($ctrlInstance)->dispatchChainAddElement($actionInstance); if (null !== $fcInstance && null !== $ctrlInstance && null !== $actionInstance) { $fcInstance->mergePriorEvents($event, $ctrlInstance, $actionInstance); } // hook default services into corresponding events if ($fcInstance && $this->context->get('phpcrystal.security_guard.enabled')) { $fcInstance->addEventListener(Event\Type\System\SecurityPolicyApplication::toType(), function ($event) { $securityGuard = SecurityGuard::create(); return $securityGuard->process($event); }); } // actions are terminate nodes $event->setTerminateNodeHandler(function ($event) { return $this->execute($event); }); return $package; }