-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | no |
RFC? | no |
Symfony version | 3.3.8 |
I'm trying to use autowring in a project and I have an issue a little similar to this one #23998. My first problem was the part in "update 2" in this same issue on stackoverflow. I use a form type and my class isn't really abstract but It's just an example to show the problem :
See below my old service declaration :
class MyFormType extends AbstractType
{
protected $mandatoryDay;
protected $translator;
public function __construct(TranslatorInterface $translator, $mandatoryDay)
{
$this->translator = $translator;
$this->mandatoryDay = $mandatoryDay;
}
}
Old service declaration :
<service id="abstract_form_type"
class="AppBundle\Form\MyFormType"
abstract="true">
<argument type="service" id="translator" />
<argument>%my_parameter%</argument>
</service>
Result with debug:container abstract_form_type --show-arguments :
Information for Service "abstract_form_type"
===========================================================
---------------- ------------------------------------------------
Option Value
---------------- ------------------------------------------------
Service ID abstract_form_type
Class AppBundle\Form\MyFormType
Tags -
Public yes
Synthetic no
Lazy no
Shared yes
Abstract yes
Autowired no
Autoconfigured no
Arguments Service(translator)
2
---------------- ------------------------------------------------
With the autowiring feature :
<service id="abstract_form_type"
class="AppBundle\Form\MyFormType"
abstract="true"
autowire="true">
<argument key="$mandatoryDay">%my_parameter%</argument>
</service>
And the same symfony command I have this error :
[Symfony\Component\DependencyInjection\Exception\RuntimeException]
Invalid constructor argument 2 for service "abstract_form_type": argument 1 must be defined before. Check your service definition.
I removed the parameter and I found that the autowring does not work with a service define as abstract.
The new class :
class MyFormType extends AbstractType
{
protected $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
}
Declaration without abstract :
<service id="abstract_form_type"
class="AppBundle\Form\MyFormType"
autowire="true">
</service>
Result with debug:container abstract_form_type --show-arguments :
Information for Service "abstract_form_type"
===========================================================
---------------- ------------------------------------------------
Option Value
---------------- ------------------------------------------------
Service ID abstract_form_type
Class AppBundle\Form\MyFormType
Tags -
Public yes
Synthetic no
Lazy no
Shared yes
Abstract no
Autowired yes
Autoconfigured no
Arguments Service(translator.data_collector)
---------------- ------------------------------------------------
Declaration with abstract :
<service id="abstract_form_type"
class="AppBundle\Form\MyFormType"
abstract="true"
autowire="true">
</service>
Result :
Information for Service "abstract_form_type"
===========================================================
---------------- ------------------------------------------------
Option Value
---------------- ------------------------------------------------
Service ID abstract_form_type
Class AppBundle\Form\MyFormType
Tags -
Public yes
Synthetic no
Lazy no
Shared yes
Abstract yes
Autowired yes
Autoconfigured no
---------------- ------------------------------------------------
No parameter is found !