Skip to content

Commit 4bb5153

Browse files
committed
minor #12318 Add a warning to imports order (tristanbes)
This PR was submitted for the master branch but it was squashed and merged into the 4.3 branch instead (closes #12318). Discussion ---------- Add a warning to imports order After spending few hours narrowing this down, I've added a note in the documentation that potentially will save time for developper; Here's what happened to me: I got a service that didn't worked, it's because the `imports` actually imports the file *before*, so the service definition got overriden with no warning by the Glob rule (`App\:`) This behaviour is not mentionned on the documentation; ```yaml // services.yaml imports: - { resource: actions_services.yaml } services: # default configuration for services in *this* file _defaults: autowire: true autoconfigure: true App\: resource: '../src/*' exclude: - '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}' ``` ```yaml // actions_services.yaml services: App\Actions\Company\CreateCompany: autowire: true autoconfigure: false parent: 'App\Handler\AbstractHandler' calls: - [setClient, ['@app\GraphQL\Client']] - [setEndpointUrlResolver, ['@app\Resolver\EndpointResolver']] - [setSuccessor, ['@app\Actions\User\CreateUser']] ``` <img width="549" alt="tbessoussa_MacBook-Pro-dex-Tristan____workspace_importer-function" src="https://user-images.githubusercontent.com/346010/64860934-eaf0cc80-d62e-11e9-94e9-a0da67d1b366.png"> **Note that the `Calls` section is missing** Working version: ```yaml // services.yaml services: # default configuration for services in *this* file _defaults: autowire: true autoconfigure: true App\: resource: '../src/*' exclude: - '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}' App\Actions\Company\CreateCompany: autowire: true autoconfigure: false parent: 'App\Handler\AbstractHandler' calls: - [setClient, ['@app\GraphQL\Client']] - [setEndpointUrlResolver, ['@app\Resolver\EndpointResolver']] - [setSuccessor, ['@app\Actions\User\CreateUser']] ``` <img width="712" alt="tbessoussa_MacBook-Pro-de-Tristan____workspace_importer-function" src="https://user-images.githubusercontent.com/346010/64860840-a9602180-d62e-11e9-9b3a-40e344f18e9f.png"> `Calls` is here, so the service is good to go. Commits ------- 175b05a Add a warning to imports order
2 parents 3dbceef + 175b05a commit 4bb5153

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

service_container/import.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ To import this file, use the ``imports`` key from a file that *is* loaded:
102102
The ``resource`` location, for files, is either a relative path from the
103103
current file or an absolute path.
104104

105+
.. caution::
106+
107+
The imported files are loaded first; You should be careful, because it can
108+
lead to some of your services definition to be overridden by rules present
109+
inside the file where you do imports
110+
105111
.. include:: /components/dependency_injection/_imports-parameters-note.rst.inc
106112

107113
.. index::

0 commit comments

Comments
 (0)