当前位置: 首页>>代码示例>>PHP>>正文


PHP EventDispatcherInterface::dispatch方法代码示例

本文整理汇总了PHP中Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch方法的典型用法代码示例。如果您正苦于以下问题:PHP EventDispatcherInterface::dispatch方法的具体用法?PHP EventDispatcherInterface::dispatch怎么用?PHP EventDispatcherInterface::dispatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\EventDispatcher\EventDispatcherInterface的用法示例。


在下文中一共展示了EventDispatcherInterface::dispatch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: indexAction

 /**
  * @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());
 }
开发者ID:AlexEvesDeveloper,项目名称:hl-stuff,代码行数:36,代码来源:NewController.php

示例2: bulkPersist

 /**
  * Bulk generates and inserts full version records for the provided versionable entities
  * in MongoDB.
  * Return an array of ids of documents that have really changed since the last version.
  *
  * @param array $versionables
  *
  * @return array
  */
 public function bulkPersist(array $versionables)
 {
     $versions = [];
     $changedDocIds = [];
     $author = VersionManager::DEFAULT_SYSTEM_USER;
     $event = $this->eventDispatcher->dispatch(BuildVersionEvents::PRE_BUILD, new BuildVersionEvent());
     if (null !== $event && null !== $event->getUsername()) {
         $author = $event->getUsername();
     }
     foreach ($versionables as $versionable) {
         $previousVersion = $this->getPreviousVersion($versionable);
         $context = $this->versionContext->getContextInfo(get_class($versionable));
         $newVersion = $this->versionBuilder->buildVersion($versionable, $author, $previousVersion, $context);
         if (count($newVersion->getChangeSet()) > 0) {
             $versions[] = $newVersion;
             $changedDocIds[] = $versionable->getId();
         }
         if (null !== $previousVersion) {
             $this->documentManager->detach($previousVersion);
         }
     }
     $mongodbVersions = [];
     foreach ($versions as $version) {
         $mongodbVersions[] = $this->normalizer->normalize($version, VersionNormalizer::FORMAT);
     }
     if (count($mongodbVersions) > 0) {
         $collection = $this->documentManager->getDocumentCollection($this->versionClass);
         $collection->batchInsert($mongodbVersions);
     }
     return $changedDocIds;
 }
开发者ID:akeneo-labs,项目名称:DirectToMongoDBBundle,代码行数:40,代码来源:BulkVersionPersister.php

示例3: runTasks

 /**
  * {@inheritdoc}
  */
 public function runTasks()
 {
     $executions = $this->taskExecutionRepository->findScheduled();
     foreach ($executions as $execution) {
         $handler = $this->taskHandlerFactory->create($execution->getHandlerClass());
         $start = microtime(true);
         $execution->setStartTime(new \DateTime());
         $execution->setStatus(TaskStatus::RUNNING);
         $this->taskExecutionRepository->save($execution);
         try {
             $this->eventDispatcher->dispatch(Events::TASK_BEFORE, new TaskExecutionEvent($execution->getTask(), $execution));
             $result = $handler->handle($execution->getWorkload());
             $execution->setStatus(TaskStatus::COMPLETED);
             $execution->setResult($result);
             $this->eventDispatcher->dispatch(Events::TASK_PASSED, new TaskExecutionEvent($execution->getTask(), $execution));
         } catch (\Exception $ex) {
             $execution->setException($ex->__toString());
             $execution->setStatus(TaskStatus::FAILED);
             $this->eventDispatcher->dispatch(Events::TASK_FAILED, new TaskExecutionEvent($execution->getTask(), $execution));
         }
         $execution->setEndTime(new \DateTime());
         $execution->setDuration(microtime(true) - $start);
         $this->eventDispatcher->dispatch(Events::TASK_FINISHED, new TaskExecutionEvent($execution->getTask(), $execution));
         $this->taskExecutionRepository->save($execution);
     }
 }
开发者ID:php-task,项目名称:php-task,代码行数:29,代码来源:TaskRunner.php

示例4: run

 /**
  * @param ExampleNode $example
  *
  * @return int
  */
 public function run(ExampleNode $example)
 {
     $startTime = microtime(true);
     $this->dispatcher->dispatch('beforeExample', new ExampleEvent($example));
     try {
         $this->executeExample($example->getSpecification()->getClassReflection()->newInstance(), $example);
         $status = ExampleEvent::PASSED;
         $exception = null;
     } catch (ExampleException\PendingException $e) {
         $status = ExampleEvent::PENDING;
         $exception = $e;
     } catch (ExampleException\SkippingException $e) {
         $status = ExampleEvent::SKIPPED;
         $exception = $e;
     } catch (ProphecyException\Prediction\PredictionException $e) {
         $status = ExampleEvent::FAILED;
         $exception = $e;
     } catch (ExampleException\FailureException $e) {
         $status = ExampleEvent::FAILED;
         $exception = $e;
     } catch (Exception $e) {
         $status = ExampleEvent::BROKEN;
         $exception = $e;
     }
     if ($exception instanceof PhpSpecException) {
         $exception->setCause($example->getFunctionReflection());
     }
     $runTime = microtime(true) - $startTime;
     $this->dispatcher->dispatch('afterExample', $event = new ExampleEvent($example, $runTime, $status, $exception));
     return $event->getResult();
 }
开发者ID:ProgrammingPeter,项目名称:nba-schedule-api,代码行数:36,代码来源:ExampleRunner.php

示例5: sendInternalRequests

 /**
  * {@inheritdoc}
  */
 protected function sendInternalRequests(array $internalRequests, $success, $error)
 {
     if (!empty($internalRequests)) {
         $this->eventDispatcher->dispatch(Events::MULTI_PRE_SEND, $multiPreSendEvent = new MultiPreSendEvent($this, $internalRequests));
         $internalRequests = $multiPreSendEvent->getRequests();
     }
     $exceptions = array();
     try {
         $responses = $this->decorate('sendRequests', array($internalRequests));
     } catch (MultiHttpAdapterException $e) {
         $responses = $e->getResponses();
         $exceptions = $e->getExceptions();
     }
     if (!empty($responses)) {
         $this->eventDispatcher->dispatch(Events::MULTI_POST_SEND, $postSendEvent = new MultiPostSendEvent($this, $responses));
         $exceptions = array_merge($exceptions, $postSendEvent->getExceptions());
         $responses = $postSendEvent->getResponses();
     }
     if (!empty($exceptions)) {
         $this->eventDispatcher->dispatch(Events::MULTI_EXCEPTION, $exceptionEvent = new MultiExceptionEvent($this, $exceptions));
         $responses = array_merge($responses, $exceptionEvent->getResponses());
         $exceptions = $exceptionEvent->getExceptions();
     }
     foreach ($responses as $response) {
         call_user_func($success, $response);
     }
     foreach ($exceptions as $exception) {
         call_user_func($error, $exception);
     }
 }
开发者ID:KGalley,项目名称:whathood,代码行数:33,代码来源:EventDispatcherHttpAdapter.php

示例6: onSettingUpSite

 /**
  * @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());
 }
开发者ID:elifesciences,项目名称:isolated-drupal-behat-extension,代码行数:10,代码来源:WriteSettingsFileListener.php

示例7: requestAuthenticationCode

 /**
  * 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;
 }
开发者ID:scheb,项目名称:two-factor-bundle,代码行数:33,代码来源:TwoFactorProviderRegistry.php

示例8: getElement

 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;
 }
开发者ID:manialib,项目名称:xml,代码行数:25,代码来源:DOMDocumentDriver.php

示例9: load

 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;
 }
开发者ID:frogriotcom,项目名称:MenuBundle,代码行数:31,代码来源:VotingNodeLoader.php

示例10: build

 /**
  * 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;
 }
开发者ID:Maksold,项目名称:platform,代码行数:41,代码来源:Builder.php

示例11: postFlush

 /**
  * @param PostFlushEventArgs $args
  */
 public function postFlush(PostFlushEventArgs $args)
 {
     foreach ($this->sources as $source) {
         $this->dispatcher->dispatch(IoEvents::SOURCE_PROCESS, new SourceEvent($source));
     }
     $this->sources = [];
 }
开发者ID:treehouselabs,项目名称:io-bundle,代码行数:10,代码来源:SourceModificationListener.php

示例12: connect

 /**
  * Connects to the database.
  *
  * @return boolean
  */
 public function connect()
 {
     if ($connected = $this->connection->connect()) {
         $this->events->dispatch(Events::postConnect, new Event\ConnectionEvent($this));
     }
     return $connected;
 }
开发者ID:jacobjjc,项目名称:PageKit-framework,代码行数:12,代码来源:Connection.php

示例13: render

 /**
  * Renders an editor.
  *
  * @param  string $name
  * @param  string $value
  * @param  array  $attributes
  * @param  array  $parameters
  * @return string
  */
 public function render($name, $value, array $attributes = [], $parameters = [])
 {
     if ($editor = $this->events->dispatch('editor.load', new EditorLoadEvent())->getEditor()) {
         return $editor->render($value, array_merge($attributes, compact('name')));
     }
     return __('Editor not found.');
 }
开发者ID:amirkheirabadi,项目名称:pagekit,代码行数:16,代码来源:EditorHelper.php

示例14: onException

 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onException(GetResponseForExceptionEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $this->eventDispatcher->dispatch(Events::REQUEST_ENDS, new RequestEnded($event->getRequest(), $event->getResponse(), $event->getException()));
 }
开发者ID:Tolerance,项目名称:Tolerance,代码行数:10,代码来源:DispatchRequestEndedEvent.php

示例15: transformFromOrder

 /**
  * Transforms an order into an invoice
  *
  * @param OrderInterface   $order
  * @param InvoiceInterface $invoice
  */
 public function transformFromOrder(OrderInterface $order, InvoiceInterface $invoice)
 {
     $event = new OrderTransformEvent($order);
     $this->eventDispatcher->dispatch(TransformerEvents::PRE_ORDER_TO_INVOICE_TRANSFORM, $event);
     $invoice->setName($order->getBillingName());
     $invoice->setAddress1($order->getBillingAddress1());
     $invoice->setAddress2($order->getBillingAddress2());
     $invoice->setAddress3($order->getBillingAddress3());
     $invoice->setCity($order->getBillingCity());
     $invoice->setCountry($order->getBillingCountryCode());
     $invoice->setPostcode($order->getBillingPostcode());
     $invoice->setEmail($order->getBillingEmail());
     $invoice->setFax($order->getBillingFax());
     $invoice->setMobile($order->getBillingMobile());
     $invoice->setPhone($order->getBillingPhone());
     $invoice->setReference($order->getReference());
     $invoice->setCurrency($order->getCurrency());
     $invoice->setCustomer($order->getCustomer());
     $invoice->setTotalExcl($order->getTotalExcl());
     $invoice->setTotalInc($order->getTotalInc());
     $invoice->setPaymentMethod($order->getPaymentMethod());
     $invoice->setLocale($order->getLocale());
     foreach ($order->getOrderElements() as $orderElement) {
         $invoiceElement = $this->createInvoiceElementFromOrderElement($orderElement);
         $invoiceElement->setInvoice($invoice);
         $invoice->addInvoiceElement($invoiceElement);
     }
     if ($order->getDeliveryCost() > 0) {
         $this->addDelivery($invoice, $order);
     }
     $invoice->setStatus(InvoiceInterface::STATUS_OPEN);
     $event = new InvoiceTransformEvent($invoice);
     $this->eventDispatcher->dispatch(TransformerEvents::POST_ORDER_TO_INVOICE_TRANSFORM, $event);
 }
开发者ID:saberyounis,项目名称:Sonata-Project,代码行数:40,代码来源:InvoiceTransformer.php


注:本文中的Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。