Answer the question
In order to leave comments, you need to log in
What is the correct way to name a service in Symfony to be called in different places?
Hello.
There is
a BaseBuilder class
public function __construct(string $file, array $mapping)
{
$this->file = $file;
$this->mapping = $mapping;
}
FirstBuilder:
public: true
autowire: false
class: App\Builder\BuilderBase
arguments:
$file: '%kernel.project_dir%/public/files/first.xml'
$mapping: '%first.mapping%'
TwoBuilder:
public: true
autowire: false
class: App\Builder\BuilderBase
arguments:
$file: '%kernel.project_dir%/public/files/two.xml'
$mapping: '%two.mapping%'
App\Factory\Point\Test:
public: true
class: App\Factory\Point\Test
arguments:
$creator: '@App\Creator\TestCreator'
$sender: '@App\Sender\TestSender'
$builder: '@FirstBuilder'
Answer the question
In order to leave comments, you need to log in
What is "not working"?
Well, you yourself turned off autowiring in the examples above. For example, here:
TwoBuilder:
public: true
###
autowire: false
###
class: App\Builder\BuilderBase
arguments:
$file: '%kernel.project_dir%/public/files/two.xml'
$mapping: '%two.mapping%'
FirstBuilder
and TwoBilder
(correctly: SecondBilder
) are configured correctly (if you omit the potential problem with passing by name without autowiring), and the configuration error occurs with the service App\Builder\BuilderBase
. Please note that I do not mean the class, but the service ID. That is, in fact, you have a manual configuration of two "virtual" services, so to speak, and one configuration of the default service representation, which is created automatically (because autowiring and autoconfiguration are enabled globally, which you did not show in the question, by the way). FirstBuilder
is valid and configured normally TwoBuilder
is valid and configured normally App\Builder\BuilderBase
- tries to configure automatically, but can't because for scalar arguments, arrays, and everything else, what does a service need or default value bindings (see services._defaults.bind
)? Or explicitly passing arguments in the configuration block you wrote. App\Builder\BuilderBase
so that the system does not try to configure another service for this class, and the second builder is already called whatever you like. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question