作者:Tony13
项目:zf-we
public function onBootstrap(EventInterface $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$eventManager->attach(MvcEvent::EVENT_DISPATCH, array($this, 'rotateXPoweredByHeader'));
}
作者:rafajaque
项目:colloquiu
/**
* 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()));
}
}
作者:Oraj
项目:DhErrorLoggin
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();
}
}
作者:ahmed-hamdy9
项目:build_web_app_using_Zend_
/**
* 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
});
}
作者:whoopl
项目:magento2-testin
/**
* {@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');
}
}
}
作者:socialo
项目:socialo
/**
* {@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;
});
}
作者:gotcm
项目:gotcm
/**
* 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);
}
}
作者:buggymanh
项目:buggyman-modul
/**
* {@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');
}
}
}
作者:CPD
项目:Sistema-de-controle-cpd
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;
}
}
作者:Carson
项目:WhatsAp
/**
* @param EventInterface $event
*/
public function checkSignals(EventInterface $event)
{
pcntl_signal_dispatch();
if ($this->shouldStop) {
$event->stopPropagation();
}
}
作者:vitapubli
项目:HumusAmqpModul
/**
* 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);
}
}
作者:facile-i
项目:sentry-modul
/**
* 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())));
}
作者:cross-solutio
项目:yawi
/**
* 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);
}
作者:madra
项目:budzet_domow
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;
}
}
作者:av4ta
项目:shet
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']);
}
作者:old-town-la
项目:cr
/**
* @param EventInterface $e
*
* @return array|void
*
* @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
*/
public function onBootstrap(EventInterface $e)
{
/** @var MvcEvent $e */
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
}
作者:stefanor
项目:zf2-fullpage-cach
/**
* {@inheritDoc}
*/
public function onBootstrap(EventInterface $e)
{
/** @var $application \Zend\Mvc\Application */
$application = $e->getParam('application');
$listener = $application->getServiceManager()->get('StrokerCache\\Listener\\CacheListener');
$application->getEventManager()->attach($listener);
}
作者:shabbirvividad
项目:magento
/**
* Handle annotation creation
*
* @param EventInterface $e
* @return false|\stdClass
*/
public function onCreateAnnotation(EventInterface $e)
{
$annotationClass = $e->getParam('class', false);
if (!$annotationClass) {
return false;
}
if (!isset($this->allowedAnnotations[$annotationClass])) {
return false;
}
$annotationString = $e->getParam('raw', false);
if (!$annotationString) {
return false;
}
// Annotation classes provided by the AnnotationScanner are already
// resolved to fully-qualified class names. Adding the global namespace
// prefix allows the Doctrine annotation parser to locate the annotation
// class correctly.
$annotationString = preg_replace('/^(@)/', '$1\\', $annotationString);
$parser = $this->getDocParser();
$annotations = $parser->parse($annotationString);
if (empty($annotations)) {
return false;
}
$annotation = array_shift($annotations);
if (!is_object($annotation)) {
return false;
}
return $annotation;
}
作者:SoufianeA
项目:SlmLocal
public function onBootstrap(EventInterface $e)
{
$app = $e->getApplication();
$sm = $app->getServiceManager();
$detector = $sm->get('SlmLocale\\Locale\\Detector');
$result = $detector->detect($app->getRequest(), $app->getResponse());
if ($result instanceof ResponseInterface) {
/**
* When the detector returns a response, a strategy has updated the response
* to reflect the found locale.
*
* To redirect the user to this new URI, we short-circuit the route event. There
* is no option to short-circuit the bootstrap event, so we attach a listener to
* the route and let the application finish the bootstrap first.
*
* The listener is attached at PHP_INT_MAX to return the response as early as
* possible.
*/
$em = $app->getEventManager();
$em->attach(MvcEvent::EVENT_ROUTE, function ($e) use($result) {
return $result;
}, PHP_INT_MAX);
}
Locale::setDefault($result);
}
作者:htw-pk1
项目:vufin
/**
* Handle event. Add config values
*
* @param EventInterface $event
* @return EventInterface
*/
public function onSearchPre(EventInterface $event)
{
$backend = $event->getTarget();
if ($backend === $this->backend) {
$params = $event->getParam('params');
if ($params) {
// Set highlighting parameters unless explicitly disabled:
$hl = $params->get('hl');
if (!isset($hl[0]) || $hl[0] != 'false') {
// Add hl.q for non query events
if (!$event->getParam('query', false)) {
$lastSearch = $this->memory->retrieve();
if ($lastSearch) {
$urlParams = parse_url($lastSearch);
parse_str($urlParams['query'], $queryParams);
if (isset($queryParams['lookfor'])) {
$params->set('hl.q', '*:"' . addslashes($queryParams['lookfor']) . '"');
}
}
}
// All all highlight config fields
foreach ($this->config as $key => $value) {
$params->set('hl.' . $key, $value);
}
}
}
}
return $event;
}