/** * {@inheritdoc} */ public function commit() { while (!$this->messages->isEmpty()) { $message = $this->messages->dequeue(); $this->eventManager->trigger($message->getName(), $message); } }
public function parse(MvcEvent $e) { $event = clone $e; $event->setName(__FUNCTION__); $event->setTarget($this); $this->events->trigger($event); }
/** * Executa a ação. * * @return mixin */ public function execute() { $dataToUseAfterResponse = $this->_getDataToUseAfterResponse(); if ($dataToUseAfterResponse === null) { return $this->error('Invalid session state. First you need to access the route "sta/oAuthConnect/ask".'); } /** @var OAuthServiceInterface $oAuthService */ $oAuthService = $this->getController()->getServiceLocator()->get('Sta\\OAuthConnect\\OAuthService\\' . $dataToUseAfterResponse['oAuthServiceName']); $requestedScopes = $dataToUseAfterResponse['scopes']; $authorizationResult = $oAuthService->isAuthorized($requestedScopes); if (!$authorizationResult instanceof AuthorizationResult) { return $this->error('This OAuth Service implementation method ' . get_class($oAuthService) . '::isAuthorized() must ' . 'return a instance of ' . \Sta\OAuthConnect\OAuthService\AuthorizationResult::class . '.'); } $oAuthConnectEvent = new OAuthConnectEvent($authorizationResult, $oAuthService); $eventResponses = $this->events->trigger(OAuthConnectEvent::EVENT_OAUTH_RESPONSE, $oAuthConnectEvent, function ($r) { return $r instanceof Response; }); $eventResult = $eventResponses->last(); if ($eventResult instanceof Response) { return $eventResult; } $routeToRedirect = $dataToUseAfterResponse['continue']; if ($routeToRedirect) { return $this->getController()->redirect()->toRoute($routeToRedirect->getRoute(), $routeToRedirect->getParams(), $routeToRedirect->getOptions()); } else { // foi uma autorizacao asincrona $viewModel = new ViewModel(); $viewModel->setTerminal(true); if ($eventResult instanceof ApiProblem || class_exists('\\ZF\\ApiProblem\\ApiProblem') && $eventResult instanceof \ZF\ApiProblem\ApiProblem) { $viewModel->error = $eventResult->toArray(); } return $viewModel; } }
public function stopQuery() { $this->profiles[$this->index]['stop'] = microtime(true); $this->profiles[$this->index]['elapse'] = $this->profiles[$this->index]['stop'] - $this->profiles[$this->index]['start']; if ($this->isLogging) { $this->profiles[$this->index]['logged'] = true; $this->events->trigger(self::EVENT_LOG_QUERY, $this, array('manager' => $this->name, 'query' => $this->profiles[$this->index])); } $this->index++; }
public function serialize($subject, &$data = array(), SerializerInterface $serializer = null) { $event = new SerializeEvent($subject, $data, $this); $this->events->trigger(SerializeEvent::DESTRUCT, $event); $this->events->trigger(SerializeEvent::EXTRACT, $event); return $event->getData(); // if (is_array($subject)) { // $result = array(); // foreach ($subject as $item) { // $result[] = $this->serialize($item); // } // return $result; // } }
/** * @param AccessInterceptorInterface $proxy * @param EventManager $eventManager */ public function addEventManagement(AccessInterceptorInterface $proxy) { $proxy->setMethodPrefixInterceptor('find', function ($proxy, $instance, $method, $params, &$returnEarly) { $results = $this->eventManager->trigger('preFind', $instance); if ($results->stopped()) { $returnEarly = true; return $results->last(); } }); $proxy->setMethodSuffixInterceptor('find', function ($proxy, $instance, $method, $params, $returnValue, &$returnEarly) { $this->eventManager->trigger('postFind', $instance, ['row' => $returnValue]); }); $proxy->setMethodPrefixInterceptor('insert', function ($proxy, $instance, $method, $params, &$returnEarly) { $returnEarly = true; $this->eventManager->trigger('preInsert', $instance, ['values' => &$params['values']]); return $instance->insert($params['values']); }); $proxy->setMethodPrefixInterceptor('update', function ($proxy, $instance, $method, $params, &$returnEarly) { $returnEarly = true; $this->eventManager->trigger('preUpdate', $instance, ['values' => &$params['values']]); return $instance->update($params['values'], $params['id']); }); $proxy->setMethodSuffixInterceptor('update', function ($proxy, $instance, $method, $params, $returnValue, &$returnEarly) { $this->eventManager->trigger('onSave', $instance, ['row' => $returnValue]); }); $proxy->setMethodSuffixInterceptor('delete', function ($proxy, $instance, $method, $params, $returnValue, &$returnEarly) { $this->eventManager->trigger('onDelete', $instance); }); $proxy->setMethodSuffixInterceptor('getQueryFindAll', function ($proxy, $instance, $method, $params, $returnValue, &$returnEarly) { $this->eventManager->trigger('postFindAll', $instance, ['qb' => $returnValue, 'criteria' => $params['criteria']]); }); }
/** * @param CommandQueryInterface $commandInterface * * @return mixed * @throws \Exception */ public final function handle(CommandQueryInterface $commandInterface) { $this->eventManager->trigger(self::commandEventPre($commandInterface::name()), $commandInterface); try { if (TRUE === $commandInterface instanceof CommandQueryInputFilterAwareInterface) { $commandInterface->validate(); } $result = $this->process($commandInterface); } catch (\Exception $exception) { $this->eventManager->trigger(self::commandEventError($commandInterface::name(), $commandInterface, ['commandError' => $exception])); throw $exception; } $this->eventManager->trigger(self::commandEventPost($commandInterface::name(), $commandInterface)); return $result; }
/** * Authenticates against the supplied adapter * * @? This is currently a BC break the original takes an auth adapter as a parameter. This still conforms to the interface though. * * @param array $authenticationContext * @return Result */ public function authenticate($authenticationContext = []) { $event = new Authenticate(); $event->setTarget($this); $event->setParams($authenticationContext); $event->setPreviousResult($this->getResult()); $this->events->triggerEvent($event); $result = $event->getResult(); if ($result->isValid()) { $event = new AuthenticationSucceeded(); } else { $event = new AuthenticationFailed(); } $event->setTarget($this); $event->setResult($result); $event->setParams($authenticationContext); $this->events->trigger($event); /** * ZF-7546 - prevent multiple successive calls from storing inconsistent results * Ensure storage has clean state */ if ($this->hasIdentity()) { $this->clearIdentity(); } $this->getStorage()->write($result); return $result; }
public function postDelete(StatementInterface $statement, ResultInterface $result) { $this->event->setTarget($this->tableGateway); $this->event->setName(__FUNCTION__); $this->event->setParams(array('statement' => $statement, 'result' => $result)); $this->eventManager->trigger($this->event); }
/** * Trigger the authorization.post event * * @param MvcEvent $mvcEvent * @return null|Response */ public function authorizationPost(MvcEvent $mvcEvent) { if (!$mvcEvent->getRequest() instanceof HttpRequest || $mvcEvent->getRequest()->isOptions()) { return; } $responses = $this->events->trigger(MvcAuthEvent::EVENT_AUTHORIZATION_POST, $this->mvcAuthEvent, function ($r) { return $r instanceof Response; }); return $responses->last(); }
/** * Parse a single page into a navigation configuration * * @param Page $page * @return array * @throws Exception\RuntimeException */ public function parsePage(PageInterface $page) { $meta = $page->getMetaData(); $navPage = Page::factory(array('type' => 'mvc', 'route' => (string) $page->getId(), 'label' => $meta->getNavigationTitle(), 'visible' => $page->isVisible())); $event = new Event(); $event->setName(__FUNCTION__ . '.' . $page->getModule()); $event->setTarget($this); $event->setParams(array('page' => $page, 'navigation' => $navPage)); $this->events->trigger($event); return $navPage; }
/** * Bulds a listener closure responsible for triggering events on service instantiation * * @param EventManagerInterface $eventManager * * @return \Closure */ private function createInstantiationListener(EventManagerInterface $eventManager) { return function ($proxy, $instance, $method, $params, $returnValue) use($eventManager) { $eventName = 'create' === $method ? ServiceManagerEvent::EVENT_SERVICEMANAGER_CREATE : ServiceManagerEvent::EVENT_SERVICEMANAGER_GET; $serviceName = $params['name']; if (is_array($serviceName)) { list($canonicalName, $serviceName) = $serviceName; } else { $canonicalName = strtolower(strtr($serviceName, array('-' => '', '_' => '', ' ' => '', '\\' => '', '/' => ''))); } $eventManager->trigger(new ServiceManagerEvent($eventName, $proxy, $returnValue, $serviceName, $canonicalName)); }; }
/** * @param $name * @param $entity */ private function trigger($name, &$entity) { if (!empty($entity) && $entity instanceof Collection) { $this->eventManager->addIdentifiers(get_class($entity->getFirst())); } else { $this->eventManager->addIdentifiers(get_class($entity)); } $event = new Event($name, $this, compact('entity')); $this->eventManager->trigger($event); if ($event->getParam('entity') && $event->getParam('entity') instanceof EntityInterface) { $entity = $event->getParam('entity'); } }
/** * (non-PHPdoc). * * @see \Zend\Json\Server\Server::_handle() */ protected function handleRequest() { try { $request = $this->getRequest(); if ($request->isParseError() === true) { throw new ParseErrorException(); } $this->events->trigger('sendRequest.pre', $this, array('methode' => $request->getMethod())); if (($ret = $this->getParentHandle()) instanceof RPCERROR && ($ret = $ret->getData()) instanceof \Exception) { throw $ret; } } catch (AbstractException $e) { if (isset($this->options['log'])) { $this->container->get($this->options['log'])->err('(' . $e->getCode() . ') ' . $e->getMessage()); } return $this->fault($e->getMessage(), $e->getCode()); } catch (\Exception $e) { if (isset($this->options['log'])) { $this->container->get($this->options['log'])->err('(' . $e->getCode() . ') ' . $e->getMessage() . ' in ' . $e->getFile() . ' line ' . $e->getLine(), $e->getTrace()); } return isset($this->options['environment']) && $this->options['environment'] === "dev" ? $this->fault('(' . $e->getCode() . ') ' . $e->getMessage() . ' in ' . $e->getFile() . ' line ' . $e->getLine(), $e->getCode(), $e->getTrace()) : $this->fault('Internal error', RPCERROR::ERROR_INTERNAL); } }
/** * Trigger the authorization.post event * * @param MvcEvent $event * @return null|Response */ public function authorizationPost(MvcEvent $event) { if (!$event->getRequest() instanceof HttpRequest || $event->getRequest()->isOptions()) { return; } // Check if dealing with an unrestricted route if (!$this->isRestrictedRoute($event->getRouteMatch()->getMatchedRouteName())) { return; } $responses = $this->events->trigger(AccessControlEvent::EVENT_AUTHORIZATION_POST, $this->accessControlEvent, function ($r) { return $r instanceof Response; }); return $responses->last(); }
public function loadPage(MvcEvent $e) { $routeMatch = $e->getRouteMatch(); $pageId = $routeMatch->getParam('page-id', null); if (null === $pageId) { return; } $page = $this->pageService->find($pageId); if (!$page instanceof Page) { throw new Exception\PageNotFoundException(sprintf('The page could not be found with id %s', $pageId)); } $event = new Event(__FUNCTION__, $this, array('page' => $page)); $this->events->trigger($event); $e->setParam('page', $page); }
/** * Runs all collectors. * * @triggers ProfilerEvent::EVENT_COLLECTED * @param MvcEvent $mvcEvent * @return Profiler * @throws Exception\ProfilerException */ public function collect(MvcEvent $mvcEvent) { $this->report->setToken(uniqid('zdt'))->setUri($mvcEvent->getRequest()->getUriString())->setMethod($mvcEvent->getRequest()->getMethod())->setTime(new \DateTime('now', new \DateTimeZone('UTC')))->setIp($mvcEvent->getRequest()->getServer()->get('REMOTE_ADDR')); if (isset($this->collectors)) { foreach ($this->collectors as $collector) { $collector->collect($mvcEvent); $this->report->addCollector(unserialize(serialize($collector))); } $this->eventManager->trigger(ProfilerEvent::EVENT_COLLECTED, $this->getEvent()); return $this; } if ($this->strict === true) { throw new Exception\ProfilerException('There is nothing to collect.'); } $this->report->addError('There is nothing to collect.'); return $this; }
/** * @todo remove unused $mailer parameter an fix tests * * @param InputFilterInterface $filter * @param Plugin\Mailer $mailer * @param Url $url * @throws \LogicException * @throws UserDoesNotHaveAnEmailException * @throws UserNotFoundException */ public function proceed(InputFilterInterface $filter, Plugin\Mailer $mailer, Url $url) { if (!$filter->isValid()) { throw new \LogicException('Form is not valid'); } $identity = $filter->getValue('identity'); $suffix = $this->loginFilter->filter(); if (!($user = $this->userRepository->findByLoginOrEmail($identity, $suffix))) { throw new UserNotFoundException('User is not found'); } if (!($email = $user->getInfo()->getEmail())) { throw new UserDoesNotHaveAnEmailException('User does not have an email'); } $tokenHash = $this->tokenGenerator->generate($user); $resetLink = $url->fromRoute('lang/goto-reset-password', array('token' => $tokenHash, 'userId' => $user->getId()), array('force_canonical' => true)); $e = new AuthEvent(); $e->setResetLink($resetLink); $e->setUser($user); $this->eventManager->trigger(AuthEvent::EVENT_AUTH_NEWPASSWORD, $e); }
/** * Trigger the "postDelete" event * * Triggers the "postDelete" event mapping the following parameters: * - $statement as "statement" * - $result as "result" * * @param StatementInterface $statement * @param ResultInterface $result * @return void */ public function postDelete(StatementInterface $statement, ResultInterface $result) { $this->event->setName(static::EVENT_POST_DELETE); $this->event->setParams(array('statement' => $statement, 'result' => $result)); $this->eventManager->trigger($this->event); }
/** * {@inheritdoc} */ public function publish(DomainEventInterface $event) { $this->eventManager->trigger($event->getName(), $event); return $this; }
private function sendEmail($message) { $this->eventManager->trigger(self::SYSTEM_MESSAGE, $_POST, ['message' => $message]); }
public function stop() { $this->running = false; $this->emitter->trigger(LoopEvent::EVENT_LOOP_STOP, $this->event); }
/** * @param string $eventName * @param RestController $controller * @param array|Paginator $resource */ protected function triggerEvent($eventName, RestController $controller, $resource) { $argv = ['resource' => $resource, 'request' => $controller->request(), 'response' => $controller->response()]; $this->eventManager->trigger($eventName, $controller, $argv); }