FileFactory is now receives FileRepository directly instead of EntityManager.
This commit is contained in:
parent
2ac54dc1b4
commit
0dc01bef2b
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue