0
votes

i'm trying to create a param converter for my project (symfony 2.4) Here is my converter:

namespace Test\ParamConvertersBundle\ProgramConverter;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface;
use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\EntityManager;


class ProgramConverter implements ParamConverterInterface{
    protected $class;
    protected $repository;

    public function __construct($class, EntityManager $em){
        $this->class = $class;
        $this->repository = $em->getRepository($class);
    }

    public function apply(Request $request, ParamConverter $configuration){
        return true;
    }

    public function supports(ParamConverter $configuration){
        return $this->class === $configuration->getClass();
    }
}

And here is the exception that drives me crazy:

FatalErrorException: Compile Error: Declaration of Test\ParamConvertersBundle\ProgramConverter\ProgramConverter::apply() must be compatible with Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface::apply(Symfony\Component\HttpFoundation\Request $request, Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter $configuration)

I don't get the problem ....

2
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; ? ;)Bartek
I think that won't work. Actually he need to: use Sensio\Bundle\FrameworkExtraBundle\Configuration as Sensio and then use Sensio\ParamConverter in method signature ;)Jovan Perovic
Worked like a charm, thx bartek :)MarcD

2 Answers

2
votes

Answered by bartek:

use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;

Thx a lot :)

1
votes

This is actually expected behavior :) Take a look at your apply method:

public function apply(Request $request, ParamConverter $configuration){
    return true;
}

The second parameter is type-hinted as ParamConverter. Since your own converter is named exactly that it assumes there is a method apply which has a second parameter of type:

namespace Test\ParamConvertersBundle\ProgramConverter\ParamConverter;

.... which does not match the method of super-class.

Solution: Try renaming you own class to be a bit more specific.