本文整理汇总了PHP中Zend\EventManager\EventInterface类的典型用法代码示例。如果您正苦于以下问题:PHP EventInterface类的具体用法?PHP EventInterface怎么用?PHP EventInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EventInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onBootstrap
public function onBootstrap(EventInterface $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$eventManager->attach(MvcEvent::EVENT_DISPATCH, array($this, 'rotateXPoweredByHeader'));
}
示例2: onBootstrap
/**
* Zend\Mvc\MvcEvent::EVENT_BOOTSTRAP event callback
*
* @param Event $event
*/
public function onBootstrap(EventInterface $event)
{
if (PHP_SAPI === 'cli') {
return;
}
$app = $event->getApplication();
$em = $app->getEventManager();
$sem = $em->getSharedManager();
$sm = $app->getServiceManager();
$options = $sm->get('ZendDeveloperTools\\Config');
if (!$options->isEnabled()) {
return;
}
$report = $sm->get('ZendDeveloperTools\\Report');
if ($options->canFlushEarly()) {
$em->attachAggregate($sm->get('ZendDeveloperTools\\FlushListener'));
}
if ($options->isStrict() && $report->hasErrors()) {
throw new Exception\InvalidOptionException(implode(' ', $report->getErrors()));
}
$em->attachAggregate($sm->get('ZendDeveloperTools\\ProfilerListener'));
if ($options->isToolbarEnabled()) {
$sem->attach('profiler', $sm->get('ZendDeveloperTools\\ToolbarListener'), null);
}
if ($options->isStrict() && $report->hasErrors()) {
throw new Exception\ProfilerException(implode(' ', $report->getErrors()));
}
}
示例3: onBootstrap
public function onBootstrap(EventInterface $e)
{
$app = $e->getApplication();
$eventManager = $app->getEventManager()->getSharedManager();
$serviceManager = $app->getServiceManager();
$this->options = $options = $serviceManager->get('DhErrorLogging\\Options\\ModuleOptions');
// return if it is not enabled
if (!$options->isEnabled()) {
return;
}
// get logger
$this->logger = $serviceManager->get('DhErrorLogging\\Logger');
$this->generator = $serviceManager->get('DhErrorLogging\\Generator\\ErrorReferenceGenerator');
$this->exceptionFilter = $serviceManager->get('DhErrorLogging\\Filter\\ExceptionFilter');
$this->nonMvcResponseSender = $serviceManager->get('DhErrorLogging\\Sender\\ResponseSender');
// Handle native PHP errors
if ($options->isErrortypeEnabled('errors')) {
$this->attachErrorHandler();
}
// Handle those exceptions that do not get caught by MVC
if ($options->isErrortypeEnabled('exceptions')) {
$this->attachExceptionHandler();
}
// Handle framework specific errors
if ($options->isErrortypeEnabled('dispatch')) {
$eventManager->attach('Zend\\Mvc\\Application', MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'attachDispatchErrorHandler'));
}
if ($options->isErrortypeEnabled('render')) {
$eventManager->attach('Zend\\Mvc\\Application', MvcEvent::EVENT_RENDER_ERROR, array($this, 'attachRenderErrorHandler'));
}
// Handle fatal errors
if ($options->isErrortypeEnabled('fatal')) {
$this->attachFatalErrorHandler();
}
}
示例4: onBootstrap
/**
* On BootStrap Listener for Book List Module
* @param EventInterface $event Event Manager Object
*/
public function onBootstrap(EventInterface $event)
{
$appliaction = $event->getTarget();
$serviceManager = $appliaction->getServiceManager();
$appliaction->getEventManager()->attach(MvcEvent::EVENT_DISPATCH, function (MvcEvent $e) use($serviceManager) {
$request = $e->getRequest();
$response = $e->getResponse();
if (!($request instanceof HttpRequest && $response instanceof HttpResponse)) {
return;
// we are not in HTTP context - CLI application?
}
$authAdapter = $serviceManager->get('AuthenticationAdapter');
$authAdapter->setRequest($request);
$authAdapter->setResponse($response);
$result = $authAdapter->authenticate();
// Then check the result of basic Http authentication
if ($result->isValid()) {
return;
// erverything OK
}
// Otherwise return Access Denaid to Book List Site
$response->setContent('Access Denied');
$response->setStatusCode(HttpResponse::STATUS_CODE_401);
$e->setResult($response);
// short-circuit to application to end
return false;
// stop event propagation
});
}
示例5: onBootstrap
/**
* {@inheritdoc}
*/
public function onBootstrap(EventInterface $e)
{
/** @var \Zend\Mvc\MvcEvent $e */
/** @var \Zend\Mvc\Application $application */
$application = $e->getApplication();
/** @var \Zend\EventManager\EventManager $events */
$events = $application->getEventManager();
/** @var \Zend\EventManager\SharedEventManager $sharedEvents */
$sharedEvents = $events->getSharedManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($events);
// Override Zend\Mvc\View\Http\InjectTemplateListener
// to process templates by Vendor/Module
$injectTemplateListener = new InjectTemplateListener();
$sharedEvents->attach('Zend\\Stdlib\\DispatchableInterface', MvcEvent::EVENT_DISPATCH, [$injectTemplateListener, 'injectTemplate'], -89);
$response = $e->getResponse();
if ($response instanceof \Zend\Http\Response) {
$headers = $response->getHeaders();
if ($headers) {
$headers->addHeaderLine('Cache-Control', 'no-cache, no-store, must-revalidate');
$headers->addHeaderLine('Pragma', 'no-cache');
$headers->addHeaderLine('Expires', '1970-01-01');
}
}
}
示例6: onBootstrap
/**
* {@inheritDoc}
*/
public function onBootstrap(EventInterface $e)
{
$app = $e->getApplication();
$sm = $app->getServiceManager();
$config = $app->getConfig();
// Set configuration options
if ($phpSettings = $config['php_ini']) {
foreach ($phpSettings as $key => $value) {
ini_set($key, $value);
}
}
$sharedEventManager = $sm->get('SharedEventManager');
// Hook into comments
$sharedEventManager->attach('theme', 'post.post', function ($e) use($sm) {
$viewRenderer = $sm->get('ViewRenderer');
return $viewRenderer->partial('socialog/comment/post', $e->getParams());
});
// Hook into comments
$sharedEventManager->attach('view', 'navigation.render', function ($e) use($sm) {
/* @var $pageMapper \Socialog\Mapper\PageMapper */
$pageMapper = $sm->get('socialog_page_mapper');
$result = "";
foreach ($pageMapper->findAllPages() as $page) {
$result .= new Theme\Menuitem($page->getTitle(), $e->getTarget()->url('socialog-page', array('id' => $page->getId())));
}
return $result;
});
}
示例7: onRoute
/**
* Check for document from route
*
* @param EventInterface $event Mvc Event
*
* @return void
*/
public function onRoute(EventInterface $event)
{
$matchedRouteName = $event->getRouteMatch()->getMatchedRouteName();
if ($matchedRouteName !== 'cms') {
return;
}
$serviceManager = $event->getApplication()->getServiceManager();
$isAdmin = $serviceManager->get('Auth')->hasIdentity();
$isPreview = ($isAdmin and $event->getRequest()->getQuery()->get('preview') === 'true');
$path = ltrim($event->getRouteMatch()->getParam('path'), '/');
if (empty($path)) {
$document = Document\Model::fromUrlKey('');
} else {
$document = $this->findDocument($path, $isPreview);
}
$this->logVisitor($isPreview, $isAdmin);
if (empty($document) or !$document->isPublished() and !$isPreview) {
$serviceManager->setService('CurrentDocument', false);
} else {
$translator = $serviceManager->get('MvcTranslator');
$translator->setLocale($this->getLocale($document));
AbstractValidator::setDefaultTranslator($translator);
$serviceManager->setService('CurrentDocument', $document);
}
}
示例8: onBootstrap
/**
* {@inheritdoc}
*/
public function onBootstrap(EventInterface $e)
{
/** @var ApplicationInterface $app */
$app = $e->getTarget();
$serviceManager = $app->getServiceManager();
/** @var Options $options */
$options = $serviceManager->get('BuggymanOptions');
if ($options->getEnabled() && $options->getToken()) {
Buggyman::setToken($options->getToken());
Buggyman::setErrorLevel($options->getErrorLevel());
Buggyman::setRoot(getcwd());
Buggyman::init();
$app->getEventManager()->attach([MvcEvent::EVENT_DISPATCH_ERROR, MvcEvent::EVENT_RENDER_ERROR], function (MvcEvent $event) use($serviceManager) {
if ($event->getParam('exception') instanceof Exception) {
Buggyman::reportException($event->getParam('exception'));
}
});
if ($options->getPublicToken() && !isset($_SERVER['HTTPS'])) {
/** @var HelperPluginManager $pluginManager */
$pluginManager = $serviceManager->get('ViewHelperManager');
/** @var InlineScript $inline */
$inline = $pluginManager->get('InlineScript');
$inline($inline::FILE, 'http://cdn.buggyman.io/v1/js/' . $options->getPublicToken() . '/collector.js');
}
}
}
示例9: onRoute
public function onRoute(\Zend\EventManager\EventInterface $e)
{
$application = $e->getApplication();
$routeMatch = $e->getRouteMatch();
$sm = $application->getServiceManager();
$auth = $sm->get('Zend\\Authentication\\AuthenticationService');
$config = $sm->get('Config');
$acl = new Acl($config);
// everyone is guest until logging in
$role = Acl::DEFAULT_ROLE;
// The default role is guest $acl
if ($auth->hasIdentity()) {
$user = $auth->getIdentity();
$role = $user->getRole()->getName();
}
$controller = $routeMatch->getParam('controller');
$action = $routeMatch->getParam('action');
if (!$acl->hasResource($controller)) {
throw new \Exception('Resource ' . $controller . ' not defined');
}
if (!$acl->isAllowed($role, $controller, $action)) {
$url = $e->getRouter()->assemble(array(), array('name' => 'home'));
$response = $e->getResponse();
$response->getHeaders()->addHeaderLine('Location', $url);
// The HTTP response status code 302 Found is a common way of performing a redirection.
// http://en.wikipedia.org/wiki/HTTP_302
$response->setStatusCode(302);
$response->sendHeaders();
exit;
}
}
示例10: checkSignals
/**
* @param EventInterface $event
*/
public function checkSignals(EventInterface $event)
{
pcntl_signal_dispatch();
if ($this->shouldStop) {
$event->stopPropagation();
}
}
示例11: onBootstrap
/**
* Listen to the bootstrap event
*
* @param EventInterface $e
* @return array
*/
public function onBootstrap(EventInterface $e)
{
/* @var $e \Zend\Mvc\MvcEvent */
$serviceManager = $e->getApplication()->getServiceManager();
/* @var $serviceManager \Zend\ServiceManager\ServiceManager */
$config = $serviceManager->get('Config');
// Use naming conventions to set up a bunch of services based on namespace:
$namespaces = array('Callback' => 'callback', 'Connection' => 'connection', 'Producer' => 'producer', 'Consumer' => 'consumer', 'RpcClient' => 'rpc_client', 'RpcServer' => 'rpc_server');
// register plugin managers
foreach ($namespaces as $ns => $configKey) {
$serviceName = __NAMESPACE__ . '\\PluginManager\\' . $ns;
$factory = function () use($serviceName, $config, $ns, $configKey, $serviceManager) {
$serviceConfig = $config['humus_amqp_module']['plugin_managers'][$configKey];
$service = new $serviceName(new Config($serviceConfig));
/* @var $service \Zend\ServiceManager\AbstractPluginManager */
$service->setServiceLocator($serviceManager);
if ('Connection' == $ns) {
$service->addInitializer(function (AMQPConnection $connection) {
if (isset($connection->persistent) && true === $connection->persistent) {
$connection->pconnect();
unset($connection->persistent);
} else {
$connection->connect();
}
});
}
return $service;
};
$serviceManager->setFactory($serviceName, $factory);
}
}
示例12: onBootstrap
/**
* Listen to the bootstrap event.
*
* @param EventInterface $e
*
* @return array
*
* @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
* @throws \Zend\ServiceManager\Exception\InvalidServiceException
* @throws \RuntimeException
* @throws \Interop\Container\Exception\NotFoundException
* @throws \Interop\Container\Exception\ContainerException
*/
public function onBootstrap(EventInterface $e)
{
/* @var MvcEvent $e */
$application = $e->getApplication();
$container = $application->getServiceManager();
$moduleConfig = $container->get('config')['facile']['sentry'];
$clients = array_keys($moduleConfig['client']);
$errorHandlerRegister = $container->get(ErrorHandlerRegister::class);
foreach ($clients as $serviceKey) {
$serviceName = sprintf('facile.sentry.client.%s', $serviceKey);
/* @var Client $client */
$client = $container->get($serviceName);
$errorHandlerRegister->registerHandlers($client, $application->getEventManager());
}
/** @var ConfigurationOptions $configurationOptions */
$configurationOptions = $container->get(ConfigurationOptions::class);
if (!$configurationOptions->isInjectRavenJavascript()) {
return;
}
/** @var \Zend\View\HelperPluginManager $viewHelperManager */
$viewHelperManager = $container->get('ViewHelperManager');
/** @var \Zend\View\Helper\HeadScript $headScriptHelper */
$headScriptHelper = $viewHelperManager->get('HeadScript');
$headScriptHelper->appendFile($configurationOptions->getRavenJavascriptUri());
$headScriptHelper->appendScript(sprintf('Raven.config(\'%s\', %s).install();', $configurationOptions->getRavenJavascriptDsn(), json_encode($configurationOptions->getRavenJavascriptOptions())));
}
示例13: onBootstrap
/**
* Listen to the bootstrap event.
*
* @param EventInterface|\Zend\Mvc\MvcEvent $e
*
* @return void
*/
public function onBootstrap(EventInterface $e)
{
$application = $e->getApplication();
$eventManager = $application->getEventManager();
$services = $application->getServiceManager();
$services->get('Install/Listener/LanguageSetter')->attach($eventManager);
}
示例14: onRoute
public function onRoute(\Zend\EventManager\EventInterface $e)
{
$application = $e->getApplication();
$routeMatch = $e->getRouteMatch();
$sm = $application->getServiceManager();
$auth = $sm->get('Zend\\Authentication\\AuthenticationService');
$config = $sm->get('Config');
$acl = new Acl($config);
$role = Acl::DEFAULT_ROLE;
if ($auth->hasIdentity()) {
$user = $auth->getIdentity();
$role = $user->getUserRole()->getRole();
}
$controller = $routeMatch->getParam('controller');
$action = $routeMatch->getParam('action');
if (!$acl->hasResource($controller)) {
throw new \Exception('Resource ' . $controller . ' not defined');
}
if (!$acl->isAllowed($role, $controller, $action)) {
$url = $e->getRouter()->assemble(array(), array('name' => 'home/login'));
$response = $e->getResponse();
$response->getHeaders()->addHeaderLine('Location', $url);
$response->setStatusCode(302);
$response->sendHeaders();
exit;
}
}
示例15: onIssueGetPost
public function onIssueGetPost(EventInterface $e)
{
$this->log->debug('ISSUES_GET.post - store in cache');
$config = $e->getParams();
$key = 'issues-' . $config['account-name'] . '-' . $config['repo'] . '-' . implode('-', $config['issue-filters']);
$this->cache->setItem($key, $config['issues']);
}