Wie füge ich ein Repository in einen Service in Symfony ein?
Ich muss zwei Objekte injizierenImageService
. Einer von ihnen ist eine Instanz vonRepository/ImageRepository
, was ich so bekomme:
$image_repository = $container->get('doctrine.odm.mongodb')
->getRepository('MycompanyMainBundle:Image');
Wie erkläre ich das in meiner services.yml? Hier ist der Service:
namespace Mycompany\MainBundle\Service\Image;
use Doctrine\ODM\MongoDB\DocumentRepository;
class ImageManager {
private $manipulator;
private $repository;
public function __construct(ImageManipulatorInterface $manipulator, DocumentRepository $repository) {
$this->manipulator = $manipulator;
$this->repository = $repository;
}
public function findAll() {
return $this->repository->findAll();
}
public function createThumbnail(ImageInterface $image) {
return $this->manipulator->resize($image->source(), 300, 200);
}
}