Skip to content

Commit f8196f1

Browse files
Richard van LaakTobion
authored andcommitted
[FrameworkBundle] Move XML service configuration to PHP
1 parent 5c52d9a commit f8196f1

File tree

3 files changed

+227
-150
lines changed

3 files changed

+227
-150
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function load(array $configs, ContainerBuilder $container)
174174
$phpLoader = new PhpFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config'));
175175

176176
$phpLoader->load('web.php');
177-
$loader->load('services.xml');
177+
$phpLoader->load('services.php');
178178
$phpLoader->load('fragment_renderer.php');
179179
$phpLoader->load('error_renderer.php');
180180

Resources/config/services.php

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
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\DependencyInjection\Loader\Configurator;
13+
14+
use Closure;
15+
use Symfony\Component\Config\Resource\SelfCheckingResourceChecker;
16+
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;
20+
use Symfony\Component\DependencyInjection\Config\ContainerParametersResourceChecker;
21+
use Symfony\Component\DependencyInjection\EnvVarProcessor;
22+
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBag;
23+
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
24+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
25+
use Symfony\Component\DependencyInjection\ReverseContainer;
26+
use Symfony\Component\EventDispatcher\EventDispatcher;
27+
use Symfony\Component\EventDispatcher\EventDispatcherInterface as EventDispatcherInterfaceComponentAlias;
28+
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;
34+
use Symfony\Component\HttpFoundation\RequestStack;
35+
use Symfony\Component\HttpFoundation\UrlHelper;
36+
use Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer;
37+
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate;
38+
use Symfony\Component\HttpKernel\Config\FileLocator;
39+
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;
48+
use Symfony\Component\HttpKernel\EventListener\LocaleAwareListener;
49+
use Symfony\Component\HttpKernel\HttpKernel;
50+
use Symfony\Component\HttpKernel\HttpKernelInterface;
51+
use Symfony\Component\HttpKernel\KernelInterface;
52+
use Symfony\Component\HttpKernel\UriSigner;
53+
use Symfony\Component\String\LazyString;
54+
use Symfony\Component\String\Slugger\AsciiSlugger;
55+
use Symfony\Component\String\Slugger\SluggerInterface;
56+
use Symfony\Component\Workflow\Event\AnnounceEvent;
57+
use Symfony\Component\Workflow\Event\CompletedEvent;
58+
use Symfony\Component\Workflow\Event\EnteredEvent;
59+
use Symfony\Component\Workflow\Event\EnterEvent;
60+
use Symfony\Component\Workflow\Event\GuardEvent;
61+
use Symfony\Component\Workflow\Event\LeaveEvent;
62+
use Symfony\Component\Workflow\Event\TransitionEvent;
63+
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
64+
65+
return static function (ContainerConfigurator $container) {
66+
// this parameter is used at compile time in RegisterListenersPass
67+
$container->parameters()->set('event_dispatcher.event_aliases', [
68+
ConsoleCommandEvent::class => 'console.command',
69+
ConsoleErrorEvent::class => 'console.error',
70+
ConsoleTerminateEvent::class => 'console.terminate',
71+
PreSubmitEvent::class => 'form.pre_submit',
72+
SubmitEvent::class => 'form.submit',
73+
PostSubmitEvent::class => 'form.post_submit',
74+
PreSetDataEvent::class => 'form.pre_set_data',
75+
PostSetDataEvent::class => 'form.post_set_data',
76+
ControllerArgumentsEvent::class => 'kernel.controller_arguments',
77+
ControllerEvent::class => 'kernel.controller',
78+
ResponseEvent::class => 'kernel.response',
79+
FinishRequestEvent::class => 'kernel.finish_request',
80+
RequestEvent::class => 'kernel.request',
81+
ViewEvent::class => 'kernel.view',
82+
ExceptionEvent::class => 'kernel.exception',
83+
TerminateEvent::class => 'kernel.terminate',
84+
GuardEvent::class => 'workflow.guard',
85+
LeaveEvent::class => 'workflow.leave',
86+
TransitionEvent::class => 'workflow.transition',
87+
EnterEvent::class => 'workflow.enter',
88+
EnteredEvent::class => 'workflow.entered',
89+
CompletedEvent::class => 'workflow.completed',
90+
AnnounceEvent::class => 'workflow.announce',
91+
]);
92+
93+
$container->services()
94+
95+
->set('parameter_bag', ContainerBag::class)
96+
->args([
97+
service('service_container'),
98+
])
99+
->alias(ContainerBagInterface::class, 'parameter_bag')
100+
->alias(ParameterBagInterface::class, 'parameter_bag')
101+
102+
->set('event_dispatcher', EventDispatcher::class)
103+
->public()
104+
->tag('container.hot_path')
105+
->alias(EventDispatcherInterfaceComponentAlias::class, 'event_dispatcher')
106+
->alias(EventDispatcherInterface::class, 'event_dispatcher')
107+
108+
->set('http_kernel', HttpKernel::class)
109+
->public()
110+
->args([
111+
service('event_dispatcher'),
112+
service('controller_resolver'),
113+
service('request_stack'),
114+
service('argument_resolver'),
115+
])
116+
->tag('container.hot_path')
117+
->alias(HttpKernelInterface::class, 'http_kernel')
118+
119+
->set('request_stack', RequestStack::class)
120+
->public()
121+
->alias(RequestStack::class, 'request_stack')
122+
123+
->set('url_helper', UrlHelper::class)
124+
->args([
125+
service('request_stack'),
126+
service('router.request_context')->ignoreOnInvalid(),
127+
])
128+
->alias(UrlHelper::class, 'url_helper')
129+
130+
->set('cache_warmer', CacheWarmerAggregate::class)
131+
->public()
132+
->args([
133+
tagged_iterator('kernel.cache_warmer'),
134+
param('kernel.debug'),
135+
sprintf('%s/%sDeprecations.log', param('kernel.cache_dir'), param('kernel.container_class')),
136+
])
137+
->tag('container.no_preload')
138+
139+
->set('cache_clearer', ChainCacheClearer::class)
140+
->public()
141+
->args([
142+
tagged_iterator('kernel.cache_clearer'),
143+
])
144+
145+
->set('kernel')
146+
->synthetic()
147+
->public()
148+
->alias(KernelInterface::class, 'kernel')
149+
150+
->set('filesystem', Filesystem::class)
151+
->public()
152+
->alias(Filesystem::class, 'filesystem')
153+
154+
->set('file_locator', FileLocator::class)
155+
->args([
156+
service('kernel'),
157+
])
158+
->alias(FileLocator::class, 'file_locator')
159+
160+
->set('uri_signer', UriSigner::class)
161+
->args([
162+
param('kernel.secret'),
163+
])
164+
->alias(UriSigner::class, 'uri_signer')
165+
166+
->set('config_cache_factory', ResourceCheckerConfigCacheFactory::class)
167+
->args([
168+
tagged_iterator('config_cache.resource_checker'),
169+
])
170+
171+
->set('dependency_injection.config.container_parameters_resource_checker', ContainerParametersResourceChecker::class)
172+
->args([
173+
service('service_container'),
174+
])
175+
->tag('config_cache.resource_checker', ['priority' => -980])
176+
177+
->set('config.resource.self_checking_resource_checker', SelfCheckingResourceChecker::class)
178+
->tag('config_cache.resource_checker', ['priority' => -990])
179+
180+
->set('services_resetter', ServicesResetter::class)
181+
->public()
182+
183+
->set('reverse_container', ReverseContainer::class)
184+
->args([
185+
service('service_container'),
186+
service_locator([]),
187+
])
188+
->alias(ReverseContainer::class, 'reverse_container')
189+
190+
->set('locale_aware_listener', LocaleAwareListener::class)
191+
->args([
192+
[], // locale aware services
193+
service('request_stack'),
194+
])
195+
->tag('kernel.event_subscriber')
196+
197+
->set('container.env_var_processor', EnvVarProcessor::class)
198+
->args([
199+
service('service_container'),
200+
tagged_iterator('container.env_var_loader'),
201+
])
202+
->tag('container.env_var_processor')
203+
204+
->set('slugger', AsciiSlugger::class)
205+
->args([
206+
param('kernel.default_locale'),
207+
])
208+
->tag('kernel.locale_aware')
209+
->alias(SluggerInterface::class, 'slugger')
210+
211+
->set('container.getenv', Closure::class)
212+
->factory([Closure::class, 'fromCallable'])
213+
->args([
214+
[service('service_container'), 'getEnv'],
215+
])
216+
->tag('routing.expression_language_function', ['function' => 'env'])
217+
218+
// inherit from this service to lazily access env vars
219+
->set('container.env', LazyString::class)
220+
->abstract()
221+
->factory([LazyString::class, 'fromCallable'])
222+
->args([
223+
service('container.getenv'),
224+
])
225+
;
226+
};

Resources/config/services.xml

Lines changed: 0 additions & 149 deletions
This file was deleted.

0 commit comments

Comments
 (0)