Issue #3055194 by catch, mikelutz, longwave, mkalkbrenner, hchonov: [Symfony 5] The signature of the "Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::dispatch()" method should be updated to "dispatch($event, string $eventName = null)", not doing so is deprecated since Symfony 4.3

merge-requests/2/head
Alex Pott 2020-07-14 10:08:00 +01:00
parent 065f4812be
commit bd4c5f075f
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
31 changed files with 100 additions and 77 deletions

View File

@ -6,6 +6,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Contracts\EventDispatcher\Event as ContractsEvent;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface;
/**
* A performance optimized container aware event dispatcher.
@ -86,9 +88,19 @@ class ContainerAwareEventDispatcher implements EventDispatcherInterface {
/**
* {@inheritdoc}
*/
public function dispatch($event_name, Event $event = NULL) {
if ($event === NULL) {
$event = new Event();
public function dispatch($event/*, string $event_name = NULL*/) {
$event_name = 1 < \func_num_args() ? func_get_arg(1) : NULL;
if (\is_object($event)) {
$event_name = $event_name ?? \get_class($event);
}
elseif (\is_string($event) && (NULL === $event_name || $event_name instanceof ContractsEvent || $event_name instanceof Event)) {
@trigger_error('Calling the Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch() method with a string event name as the first argument is deprecated in drupal:9.1.0, an Event object will be required instead in drupal:10.0.0. See https://www.drupal.org/node/3154407', E_USER_DEPRECATED);
$swap = $event;
$event = $event_name ?? new Event();
$event_name = $swap;
}
else {
throw new \TypeError(sprintf('Argument 1 passed to "%s::dispatch()" must be an object, %s given.', ContractsEventDispatcherInterface::class, \gettype($event)));
}
if (isset($this->listeners[$event_name])) {

View File

@ -7,7 +7,8 @@
"require": {
"php": ">=7.3.0",
"symfony/dependency-injection": "^4.4",
"symfony/event-dispatcher": "^4.4"
"symfony/event-dispatcher": "^4.4",
"symfony/event-dispatcher-contracts": "^1.1"
},
"autoload": {
"psr-4": {

View File

@ -228,7 +228,7 @@ class Config extends StorableConfigBase {
Cache::invalidateTags($this->getCacheTags());
}
$this->isNew = FALSE;
$this->eventDispatcher->dispatch(ConfigEvents::SAVE, new ConfigCrudEvent($this));
$this->eventDispatcher->dispatch(new ConfigCrudEvent($this), ConfigEvents::SAVE);
$this->originalData = $this->data;
return $this;
}
@ -245,7 +245,7 @@ class Config extends StorableConfigBase {
Cache::invalidateTags($this->getCacheTags());
$this->isNew = TRUE;
$this->resetOverriddenData();
$this->eventDispatcher->dispatch(ConfigEvents::DELETE, new ConfigCrudEvent($this));
$this->eventDispatcher->dispatch(new ConfigCrudEvent($this), ConfigEvents::DELETE);
$this->originalData = $this->data;
return $this;
}

View File

@ -260,7 +260,7 @@ class ConfigFactory implements ConfigFactoryInterface, EventSubscriberInterface
// Prime the cache and load the configuration with the correct overrides.
$config = $this->get($new_name);
$this->eventDispatcher->dispatch(ConfigEvents::RENAME, new ConfigRenameEvent($config, $old_name));
$this->eventDispatcher->dispatch(new ConfigRenameEvent($config, $old_name), ConfigEvents::RENAME);
return $this;
}

View File

@ -640,7 +640,7 @@ class ConfigImporter {
if (!empty($missing_content)) {
$event = new MissingContentEvent($missing_content);
// Fire an event to allow listeners to create the missing content.
$this->eventDispatcher->dispatch(ConfigEvents::IMPORT_MISSING_CONTENT, $event);
$this->eventDispatcher->dispatch($event, ConfigEvents::IMPORT_MISSING_CONTENT);
$sandbox['missing_content']['data'] = $event->getMissingContent();
}
$current_count = count($sandbox['missing_content']['data']);
@ -660,7 +660,7 @@ class ConfigImporter {
* The batch context.
*/
protected function finish(&$context) {
$this->eventDispatcher->dispatch(ConfigEvents::IMPORT, new ConfigImporterEvent($this));
$this->eventDispatcher->dispatch(new ConfigImporterEvent($this), ConfigEvents::IMPORT);
// The import is now complete.
$this->lock->release(static::LOCK_NAME);
$this->reset();
@ -742,7 +742,7 @@ class ConfigImporter {
$this->logError($this->t('Rename operation for simple configuration. Existing configuration @old_name and staged configuration @new_name.', ['@old_name' => $names['old_name'], '@new_name' => $names['new_name']]));
}
}
$this->eventDispatcher->dispatch(ConfigEvents::IMPORT_VALIDATE, new ConfigImporterEvent($this));
$this->eventDispatcher->dispatch(new ConfigImporterEvent($this), ConfigEvents::IMPORT_VALIDATE);
if (count($this->getErrors())) {
$errors = array_merge(['There were errors validating the config synchronization.'], $this->getErrors());
throw new ConfigImporterException(implode(PHP_EOL, $errors));

View File

@ -378,7 +378,7 @@ class ConfigManager implements ConfigManagerInterface {
public function getConfigCollectionInfo() {
if (!isset($this->configCollectionInfo)) {
$this->configCollectionInfo = new ConfigCollectionInfo();
$this->eventDispatcher->dispatch(ConfigEvents::COLLECTION_INFO, $this->configCollectionInfo);
$this->eventDispatcher->dispatch($this->configCollectionInfo, ConfigEvents::COLLECTION_INFO);
}
return $this->configCollectionInfo;
}

View File

@ -85,7 +85,7 @@ final class ExportStorageManager implements StorageManagerInterface {
}
self::replaceStorageContents($this->active, $this->storage);
$this->eventDispatcher->dispatch(ConfigEvents::STORAGE_TRANSFORM_EXPORT, new StorageTransformEvent($this->storage));
$this->eventDispatcher->dispatch(new StorageTransformEvent($this->storage), ConfigEvents::STORAGE_TRANSFORM_EXPORT);
return new ReadOnlyStorage($this->storage);
}

View File

@ -117,7 +117,7 @@ final class ImportStorageTransformer {
self::replaceStorageContents($storage, $mutable);
// Dispatch the event so that event listeners can alter the configuration.
$this->eventDispatcher->dispatch(ConfigEvents::STORAGE_TRANSFORM_IMPORT, new StorageTransformEvent($mutable));
$this->eventDispatcher->dispatch(new StorageTransformEvent($mutable), ConfigEvents::STORAGE_TRANSFORM_IMPORT);
// Return the storage with the altered configuration.
return $mutable;

View File

@ -4,6 +4,7 @@ namespace Drupal\Core;
use Composer\Autoload\ClassLoader;
use Drupal\Component\Assertion\Handle;
use Symfony\Component\EventDispatcher\Event;
use Drupal\Component\FileCache\FileCacheFactory;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Cache\DatabaseBackend;
@ -952,7 +953,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
// Allow other parts of the codebase to react on container initialization in
// subrequest.
if (!empty($subrequest)) {
$this->container->get('event_dispatcher')->dispatch(self::CONTAINER_INITIALIZE_SUBREQUEST_FINISHED);
$this->container->get('event_dispatcher')->dispatch(new Event(), self::CONTAINER_INITIALIZE_SUBREQUEST_FINISHED);
}
// If needs dumping flag was set, dump the container.

View File

@ -76,7 +76,7 @@ class EntityTypeListener implements EntityTypeListenerInterface {
$this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinitions($entity_type_id, $this->entityFieldManager->getFieldStorageDefinitions($entity_type_id));
}
$this->eventDispatcher->dispatch(EntityTypeEvents::CREATE, new EntityTypeEvent($entity_type));
$this->eventDispatcher->dispatch(new EntityTypeEvent($entity_type), EntityTypeEvents::CREATE);
$this->clearCachedDefinitions();
}
@ -98,7 +98,7 @@ class EntityTypeListener implements EntityTypeListenerInterface {
$this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinitions($entity_type_id, $field_storage_definitions);
}
$this->eventDispatcher->dispatch(EntityTypeEvents::CREATE, new EntityTypeEvent($entity_type));
$this->eventDispatcher->dispatch(new EntityTypeEvent($entity_type), EntityTypeEvents::CREATE);
$this->clearCachedDefinitions();
}
@ -119,7 +119,7 @@ class EntityTypeListener implements EntityTypeListenerInterface {
$this->entityLastInstalledSchemaRepository->setLastInstalledDefinition($entity_type);
$this->eventDispatcher->dispatch(EntityTypeEvents::UPDATE, new EntityTypeEvent($entity_type, $original));
$this->eventDispatcher->dispatch(new EntityTypeEvent($entity_type, $original), EntityTypeEvents::UPDATE);
$this->clearCachedDefinitions();
}
@ -142,7 +142,7 @@ class EntityTypeListener implements EntityTypeListenerInterface {
$this->entityLastInstalledSchemaRepository->deleteLastInstalledDefinition($entity_type_id);
$this->eventDispatcher->dispatch(EntityTypeEvents::DELETE, new EntityTypeEvent($entity_type));
$this->eventDispatcher->dispatch(new EntityTypeEvent($entity_type), EntityTypeEvents::DELETE);
$this->clearCachedDefinitions();
}
@ -165,7 +165,7 @@ class EntityTypeListener implements EntityTypeListenerInterface {
$this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinitions($entity_type_id, $field_storage_definitions);
}
$this->eventDispatcher->dispatch(EntityTypeEvents::UPDATE, new EntityTypeEvent($entity_type, $original));
$this->eventDispatcher->dispatch(new EntityTypeEvent($entity_type, $original), EntityTypeEvents::UPDATE);
$this->clearCachedDefinitions();
}
}

View File

@ -87,7 +87,7 @@ class FieldStorageDefinitionListener implements FieldStorageDefinitionListenerIn
$this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinition($storage_definition);
$this->eventDispatcher->dispatch(FieldStorageDefinitionEvents::CREATE, new FieldStorageDefinitionEvent($storage_definition));
$this->eventDispatcher->dispatch(new FieldStorageDefinitionEvent($storage_definition), FieldStorageDefinitionEvents::CREATE);
$this->entityFieldManager->clearCachedFieldDefinitions();
}
@ -106,7 +106,7 @@ class FieldStorageDefinitionListener implements FieldStorageDefinitionListenerIn
$this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinition($storage_definition);
$this->eventDispatcher->dispatch(FieldStorageDefinitionEvents::UPDATE, new FieldStorageDefinitionEvent($storage_definition, $original));
$this->eventDispatcher->dispatch(new FieldStorageDefinitionEvent($storage_definition, $original), FieldStorageDefinitionEvents::UPDATE);
$this->entityFieldManager->clearCachedFieldDefinitions();
}
@ -135,7 +135,7 @@ class FieldStorageDefinitionListener implements FieldStorageDefinitionListenerIn
$this->entityLastInstalledSchemaRepository->deleteLastInstalledFieldStorageDefinition($storage_definition);
$this->eventDispatcher->dispatch(FieldStorageDefinitionEvents::DELETE, new FieldStorageDefinitionEvent($storage_definition));
$this->eventDispatcher->dispatch(new FieldStorageDefinitionEvent($storage_definition), FieldStorageDefinitionEvents::DELETE);
$this->entityFieldManager->clearCachedFieldDefinitions();
}

View File

@ -206,7 +206,7 @@ class HtmlRenderer implements MainContentRendererInterface {
// Select the page display variant to be used to render this main content,
// default to the built-in "simple page".
$event = new PageDisplayVariantSelectionEvent('simple_page', $route_match);
$this->eventDispatcher->dispatch(RenderEvents::SELECT_PAGE_DISPLAY_VARIANT, $event);
$this->eventDispatcher->dispatch($event, RenderEvents::SELECT_PAGE_DISPLAY_VARIANT);
$variant_id = $event->getPluginId();
// We must render the main content now already, because it might provide a

View File

@ -181,12 +181,12 @@ class RouteBuilder implements RouteBuilderInterface, DestructableInterface {
// DYNAMIC is supposed to be used to add new routes based upon all the
// static defined ones.
$this->dispatcher->dispatch(RoutingEvents::DYNAMIC, new RouteBuildEvent($collection));
$this->dispatcher->dispatch(new RouteBuildEvent($collection), RoutingEvents::DYNAMIC);
// ALTER is the final step to alter all the existing routes. We cannot stop
// people from adding new routes here, but we define two separate steps to
// make it clear.
$this->dispatcher->dispatch(RoutingEvents::ALTER, new RouteBuildEvent($collection));
$this->dispatcher->dispatch(new RouteBuildEvent($collection), RoutingEvents::ALTER);
$this->checkProvider->setChecks($collection);
@ -194,7 +194,7 @@ class RouteBuilder implements RouteBuilderInterface, DestructableInterface {
$this->dumper->dump();
$this->lock->release('router_rebuild');
$this->dispatcher->dispatch(RoutingEvents::FINISHED, new Event());
$this->dispatcher->dispatch(new Event(), RoutingEvents::FINISHED);
$this->building = FALSE;
$this->rebuildNeeded = FALSE;

View File

@ -62,7 +62,7 @@ class AccountProxy implements AccountProxyInterface {
}
$this->account = $account;
$this->id = $account->id();
$this->eventDispatcher->dispatch(AccountEvents::SET_USER, new AccountSetEvent($account));
$this->eventDispatcher->dispatch(new AccountSetEvent($account), AccountEvents::SET_USER);
}
/**

View File

@ -649,7 +649,7 @@ EOF;
assert($request_type === HttpKernelInterface::MASTER_REQUEST || $request_type === HttpKernelInterface::SUB_REQUEST);
$this->requestStack->push($request);
$event = new ResponseEvent($this->httpKernel, $request, $request_type, $response);
$this->eventDispatcher->dispatch(KernelEvents::RESPONSE, $event);
$this->eventDispatcher->dispatch($event, KernelEvents::RESPONSE);
$filtered_response = $event->getResponse();
$this->requestStack->pop();
return $filtered_response;

View File

@ -73,7 +73,7 @@ class BlockContentAccessControlHandler extends EntityAccessControlHandler implem
if (empty($dependency)) {
// If an access dependency has not been set let modules set one.
$event = new BlockContentGetDependencyEvent($entity);
$this->eventDispatcher->dispatch(BlockContentEvents::BLOCK_CONTENT_GET_DEPENDENCY, $event);
$this->eventDispatcher->dispatch($event, BlockContentEvents::BLOCK_CONTENT_GET_DEPENDENCY);
$dependency = $event->getAccessDependency();
if (empty($dependency)) {
return AccessResult::forbidden("Non-reusable blocks must set an access dependency for access control.");

View File

@ -384,7 +384,7 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
$this->langcode = $route_match->getParameter('langcode');
$event = new ConfigMapperPopulateEvent($this, $route_match);
$this->eventDispatcher->dispatch(ConfigTranslationEvents::POPULATE_MAPPER, $event);
$this->eventDispatcher->dispatch($event, ConfigTranslationEvents::POPULATE_MAPPER);
}
/**

View File

@ -154,7 +154,7 @@ class ResourceTypeRepository implements ResourceTypeRepositoryInterface {
$fields = static::getFields($raw_fields, $entity_type, $bundle);
if (!$internalize_resource_type) {
$event = ResourceTypeBuildEvent::createFromEntityTypeAndBundle($entity_type, $bundle, $fields);
$this->eventDispatcher->dispatch(ResourceTypeBuildEvents::BUILD, $event);
$this->eventDispatcher->dispatch($event, ResourceTypeBuildEvents::BUILD);
$internalize_resource_type = $event->resourceTypeShouldBeDisabled();
$fields = $event->getFields();
}

View File

@ -62,7 +62,7 @@ class LanguageConfigOverride extends StorableConfigBase {
// an update of configuration, but only for a specific language.
Cache::invalidateTags($this->getCacheTags());
$this->isNew = FALSE;
$this->eventDispatcher->dispatch(LanguageConfigOverrideEvents::SAVE_OVERRIDE, new LanguageConfigOverrideCrudEvent($this));
$this->eventDispatcher->dispatch(new LanguageConfigOverrideCrudEvent($this), LanguageConfigOverrideEvents::SAVE_OVERRIDE);
$this->originalData = $this->data;
return $this;
}
@ -75,7 +75,7 @@ class LanguageConfigOverride extends StorableConfigBase {
$this->storage->delete($this->name);
Cache::invalidateTags($this->getCacheTags());
$this->isNew = TRUE;
$this->eventDispatcher->dispatch(LanguageConfigOverrideEvents::DELETE_OVERRIDE, new LanguageConfigOverrideCrudEvent($this));
$this->eventDispatcher->dispatch(new LanguageConfigOverrideCrudEvent($this), LanguageConfigOverrideEvents::DELETE_OVERRIDE);
$this->originalData = $this->data;
return $this;
}

View File

@ -87,7 +87,7 @@ class SectionComponent {
*/
public function toRenderArray(array $contexts = [], $in_preview = FALSE) {
$event = new SectionComponentBuildRenderArrayEvent($this, $contexts, $in_preview);
$this->eventDispatcher()->dispatch(LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY, $event);
$this->eventDispatcher()->dispatch($event, LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY);
$output = $event->getBuild();
$event->getCacheableMetadata()->applyTo($output);
return $output;

View File

@ -33,11 +33,11 @@ class SectionComponentTest extends UnitTestCase {
// Imitate an event subscriber by setting a resulting build on the event.
$event_dispatcher = $this->prophesize(EventDispatcherInterface::class);
$event_dispatcher
->dispatch(LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY, Argument::type(SectionComponentBuildRenderArrayEvent::class))
->dispatch(Argument::type(SectionComponentBuildRenderArrayEvent::class), LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY)
->shouldBeCalled()
->will(function ($args) {
/** @var \Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent $event */
$event = $args[1];
$event = $args[0];
$event->setBuild(['#markup' => $event->getPlugin()->getPluginId()]);
return;
});

View File

@ -1057,7 +1057,7 @@ function _locale_refresh_translations($langcodes, $lids = []) {
}
// Throw locale.save_translation event.
\Drupal::service('event_dispatcher')->dispatch(LocaleEvents::SAVE_TRANSLATION, new LocaleEvent($langcodes, $lids));
\Drupal::service('event_dispatcher')->dispatch(new LocaleEvent($langcodes, $lids), LocaleEvents::SAVE_TRANSLATION);
}
/**

View File

@ -157,7 +157,7 @@ class MigrateExecutable implements MigrateExecutableInterface {
]), 'error');
return MigrationInterface::RESULT_FAILED;
}
$this->getEventDispatcher()->dispatch(MigrateEvents::PRE_IMPORT, new MigrateImportEvent($this->migration, $this->message));
$this->getEventDispatcher()->dispatch(new MigrateImportEvent($this->migration, $this->message), MigrateEvents::PRE_IMPORT);
// Knock off migration if the requirements haven't been met.
try {
@ -220,11 +220,11 @@ class MigrateExecutable implements MigrateExecutableInterface {
if ($save) {
try {
$this->getEventDispatcher()->dispatch(MigrateEvents::PRE_ROW_SAVE, new MigratePreRowSaveEvent($this->migration, $this->message, $row));
$this->getEventDispatcher()->dispatch(new MigratePreRowSaveEvent($this->migration, $this->message, $row), MigrateEvents::PRE_ROW_SAVE);
$destination_ids = $id_map->lookupDestinationIds($this->sourceIdValues);
$destination_id_values = $destination_ids ? reset($destination_ids) : [];
$destination_id_values = $destination->import($row, $destination_id_values);
$this->getEventDispatcher()->dispatch(MigrateEvents::POST_ROW_SAVE, new MigratePostRowSaveEvent($this->migration, $this->message, $row, $destination_id_values));
$this->getEventDispatcher()->dispatch(new MigratePostRowSaveEvent($this->migration, $this->message, $row, $destination_id_values), MigrateEvents::POST_ROW_SAVE);
if ($destination_id_values) {
// We do not save an idMap entry for config.
if ($destination_id_values !== TRUE) {
@ -276,7 +276,7 @@ class MigrateExecutable implements MigrateExecutableInterface {
}
}
$this->getEventDispatcher()->dispatch(MigrateEvents::POST_IMPORT, new MigrateImportEvent($this->migration, $this->message));
$this->getEventDispatcher()->dispatch(new MigrateImportEvent($this->migration, $this->message), MigrateEvents::POST_IMPORT);
$this->migration->setStatus(MigrationInterface::STATUS_IDLE);
return $return;
}
@ -292,7 +292,7 @@ class MigrateExecutable implements MigrateExecutableInterface {
}
// Announce that rollback is about to happen.
$this->getEventDispatcher()->dispatch(MigrateEvents::PRE_ROLLBACK, new MigrateRollbackEvent($this->migration));
$this->getEventDispatcher()->dispatch(new MigrateRollbackEvent($this->migration), MigrateEvents::PRE_ROLLBACK);
// Optimistically assume things are going to work out; if not, $return will be
// updated to some other status.
@ -310,10 +310,10 @@ class MigrateExecutable implements MigrateExecutableInterface {
$map_row = $id_map->getRowByDestination($destination_key);
if ($map_row['rollback_action'] == MigrateIdMapInterface::ROLLBACK_DELETE) {
$this->getEventDispatcher()
->dispatch(MigrateEvents::PRE_ROW_DELETE, new MigrateRowDeleteEvent($this->migration, $destination_key));
->dispatch(new MigrateRowDeleteEvent($this->migration, $destination_key), MigrateEvents::PRE_ROW_DELETE);
$destination->rollback($destination_key);
$this->getEventDispatcher()
->dispatch(MigrateEvents::POST_ROW_DELETE, new MigrateRowDeleteEvent($this->migration, $destination_key));
->dispatch(new MigrateRowDeleteEvent($this->migration, $destination_key), MigrateEvents::POST_ROW_DELETE);
}
// We're now done with this row, so remove it from the map.
$id_map->deleteDestination($destination_key);
@ -340,7 +340,7 @@ class MigrateExecutable implements MigrateExecutableInterface {
}
// Notify modules that rollback attempt was complete.
$this->getEventDispatcher()->dispatch(MigrateEvents::POST_ROLLBACK, new MigrateRollbackEvent($this->migration));
$this->getEventDispatcher()->dispatch(new MigrateRollbackEvent($this->migration), MigrateEvents::POST_ROLLBACK);
$this->migration->setStatus(MigrationInterface::STATUS_IDLE);
return $return;

View File

@ -645,7 +645,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
}
$keys = [$this::SOURCE_IDS_HASH => $this->getSourceIdsHash($source_id_values)];
// Notify anyone listening of the map row we're about to save.
$this->eventDispatcher->dispatch(MigrateEvents::MAP_SAVE, new MigrateMapSaveEvent($this, $fields));
$this->eventDispatcher->dispatch(new MigrateMapSaveEvent($this, $fields), MigrateEvents::MAP_SAVE);
$this->getDatabase()->merge($this->mapTableName())
->key($keys)
->fields($fields)
@ -670,8 +670,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
->execute();
// Notify anyone listening of the message we've saved.
$this->eventDispatcher->dispatch(MigrateEvents::IDMAP_MESSAGE,
new MigrateIdMapMessageEvent($this->migration, $source_id_values, $message, $level));
$this->eventDispatcher->dispatch(new MigrateIdMapMessageEvent($this->migration, $source_id_values, $message, $level), MigrateEvents::IDMAP_MESSAGE);
}
/**
@ -785,7 +784,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
$map_query = $this->getDatabase()->delete($this->mapTableName());
$map_query->condition($this::SOURCE_IDS_HASH, $this->getSourceIdsHash($source_id_values));
// Notify anyone listening of the map row we're about to delete.
$this->eventDispatcher->dispatch(MigrateEvents::MAP_DELETE, new MigrateMapDeleteEvent($this, $source_id_values));
$this->eventDispatcher->dispatch(new MigrateMapDeleteEvent($this, $source_id_values), MigrateEvents::MAP_DELETE);
$map_query->execute();
}
$message_query = $this->getDatabase()->delete($this->messageTableName());
@ -805,7 +804,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
$map_query->condition($destination_id, $destination_id_values[$field_name]);
}
// Notify anyone listening of the map row we're about to delete.
$this->eventDispatcher->dispatch(MigrateEvents::MAP_DELETE, new MigrateMapDeleteEvent($this, $source_id_values));
$this->eventDispatcher->dispatch(new MigrateMapDeleteEvent($this, $source_id_values), MigrateEvents::MAP_DELETE);
$map_query->execute();
$message_query->condition($this::SOURCE_IDS_HASH, $this->getSourceIdsHash($source_id_values));

View File

@ -45,7 +45,7 @@ class TimezoneResolverTest extends KernelTestBase {
$eventDispatcher = $this->container->get('event_dispatcher');
$kernel = $this->container->get('kernel');
$eventDispatcher->dispatch(KernelEvents::REQUEST, new RequestEvent($kernel, Request::create('http://www.example.com'), HttpKernelInterface::MASTER_REQUEST));
$eventDispatcher->dispatch(new RequestEvent($kernel, Request::create('http://www.example.com'), HttpKernelInterface::MASTER_REQUEST, KernelEvents::REQUEST));
$this->assertEquals('Australia/Adelaide', date_default_timezone_get());

View File

@ -69,7 +69,7 @@ class UserFloodControl implements UserFloodControlInterface {
$identifier = $this->requestStack->getCurrentRequest()->getClientIp();
}
$event = new UserFloodEvent($name, $threshold, $window, $identifier);
$this->eventDispatcher->dispatch($event_map[$name], $event);
$this->eventDispatcher->dispatch($event, $event_map[$name]);
}
return FALSE;
}

View File

@ -107,7 +107,7 @@ class ViewsEntitySchemaSubscriberIntegrationTest extends ViewsKernelTestBase {
$this->assertTrue(isset($views['test_view_entity_test_additional_base_field']));
$event = new EntityTypeEvent($this->entityTypeManager->getDefinition('entity_test_update'));
$this->eventDispatcher->dispatch(EntityTypeEvents::DELETE, $event);
$this->eventDispatcher->dispatch($event, EntityTypeEvents::DELETE);
// We expect that views which use 'entity_test_update' as base tables are
// disabled.

View File

@ -110,7 +110,7 @@ class ContainerAwareEventDispatcherTest extends TestCase {
];
$dispatcher = new ContainerAwareEventDispatcher($container, $listeners);
$dispatcher->dispatch('test_event');
$dispatcher->dispatch(new Event(), 'test_event');
$this->assertTrue($thirdListener[0]->preFooInvoked);
}
@ -140,6 +140,18 @@ class ContainerAwareEventDispatcherTest extends TestCase {
$this->assertSame($expectedListeners, $actualListeners);
}
/**
* Tests argument order deprecation.
*
* @group legacy
* @expectedDeprecation Calling the Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch() method with a string event name as the first argument is deprecated in drupal:9.1.0, an Event object will be required instead in drupal:10.0.0. See https://www.drupal.org/node/3154407
*/
public function testDispatchArgumentOrderDeprecation() {
$container = new ContainerBuilder();
$dispatcher = new ContainerAwareEventDispatcher($container, []);
$dispatcher->dispatch('foo');
}
public function testDispatchWithServices() {
$container = new ContainerBuilder();
$container->register('listener_service', TestEventListener::class);
@ -154,7 +166,7 @@ class ContainerAwareEventDispatcherTest extends TestCase {
$dispatcher = new ContainerAwareEventDispatcher($container, $listeners);
$dispatcher->dispatch('test_event');
$dispatcher->dispatch(new Event(), 'test_event');
$listenerService = $container->get('listener_service');
$this->assertTrue($listenerService->preFooInvoked);
@ -183,7 +195,7 @@ class ContainerAwareEventDispatcherTest extends TestCase {
// listener service.
$this->assertFalse($container->initialized('other_listener_service'));
$dispatcher->dispatch('test_event');
$dispatcher->dispatch(new Event(), 'test_event');
$this->assertFalse($listenerService->preFooInvoked);
$otherService = $container->get('other_listener_service');
@ -287,13 +299,13 @@ class ContainerAwareEventDispatcherTest extends TestCase {
public function testDispatch() {
$this->dispatcher->addListener('pre.foo', [$this->listener, 'preFoo']);
$this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo']);
$this->dispatcher->dispatch(self::PREFOO);
$this->dispatcher->dispatch(new Event(), self::PREFOO);
$this->assertTrue($this->listener->preFooInvoked);
$this->assertFalse($this->listener->postFooInvoked);
$this->assertInstanceOf(Event::class, $this->dispatcher->dispatch('noevent'));
$this->assertInstanceOf(Event::class, $this->dispatcher->dispatch(self::PREFOO));
$this->assertInstanceOf(Event::class, $this->dispatcher->dispatch(new Event(), 'noevent'));
$this->assertInstanceOf(Event::class, $this->dispatcher->dispatch(new Event(), self::PREFOO));
$event = new Event();
$return = $this->dispatcher->dispatch(self::PREFOO, $event);
$return = $this->dispatcher->dispatch($event, self::PREFOO);
$this->assertSame($event, $return);
}
@ -304,7 +316,7 @@ class ContainerAwareEventDispatcherTest extends TestCase {
};
$this->dispatcher->addListener('pre.foo', $listener);
$this->dispatcher->addListener('post.foo', $listener);
$this->dispatcher->dispatch(self::PREFOO);
$this->dispatcher->dispatch(new Event(), self::PREFOO);
$this->assertEquals(1, $invoked);
}
@ -316,7 +328,7 @@ class ContainerAwareEventDispatcherTest extends TestCase {
// Manually set priority to enforce $this->listener to be called first
$this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo'], 10);
$this->dispatcher->addListener('post.foo', [$otherListener, 'postFoo']);
$this->dispatcher->dispatch(self::POSTFOO);
$this->dispatcher->dispatch(new Event(), self::POSTFOO);
$this->assertTrue($this->listener->postFooInvoked);
$this->assertFalse($otherListener->postFooInvoked);
}
@ -335,7 +347,7 @@ class ContainerAwareEventDispatcherTest extends TestCase {
$this->dispatcher->addListener('pre.foo', $listener1, -10);
$this->dispatcher->addListener('pre.foo', $listener2);
$this->dispatcher->addListener('pre.foo', $listener3, 10);
$this->dispatcher->dispatch(self::PREFOO);
$this->dispatcher->dispatch(new Event(), self::PREFOO);
$this->assertEquals(['3', '2', '1'], $invoked);
}
@ -409,7 +421,7 @@ class ContainerAwareEventDispatcherTest extends TestCase {
$this->dispatcher->addListener('test', [$listener, 'foo']);
$this->assertNull($listener->name);
$this->assertNull($listener->dispatcher);
$this->dispatcher->dispatch('test');
$this->dispatcher->dispatch(new Event(), 'test');
$this->assertEquals('test', $listener->name);
$this->assertSame($this->dispatcher, $listener->dispatcher);
}
@ -477,8 +489,8 @@ class ContainerAwareEventDispatcherTest extends TestCase {
};
$this->dispatcher->addListener('foo', [$factory, 'foo']);
$this->assertSame(0, $called);
$this->dispatcher->dispatch('foo', new Event());
$this->dispatcher->dispatch('foo', new Event());
$this->dispatcher->dispatch(new Event(), 'foo');
$this->dispatcher->dispatch(new Event(), 'foo');
$this->assertSame(1, $called);
}

View File

@ -84,7 +84,7 @@ class RedirectResponseSubscriberTest extends UnitTestCase {
$listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext);
$dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']);
$event = new ResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response);
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
$dispatcher->dispatch($event, KernelEvents::RESPONSE);
$target_url = $event->getResponse()->getTargetUrl();
if ($expected) {
@ -125,7 +125,7 @@ class RedirectResponseSubscriberTest extends UnitTestCase {
$dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']);
$event = new ResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response);
$this->expectException(Error::class);
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
$dispatcher->dispatch($event, KernelEvents::RESPONSE);
}
/**
@ -141,7 +141,7 @@ class RedirectResponseSubscriberTest extends UnitTestCase {
$listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext);
$dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']);
$event = new ResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response);
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
$dispatcher->dispatch($event, KernelEvents::RESPONSE);
$target_url = $event->getResponse()->getTargetUrl();
$this->assertEquals('http://external-url.com', $target_url);
@ -173,7 +173,7 @@ class RedirectResponseSubscriberTest extends UnitTestCase {
$dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']);
$event = new ResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response);
$this->expectException(Error::class);
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
$dispatcher->dispatch($event, KernelEvents::RESPONSE);
}
/**

View File

@ -161,11 +161,11 @@ class RouteBuilderTest extends UnitTestCase {
// Ensure that the alter routes events are fired.
$this->dispatcher->expects($this->at(0))
->method('dispatch')
->with(RoutingEvents::DYNAMIC, $route_build_event);
->with($route_build_event, RoutingEvents::DYNAMIC);
$this->dispatcher->expects($this->at(1))
->method('dispatch')
->with(RoutingEvents::ALTER, $route_build_event);
->with($route_build_event, RoutingEvents::ALTER);
// Ensure that access checks are set.
$this->checkProvider->expects($this->once())
@ -231,11 +231,11 @@ class RouteBuilderTest extends UnitTestCase {
// Ensure that the alter routes events are fired.
$this->dispatcher->expects($this->at(0))
->method('dispatch')
->with(RoutingEvents::DYNAMIC, $route_build_event);
->with($route_build_event, RoutingEvents::DYNAMIC);
$this->dispatcher->expects($this->at(1))
->method('dispatch')
->with(RoutingEvents::ALTER, $route_build_event);
->with($route_build_event, RoutingEvents::ALTER);
// Ensure that access checks are set.
$this->checkProvider->expects($this->once())
@ -314,7 +314,7 @@ class RouteBuilderTest extends UnitTestCase {
$route_build_event = new RouteBuildEvent($route_collection_filled);
$this->dispatcher->expects($this->at(0))
->method('dispatch')
->with(RoutingEvents::DYNAMIC, $route_build_event);
->with($route_build_event, RoutingEvents::DYNAMIC);
$this->assertTrue($this->routeBuilder->rebuild());
}

View File

@ -149,8 +149,6 @@ trait DeprecationListenerTrait {
'The "Drupal\Core\File\MimeType\MimeTypeGuesser" class implements "Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface" that is deprecated since Symfony 4.3, use {@link MimeTypesInterface} instead.',
'The "Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser" class is deprecated since Symfony 4.3, use "Symfony\Component\Mime\FileBinaryMimeTypeGuesser" instead.',
'The "Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser" class is deprecated since Symfony 4.3, use "Symfony\Component\Mime\FileinfoMimeTypeGuesser" instead.',
'The signature of the "Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::dispatch()" method should be updated to "dispatch($event, string $eventName = null)", not doing so is deprecated since Symfony 4.3.',
'Calling the "Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch()" method with the event name as the first argument is deprecated since Symfony 4.3, pass it as the second argument and provide the event object as the first argument instead.',
'The "Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::dispatch()" method will require a new "string|null $eventName" argument in the next major version of its interface "Symfony\Contracts\EventDispatcher\EventDispatcherInterface", not defining it is deprecated.',
'The "Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::dispatch()" method will require a new "string|null $eventName" argument in the next major version of its parent class "Symfony\Contracts\EventDispatcher\EventDispatcherInterface", not defining it is deprecated.',
'Passing a command as string when creating a "Symfony\Component\Process\Process" instance is deprecated since Symfony 4.2, pass it as an array of its arguments instead, or use the "Process::fromShellCommandline()" constructor if you need features provided by the shell.',