public function onBootstrap(EventInterface $e) { $eventManager = $e->getApplication()->getEventManager(); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager); $eventManager->attach(MvcEvent::EVENT_DISPATCH, array($this, 'rotateXPoweredByHeader')); }
/** * 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())); } }
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(); } }
/** * 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 }); }
/** * {@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'); } } }
/** * {@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; }); }
/** * 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); } }
/** * {@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'); } } }
public function getModulosCarregados(Event $e) { echo $e->getName() . "<br>"; echo get_class($e->getTarget()); $moduleManager = $e->getTarget(); print_r($moduleManager->getLoadedModules()); }
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; } }
/** * @param EventInterface $event */ public function checkSignals(EventInterface $event) { pcntl_signal_dispatch(); if ($this->shouldStop) { $event->stopPropagation(); } }
/** * 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); } }
/** * 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()))); }
/** * 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); }
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; } }
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']); }
/** * @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); }
/** * {@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); }
/** * 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; }
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); }
/** * 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; }
public function onBootstrap(EventInterface $event) { /*$eventManager = $e->getApplication()->getEventManager(); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager);*/ $application = $event->getTarget(); $serviceManager = $application->getServiceManager(); $translator = $serviceManager->get('translator'); $translator->setLocale(\Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']))->setFallbackLocale('en_US'); $application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH, function (MvcEvent $event) use($serviceManager) { $request = $event->getRequest(); $response = $event->getResponse(); if (!($request instanceof HttpRequest && $response instanceof HttpResponse)) { return; // CLI application maybe? } $authAdapter = $serviceManager->get('AuthenticationAdapter'); $authAdapter->setRequest($request); $authAdapter->setResponse($response); $result = $authAdapter->authenticate(); if ($result->isValid()) { return; // OK } $response->setContent('Access denied'); $response->setStatusCode(HttpResponse::STATUS_CODE_401); $event->setResult($response); // to end return false; // event propagation stop }); }
private function attachListeners(EventInterface $event) { $request = $event->getRequest(); $application = $event->getApplication(); $services = $application->getServiceManager(); $events = $application->getEventManager(); $config = $services->get('Config'); //Display exceptions based on configuration and console mode if ($request instanceof ConsoleRequest || empty($config['view_manager']['display_exceptions'])) { return; } $jsonHandler = new JsonResponseHandler(); if (!empty($config['view_manager']['json_exceptions']['show_trace'])) { //Add trace to the JSON output $jsonHandler->addTraceToOutput(true); } if (!empty($config['view_manager']['json_exceptions']['ajax_only'])) { //Only return JSON response for AJAX requests $jsonHandler->onlyForAjaxRequests(true); } if (!empty($config['view_manager']['json_exceptions']['display'])) { //Turn on JSON handler $this->run->pushHandler($jsonHandler); } //Attach the Whoops ExceptionStrategy $exceptionStrategy = new ExceptionStrategy($this->run); $exceptionStrategy->attach($events); //Attach the Whoops RouteNotFoundStrategy $routeNotFoundStrategy = new RouteNotFoundStrategy($this->run); $routeNotFoundStrategy->attach($events); //Detach default ExceptionStrategy $services->get('Zend\\Mvc\\View\\Http\\ExceptionStrategy')->detach($events); //Detach default RouteNotFoundStrategy $services->get('Zend\\Mvc\\View\\Http\\RouteNotFoundStrategy')->detach($events); }
/** * Listen to the bootstrap event * * @param EventInterface $e * @return array */ public function onBootstrap(EventInterface $e) { /** * For now, tests die completely due to the view helper manager not being * available in the view manager */ if (PHP_SAPI === 'cli') { return; } $app = $e->getApplication(); $services = $app->getServiceManager(); /** * Make sure that the session is initialised early on as this * is where we decide which ref/release to view. * If the document is located before the session is initialised, * we'll always end up looking at the master ref. */ $services->get('NetgluePrismic\\Session\\PrismicContainer'); // Cache Buster that's triggered when we receive a valid webhook payload from the Prismic API $listener = $services->get('NetgluePrismic\\Mvc\\Listener\\CacheBusterListener'); $app->getEventManager()->attach($listener); // Listener to automatically set head meta tags etc. $listener = $services->get('NetgluePrismic\\Mvc\\Listener\\HeadMetaListener'); $app->getEventManager()->attach($listener); // Listener that provides the current document to the prismic view helper $listener = $services->get('NetgluePrismic\\Mvc\\Listener\\ViewHelperDocumentListener'); $app->getEventManager()->attach($listener); // Listener to inject a toolbar into the view $app->getEventManager()->attach(\Zend\Mvc\MvcEvent::EVENT_FINISH, array($services->get('NetgluePrismic\\Mvc\\Listener\\ToolbarListener'), 'injectToolbar')); // Listener that decides which ref to set in the global context $listener = $services->get('NetgluePrismic\\Mvc\\Listener\\SelectedRefListener'); $app->getEventManager()->attach($listener); }
public function onRenderEntity(EventInterface $event) { $halEntity = $event->getParam('entity'); $link = new \ZF\Hal\Link\Link('search'); $link->setUrl('http://www.google.com/?q=thing' . $halEntity->entity->getId()); $halEntity->getLinks()->add($link); }
/** * Inject Form defined by type to BlogService when triggered * * @param EventInterface */ public function onFormSet(EventInterface $e) { $type = $e->getParam('type', 'create'); $service = $this->serviceLocator->get('Blog\\Service\\Blog'); $form = $this->serviceLocator->get('Blog\\Form\\' . ucfirst($type)); $service->setForm($form, $type); }
public function onAfterSimpleMailerSend(EventInterface $event) { /** @var \Detail\Mail\Service\MailerInterface $mailer */ $mailer = $event->getTarget(); $message = $event->getParam('message'); if ($message === null) { throw new RuntimeException(sprintf('Event "%s" is missing param "message"', $event->getName())); } elseif (!$message instanceof MessageInterface) { throw new RuntimeException(sprintf('Event "%s" has invalid value for param "message"; ' . 'expected Detail\\Mail\\Message\\MessageInterface object but got ' . is_object($message) ? get_class($message) : gettype($message), $event->getName())); } $headersText = preg_replace('/\\s+/', ' ', str_replace(PHP_EOL, ' ', var_export($message->getHeaders(), true))); if ($mailer instanceof SimpleMailer) { /** @var \Detail\Mail\Service\SimpleMailer $mailer */ $driverClass = get_class($mailer->getDriver()); switch ($driverClass) { case 'Detail\\Mail\\Driver\\Bernard\\BernardDriver': $text = 'Queued email message "%s" of type "%s" (headers: "%s", driver: %s)'; break; default: $text = 'Sent email message "%s" of type "%s" (headers: "%s", driver: %s)'; break; } $text = sprintf($text, $message->getId(), $message->getName(), $headersText, $driverClass); } else { $text = sprintf('Sent email message "%s" of type "%s" (headers: "%s")', $message->getId(), $message->getName(), $headersText); } $this->log($text); }
/** * Set up spelling parameters. * * @param EventInterface $event Event * * @return EventInterface */ public function onSearchPre(EventInterface $event) { $backend = $event->getTarget(); if ($backend === $this->backend) { $params = $event->getParam('params'); if ($params) { // Set spelling parameters unless explicitly disabled: $sc = $params->get('swissbibspellcheck'); if (!empty($sc) && $sc[0] != 'false') { //remove the homegrown parameter only needed to activate // the spellchecker in case of zero hits $params->remove("swissbibspellcheck"); $this->active = true; if (empty($this->dictionaries)) { throw new \Exception('Spellcheck requested but no dictionary configured'); } // Set relevant Solr parameters: reset($this->dictionaries); $params->set('spellcheck', 'true'); $params->set('spellcheck.dictionary', current($this->dictionaries)); // Turn on spellcheck.q generation in query builder: $this->backend->getQueryBuilder()->setCreateSpellingQuery(true); } } } return $event; }
/** * {@inheritDoc} */ public function onBootstrap(EventInterface $e) { /* @var $app \Zend\Mvc\ApplicationInterface */ $app = $e->getTarget(); $events = $app->getEventManager()->getSharedManager(); // Attach to helper set event and load the entity manager helper. $events->attach('doctrine', 'loadCli.post', function (EventInterface $e) { /* @var $cli \Symfony\Component\Console\Application */ $cli = $e->getTarget(); ConsoleRunner::addCommands($cli); $cli->addCommands(array(new DiffCommand(), new ExecuteCommand(), new GenerateCommand(), new MigrateCommand(), new StatusCommand(), new VersionCommand())); /* @var $sm ServiceLocatorInterface */ $sm = $e->getParam('ServiceManager'); /* @var $em \Doctrine\ORM\EntityManager */ $em = $sm->get('doctrine.entitymanager.orm_default'); $helperSet = $cli->getHelperSet(); $helperSet->set(new DialogHelper(), 'dialog'); $helperSet->set(new ConnectionHelper($em->getConnection()), 'db'); $helperSet->set(new EntityManagerHelper($em), 'em'); }); $config = $app->getServiceManager()->get('Config'); $app->getServiceManager()->get('doctrine.entity_resolver.orm_default'); if (isset($config['zenddevelopertools']['profiler']['enabled']) && $config['zenddevelopertools']['profiler']['enabled']) { $app->getServiceManager()->get('doctrine.sql_logger_collector.orm_default'); } }
public function onBootstrap(EventInterface $e) { /** @var \Zend\Mvc\MvcEvent $e*/ $application = $e->getApplication(); $serviceManager = $application->getServiceManager(); $environment = $serviceManager->get('Twig_Environment'); /** @var \ZfcTwig\moduleOptions $options */ $options = $serviceManager->get('ZfcTwig\\ModuleOptions'); // Setup extensions foreach ($options->getExtensions() as $extension) { // Allows modules to override/remove extensions. if (empty($extension)) { continue; } else { if (is_string($extension)) { if ($serviceManager->has($extension)) { $extension = $serviceManager->get($extension); } else { $extension = new $extension(); } } elseif (!is_object($extension)) { throw new InvalidArgumentException('Extensions should be a string or object.'); } } $environment->addExtension($extension); } }