Skip to content

Commit 59fd3a3

Browse files
committed
Tweaks
1 parent 2e90c4f commit 59fd3a3

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

service_container.rst

+44
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,50 @@ each time you ask for it.
223223
it. Later, you'll learn how to :ref:`import many services at once
224224
<service-psr4-loader>` with resource.
225225

226+
If some files or directories in your project should not become services, you
227+
can exclude them using the ``exclude`` option:
228+
229+
.. configuration-block::
230+
231+
.. code-block:: yaml
232+
233+
# config/services.yaml
234+
services:
235+
# ...
236+
App\:
237+
resource: '../src/'
238+
exclude:
239+
- '../src/SomeDirectory/'
240+
- '../src/AnotherDirectory/'
241+
- '../src/SomeFile.php'
242+
243+
.. code-block:: xml
244+
245+
<!-- config/services.xml -->
246+
<?xml version="1.0" encoding="UTF-8" ?>
247+
<container xmlns="http://symfony.com/schema/dic/services"
248+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
249+
xsi:schemaLocation="http://symfony.com/schema/dic/services
250+
https://symfony.com/schema/dic/services/services-1.0.xsd">
251+
252+
<services>
253+
<prototype namespace="App\" resource="../src/" exclude="../src/{SomeDirectory,AnotherDirectory,Kernel.php}"/>
254+
<!-- ... -->
255+
</services>
256+
</container>
257+
258+
.. code-block:: php
259+
260+
// config/services.php
261+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
262+
263+
return function(ContainerConfigurator $container): void {
264+
// ...
265+
266+
$services->load('App\\', '../src/')
267+
->exclude('../src/{SomeDirectory,AnotherDirectory,Kernel.php}');
268+
};
269+
226270
If you'd prefer to manually wire your service, you can
227271
:ref:`use explicit configuration <services-explicitly-configure-wire-services>`.
228272

service_container/import.rst

+2-5
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ a relative or absolute path to the imported file:
8282
8383
App\:
8484
resource: '../src/*'
85-
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
8685
8786
# ...
8887
@@ -104,8 +103,7 @@ a relative or absolute path to the imported file:
104103
<services>
105104
<defaults autowire="true" autoconfigure="true"/>
106105
107-
<prototype namespace="App\" resource="../src/*"
108-
exclude="../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}"/>
106+
<prototype namespace="App\" resource="../src/*"/>
109107
110108
<!-- ... -->
111109
</services>
@@ -127,8 +125,7 @@ a relative or absolute path to the imported file:
127125
->autoconfigure()
128126
;
129127
130-
$services->load('App\\', '../src/*')
131-
->exclude('../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}');
128+
$services->load('App\\', '../src/*');
132129
};
133130
134131
When loading a configuration file, Symfony loads first the imported files and

0 commit comments

Comments
 (0)