JMSDiExtraBundle
JMSDiExtraBundle copied to clipboard
Injecting a collection (array) in constuctor
Hi,
i'm trying injecting an array via InjectParams but cant get it to work (if there is a way its not described in the docs)
Here is what i'm trying to do
/**
* @param array $options
* @InjectParams({
* "options" = {@Inject("%something%"), @Inject("%something else%")}
* })
public function __construct(array $options)
This will throw:
[Doctrine\Common\Annotations\AnnotationException]
[Type Error] Attribute "value" of @InjectParams declared on method MyClass::__construct() expects either a(n) JMS\DiExtraBundle\Annotation\Inject, or an array of JMS\DiExtraBundle\Annotation\Injects, but got array.
I tried different syntax variations too but always get an error.
This is not supported atm.
Would be useful I guess. I am extending the FOSUser Mailer class and I have to inject this array:
<argument type="collection">
<argument key="template" type="collection">
<argument key="confirmation">%fos_user.registration.confirmation.template%</argument>
<argument key="resetting">%fos_user.resetting.email.template%</argument>
</argument>
<argument key="from_email" type="collection">
<argument key="confirmation">%fos_user.registration.confirmation.from_email%</argument>
<argument key="resetting">%fos_user.resetting.email.from_email%</argument>
</argument>
</argument>
+1
I would need this also for some adaption of FOS UserBundle
Would this work?
config.yml
parameters:
my_array:
- first
- second
Your class:
/**
* @param array $options
* @InjectParams({
* "options" = @Inject("%my_array%")
* })
public function __construct(array $options)
I guess that will work, but the idea behind all is to use annotation rather than working with a yml file :)
+1 I'm also need it for FOSUserBundle Authentication Success Handler
+1 "I guess that will work, but the idea behind all is to use annotation rather than working with a yml file"
+1
- 1