Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php ParamConverter:声明异常symfony2_Php_Symfony - Fatal编程技术网

Php ParamConverter:声明异常symfony2

Php ParamConverter:声明异常symfony2,php,symfony,Php,Symfony,我正在尝试为我的项目(symfony 2.4)创建一个参数转换器 这是我的转换器: namespace Test\ParamConvertersBundle\ProgramConverter; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface; use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverte

我正在尝试为我的项目(symfony 2.4)创建一个参数转换器 这是我的转换器:

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();
    }
}
这是一个让我发疯的例外:

FatalErrorException:编译错误:Test\ParamConvertersBundle\ProgramConverter\ProgramConverter::apply()的声明必须与Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface::apply()兼容(Symfony\Component\HttpFoundation\Request$Request,Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter$Configuration)


我不明白这个问题……

这实际上是预期的行为:)看看你的
apply
方法:

public function apply(Request $request, ParamConverter $configuration){
    return true;
}
第二个参数是类型,提示为
ParamConverter
。由于您自己的转换器的命名准确,因此它假定存在一个方法
apply
,该方法具有第二个类型的参数:

namespace Test\ParamConvertersBundle\ProgramConverter\ParamConverter;
。。。。它与超类的方法不匹配


解决方案:尝试重命名您自己的类,使其更加具体。

这实际上是预期的行为:)看看您的
apply
方法:

public function apply(Request $request, ParamConverter $configuration){
    return true;
}
第二个参数是类型,提示为
ParamConverter
。由于您自己的转换器的命名准确,因此它假定存在一个方法
apply
,该方法具有第二个类型的参数:

namespace Test\ParamConvertersBundle\ProgramConverter\ParamConverter;
。。。。它与超类的方法不匹配


解决方案:尝试重命名您自己的类,使其更加具体。

这实际上是预期的行为:)看看您的
apply
方法:

public function apply(Request $request, ParamConverter $configuration){
    return true;
}
第二个参数是类型,提示为
ParamConverter
。由于您自己的转换器的命名准确,因此它假定存在一个方法
apply
,该方法具有第二个类型的参数:

namespace Test\ParamConvertersBundle\ProgramConverter\ParamConverter;
。。。。它与超类的方法不匹配


解决方案:尝试重命名您自己的类,使其更加具体。

这实际上是预期的行为:)看看您的
apply
方法:

public function apply(Request $request, ParamConverter $configuration){
    return true;
}
第二个参数是类型,提示为
ParamConverter
。由于您自己的转换器的命名准确,因此它假定存在一个方法
apply
,该方法具有第二个类型的参数:

namespace Test\ParamConvertersBundle\ProgramConverter\ParamConverter;
。。。。它与超类的方法不匹配

解决方案:尝试重命名您自己的类,使其更加具体。

bartek回答:

使用Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter

Thx很多:)

巴特克回答:

使用Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter

Thx很多:)

巴特克回答:

使用Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter

Thx很多:)

巴特克回答:

使用Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter


Thx很多:)

使用Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter?;)我想那是行不通的。实际上他需要:
使用Sensio\Bundle\FrameworkExtraBundle\Configuration作为Sensio
,然后在方法签名中使用
Sensio\ParamConverter
)工作起来很有魅力,thx bartek:)
使用Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter?;)我想那是行不通的。实际上他需要:
使用Sensio\Bundle\FrameworkExtraBundle\Configuration作为Sensio
,然后在方法签名中使用
Sensio\ParamConverter
)工作起来很有魅力,thx bartek:)
使用Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter?;)我想那是行不通的。实际上他需要:
使用Sensio\Bundle\FrameworkExtraBundle\Configuration作为Sensio
,然后在方法签名中使用
Sensio\ParamConverter
)工作起来很有魅力,thx bartek:)
使用Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter?;)我想那是行不通的。实际上他需要:
使用Sensio\Bundle\FrameworkExtraBundle\Configuration作为Sensio
,然后在方法签名中使用
Sensio\ParamConverter
)工作起来很有魅力,thx bartek:)