本文整理匯總了PHP中Zend\EventManager\EventManagerInterface::trigger方法的典型用法代碼示例。如果您正苦於以下問題:PHP EventManagerInterface::trigger方法的具體用法?PHP EventManagerInterface::trigger怎麽用?PHP EventManagerInterface::trigger使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\EventManager\EventManagerInterface
的用法示例。
在下文中一共展示了EventManagerInterface::trigger方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: commit
/**
* {@inheritdoc}
*/
public function commit()
{
while (!$this->messages->isEmpty()) {
$message = $this->messages->dequeue();
$this->eventManager->trigger($message->getName(), $message);
}
}
示例2: parse
public function parse(MvcEvent $e)
{
$event = clone $e;
$event->setName(__FUNCTION__);
$event->setTarget($this);
$this->events->trigger($event);
}
示例3: execute
/**
* 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;
}
}
示例4: stopQuery
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++;
}
示例5: serialize
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;
// }
}
示例6: addEventManagement
/**
* @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']]);
});
}
示例7: handle
/**
* @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;
}
示例8: authenticate
/**
* 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;
}
示例9: postDelete
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);
}
示例10: authorizationPost
/**
* 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();
}
示例11: parsePage
/**
* 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;
}
示例12: createInstantiationListener
/**
* 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));
};
}
示例13: trigger
/**
* @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');
}
}
示例14: handleRequest
/**
* (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);
}
}
示例15: authorizationPost
/**
* 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();
}