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;
|
namespace Skobkin\Bundle\PointToolsBundle\Repository\Blogs;
|
||||||
|
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
|
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\File;
|
||||||
|
|
||||||
class FileRepository extends EntityRepository
|
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
|
class: Skobkin\Bundle\PointToolsBundle\Repository\Blogs\TagRepository
|
||||||
factory: 'doctrine:getRepository'
|
factory: 'doctrine:getRepository'
|
||||||
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Tag']
|
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
|
# Factories
|
||||||
|
@ -115,7 +120,7 @@ services:
|
||||||
# File factory
|
# File factory
|
||||||
app.point.file_factory:
|
app.point.file_factory:
|
||||||
class: Skobkin\Bundle\PointToolsBundle\Service\Factory\Blogs\FileFactory
|
class: Skobkin\Bundle\PointToolsBundle\Service\Factory\Blogs\FileFactory
|
||||||
arguments: [ '@logger', '@doctrine.orm.entity_manager' ]
|
arguments: [ '@logger', '@app.point.file_repository' ]
|
||||||
|
|
||||||
# Post factory
|
# Post factory
|
||||||
app.point.post_factory:
|
app.point.post_factory:
|
||||||
|
|
|
@ -2,35 +2,28 @@
|
||||||
|
|
||||||
namespace Skobkin\Bundle\PointToolsBundle\Service\Factory\Blogs;
|
namespace Skobkin\Bundle\PointToolsBundle\Service\Factory\Blogs;
|
||||||
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
|
||||||
use Doctrine\ORM\EntityRepository;
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\File;
|
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\File;
|
||||||
|
use Skobkin\Bundle\PointToolsBundle\Repository\Blogs\FileRepository;
|
||||||
use Skobkin\Bundle\PointToolsBundle\Service\Exceptions\InvalidResponseException;
|
use Skobkin\Bundle\PointToolsBundle\Service\Exceptions\InvalidResponseException;
|
||||||
|
|
||||||
class FileFactory
|
class FileFactory
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var EntityManagerInterface
|
|
||||||
*/
|
|
||||||
private $em;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var LoggerInterface
|
* @var LoggerInterface
|
||||||
*/
|
*/
|
||||||
private $log;
|
private $log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var EntityRepository
|
* @var FileRepository
|
||||||
*/
|
*/
|
||||||
private $fileRepository;
|
private $fileRepository;
|
||||||
|
|
||||||
|
|
||||||
public function __construct(LoggerInterface $log, EntityManagerInterface $em)
|
public function __construct(LoggerInterface $log, FileRepository $fileRepository)
|
||||||
{
|
{
|
||||||
$this->log = $log;
|
$this->log = $log;
|
||||||
$this->em = $em;
|
$this->fileRepository = $fileRepository;
|
||||||
$this->fileRepository = $em->getRepository('SkobkinPointToolsBundle:Blogs\File');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,7 +65,7 @@ class FileFactory
|
||||||
if (null === ($file = $this->fileRepository->findOneBy(['remoteUrl' => $url]))) {
|
if (null === ($file = $this->fileRepository->findOneBy(['remoteUrl' => $url]))) {
|
||||||
// Creating new file
|
// Creating new file
|
||||||
$file = new File($url);
|
$file = new File($url);
|
||||||
$this->em->persist($file);
|
$this->fileRepository->add($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $file;
|
return $file;
|
||||||
|
|
Loading…
Reference in a new issue