Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How pass arguments without the need of override the constructor #244

Open
rafrsr opened this issue Feb 25, 2016 · 5 comments
Open

How pass arguments without the need of override the constructor #244

rafrsr opened this issue Feb 25, 2016 · 5 comments

Comments

@rafrsr
Copy link

rafrsr commented Feb 25, 2016

It's possible pass some arguments to a constructor without the need of override the constructor method?

When create a service based on another class in some cases is needed pass some arguments to the constructor.

Now:

/**
 * @Service()
 * @Tag(name="form.type_guesser")
 */
class SerialsTypeGuesser extends DoctrineOrmTypeGuesser
{
    /**
     * @param ManagerRegistry $registry
     *
     * @InjectParams({
     *     "registry" = @Inject("doctrine")
     * })
     */
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry);
    }

Something like this would be very useful

Suggestion:

/**
 * @Service()
 * @Tag(name="form.type_guesser")
 * @Arguments({
 *        "registry" = @Inject("doctrine")
 *    })
 */
class SerialsTypeGuesser extends DoctrineOrmTypeGuesser
{

In the other hand, something similar to call a setter without the need of override the parent class method would be very helpful to.

NOW:

/**
 * @Service()
 */
class ServiceClass
{
   use ContainerAwareTrait;

   /**
     * @inheritDoc
     * @InjectParams({
     *     "container" = @Inject("service_container")
     * })
     */
    public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }

Suggestion:

/**
 * @Service()
*  @Call(name="setContainer", params= {
*         "container" = @Inject("service_container")
*     })
 */
class ServiceClass
{
   use ContainerAwareTrait;
@GuilhemN
Copy link
Collaborator

Well this makes new annotations to support for a very small benefit...

@wodka
Copy link
Contributor

wodka commented Feb 29, 2016

Hi, for both cases you could create a custom annotation -> similar to https://github.com/wodka/SonataAdminBundle/blob/jms-annotation/Annotation/Admin.php

it would also be possible to extend your trait and define the annotation there.

@rafrsr
Copy link
Author

rafrsr commented Feb 29, 2016

@Ener-Getick is a small benefit depending on use cases, for some pepole like me is a good feature.

@wodka, didn't know this annotation, I use sonata and each administration is dificult to implement with JMSDiExtraBundle. Thanks, in the other hand, I think that the above annotations can be like a good feature for future versions. Its not really a good practice the need of implements a custom annotation for some cases.

@rafrsr
Copy link
Author

rafrsr commented Feb 29, 2016

I thinks that if the target of JMSDiExtraBundle is to use Dependency Injection in annotations. Knowing this arguments and call are widely used features in service definitions when use .yml or other configuration formats.

@wodka
Copy link
Contributor

wodka commented Feb 29, 2016

could be a nice addition to: #240

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants