Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf20060c

Browse files
GrinWayjaviereguiluz
authored andcommitted
Update import.rst
It's better to use imports statements only in the services.yaml file.The following explains that.
1 parentefffcc8 commitf20060c

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

‎service_container/import.rst

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,28 @@ as in the above example, the ``App\`` definition creates services for classes
138138
found in ``../src/*``. If your imported file defines services for those classes
139139
too, they will be overridden.
140140

141-
A possible solution for this is to add the classes and/or directories of the
142-
imported files in the ``exclude`` option of the ``App\`` definition. Another
143-
solution is to not use imports and add the service definitions in the same file,
144-
but after the ``App\`` definition to override it.
141+
There are exactly three possible solutions in order services not to get overriden:
142+
1. Include the file with ``App\`` statement in the ``imports`` as the first element.
143+
In order to the fact that the ``imports`` statement not override existing services, it checks if the services exists,
144+
also take into account that the last element of the ``imports`` has the highest priority and will be executed first,
145+
having included ``App\`` as a first element of ``imports`` (with the lowest priority) it will be imported in the end.
146+
And being the last import element it will only add not existing services in the container.
147+
2. Include the path to the service in the ``exclude`` section.
148+
3. Write service definitions down the ``App\`` statement to override it
149+
150+
It's recommended to use the 1st approach to define services in the container
151+
Using the first approach the whole ``services.yaml`` file will look the foolowing way:
152+
153+
..configuration-block::
154+
..code-block::yaml
155+
###> imports are loaded first (imports not overrides existing services) ###
156+
imports:
157+
- resource: 'services_yaml/resource_services.yaml' # PRIORITY 1 (last) (contains App\with resource statement)
158+
- resource: 'services_yaml/services/' # PRIORITY 2
159+
- resource: 'services_yaml/parameters/' # PRIORITY 3 (first)
160+
161+
###> then services.yaml (what below overrides imports) ###
162+
###>... it's better to use only imports
145163

146164
..include::/components/dependency_injection/_imports-parameters-note.rst.inc
147165

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp