stopPropagation example

'Ä Ö Ü Å Ø äöüåøhello',
      ],
    ];
  }

  /** * @covers ::stopPropagation */
  public function testStopPropagation() {
    $this->expectException(\RuntimeException::class);
    $event = new FileUploadSanitizeNameEvent('test.txt', '');
    $event->stopPropagation();
  }

}


    /** * Sets a response and stops event propagation. * * @return void */
    public function setResponse(Response $response)
    {
        $this->response = $response;

        $this->stopPropagation();
    }

    /** * Returns whether a response was set. */
    public function hasResponse(): bool
    {
        return null !== $this->response;
    }
}
$response ??= new Response())->setLastModified($lastModified);
            }

            if (null !== $cache->etag) {
                $etag = hash('sha256', $this->getExpressionLanguage()->evaluate($cache->etag, array_merge($request->attributes->all()$event->getNamedArguments())));
                ($response ??= new Response())->setEtag($etag);
            }
        }

        if ($response?->isNotModified($request)) {
            $event->setController(static fn () => $response);
            $event->stopPropagation();

            return;
        }

        if (null !== $etag) {
            $this->etags[$request] = $etag;
        }
        if (null !== $lastModified) {
            $this->lastModified[$request] = $lastModified;
        }
    }

    
$shopUserToken = 'sh0p-us3r-t0k3n';
        $shopSecret = 'sh0p-s3cr3t';
        $context = $this->createAdminStoreContext();

        $this->setFrwUserToken($context, 'frw-us3r-t0k3n');

        $this->addEventListener(
            $this->getContainer()->get('event_dispatcher'),
            FirstRunWizardFinishedEvent::class,
            function DFirstRunWizardFinishedEvent $event) use (&$dispatchedEvent): void {
                $dispatchedEvent = $event;
                $event->stopPropagation();
            },
            99999,
        );

        // Response for request of TrackEventClient::fireTrackingEvent()         $this->getRequestHandler()->append(new Response());

        // Response for request of FirstRunWizardClient::upgradeAccessToken()         $this->getFrwRequestHandler()->append(new Response(
            body: json_encode([
                'shopUserToken' => [
                    


    /** * Sets a response and stops event propagation. * * @return void */
    public function setResponse(Response $response)
    {
        $this->response = $response;

        $this->stopPropagation();
    }

    /** * Returns whether a response was set. */
    public function hasResponse(): bool
    {
        return null !== $this->response;
    }
}
final class LazyResponseEvent extends RequestEvent
{
    private parent $event;

    public function __construct(parent $event)
    {
        $this->event = $event;
    }

    public function setResponse(Response $response): never
    {
        $this->stopPropagation();
        $this->event->stopPropagation();

        throw new LazyResponseException($response);
    }

    public function getKernel(): HttpKernelInterface
    {
        return $this->event->getKernel();
    }

    public function getRequest(): Request
    {
/** * Listener methods. */
  public function preFoo(object $e) {
    $this->preFooInvoked = TRUE;
  }

  public function postFoo(Event $e) {
    $this->postFooInvoked = TRUE;

    $e->stopPropagation();
  }

}

class TestWithDispatcher {

  public $name;
  public $dispatcher;

  public function foo(Event $e$name$dispatcher) {
    $this->name = $name;
    
yield [['test_case' => 'CsrfFormLogin', 'root_config' => 'config.yml']];
        yield [['test_case' => 'CsrfFormLogin', 'root_config' => 'routes_as_path.yml']];
    }

    private function callInRequestContext(KernelBrowser $client, callable $callable): void
    {
        /** @var EventDispatcherInterface $eventDispatcher */
        $eventDispatcher = static::getContainer()->get(EventDispatcherInterface::class);
        $wrappedCallable = function DRequestEvent $event) use (&$callable) {
            $callable();
            $event->setResponse(new Response(''));
            $event->stopPropagation();
        };

        $eventDispatcher->addListener(KernelEvents::REQUEST, $wrappedCallable);
        try {
            $client->request('GET', '/'.uniqid('', true));
        } finally {
            $eventDispatcher->removeListener(KernelEvents::REQUEST, $wrappedCallable);
        }
    }
}
$section->appendComponent(new SectionComponent('fake-uuid', 'content', [
          'id' => 'static_block',
          'label' => 'Test static block title',
          'label_display' => 'visible',
          'provider' => 'fake_provider',
        ]));
        $section_storage->appendSection($section);
      }

      // Node 2: Stop event propagation.       if ($entity->id() === '2') {
        $event->stopPropagation();
      }
    }
  }

  /** * Subscriber to test acting after the LB subscriber. * * @param \Drupal\layout_builder\Event\PrepareLayoutEvent $event * The prepare layout event. */
  public function onAfterPrepareLayout(PrepareLayoutEvent $event) {
    
SystemConfigChangedEvent::class => 'onSystemConfigChanged',
        ];
    }

    public function onError(ExceptionEvent $event): void
    {
        $request = $event->getRequest();
        if ($this->kernelDebug) {
            return;
        }

        $event->stopPropagation();

        $salesChannelId = $request->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_ID, '');
        $domainId = $request->attributes->get(SalesChannelRequest::ATTRIBUTE_DOMAIN_ID, '');
        $languageId = $request->attributes->get(PlatformRequest::HEADER_LANGUAGE_ID, '');

        if (!$request->attributes->has(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_CONTEXT_OBJECT)) {
            // When no sales-channel context is resolved, we need to resolve it now.             $this->setSalesChannelContext($request);
        }

        $is404StatusCode = $event->getThrowable() instanceof HttpException && $event->getThrowable()->getStatusCode() === Response::HTTP_NOT_FOUND;

        
$response ??= new Response())->setLastModified($lastModified);
            }

            if (null !== $cache->etag) {
                $etag = hash('sha256', $this->getExpressionLanguage()->evaluate($cache->etag, array_merge($request->attributes->all()$event->getNamedArguments())));
                ($response ??= new Response())->setEtag($etag);
            }
        }

        if ($response?->isNotModified($request)) {
            $event->setController(static fn () => $response);
            $event->stopPropagation();

            return;
        }

        if (null !== $etag) {
            $this->etags[$request] = $etag;
        }
        if (null !== $lastModified) {
            $this->lastModified[$request] = $lastModified;
        }
    }

    
public function preFoo($e)
    {
        $this->preFooInvoked = true;
    }

    public function postFoo($e)
    {
        $this->postFooInvoked = true;

        if (!$this->preFooInvoked) {
            $e->stopPropagation();
        }
    }

    public function __invoke()
    {
    }
}

class TestWithDispatcher
{
    public ?string $name = null;
    

  public function onConfigImporterValidateNotEmpty(ConfigImporterEvent $event) {
    $importList = $event->getConfigImporter()->getStorageComparer()->getSourceStorage()->listAll();
    if (empty($importList)) {
      $event->getConfigImporter()->logError($this->t('This import is empty and if applied would delete all of your configuration, so has been rejected.'));
      $event->stopPropagation();
    }
  }

  /** * Checks that the configuration synchronization is valid. * * This event listener checks that the system.site:uuid's in the source and * target match. * * @param \Drupal\Core\Config\ConfigImporterEvent $event * The config import event. */

  public function onConfigImporterMissingContentOne(MissingContentEvent $event) {
    if ($this->state->get('config_import_test.config_import_missing_content', FALSE) && $this->state->get('config_import_test.config_import_missing_content_one', FALSE) === FALSE) {
      $missing = $event->getMissingContent();
      $uuid = key($missing);
      $this->state->set('config_import_test.config_import_missing_content_one', key($missing));
      $event->resolveMissingContent($uuid);
      // Stopping propagation ensures that onConfigImporterMissingContentTwo       // will be fired on the next batch step.       $event->stopPropagation();
    }
  }

  /** * Handles the missing content event. * * @param \Drupal\Core\Config\Importer\MissingContentEvent $event * The missing content event. */
  public function onConfigImporterMissingContentTwo(MissingContentEvent $event) {
    if ($this->state->get('config_import_test.config_import_missing_content', FALSE) && $this->state->get('config_import_test.config_import_missing_content_two', FALSE) === FALSE) {
      
$this->assertResponseStatusCodeSame(Response::HTTP_FORBIDDEN);
    }

    private function callInRequestContext(KernelBrowser $client, callable $callable): void
    {
        /** @var EventDispatcherInterface $eventDispatcher */
        $eventDispatcher = static::getContainer()->get(EventDispatcherInterface::class);
        $wrappedCallable = function DRequestEvent $event) use (&$callable) {
            $callable();
            $event->setResponse(new Response(''));
            $event->stopPropagation();
        };

        $eventDispatcher->addListener(KernelEvents::REQUEST, $wrappedCallable);
        try {
            $client->request('GET', '/'.uniqid('', true));
        } finally {
            $eventDispatcher->removeListener(KernelEvents::REQUEST, $wrappedCallable);
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.