JMSDiExtraBundle icon indicating copy to clipboard operation
JMSDiExtraBundle copied to clipboard

Parameter injection failing for doctrine repositories

Open Adirelle opened this issue 9 years ago • 6 comments

It seems there is an issue with version 1.6.0.

The following snippet fails to inject the actual value of the parameter, instead, it injects the string %my_parameter%.

use JMS\DiExtraBundle\Annotation as DI;

class MyEntityRepository extends EntityRepository
{
  private $var;

  /**
   * @param float $var
   * @DI\InjectParams({"var" = @DI\Inject("%my_parameter%")})
  */
  public function setVar($var) 
  {
    $this->var = $var;
  }
}

It seems this case is not covered by the tests.

Adirelle avatar Nov 03 '15 16:11 Adirelle

This repository is not a service, hence why it won't work.

hoshsadiq avatar Nov 08 '15 16:11 hoshsadiq

@hoshsadiq I think you overlooked the documentation and what I've said:

  • With the Doctrine integration enabled (which is the case by default), JMSDiExtraBundle can inject into Doctrine repositories (it decorates the entity manager to do so).
  • In my case, JMSDiExtraBundle actually injects something, which verifies the previous point, but not the right thing, i.e. it injects %my_parameter% instead of the actual value of my_parameter.

Adirelle avatar Nov 09 '15 09:11 Adirelle

I can confirm this in my situation as well. The property is populated with the provided parameter string instead of the value of the parameter.

nibynool avatar Nov 09 '15 22:11 nibynool

Same issue here.

It injects the parameter %my_parameter% and not the actual value. There is a stackoverflow question with an answer saying that you can use this bundle to inject a parameter in a repository : http://stackoverflow.com/a/23297355/3726645

I guess this worked at some point, but not anymore ?

antoinemineau avatar Dec 18 '15 15:12 antoinemineau

Is there a pull-request for this?

schmittjoh avatar Dec 18 '15 16:12 schmittjoh

@schmittjoh I've tried to create a functional test (see above) but I'm having issues to make it run on my Windows box.

Adirelle avatar Dec 21 '15 18:12 Adirelle