Skip to content

Commit 28e6f6f

Browse files
committed
Move event alias mappings to their components.
1 parent d555112 commit 28e6f6f

File tree

11 files changed

+215
-65
lines changed

11 files changed

+215
-65
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/services.php

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
1515
use Symfony\Component\Config\Resource\SelfCheckingResourceChecker;
1616
use Symfony\Component\Config\ResourceCheckerConfigCacheFactory;
17-
use Symfony\Component\Console\Event\ConsoleCommandEvent;
18-
use Symfony\Component\Console\Event\ConsoleErrorEvent;
19-
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
17+
use Symfony\Component\Console\ConsoleEvents;
2018
use Symfony\Component\DependencyInjection\Config\ContainerParametersResourceChecker;
2119
use Symfony\Component\DependencyInjection\EnvVarProcessor;
2220
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBag;
@@ -26,70 +24,34 @@
2624
use Symfony\Component\EventDispatcher\EventDispatcher;
2725
use Symfony\Component\EventDispatcher\EventDispatcherInterface as EventDispatcherInterfaceComponentAlias;
2826
use Symfony\Component\Filesystem\Filesystem;
29-
use Symfony\Component\Form\Event\PostSetDataEvent;
30-
use Symfony\Component\Form\Event\PostSubmitEvent;
31-
use Symfony\Component\Form\Event\PreSetDataEvent;
32-
use Symfony\Component\Form\Event\PreSubmitEvent;
33-
use Symfony\Component\Form\Event\SubmitEvent;
27+
use Symfony\Component\Form\FormEvents;
3428
use Symfony\Component\HttpFoundation\RequestStack;
3529
use Symfony\Component\HttpFoundation\UrlHelper;
3630
use Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer;
3731
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate;
3832
use Symfony\Component\HttpKernel\Config\FileLocator;
3933
use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;
40-
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
41-
use Symfony\Component\HttpKernel\Event\ControllerEvent;
42-
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
43-
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
44-
use Symfony\Component\HttpKernel\Event\RequestEvent;
45-
use Symfony\Component\HttpKernel\Event\ResponseEvent;
46-
use Symfony\Component\HttpKernel\Event\TerminateEvent;
47-
use Symfony\Component\HttpKernel\Event\ViewEvent;
4834
use Symfony\Component\HttpKernel\EventListener\LocaleAwareListener;
4935
use Symfony\Component\HttpKernel\HttpCache\Store;
5036
use Symfony\Component\HttpKernel\HttpKernel;
5137
use Symfony\Component\HttpKernel\HttpKernelInterface;
38+
use Symfony\Component\HttpKernel\KernelEvents;
5239
use Symfony\Component\HttpKernel\KernelInterface;
5340
use Symfony\Component\HttpKernel\UriSigner;
5441
use Symfony\Component\String\LazyString;
5542
use Symfony\Component\String\Slugger\AsciiSlugger;
5643
use Symfony\Component\String\Slugger\SluggerInterface;
57-
use Symfony\Component\Workflow\Event\AnnounceEvent;
58-
use Symfony\Component\Workflow\Event\CompletedEvent;
59-
use Symfony\Component\Workflow\Event\EnteredEvent;
60-
use Symfony\Component\Workflow\Event\EnterEvent;
61-
use Symfony\Component\Workflow\Event\GuardEvent;
62-
use Symfony\Component\Workflow\Event\LeaveEvent;
63-
use Symfony\Component\Workflow\Event\TransitionEvent;
44+
use Symfony\Component\Workflow\WorkflowEvents;
6445
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
6546

6647
return static function (ContainerConfigurator $container) {
6748
// this parameter is used at compile time in RegisterListenersPass
68-
$container->parameters()->set('event_dispatcher.event_aliases', [
69-
ConsoleCommandEvent::class => 'console.command',
70-
ConsoleErrorEvent::class => 'console.error',
71-
ConsoleTerminateEvent::class => 'console.terminate',
72-
PreSubmitEvent::class => 'form.pre_submit',
73-
SubmitEvent::class => 'form.submit',
74-
PostSubmitEvent::class => 'form.post_submit',
75-
PreSetDataEvent::class => 'form.pre_set_data',
76-
PostSetDataEvent::class => 'form.post_set_data',
77-
ControllerArgumentsEvent::class => 'kernel.controller_arguments',
78-
ControllerEvent::class => 'kernel.controller',
79-
ResponseEvent::class => 'kernel.response',
80-
FinishRequestEvent::class => 'kernel.finish_request',
81-
RequestEvent::class => 'kernel.request',
82-
ViewEvent::class => 'kernel.view',
83-
ExceptionEvent::class => 'kernel.exception',
84-
TerminateEvent::class => 'kernel.terminate',
85-
GuardEvent::class => 'workflow.guard',
86-
LeaveEvent::class => 'workflow.leave',
87-
TransitionEvent::class => 'workflow.transition',
88-
EnterEvent::class => 'workflow.enter',
89-
EnteredEvent::class => 'workflow.entered',
90-
CompletedEvent::class => 'workflow.completed',
91-
AnnounceEvent::class => 'workflow.announce',
92-
]);
49+
$container->parameters()->set('event_dispatcher.event_aliases', array_merge(
50+
class_exists(ConsoleEvents::class) ? ConsoleEvents::ALIASES : [],
51+
class_exists(FormEvents::class) ? FormEvents::ALIASES : [],
52+
KernelEvents::ALIASES,
53+
class_exists(WorkflowEvents::class) ? WorkflowEvents::ALIASES : []
54+
));
9355

9456
$container->services()
9557

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636
"doctrine/cache": "~1.0",
3737
"symfony/asset": "^5.1",
3838
"symfony/browser-kit": "^4.4|^5.0",
39-
"symfony/console": "^4.4|^5.0",
39+
"symfony/console": "^5.2",
4040
"symfony/css-selector": "^4.4|^5.0",
4141
"symfony/dom-crawler": "^4.4|^5.0",
4242
"symfony/dotenv": "^5.1",
4343
"symfony/polyfill-intl-icu": "~1.0",
44-
"symfony/form": "^4.4|^5.0",
44+
"symfony/form": "^5.2",
4545
"symfony/expression-language": "^4.4|^5.0",
4646
"symfony/http-client": "^4.4|^5.0",
4747
"symfony/lock": "^4.4|^5.0",
@@ -58,7 +58,7 @@
5858
"symfony/translation": "^5.0",
5959
"symfony/twig-bundle": "^4.4|^5.0",
6060
"symfony/validator": "^4.4|^5.0",
61-
"symfony/workflow": "^4.4|^5.0",
61+
"symfony/workflow": "^5.2",
6262
"symfony/yaml": "^4.4|^5.0",
6363
"symfony/property-info": "^4.4|^5.0",
6464
"symfony/web-link": "^4.4|^5.0",
@@ -73,7 +73,7 @@
7373
"phpunit/phpunit": "<5.4.3",
7474
"symfony/asset": "<5.1",
7575
"symfony/browser-kit": "<4.4",
76-
"symfony/console": "<4.4",
76+
"symfony/console": "<5.2",
7777
"symfony/dotenv": "<5.1",
7878
"symfony/dom-crawler": "<4.4",
7979
"symfony/http-client": "<4.4",
@@ -90,7 +90,7 @@
9090
"symfony/twig-bundle": "<4.4",
9191
"symfony/validator": "<4.4",
9292
"symfony/web-profiler-bundle": "<4.4",
93-
"symfony/workflow": "<4.4"
93+
"symfony/workflow": "<5.2"
9494
},
9595
"suggest": {
9696
"ext-apcu": "For best performance of the system caches",

src/Symfony/Bundle/SecurityBundle/SecurityBundle.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@
3737
use Symfony\Component\EventDispatcher\DependencyInjection\AddEventAliasesPass;
3838
use Symfony\Component\HttpKernel\Bundle\Bundle;
3939
use Symfony\Component\Security\Core\AuthenticationEvents;
40-
use Symfony\Component\Security\Core\Event\AuthenticationFailureEvent;
41-
use Symfony\Component\Security\Core\Event\AuthenticationSuccessEvent;
42-
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
43-
use Symfony\Component\Security\Http\Event\SwitchUserEvent;
4440
use Symfony\Component\Security\Http\SecurityEvents;
4541

4642
/**
@@ -79,11 +75,9 @@ public function build(ContainerBuilder $container)
7975
// must be registered after RegisterListenersPass (in the FrameworkBundle)
8076
$container->addCompilerPass(new RegisterGlobalSecurityEventListenersPass(), PassConfig::TYPE_BEFORE_REMOVING, -200);
8177

82-
$container->addCompilerPass(new AddEventAliasesPass([
83-
AuthenticationSuccessEvent::class => AuthenticationEvents::AUTHENTICATION_SUCCESS,
84-
AuthenticationFailureEvent::class => AuthenticationEvents::AUTHENTICATION_FAILURE,
85-
InteractiveLoginEvent::class => SecurityEvents::INTERACTIVE_LOGIN,
86-
SwitchUserEvent::class => SecurityEvents::SWITCH_USER,
87-
]));
78+
$container->addCompilerPass(new AddEventAliasesPass(array_merge(
79+
AuthenticationEvents::ALIASES,
80+
SecurityEvents::ALIASES
81+
)));
8882
}
8983
}

src/Symfony/Bundle/SecurityBundle/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
"symfony/event-dispatcher": "^5.1",
2424
"symfony/http-kernel": "^5.0",
2525
"symfony/polyfill-php80": "^1.15",
26-
"symfony/security-core": "^5.1",
26+
"symfony/security-core": "^5.2",
2727
"symfony/security-csrf": "^4.4|^5.0",
2828
"symfony/security-guard": "^5.1",
29-
"symfony/security-http": "^5.1,>=5.1.2"
29+
"symfony/security-http": "^5.2"
3030
},
3131
"require-dev": {
3232
"doctrine/doctrine-bundle": "^2.0",

src/Symfony/Component/Console/ConsoleEvents.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
namespace Symfony\Component\Console;
1313

14+
use Symfony\Component\Console\Event\ConsoleCommandEvent;
15+
use Symfony\Component\Console\Event\ConsoleErrorEvent;
16+
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
17+
1418
/**
1519
* Contains all events dispatched by an Application.
1620
*
@@ -44,4 +48,15 @@ final class ConsoleEvents
4448
* @Event("Symfony\Component\Console\Event\ConsoleErrorEvent")
4549
*/
4650
const ERROR = 'console.error';
51+
52+
/**
53+
* Event aliases.
54+
*
55+
* These aliases can be consumed by RegisterListenersPass.
56+
*/
57+
const ALIASES = [
58+
ConsoleCommandEvent::class => self::COMMAND,
59+
ConsoleErrorEvent::class => self::ERROR,
60+
ConsoleTerminateEvent::class => self::TERMINATE,
61+
];
4762
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Console\Tests;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Console\Application;
16+
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\Console\ConsoleEvents;
18+
use Symfony\Component\Console\Event\ConsoleCommandEvent;
19+
use Symfony\Component\Console\Event\ConsoleErrorEvent;
20+
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
21+
use Symfony\Component\Console\Input\InputInterface;
22+
use Symfony\Component\Console\Output\OutputInterface;
23+
use Symfony\Component\Console\Tester\ApplicationTester;
24+
use Symfony\Component\DependencyInjection\ContainerBuilder;
25+
use Symfony\Component\DependencyInjection\Reference;
26+
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
27+
use Symfony\Component\EventDispatcher\EventDispatcher;
28+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
29+
30+
class ConsoleEventsTest extends TestCase
31+
{
32+
public function testEventAliases()
33+
{
34+
$container = new ContainerBuilder();
35+
$container->setParameter('event_dispatcher.event_aliases', ConsoleEvents::ALIASES);
36+
$container->addCompilerPass(new RegisterListenersPass());
37+
38+
$container->register('event_dispatcher', EventDispatcher::class);
39+
$container->register('tracer', EventTraceSubscriber::class)
40+
->setPublic(true)
41+
->addTag('kernel.event_subscriber');
42+
$container->register('failing_command', FailingCommand::class);
43+
$container->register('application', Application::class)
44+
->setPublic(true)
45+
->addMethodCall('setAutoExit', [false])
46+
->addMethodCall('setDispatcher', [new Reference('event_dispatcher')])
47+
->addMethodCall('add', [new Reference('failing_command')])
48+
;
49+
50+
$container->compile();
51+
52+
$tester = new ApplicationTester($container->get('application'));
53+
$tester->run(['fail']);
54+
55+
$this->assertSame([ConsoleCommandEvent::class, ConsoleErrorEvent::class, ConsoleTerminateEvent::class], $container->get('tracer')->observedEvents);
56+
}
57+
}
58+
59+
class EventTraceSubscriber implements EventSubscriberInterface
60+
{
61+
public $observedEvents = [];
62+
63+
public static function getSubscribedEvents(): array
64+
{
65+
return [
66+
ConsoleCommandEvent::class => 'observe',
67+
ConsoleErrorEvent::class => 'observe',
68+
ConsoleTerminateEvent::class => 'observe',
69+
];
70+
}
71+
72+
public function observe(object $event): void
73+
{
74+
$this->observedEvents[] = get_debug_type($event);
75+
}
76+
}
77+
78+
class FailingCommand extends Command
79+
{
80+
protected static $defaultName = 'fail';
81+
82+
protected function execute(InputInterface $input, OutputInterface $output): int
83+
{
84+
throw new \RuntimeException('I failed. Sorry.');
85+
}
86+
}

src/Symfony/Component/Form/FormEvents.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111

1212
namespace Symfony\Component\Form;
1313

14+
use Symfony\Component\Form\Event\PostSetDataEvent;
15+
use Symfony\Component\Form\Event\PostSubmitEvent;
16+
use Symfony\Component\Form\Event\PreSetDataEvent;
17+
use Symfony\Component\Form\Event\PreSubmitEvent;
18+
use Symfony\Component\Form\Event\SubmitEvent;
19+
1420
/**
1521
* To learn more about how form events work check the documentation
1622
* entry at {@link https://symfony.com/doc/any/components/form/form_events.html}.
@@ -88,6 +94,19 @@ final class FormEvents
8894
*/
8995
const POST_SET_DATA = 'form.post_set_data';
9096

97+
/**
98+
* Event aliases.
99+
*
100+
* These aliases can be consumed by RegisterListenersPass.
101+
*/
102+
const ALIASES = [
103+
PreSubmitEvent::class => self::PRE_SUBMIT,
104+
SubmitEvent::class => self::SUBMIT,
105+
PostSubmitEvent::class => self::POST_SUBMIT,
106+
PreSetDataEvent::class => self::PRE_SET_DATA,
107+
PostSetDataEvent::class => self::POST_SET_DATA,
108+
];
109+
91110
private function __construct()
92111
{
93112
}

src/Symfony/Component/HttpKernel/KernelEvents.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111

1212
namespace Symfony\Component\HttpKernel;
1313

14+
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
15+
use Symfony\Component\HttpKernel\Event\ControllerEvent;
16+
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
17+
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
18+
use Symfony\Component\HttpKernel\Event\RequestEvent;
19+
use Symfony\Component\HttpKernel\Event\ResponseEvent;
20+
use Symfony\Component\HttpKernel\Event\TerminateEvent;
21+
use Symfony\Component\HttpKernel\Event\ViewEvent;
22+
1423
/**
1524
* Contains all events thrown in the HttpKernel component.
1625
*
@@ -100,4 +109,20 @@ final class KernelEvents
100109
* @Event("Symfony\Component\HttpKernel\Event\TerminateEvent")
101110
*/
102111
const TERMINATE = 'kernel.terminate';
112+
113+
/**
114+
* Event aliases.
115+
*
116+
* These aliases can be consumed by RegisterListenersPass.
117+
*/
118+
const ALIASES = [
119+
ControllerArgumentsEvent::class => self::CONTROLLER_ARGUMENTS,
120+
ControllerEvent::class => self::CONTROLLER,
121+
ResponseEvent::class => self::RESPONSE,
122+
FinishRequestEvent::class => self::FINISH_REQUEST,
123+
RequestEvent::class => self::REQUEST,
124+
ViewEvent::class => self::VIEW,
125+
ExceptionEvent::class => self::EXCEPTION,
126+
TerminateEvent::class => self::TERMINATE,
127+
];
103128
}

src/Symfony/Component/Security/Core/AuthenticationEvents.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespace Symfony\Component\Security\Core;
1313

14+
use Symfony\Component\Security\Core\Event\AuthenticationFailureEvent;
15+
use Symfony\Component\Security\Core\Event\AuthenticationSuccessEvent;
16+
1417
final class AuthenticationEvents
1518
{
1619
/**
@@ -28,4 +31,14 @@ final class AuthenticationEvents
2831
* @Event("Symfony\Component\Security\Core\Event\AuthenticationFailureEvent")
2932
*/
3033
const AUTHENTICATION_FAILURE = 'security.authentication.failure';
34+
35+
/**
36+
* Event aliases.
37+
*
38+
* These aliases can be consumed by RegisterListenersPass.
39+
*/
40+
const ALIASES = [
41+
AuthenticationSuccessEvent::class => self::AUTHENTICATION_SUCCESS,
42+
AuthenticationFailureEvent::class => self::AUTHENTICATION_FAILURE,
43+
];
3144
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy