JMSDiExtraBundle icon indicating copy to clipboard operation
JMSDiExtraBundle copied to clipboard

Use String as Parameter

Open ad3n opened this issue 9 years ago • 6 comments

services:
    app.manager.propinsi:
        class: AppBundle\Manager\PropinsiManager
        arguments:
            - @doctrine.orm.entity_manager
            - @app.cache.cache_key_generator
            - AppBundle\Entity\Propinsi

That is my service, i convert that service using DIExtraBundle and i do like it:

@InjectParams({"class"=@Inject("AppBundle\Entity\Propinsi")})

And got error, service appbundle\entity\propinsi is not exist

ad3n avatar Apr 10 '15 16:04 ad3n

Won't work unless you move that value into a parameter.

to get this working something like https://github.com/schmittjoh/JMSDiExtraBundle/pull/207 would need to be merged.

wodka avatar Jul 30 '15 12:07 wodka

I needed it for SonataAdminBundle.

why don't you create a custom annotation for your needs? It's quite easy and gives you more flexibility https://github.com/wodka/SonataAdminBundle/blob/jms-annotation/Annotation/Admin.php

wodka avatar Sep 21 '15 09:09 wodka

@Ener-Getick perhaps we can change how argument injection works something like:

/**
 * @DI\Call({
 *     "service" = @DI\Argument("@foo"),
 *     "parameter" = @DI\Argument("%some.parameter%"),
 *     "string" = @DI\Argument("bar"),
 *     "array" = @DI\Argument({"first", "second","third"})
 * })
 */
function doSomething(FooInterface $service, $parameter, $string, array $array)
{}

wodka avatar Feb 15 '16 12:02 wodka

what do you think @schmittjoh ?

GuilhemN avatar Feb 15 '16 15:02 GuilhemN

Why not add this in the code directly?

function doSomething(FooInterface $service, $parameter, $string = "bar", array $array = array('abc', 'def'))
{}

schmittjoh avatar Feb 15 '16 15:02 schmittjoh

Here you have a good example of why with some new features a default value does not help:

use JMS\DiExtraBundle\Annotation as DI;

/**
 * @DI\Service("api.first")
 * @DI\Service("api.second")
 */
class RemoteApi
{
    /**
     * @DI\Call(
     *     {
     *         "service" = @DI\Argument("@foo"),
     *         "host" = @DI\Argument("https://first")
     *     },
     *     services = {"api.first"}
     * )
     *
     * @DI\Call(
     *     {
     *         "service" = @DI\Argument("@foo"),
     *         "host" = @DI\Argument("https://second")
     *     },
     *     services = {"api.second"}
     * )
     */
    public function doSomething($service, $host)
    {}
}

wodka avatar Feb 15 '16 21:02 wodka