Пример #1
0
 /**
  * Logs the current user out.
  *
  * @return Response
  */
 public function logout()
 {
     $event = $this->events->trigger(new LogoutEvent(AuthEvents::LOGOUT, $this->user));
     $this->user = null;
     $this->session->invalidate();
     return $event->getResponse();
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function render($name, array $parameters = [])
 {
     $event = new ViewEvent('render', $name);
     $event->setParameters(array_replace($this->globals, end($this->parameters) ?: [], $parameters));
     $this->events->trigger($event, [$this]);
     if (!$event->isPropagationStopped()) {
         $name = preg_replace('/\\.php$/i', '', $name);
         $this->events->trigger($event->setName($name), [$this]);
     }
     $result = $event->getResult();
     $params = $this->parameters[] = $event->getParameters();
     if ($result === null && $this->engine->supports($event->getTemplate())) {
         $result = $this->engine->render($event->getTemplate(), array_replace(['params' => new ArrObject($params)], $params));
     }
     array_pop($this->parameters);
     return $result;
 }
Пример #3
0
 /**
  * Handles the exception event.
  *
  * @param  \Exception $e
  * @return Response
  * @throws \Exception
  */
 protected function handleException(\Exception $e)
 {
     $event = new ExceptionEvent('exception', $this, $e);
     $this->events->trigger($event, [$this->getRequest()]);
     $e = $event->getException();
     if (!$event->hasResponse()) {
         throw $e;
     }
     $response = $event->getResponse();
     if (!$response->isClientError() && !$response->isServerError() && !$response->isRedirect()) {
         if ($e instanceof HttpException) {
             $response->setStatusCode($e->getCode());
         } else {
             $response->setStatusCode(500);
         }
     }
     try {
         return $this->handleResponse($response);
     } catch (\Exception $e) {
         return $response;
     }
 }
Пример #4
0
 /**
  * Dispatches an event to all registered listeners.
  *
  * @param  string   $name
  * @param  Metadata $metadata
  * @param  array    $arguments
  * @return bool
  */
 public function trigger($name, Metadata $metadata, array $arguments)
 {
     $this->events->trigger("{$metadata->getEventPrefix()}.{$name}", $arguments);
 }
Пример #5
0
 /**
  * Adds a route.
  *
  * @param Route $route
  */
 protected function addRoute($route)
 {
     $this->routes->add($route->getName(), $route);
     $this->events->trigger('route.configure', [$route, $this->routes]);
 }
Пример #6
0
 /**
  * Logs the current user out.
  *
  * @return Response
  */
 public function logout()
 {
     $event = $this->events->trigger(new LogoutEvent(AuthEvents::LOGOUT, $this->getUser()));
     $this->removeUser();
     return $event->getResponse();
 }