Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[EventDispatcher] Removed deprecated code #41358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,18 @@
class AddEventAliasesPass implements CompilerPassInterface
{
private $eventAliases;
private $eventAliasesParameter;

public function __construct(array $eventAliases, string $eventAliasesParameter = 'event_dispatcher.event_aliases')
public function __construct(array $eventAliases)
{
if (1 < \func_num_args()) {
trigger_deprecation('symfony/event-dispatcher', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
}

$this->eventAliases = $eventAliases;
$this->eventAliasesParameter = $eventAliasesParameter;
}

public function process(ContainerBuilder $container): void
{
$eventAliases = $container->hasParameter($this->eventAliasesParameter) ? $container->getParameter($this->eventAliasesParameter) : [];
$eventAliases = $container->hasParameter('event_dispatcher.event_aliases') ? $container->getParameter('event_dispatcher.event_aliases') : [];

$container->setParameter(
$this->eventAliasesParameter,
'event_dispatcher.event_aliases',
array_merge($eventAliases, $this->eventAliases)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,11 @@
*/
class RegisterListenersPass implements CompilerPassInterface
{
protected $dispatcherService;
protected $listenerTag;
protected $subscriberTag;
protected $eventAliasesParameter;

private $hotPathEvents = [];
private $hotPathTagName;
private $noPreloadEvents = [];
private $noPreloadTagName;

public function __construct(string $dispatcherService = 'event_dispatcher', string $listenerTag = 'kernel.event_listener', string $subscriberTag = 'kernel.event_subscriber', string $eventAliasesParameter = 'event_dispatcher.event_aliases')
{
if (0 < \func_num_args()) {
trigger_deprecation('symfony/event-dispatcher', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
}

$this->dispatcherService = $dispatcherService;
$this->listenerTag = $listenerTag;
$this->subscriberTag = $subscriberTag;
$this->eventAliasesParameter = $eventAliasesParameter;
}

/**
* @return $this
*/
Expand All @@ -71,26 +54,26 @@ public function setNoPreloadEvents(array $noPreloadEvents, string $tagName = 'co

public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition($this->dispatcherService) && !$container->hasAlias($this->dispatcherService)) {
if (!$container->hasDefinition('event_dispatcher') && !$container->hasAlias('event_dispatcher')) {
return;
}

$aliases = [];

if ($container->hasParameter($this->eventAliasesParameter)) {
$aliases = $container->getParameter($this->eventAliasesParameter);
if ($container->hasParameter('event_dispatcher.event_aliases')) {
$aliases = $container->getParameter('event_dispatcher.event_aliases');
}

$globalDispatcherDefinition = $container->findDefinition($this->dispatcherService);
$globalDispatcherDefinition = $container->findDefinition('event_dispatcher');

foreach ($container->findTaggedServiceIds($this->listenerTag, true) as $id => $events) {
foreach ($container->findTaggedServiceIds('kernel.event_listener', true) as $id => $events) {
$noPreload = 0;

foreach ($events as $event) {
$priority = $event['priority'] ?? 0;

if (!isset($event['event'])) {
if ($container->getDefinition($id)->hasTag($this->subscriberTag)) {
if ($container->getDefinition($id)->hasTag('kernel.event_subscriber')) {
continue;
}

Expand Down Expand Up @@ -133,7 +116,7 @@ public function process(ContainerBuilder $container)

$extractingDispatcher = new ExtractingEventDispatcher();

foreach ($container->findTaggedServiceIds($this->subscriberTag, true) as $id => $tags) {
foreach ($container->findTaggedServiceIds('kernel.event_subscriber', true) as $id => $tags) {
$def = $container->getDefinition($id);

// We must assume that the class value has been correctly filled, even if the service is created by a factory
Expand Down Expand Up @@ -195,7 +178,7 @@ private function getEventFromTypeDeclaration(ContainerBuilder $container, string
|| $type->isBuiltin()
|| Event::class === ($name = $type->getName())
) {
throw new InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "%s" tags.', $id, $this->listenerTag));
throw new InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "kernel.event_listener" tags.', $id));
}

return $name;
Expand Down