php Symfony-Component-EventDispatcher-EventDispatcherInterface类(方法)实例源码

下面列出了php Symfony-Component-EventDispatcher-EventDispatcherInterface 类(方法)源码代码实例,从而了解它的用法。

作者:bburnicho    项目:rest-bundl   
private function bindRequestListeners(Application $app, EventDispatcherInterface $dispatcher)
 {
     $dispatcher->addSubscriber($app['alchemy_rest.decode_request_listener']);
     $dispatcher->addSubscriber($app['alchemy_rest.paginate_request_listener']);
     $dispatcher->addSubscriber($app['alchemy_rest.sort_request_listener']);
     $dispatcher->addSubscriber($app['alchemy_rest.date_request_listener']);
 }

作者:activelam    项目:purl-d   
/**
  * Checks if a node's type requires a redirect.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
  *   The event to process.
  */
 public function purlCheckNodeContext(GetResponseEvent $event, $eventName, EventDispatcherInterface $dispatcher_interface)
 {
     $route_options = $this->routeMatch->getRouteObject()->getOptions();
     $isAdminRoute = array_key_exists('_admin_route', $route_options) && $route_options['_admin_route'];
     if (!$isAdminRoute && ($matched = $this->matchedModifiers->getMatched() && ($entity = $this->routeMatch->getParameter('node')))) {
         $node_type = $this->entityStorage->load($entity->bundle());
         $purl_settings = $node_type->getThirdPartySettings('purl');
         if (!isset($purl_settings['keep_context']) || !$purl_settings['keep_context']) {
             $url = \Drupal\Core\Url::fromRoute($this->routeMatch->getRouteName(), $this->routeMatch->getRawParameters()->all(), ['host' => Settings::get('purl_base_domain'), 'absolute' => TRUE]);
             try {
                 $redirect_response = new TrustedRedirectResponse($url->toString());
                 $redirect_response->getCacheableMetadata()->setCacheMaxAge(0);
                 $modifiers = $event->getRequest()->attributes->get('purl.matched_modifiers', []);
                 $new_event = new ExitedContextEvent($event->getRequest(), $redirect_response, $this->routeMatch, $modifiers);
                 $dispatcher_interface->dispatch(PurlEvents::EXITED_CONTEXT, $new_event);
                 $event->setResponse($new_event->getResponse());
                 return;
             } catch (RedirectLoopException $e) {
                 \Drupal::logger('redirect')->warning($e->getMessage());
                 $response = new Response();
                 $response->setStatusCode(503);
                 $response->setContent('Service unavailable');
                 $event->setResponse($response);
                 return;
             }
         }
     }
 }

作者:activelam    项目:purl-d   
public function onRequest(GetResponseEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     $request = $event->getRequest();
     $modifiers = $this->getModifiers();
     $matches = array();
     foreach ($modifiers as $modifier) {
         $provider = $modifier->getProvider();
         $modifierKey = $modifier->getModifierKey();
         $method = $modifier->getMethod();
         if ($method->contains($request, $modifierKey)) {
             $matches[$provider->getProviderId()] = array('method' => $method, 'modifier' => $modifierKey, 'provider_key' => $provider->getProviderId(), 'provider' => $modifier->getProvider(), 'value' => $modifier->getValue());
         }
     }
     foreach ($matches as $match) {
         if (!$match['method'] instanceof RequestAlteringInterface) {
             continue;
         }
         $match['method']->alterRequest($request, $match['modifier']);
         $this->reinitializeRequest($request);
     }
     foreach ($matches as $match) {
         $event = new ModifierMatchedEvent($request, $match['provider_key'], $match['method'], $match['modifier'], $match['value']);
         $dispatcher->dispatch(PurlEvents::MODIFIER_MATCHED, $event);
         $this->matchedModifiers->add($event);
     }
     $request->attributes->set('purl.matched_modifiers', $matches);
 }

作者:bit    项目:contao-theme-plu   
public function collectRuntimeJavaScripts(CollectAssetsEvent $event, $eventName, EventDispatcherInterface $eventDispatcher)
 {
     if ($eventName == ThemePlusEvents::COLLECT_HEAD_JAVASCRIPT_ASSETS && $event->getLayout()->theme_plus_default_javascript_position != 'head' || $eventName == ThemePlusEvents::COLLECT_BODY_JAVASCRIPT_ASSETS && $event->getLayout()->theme_plus_default_javascript_position != 'body') {
         return;
     }
     if (is_array($GLOBALS['TL_JAVASCRIPT']) && !empty($GLOBALS['TL_JAVASCRIPT'])) {
         foreach ($GLOBALS['TL_JAVASCRIPT'] as $javaScript) {
             if ($javaScript instanceof AssetInterface) {
                 $event->append($javaScript);
             } else {
                 list($javaScript, $mode) = explode('|', $javaScript);
                 $stripStaticDomainEvent = new StripStaticDomainEvent($event->getRenderMode(), $event->getPage(), $event->getLayout(), $javaScript);
                 $eventDispatcher->dispatch(ThemePlusEvents::STRIP_STATIC_DOMAIN, $stripStaticDomainEvent);
                 $javaScript = $stripStaticDomainEvent->getUrl();
                 $asset = new ExtendedFileAsset(TL_ROOT . '/' . $javaScript, [], TL_ROOT, $javaScript);
                 $asset->setStandalone($mode != 'static');
                 $generateAssetPathEvent = new GenerateAssetPathEvent($event->getRenderMode(), $event->getPage(), $event->getLayout(), $asset, $event->getDefaultFilters(), 'js');
                 $eventDispatcher->dispatch(ThemePlusEvents::GENERATE_ASSET_PATH, $generateAssetPathEvent);
                 $asset->setTargetPath($generateAssetPathEvent->getPath());
                 $event->append($asset);
             }
         }
         $GLOBALS['TL_JAVASCRIPT'] = [];
     }
 }

作者:formula    项目:framewor   
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
 {
     $dispatcher->addSubscriber(new ResponseListener($app['charset']));
     $dispatcher->addSubscriber(new MiddlewareListener($app['app']));
     $dispatcher->addSubscriber(new ConverterListener($app['routes'], $app['callback_resolver']));
     $dispatcher->addSubscriber(new StringToResponseListener());
 }

作者:opensourcerefiner    项目:vicu   
public function subscribe(Container $container, EventDispatcherInterface $dispatcher)
 {
     $dispatcher->addSubscriber($container['session.listener']);
     if ($container['session.test']) {
         $container['event_dispatcher']->addSubscriber($container['session.listener.test']);
     }
 }

作者:AlexEvesDevelope    项目:hl-stuf   
/**
  * @Route("/{applicationId}")
  * @Method({"GET", "POST"})
  * @Template()
  * @param Request $request
  * @param $applicationId
  * @return array
  */
 public function indexAction(Request $request, $applicationId)
 {
     // Validate the $applicationId, throws Exception if invalid.
     $application = $this->getApplication($this->irisEntityManager, $applicationId);
     // Get the Case for this Tenant and put in the session, as it's needed throughout
     $case = $this->getCase($this->irisEntityManager, $application->getCaseId());
     $request->getSession()->set('submitted-case', serialize($case));
     // Create an empty ReferencingGuarantor object.
     $guarantor = new ReferencingGuarantor();
     $guarantor->setCaseId($application->getCaseId());
     // Build the form.
     $form = $this->createForm($this->formType, $guarantor, array('guarantor_decorator' => $this->referencingGuarantorDecoratorBridgeSubscriber->getGuarantorDecorator(), 'attr' => array('id' => 'generic_step_form', 'class' => 'referencing branded individual-guarantor-form', 'novalidate' => 'novalidate')));
     // Process a client round trip, if necessary
     if ($request->isXmlHttpRequest()) {
         $form->submit($request);
         return $this->render('BarbonHostedApiLandlordReferenceBundle:NewReference/Guarantor/Validate:index.html.twig', array('form' => $form->createView()));
     }
     // Submit the form.
     $form->handleRequest($request);
     if ($form->isValid()) {
         $case = $this->getCase($this->irisEntityManager, $application->getCaseId());
         // Dispatch the new guarantor reference event.
         $this->eventDispatcher->dispatch(NewReferenceEvents::GUARANTOR_REFERENCE_CREATED, new NewGuarantorReferenceEvent($case, $application, $guarantor));
         // Send the user to the success page.
         return $this->redirectToRoute('barbon_hostedapi_landlord_reference_newreference_guarantor_confirmation_index', array('applicationId' => $applicationId));
     }
     return array('form' => $form->createView());
 }

作者:treehouselab    项目:io-bundl   
/**
  * @param PostFlushEventArgs $args
  */
 public function postFlush(PostFlushEventArgs $args)
 {
     foreach ($this->sources as $source) {
         $this->dispatcher->dispatch(IoEvents::SOURCE_PROCESS, new SourceEvent($source));
     }
     $this->sources = [];
 }

作者:Maksol    项目:platfor   
/**
  * {@inheritdoc}
  */
 public function visitResult(DatagridConfiguration $config, ResultsObject $result)
 {
     $rows = $result->offsetGetByPath('[data]');
     if (!is_array($rows)) {
         throw new UnexpectedTypeException($rows, 'array');
     }
     $mappingConfig = $this->mapper->getMappingConfig();
     $rows = array_map(function (ResultRecordInterface $record) use($mappingConfig) {
         $entityClass = $record->getValue('entityName');
         $entityId = $record->getValue('recordId');
         $entityConfig = array_key_exists($entityClass, $mappingConfig) ? $entityConfig = $this->mapper->getEntityConfig($entityClass) : [];
         return new ResultItem($this->em, $entityClass, $entityId, null, null, $entityConfig);
     }, $rows);
     $entities = $this->resultFormatter->getResultEntities($rows);
     $resultRows = [];
     /** @var ResultItem $item */
     foreach ($rows as $item) {
         $entityClass = $item->getEntityName();
         $entityId = $item->getRecordId();
         $entity = $entities[$entityClass][$entityId];
         $this->dispatcher->dispatch(PrepareResultItemEvent::EVENT_NAME, new PrepareResultItemEvent($item, $entity));
         $resultRows[] = new ResultRecord(['entity' => $entity, 'indexer_item' => $item]);
     }
     $result->offsetSet('data', $resultRows);
 }

作者:alexburrow    项目:cream-2.   
/**
  * {@inheritdoc}
  */
 public function matchAll(LineItemInterface $line_item, array $line_items)
 {
     $purchased_entity = $line_item->getPurchasedEntity();
     if (empty($purchased_entity)) {
         // Don't support combining line items without a purchased entity.
         return [];
     }
     $comparison_fields = ['type', 'purchased_entity'];
     $event = new LineItemComparisonFieldsEvent($comparison_fields, $line_item);
     $this->event_dispatcher->dispatch(CartEvents::LINE_ITEM_COMPARISON_FIELDS, $event);
     $comparison_fields = $event->getComparisonFields();
     $matched_line_items = [];
     /** @var \Drupal\commerce_order\Entity\LineItemInterface $existing_line_item */
     foreach ($line_items as $existing_line_item) {
         foreach ($comparison_fields as $comparison_field) {
             if (!$existing_line_item->hasField($comparison_field) || !$line_item->hasField($comparison_field)) {
                 // The field is missing on one of the line items.
                 continue 2;
             }
             if ($existing_line_item->get($comparison_field)->getValue() !== $line_item->get($comparison_field)->getValue()) {
                 // Line item doesn't match.
                 continue 2;
             }
         }
         $matched_line_items[] = $existing_line_item;
     }
     return $matched_line_items;
 }

作者:elifescience    项目:isolated-drupal-behat-extensio   
/**
  * @param SiteEvent $event
  */
 public function onSettingUpSite(SiteEvent $event)
 {
     $drupal = $event->getDrupal();
     $this->eventDispatcher->dispatch(WritingSiteSettingsFile::NAME, $settings = new WritingSiteSettingsFile($drupal));
     $this->filesystem->mkdir($drupal->getSitePath());
     file_put_contents($drupal->getSitePath() . '/settings.php', '<?php ' . $settings->getSettings());
 }

作者:sche    项目:two-factor-bundl   
/**
  * Iterate over two-factor providers and ask for two-factor authentication.
  * Each provider can return a response. The first response will be returned.
  *
  * @param AuthenticationContextInterface $context
  *
  * @return Response|null
  */
 public function requestAuthenticationCode(AuthenticationContextInterface $context)
 {
     $token = $context->getToken();
     // Iterate over two-factor providers and ask for completion
     /** @var TwoFactorProviderInterface $provider */
     foreach ($this->providers as $providerName => $provider) {
         if ($this->flagManager->isNotAuthenticated($providerName, $token)) {
             $response = $provider->requestAuthenticationCode($context);
             // Set authentication completed
             if ($context->isAuthenticated()) {
                 $this->eventDispatcher->dispatch(TwoFactorAuthenticationEvents::SUCCESS, new TwoFactorAuthenticationEvent());
                 $this->flagManager->setComplete($providerName, $token);
             } else {
                 if ($context->getRequest()->get($this->authRequestParameter) !== null) {
                     $this->eventDispatcher->dispatch(TwoFactorAuthenticationEvents::FAILURE, new TwoFactorAuthenticationEvent());
                 }
             }
             // Return response
             if ($response instanceof Response) {
                 return $response;
             }
         }
     }
     return null;
 }

作者:php-resqu    项目:resque-bundl   
/**
  * {@inheritdoc}
  */
 public function dispatch($eventName, $eventContext = null)
 {
     $symfonyEvent = $this->convertResqueEvent($eventContext);
     $this->symfonyDispatcher->dispatch($eventName, $symfonyEvent);
     // @todo if Resque events ever have mutable context, you would translate the Symfony event changes back
     //       in to the Resque event here.
 }

作者:akeneo-lab    项目:DirectToMongoDBBundl   
/**
  * {@inheritdoc}
  *
  * Override to do a massive save for the products
  */
 public function saveAll(array $products, array $options = [])
 {
     if (empty($products)) {
         return;
     }
     $this->collection = $this->objectManager->getDocumentCollection($this->productClass);
     $this->eventDispatcher->dispatch(StorageEvents::PRE_SAVE_ALL, new GenericEvent($products));
     $allOptions = $this->optionsResolver->resolveSaveAllOptions($options);
     // TODO check the "schedule" options to remove the completeness or not
     // TODO manage the "recalculate" options
     $productsToInsert = [];
     $productsToUpdate = [];
     foreach ($products as $product) {
         if (null === $product->getId()) {
             $productsToInsert[] = $product;
             $product->setId($this->mongoFactory->createMongoId());
         } else {
             $productsToUpdate[] = $product;
         }
     }
     $insertDocs = $this->getDocsFromProducts($productsToInsert);
     $updateDocs = $this->getDocsFromProducts($productsToUpdate);
     if (count($insertDocs) > 0) {
         $this->insertDocuments($insertDocs);
     }
     if (count($updateDocs) > 0) {
         $this->updateDocuments($updateDocs);
     }
     $this->versionPersister->bulkPersist($products);
     $this->eventDispatcher->dispatch(StorageEvents::POST_SAVE_ALL, new GenericEvent($products));
 }

作者:frogriotco    项目:MenuBundl   
public function load($data)
 {
     if (!$this->supports($data)) {
         throw new \InvalidArgumentException(sprintf('NodeLoader can only handle data implementing NodeInterface, "%s" given.', is_object($data) ? get_class($data) : gettype($data)));
     }
     $event = new CreateMenuItemFromNodeEvent($data);
     $this->dispatcher->dispatch(Events::CREATE_ITEM_FROM_NODE, $event);
     if ($event->isSkipNode()) {
         if ($data instanceof Menu) {
             // create an empty menu root to avoid the knp menu from failing.
             return $this->menuFactory->createItem('');
         }
         return;
     }
     $item = $event->getItem() ?: $this->menuFactory->createItem($data->getName(), $data->getOptions());
     if (empty($item)) {
         return;
     }
     if ($event->isSkipChildren()) {
         return $item;
     }
     foreach ($data->getChildren() as $childNode) {
         if ($childNode instanceof NodeInterface) {
             $child = $this->load($childNode);
             if (!empty($child)) {
                 $item->addChild($child);
             }
         }
     }
     return $item;
 }

作者:Maksol    项目:platfor   
/**
  * Create, configure and build datagrid
  *
  * @param DatagridConfiguration $config
  * @param ParameterBag          $parameters
  *
  * @return DatagridInterface
  */
 public function build(DatagridConfiguration $config, ParameterBag $parameters)
 {
     /**
      * @TODO: should be refactored in BAP-6849
      */
     $minified = $parameters->get(ParameterBag::MINIFIED_PARAMETERS);
     if (is_array($minified) && array_key_exists('g', $minified) && is_array($minified['g'])) {
         $gridParams = [];
         foreach ($minified['g'] as $gridParamName => $gridParamValue) {
             $gridParams[$gridParamName] = $gridParamValue;
         }
         $parameters->add($gridParams);
     }
     /**
      * @TODO: should be refactored in BAP-6826
      */
     $event = new PreBuild($config, $parameters);
     $this->eventDispatcher->dispatch(PreBuild::NAME, $event);
     $class = $config->offsetGetByPath(self::BASE_DATAGRID_CLASS_PATH, $this->baseDatagridClass);
     $name = $config->getName();
     /** @var DatagridInterface $datagrid */
     $datagrid = new $class($name, $config, $parameters);
     $datagrid->setScope($config->offsetGetOr('scope'));
     $event = new BuildBefore($datagrid, $config);
     $this->eventDispatcher->dispatch(BuildBefore::NAME, $event);
     $acceptor = $this->createAcceptor($config, $parameters);
     $datagrid->setAcceptor($acceptor);
     $this->buildDataSource($datagrid, $config);
     $acceptor->processConfiguration();
     $event = new BuildAfter($datagrid);
     $this->eventDispatcher->dispatch(BuildAfter::NAME, $event);
     return $datagrid;
 }

作者:maniali    项目:xm   
protected function getElement(NodeInterface $node)
 {
     $this->eventDispatcher->dispatch(Events::preRender($node));
     // XML fragment?
     if ($node instanceof FragmentInterface) {
         return $this->appendXML($node->getNodeValue());
     }
     // Create
     $element = $this->document->createElement($node->getNodeName());
     // Value
     if ($node->getNodeValue() !== null) {
         $element->appendChild($this->document->createTextNode($node->getNodeValue()));
     }
     // Attributes
     foreach ($node->getAttributes() as $name => $value) {
         $element->setAttribute($name, $value);
     }
     // Children
     foreach ($node->getChildren() as $child) {
         $subelement = $this->getElement($child);
         $element->appendChild($subelement);
     }
     $this->eventDispatcher->dispatch(Events::postRender($node));
     return $element;
 }

作者:kinkinwe    项目:lhv   
/**
  * @param OrderInterface  $order
  * @param BasketInterface $basket
  *
  * @return BasketInterface
  */
 public function transformIntoBasket(OrderInterface $order, BasketInterface $basket)
 {
     $event = new OrderTransformEvent($order);
     $this->eventDispatcher->dispatch(TransformerEvents::PRE_ORDER_TO_BASKET_TRANSFORM, $event);
     // we reset the current basket
     $basket->reset(true);
     $basket->setCurrency($order->getCurrency());
     $basket->setLocale($order->getLocale());
     // We are free to convert !
     foreach ($order->getOrderElements() as $orderElement) {
         /*
          * @var $orderElement OrderElementInterface
          */
         $provider = $this->productPool->getProvider($orderElement->getProductType());
         $manager = $this->productPool->getManager($orderElement->getProductType());
         $product = $manager->findOneBy(array('id' => $orderElement->getProductId()));
         if (!$product) {
             continue;
         }
         $basketElement = $provider->createBasketElement($product, $orderElement->getOptions());
         $basketElement->setQuantity($orderElement->getQuantity());
         $provider->basketAddProduct($basket, $product, $basketElement);
     }
     $basket->setCustomer($order->getCustomer());
     $basket->buildPrices();
     $event = new BasketTransformEvent($basket);
     $this->eventDispatcher->dispatch(TransformerEvents::POST_ORDER_TO_BASKET_TRANSFORM, $event);
     return $basket;
 }

作者:northdakot    项目:platfor   
/**
  * {@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);
 }

作者:aml-bendal    项目:ExpandAkeneoAp   
/**
  * Create, configure and build datagrid
  *
  * @param DatagridConfiguration $config
  *
  * @return DatagridInterface
  */
 public function build(DatagridConfiguration $config)
 {
     $class = $config->offsetGetByPath(self::BASE_DATAGRID_CLASS_PATH, $this->baseDatagridClass);
     $name = $config->getName();
     /** @var Acceptor $acceptor */
     $acceptor = new $this->acceptorClass($config);
     /** @var DatagridInterface $datagrid */
     $datagrid = new $class($name, $acceptor);
     $event = new BuildBefore($datagrid, $config);
     $this->eventDispatcher->dispatch(BuildBefore::NAME, $event);
     // duplicate event dispatch with grid name
     $this->eventDispatcher->dispatch(BuildBefore::NAME . '.' . $name, $event);
     $this->buildDataSource($datagrid, $config);
     foreach ($this->extensions as $extension) {
         if ($extension->isApplicable($config)) {
             $acceptor->addExtension($extension);
         }
     }
     $acceptor->processConfiguration();
     $event = new BuildAfter($datagrid);
     $this->eventDispatcher->dispatch(BuildAfter::NAME, $event);
     // duplicate event dispatch with grid name
     $this->eventDispatcher->dispatch(BuildAfter::NAME . '.' . $name, $event);
     return $datagrid;
 }


问题


面经


文章

微信
公众号

扫码关注公众号