Example #1
0
 /**
  * @param EventInterface $event
  */
 public function checkSignals(EventInterface $event)
 {
     pcntl_signal_dispatch();
     if ($this->shouldStop) {
         $event->stopPropagation();
     }
 }
 /**
  * Triggered on disconnect.
  *
  * @param EventInterface $event The triggered event
  */
 public function onDisconnect(EventInterface $event)
 {
     if (!$this->connected) {
         $event->stopPropagation(true);
     } else {
         $this->connected = false;
     }
 }
 /**
  * onFailure
  *
  * Event listener to handle unsuccessful authentication.
  *
  * @param EventInterface  $event  The authentication event.
  *
  * @return Request
  */
 public function onFailure(EventInterface $event)
 {
     /** @var  LoginControllerInterface $controller */
     $controller = $event->getTarget();
     //$controller->flashMessenger()->addErrorMessage('The username or password was incorrect.');
     $route = $controller->getRouteProvider()->getRoute('authentication.failure');
     $event->stopPropagation(true);
     return $controller->redirect()->toRoute($route);
 }
 /**
  * @param EventInterface $event
  */
 public function preFind(EventInterface $event)
 {
     if (!preg_match('/\\d$/', $this->cacheId)) {
         return;
         //The current route is a POST, do not cache new resources with this cache ID
     }
     if ($this->cache->contains($this->cacheId)) {
         $event->stopPropagation(true);
         return $this->cache->fetch($this->cacheId);
     }
 }
Example #5
0
 /**
  * Checks if the current page should be visible in the navigation menu.
  *
  * @param EventInterface $event
  * @return boolean
  */
 public function accept(EventInterface $event)
 {
     $event->stopPropagation();
     $accepted = true;
     $page = $event->getParam('page');
     $permission = $page->getPermission();
     if ($permission === '*') {
         return true;
     } elseif ($permission) {
         $accepted = $this->authService->isGranted($permission);
     }
     return $accepted;
 }
 public function isAllowed(EventInterface $event)
 {
     $target = $event->getTarget();
     if ($target instanceof \Zend\View\Helper\Navigation\AbstractHelper) {
         $page = $event->getParam('page');
         if (!$page instanceof AbstractPage) {
             return;
         }
         $permission = $page->getPermission();
         if (null === $permission) {
             return;
         }
         $event->stopPropagation();
         return $this->authorizationService->isGranted($permission);
     }
 }
Example #7
0
 protected function redirect(EventInterface $e, $route)
 {
     $app = $e->getApplication();
     $sm = $app->getServiceManager();
     /** @var \Zend\Mvc\Router\Http\TreeRouteStack $route */
     $currentRoute = $app->getMvcEvent()->getRouteMatch()->getMatchedRouteName();
     if ($currentRoute == $route) {
         return false;
     }
     $matchedRoute = $sm->get('Router')->assemble(array(), array('name' => $route));
     $response = $e->getResponse();
     $response->getHeaders()->addHeaderLine('Location', $matchedRoute);
     $response->setStatusCode(302);
     $response->sendHeaders();
     $e->stopPropagation();
     return false;
 }
Example #8
0
 /**
  * Check if ssl is forced or not
  *
  * @param EventInterface $event Mvc event
  *
  * @return null|Zend\Http\PhpEnvironment\Response
  */
 public function check(EventInterface $event)
 {
     $coreConfig = $event->getApplication()->getServiceManager()->get('CoreConfig');
     $matchedRouteName = $event->getRouteMatch()->getMatchedRouteName();
     $request = $event->getRequest();
     $uri = $request->getUri();
     if ($matchedRouteName === 'cms') {
         if ($uri->getScheme() === 'https' or $coreConfig->getValue('force_frontend_ssl')) {
             $newUri = new Uri($coreConfig->getValue('secure_frontend_base_path'));
             $newUri->setScheme('https');
         } else {
             $newUri = new Uri($coreConfig->getValue('unsecure_frontend_base_path'));
         }
     } else {
         if ($uri->getScheme() === 'https' or $coreConfig->getValue('force_backend_ssl')) {
             $newUri = new Uri($coreConfig->getValue('secure_backend_base_path'));
             $newUri->setScheme('https');
         } else {
             $newUri = new Uri($coreConfig->getValue('unsecure_backend_base_path'));
         }
     }
     if (!empty($newUri) and $newUri->isValid() and ($newUri->getHost() != '' and $uri->getHost() != $newUri->getHost()) or $newUri->getScheme() != '' and $uri->getScheme() != $newUri->getScheme()) {
         $uri->setPort($newUri->getPort());
         if ($newUri->getHost() != '') {
             $uri->setHost($newUri->getHost());
         }
         if ($newUri->getScheme() != '') {
             $uri->setScheme($newUri->getScheme());
         }
         $response = $event->getResponse();
         $response->setStatusCode(302);
         $response->getHeaders()->addHeaderLine('Location', $request->getUri());
         $event->stopPropagation();
         return $response;
     }
 }
 /**
  * Останавливаем обработку событий
  *
  * @param EventInterface $event
  */
 public function onDoctrineLoadCliPost(EventInterface $event)
 {
     $event->stopPropagation(true);
 }
Example #10
0
 /**
  * Trigger listeners
  *
  * Actual functionality for triggering listeners, to which trigger() delegate.
  *
  * @param  EventInterface $event
  * @param  null|callable $callback
  * @return ResponseCollection
  */
 protected function triggerListeners(EventInterface $event, callable $callback = null)
 {
     $name = $event->getName();
     if (empty($name)) {
         throw new Exception\RuntimeException('Event is missing a name; cannot trigger!');
     }
     // Initial value of stop propagation flag should be false
     $event->stopPropagation(false);
     $responses = new ResponseCollection();
     foreach ($this->getListenersByEventName($name) as $listener) {
         $response = $listener($event);
         $responses->push($response);
         // If the event was asked to stop propagating, do so
         if ($event->propagationIsStopped()) {
             $responses->setStopped(true);
             break;
         }
         // If the result causes our validation callback to return true,
         // stop propagation
         if ($callback && $callback($response)) {
             $responses->setStopped(true);
             break;
         }
     }
     return $responses;
 }