本文整理汇总了PHP中Symfony\Component\EventDispatcher\EventDispatcherInterface::hasListeners方法的典型用法代码示例。如果您正苦于以下问题:PHP EventDispatcherInterface::hasListeners方法的具体用法?PHP EventDispatcherInterface::hasListeners怎么用?PHP EventDispatcherInterface::hasListeners使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\EventDispatcher\EventDispatcherInterface
的用法示例。
在下文中一共展示了EventDispatcherInterface::hasListeners方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postDispatch
/**
* @param Response\ResponseInterface $response
* @param string $command
*/
public function postDispatch(Response\ResponseInterface $response, $command)
{
$eventName = sprintf('beanstalk.post.dispatch.%s', str_replace('-', '.', $command));
if (!is_null($this->dispatcher) && $this->dispatcher->hasListeners($eventName)) {
$this->dispatcher->dispatch($eventName, new Event\PostDispatchEvent($response));
}
}
示例2: visitMetadata
/**
* {@inheritDoc}
*/
public function visitMetadata(DatagridConfiguration $config, MetadataObject $data)
{
$params = $this->getParameters()->get(ParameterBag::ADDITIONAL_PARAMETERS, []);
$currentView = isset($params[self::VIEWS_PARAM_KEY]) ? $params[self::VIEWS_PARAM_KEY] : null;
$data->offsetAddToArray('initialState', ['gridView' => '__all__']);
$data->offsetAddToArray('state', ['gridView' => $currentView]);
$allLabel = null;
if (isset($config['options']) && isset($config['options']['gridViews']) && isset($config['options']['gridViews']['allLabel'])) {
$allLabel = $this->translator->trans($config['options']['gridViews']['allLabel']);
}
/** @var AbstractViewsList $list */
$list = $config->offsetGetOr(self::VIEWS_LIST_KEY, false);
$gridViews = ['choices' => [['label' => $allLabel, 'value' => '__all__']], 'views' => [(new View('__all__'))->getMetadata()]];
if ($list !== false) {
$configuredGridViews = $list->getMetadata();
$configuredGridViews['views'] = array_merge($gridViews['views'], $configuredGridViews['views']);
$configuredGridViews['choices'] = array_merge($gridViews['choices'], $configuredGridViews['choices']);
$gridViews = $configuredGridViews;
}
if ($this->eventDispatcher->hasListeners(GridViewsLoadEvent::EVENT_NAME)) {
$event = new GridViewsLoadEvent($config->getName(), $gridViews);
$this->eventDispatcher->dispatch(GridViewsLoadEvent::EVENT_NAME, $event);
$gridViews = $event->getGridViews();
}
$gridViews['gridName'] = $config->getName();
$gridViews['permissions'] = $this->getPermissions();
$data->offsetSet('gridViews', $gridViews);
}
示例3: readLine
/**
* @@inheritdoc
*/
public function readLine()
{
$read = parent::readLine();
if (!is_null($this->dispatcher) && $this->dispatcher->hasListeners(BeanstalkEvents::STREAM_READ)) {
$this->dispatcher->dispatch(BeanstalkEvents::STREAM_READ, new StreamReadEvent($read, $this->getTimeStamp()));
}
return $read;
}
示例4: updateSegmentConditionBuilderOptions
/**
* @param array $options
*
* @return array
*/
public function updateSegmentConditionBuilderOptions(array $options)
{
if (!$this->dispatcher->hasListeners(ConditionBuilderOptionsLoadEvent::EVENT_NAME)) {
return $options;
}
$event = new ConditionBuilderOptionsLoadEvent($options);
$this->dispatcher->dispatch(ConditionBuilderOptionsLoadEvent::EVENT_NAME, $event);
return $event->getOptions();
}
示例5: onSuccess
/**
* Form validated and can be processed.
*/
protected function onSuccess()
{
/** @var Mailbox $mailbox */
$mailbox = $this->form->getData();
$this->getEntityManager()->persist($mailbox);
$this->getEntityManager()->flush();
if ($this->dispatcher->hasListeners(MailboxSaved::NAME)) {
$this->dispatcher->dispatch(MailboxSaved::NAME, new MailboxSaved($mailbox));
}
}
示例6: getThemes
/**
* @param FormView $view
*
* @return array
*/
public function getThemes(FormView $view)
{
$themes = [static::DEFAULT_THEME];
if (!$this->dispatcher->hasListeners(LoadIntegrationThemesEvent::NAME)) {
return $themes;
}
$event = new LoadIntegrationThemesEvent($view, $themes);
$this->dispatcher->dispatch(LoadIntegrationThemesEvent::NAME, $event);
return $event->getThemes();
}
示例7: renderNotifications
protected function renderNotifications($notificationsViews)
{
$views = [];
$colorChooser = $this->buildColorChooser();
$unviewedNotificationIds = [];
foreach ($notificationsViews as $notificationView) {
$notification = $notificationView->getNotification();
$iconKey = $notification->getIconKey();
if (!empty($iconKey)) {
$notificationColor = $colorChooser->getColorForName($iconKey);
$notification->setIconColor($notificationColor);
}
$eventName = 'create_notification_item_' . $notification->getActionKey();
$event = new NotificationCreateDelegateViewEvent($notificationView, $this->platformName);
/* @var EventDispatcher $eventDispatcher */
if ($this->eventDispatcher->hasListeners($eventName)) {
$event = $this->eventDispatcher->dispatch($eventName, $event);
$views[$notificationView->getId() . ''] = $event->getResponseContent();
}
if ($notificationView->getStatus() === false) {
array_push($unviewedNotificationIds, $notificationView->getId());
}
}
$this->markNotificationsAsViewed($unviewedNotificationIds);
return ['views' => $views, 'colors' => $colorChooser->getColorObjectArray()];
}
示例8: visitMetadata
/**
* {@inheritdoc}
*/
public function visitMetadata(DatagridConfiguration $config, MetadataObject $data)
{
$currentViewId = $this->getCurrentViewId($config->getName());
$this->setDefaultParams($config->getName());
$data->offsetAddToArray('initialState', ['gridView' => self::DEFAULT_VIEW_ID]);
$data->offsetAddToArray('state', ['gridView' => $currentViewId]);
$allLabel = null;
if (isset($config['options'], $config['options']['gridViews'], $config['options']['gridViews']['allLabel'])) {
$allLabel = $this->translator->trans($config['options']['gridViews']['allLabel']);
}
/** @var AbstractViewsList $list */
$list = $config->offsetGetOr(self::VIEWS_LIST_KEY, false);
$systemGridView = new View(self::DEFAULT_VIEW_ID);
$systemGridView->setDefault($this->getDefaultViewId($config->getName()) === null);
$gridViews = ['choices' => [['label' => $allLabel, 'value' => self::DEFAULT_VIEW_ID]], 'views' => [$systemGridView->getMetadata()]];
if ($list !== false) {
$configuredGridViews = $list->getMetadata();
$configuredGridViews['views'] = array_merge($gridViews['views'], $configuredGridViews['views']);
$configuredGridViews['choices'] = array_merge($gridViews['choices'], $configuredGridViews['choices']);
$gridViews = $configuredGridViews;
}
if ($this->eventDispatcher->hasListeners(GridViewsLoadEvent::EVENT_NAME)) {
$event = new GridViewsLoadEvent($config->getName(), $gridViews);
$this->eventDispatcher->dispatch(GridViewsLoadEvent::EVENT_NAME, $event);
$gridViews = $event->getGridViews();
}
$gridViews['gridName'] = $config->getName();
$gridViews['permissions'] = $this->getPermissions();
$data->offsetAddToArray('gridViews', $gridViews);
}
示例9: hasListeners
/**
* @deprecated since 1.9. Should be removed together with deprecated events
* @see Oro\Bundle\EntityConfigBundle\Event\Events
*
* @param string $eventName
*
* @return bool
*/
private function hasListeners($eventName)
{
if (!isset($this->hasListenersCache[$eventName])) {
$this->hasListenersCache[$eventName] = $this->eventDispatcher->hasListeners($eventName);
}
return $this->hasListenersCache[$eventName];
}
示例10: dispatchEvent
/**
* Dispatches an event to all registered listeners.
*
* @param string $eventName The name of the event to dispatch
* @param Event $event The event to pass to the event handlers/listeners.
*/
private function dispatchEvent($eventName, Event $event)
{
if (!$this->dispatcher->hasListeners($eventName)) {
return;
}
$this->dispatcher->dispatch($eventName, $event);
}
示例11: authenticateToken
/**
* @param TokenInterface $token
* @param UserProviderInterface $userProvider
* @param $providerKey
*
* @return UsernamePasswordToken
*/
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
{
$authenticated = false;
$authenticationService = null;
$response = null;
$failedAuthMessage = null;
$user = $token->getUser();
$authenticatingService = $token instanceof PluginToken ? $token->getAuthenticatingService() : null;
if (!$user instanceof User) {
try {
$user = $userProvider->loadUserByUsername($token->getUsername());
} catch (UsernameNotFoundException $e) {
}
// Will try with the given password unless the plugin explicitly failed authentication
$tryWithPassword = true;
// Try authenticating with a plugin first
if ($this->dispatcher->hasListeners(UserEvents::USER_FORM_AUTHENTICATION)) {
$integrations = $this->integrationHelper->getIntegrationObjects($authenticatingService, ['sso_form'], false, null, true);
$authEvent = new AuthenticationEvent($user, $token, $userProvider, $this->request, false, $authenticatingService, $integrations);
$this->dispatcher->dispatch(UserEvents::USER_FORM_AUTHENTICATION, $authEvent);
if ($authenticated = $authEvent->isAuthenticated()) {
$user = $authEvent->getUser();
$authenticatingService = $authEvent->getAuthenticatingService();
} elseif ($authEvent->isFailed()) {
$tryWithPassword = false;
}
$response = $authEvent->getResponse();
$failedAuthMessage = $authEvent->getFailedAuthenticationMessage();
}
if (!$authenticated && $tryWithPassword && $user instanceof User) {
// Try authenticating with local password
$authenticated = $this->encoder->isPasswordValid($user, $token->getCredentials());
}
} else {
// Assume the user is authenticated although the token will tell for sure
$authenticated = true;
}
if ($authenticated) {
return new PluginToken($providerKey, $authenticatingService, $user, $user->getPassword(), $user->getRoles(), $response);
} elseif ($response) {
return new PluginToken($providerKey, $authenticatingService, $user, '', [], $response);
}
if ($failedAuthMessage) {
throw new AuthenticationException($failedAuthMessage);
}
throw new BadCredentialsException();
}
示例12: getDispatchEventName
/**
* Get the event name for the loop depending of the event name and the loop name.
*
* This function also checks if there are services that listen to this event.
* If not the function returns null.
*
* @param string $eventName the event name (`TheliaEvents::LOOP_EXTENDS_ARG_DEFINITIONS`,
* `TheliaEvents::LOOP_EXTENDS_INITIALIZE_ARGS`, ...)
* @return null|string The event name for the loop if listeners exist, otherwise null is returned
*/
protected function getDispatchEventName($eventName)
{
$customEventName = TheliaEvents::getLoopExtendsEvent($eventName, $this->loopName);
if (!isset(self::$dispatchCache[$customEventName])) {
self::$dispatchCache[$customEventName] = $this->dispatcher->hasListeners($customEventName);
}
return self::$dispatchCache[$customEventName] ? $customEventName : null;
}
示例13: logout
/**
* {@inheritdoc}
*
* @param Request $request
*
* @return Response never null
*/
public function logout(Request $request, Response $response, TokenInterface $token)
{
$this->userModel->setOnlineStatus('offline');
if ($this->dispatcher->hasListeners(UserEvents::USER_LOGOUT)) {
$event = new LogoutEvent($this->user, $request);
$this->dispatcher->dispatch(UserEvents::USER_LOGOUT, $event);
}
// Clear session
$session = $request->getSession();
$session->clear();
if (isset($event)) {
$sessionItems = $event->getPostSessionItems();
foreach ($sessionItems as $key => $value) {
$session->set($key, $value);
}
}
// Note that a logout occurred
$session->set('post_logout', true);
}
示例14: resolveCommand
/**
* {@inheritdoc}
*/
public function resolveCommand(RawArgs $args)
{
if ($this->dispatcher && $this->dispatcher->hasListeners(ConsoleEvents::PRE_RESOLVE)) {
$event = new PreResolveEvent($args, $this);
$this->dispatcher->dispatch(ConsoleEvents::PRE_RESOLVE, $event);
if ($resolvedCommand = $event->getResolvedCommand()) {
return $resolvedCommand;
}
}
return $this->config->getCommandResolver()->resolveCommand($args, $this);
}
示例15: createQuery
/**
*
* @param type $sql
* @param array $parameters
* @return PDOStatement
*/
public function createQuery($sql, array $parameters = array())
{
$statement = $this->getPDO()->prepare($sql);
$statement->setFetchMode(PDO::FETCH_ASSOC);
$statement->execute($parameters);
if ($this->dispatcher->hasListeners(Events::QUERY)) {
$event = new QueryEvent($statement, $parameters);
$this->dispatcher->dispatch(Events::QUERY, $event);
}
return $statement;
}