diff --git a/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/FileRepository.php b/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/FileRepository.php index 8727914..5e3ead2 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/FileRepository.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/FileRepository.php @@ -3,7 +3,12 @@ namespace Skobkin\Bundle\PointToolsBundle\Repository\Blogs; use Doctrine\ORM\EntityRepository; +use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\File; class FileRepository extends EntityRepository { + public function add(File $entity) + { + $this->getEntityManager()->persist($entity); + } } diff --git a/src/Skobkin/Bundle/PointToolsBundle/Resources/config/services.yml b/src/Skobkin/Bundle/PointToolsBundle/Resources/config/services.yml index c6c0201..22a4b7e 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Resources/config/services.yml +++ b/src/Skobkin/Bundle/PointToolsBundle/Resources/config/services.yml @@ -91,6 +91,11 @@ services: class: Skobkin\Bundle\PointToolsBundle\Repository\Blogs\TagRepository factory: 'doctrine:getRepository' arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Tag'] + # File repository + app.point.file_repository: + class: Skobkin\Bundle\PointToolsBundle\Repository\Blogs\FileRepository + factory: 'doctrine:getRepository' + arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\Blogs\File'] # Factories @@ -115,7 +120,7 @@ services: # File factory app.point.file_factory: class: Skobkin\Bundle\PointToolsBundle\Service\Factory\Blogs\FileFactory - arguments: [ '@logger', '@doctrine.orm.entity_manager' ] + arguments: [ '@logger', '@app.point.file_repository' ] # Post factory app.point.post_factory: diff --git a/src/Skobkin/Bundle/PointToolsBundle/Service/Factory/Blogs/FileFactory.php b/src/Skobkin/Bundle/PointToolsBundle/Service/Factory/Blogs/FileFactory.php index a3e3624..ebef995 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Service/Factory/Blogs/FileFactory.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Service/Factory/Blogs/FileFactory.php @@ -2,35 +2,28 @@ namespace Skobkin\Bundle\PointToolsBundle\Service\Factory\Blogs; -use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\EntityRepository; use Psr\Log\LoggerInterface; use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\File; +use Skobkin\Bundle\PointToolsBundle\Repository\Blogs\FileRepository; use Skobkin\Bundle\PointToolsBundle\Service\Exceptions\InvalidResponseException; class FileFactory { - /** - * @var EntityManagerInterface - */ - private $em; - /** * @var LoggerInterface */ private $log; /** - * @var EntityRepository + * @var FileRepository */ private $fileRepository; - public function __construct(LoggerInterface $log, EntityManagerInterface $em) + public function __construct(LoggerInterface $log, FileRepository $fileRepository) { $this->log = $log; - $this->em = $em; - $this->fileRepository = $em->getRepository('SkobkinPointToolsBundle:Blogs\File'); + $this->fileRepository = $fileRepository; } /** @@ -72,7 +65,7 @@ class FileFactory if (null === ($file = $this->fileRepository->findOneBy(['remoteUrl' => $url]))) { // Creating new file $file = new File($url); - $this->em->persist($file); + $this->fileRepository->add($file); } return $file;