传递给 __construct() 的参数应该是 SomeRepository,而不是 EntityRepository 的实例
Argument passed to __construct() expected to be SomeRepository, instance of EntityRepository instead
我已经根据 symfony docs and followed this blog post 定义了我的自定义存储库,将它们定义为一项服务。这通常工作正常,除了有时我会遇到异常:
FatalThrowableError in SomeService.php line 20: Type error: Argument 3
passed to SomeService::__construct() must be an instance of
SomeRepository, instance of Doctrine\ORM\EntityRepository
given, called in var/cache/dev/appDevDebugProjectContainer.php on line
7651
这种情况经常发生,一般清除缓存和条令元数据缓存即可解决。但有时它不会。
php app/console cache:clear
php app/console doctrine:cache:clear-metadata
我实际上不明白为什么会发生这种情况,或者在清除缓存不起作用时如何修复它。我知道这个问题(或它的衍生问题)已经被问了很多,比如 here, here, , and here。但是 none 这些答案实际上解决了我的问题,因为据我所知我已经正确定义了所有内容,而且我们还有一堆其他存储库以完全相同的方式定义并且它们都可以正常工作。
# services.yml
app.repository.some:
class: AppBundle\Repository\SomeRepository
factory: ["@doctrine.orm.default_entity_manager", getRepository]
arguments:
- AppBundle\Entity\Some
app.some_service:
class: AppBundle\Services\SomeService
arguments:
- "@app.repository.some"
// Repository class
<?php
namespace AppBundle\Repository;
use Doctrine\ORM\EntityRepository;
class SomeRepository extends EntityRepository
{
}
// Entity class
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="AppBundle\Repository\SomeRepository")
* @ORM\Table()
* @ORM\Entity
*/
class Some
{
// Service class
<?php
namespace AppBundle\Services;
use AppBundle\Repository\SomeRepository;
class NotificationService
{
/** @var SomeRepository */
protected $someRepository;
public function __construct(
SomeRepository $someRepository,
) {
是否有其他缓存需要清除或我遗漏了什么?
去掉第二个@ORM\Entity,它将正常工作
我已经根据 symfony docs and followed this blog post 定义了我的自定义存储库,将它们定义为一项服务。这通常工作正常,除了有时我会遇到异常:
FatalThrowableError in SomeService.php line 20: Type error: Argument 3 passed to SomeService::__construct() must be an instance of SomeRepository, instance of Doctrine\ORM\EntityRepository given, called in var/cache/dev/appDevDebugProjectContainer.php on line 7651
这种情况经常发生,一般清除缓存和条令元数据缓存即可解决。但有时它不会。
php app/console cache:clear
php app/console doctrine:cache:clear-metadata
我实际上不明白为什么会发生这种情况,或者在清除缓存不起作用时如何修复它。我知道这个问题(或它的衍生问题)已经被问了很多,比如 here, here,
# services.yml
app.repository.some:
class: AppBundle\Repository\SomeRepository
factory: ["@doctrine.orm.default_entity_manager", getRepository]
arguments:
- AppBundle\Entity\Some
app.some_service:
class: AppBundle\Services\SomeService
arguments:
- "@app.repository.some"
// Repository class
<?php
namespace AppBundle\Repository;
use Doctrine\ORM\EntityRepository;
class SomeRepository extends EntityRepository
{
}
// Entity class
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="AppBundle\Repository\SomeRepository")
* @ORM\Table()
* @ORM\Entity
*/
class Some
{
// Service class
<?php
namespace AppBundle\Services;
use AppBundle\Repository\SomeRepository;
class NotificationService
{
/** @var SomeRepository */
protected $someRepository;
public function __construct(
SomeRepository $someRepository,
) {
是否有其他缓存需要清除或我遗漏了什么?
去掉第二个@ORM\Entity,它将正常工作