本文整理汇总了PHP中Symfony\Component\EventDispatcher\EventDispatcherInterface类的典型用法代码示例。如果您正苦于以下问题:PHP EventDispatcherInterface类的具体用法?PHP EventDispatcherInterface怎么用?PHP EventDispatcherInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EventDispatcherInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bindRequestListeners
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']);
}
示例2: purlCheckNodeContext
/**
* 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;
}
}
}
}
示例3: onRequest
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);
}
示例4: collectRuntimeJavaScripts
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'] = [];
}
}
示例5: subscribe
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());
}
示例6: 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());
}
示例7: 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 = [];
}
示例8: visitResult
/**
* {@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);
}
示例9: matchAll
/**
* {@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;
}
示例10: 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());
}
示例11: 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;
}
示例12: dispatch
/**
* {@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.
}
示例13: saveAll
/**
* {@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));
}
示例14: 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;
}
示例15: 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;
}