I've defined my custom repositories according to the symfony docs and followed this blog post to define them as a service. This normally works fine, except sometimes I get the exception:
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
This happens quite a lot, and normally clearing the cache and the doctrine metadata cache solves it. But sometimes it doesn't.
php app/console cache:clear
php app/console doctrine:cache:clear-metadata
I don't actually understand why this happens or how to fix it in the times that clearing the cache doesn't work. I know that this question (or derivative of it) has been asked a lot, like here, here, here, here and here. But none of those answers actually solves my problem, because as far as I can see I've defined everything correctly, also we have a bunch of other repositories defined exactly the same way and they all work fine.
# 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,
) {
Is there some other cache that needs to be cleared or something I'm missing?