CommentFactory is now gets direct injection of CommentRepository and PostRepository instead of EntityManager.
This commit is contained in:
parent
097d9a5f65
commit
09cc3741e7
|
@ -7,12 +7,10 @@ use Doctrine\ORM\Mapping as ORM;
|
||||||
use Skobkin\Bundle\PointToolsBundle\Entity\User;
|
use Skobkin\Bundle\PointToolsBundle\Entity\User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comment
|
|
||||||
*
|
|
||||||
* @ORM\Table(name="comments", schema="posts", indexes={
|
* @ORM\Table(name="comments", schema="posts", indexes={
|
||||||
* @ORM\Index(name="idx_comment_created_at", columns={"created_at"})
|
* @ORM\Index(name="idx_comment_created_at", columns={"created_at"})
|
||||||
* })
|
* })
|
||||||
* @ORM\Entity
|
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\CommentRepository")
|
||||||
*/
|
*/
|
||||||
class Comment
|
class Comment
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Skobkin\Bundle\PointToolsBundle\Repository\Blogs;
|
||||||
|
|
||||||
|
use Doctrine\ORM\EntityRepository;
|
||||||
|
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment;
|
||||||
|
|
||||||
|
class CommentRepository extends EntityRepository
|
||||||
|
{
|
||||||
|
public function add(Comment $entity)
|
||||||
|
{
|
||||||
|
$this->getEntityManager()->persist($entity);
|
||||||
|
}
|
||||||
|
}
|
|
@ -76,6 +76,16 @@ services:
|
||||||
class: Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionEventRepository
|
class: Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionEventRepository
|
||||||
factory: 'doctrine:getRepository'
|
factory: 'doctrine:getRepository'
|
||||||
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionEvent']
|
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\SubscriptionEvent']
|
||||||
|
# Post repository
|
||||||
|
app.point.post_repository:
|
||||||
|
class: Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostRepository
|
||||||
|
factory: 'doctrine:getRepository'
|
||||||
|
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Post']
|
||||||
|
# Comment repository
|
||||||
|
app.point.comment_repository:
|
||||||
|
class: Skobkin\Bundle\PointToolsBundle\Repository\Blogs\CommentRepository
|
||||||
|
factory: 'doctrine:getRepository'
|
||||||
|
arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment']
|
||||||
|
|
||||||
|
|
||||||
# Factories
|
# Factories
|
||||||
|
@ -87,7 +97,10 @@ services:
|
||||||
# Comment factory
|
# Comment factory
|
||||||
app.point.comment_factory:
|
app.point.comment_factory:
|
||||||
class: Skobkin\Bundle\PointToolsBundle\Service\Factory\Blogs\CommentFactory
|
class: Skobkin\Bundle\PointToolsBundle\Service\Factory\Blogs\CommentFactory
|
||||||
arguments: [ '@doctrine.orm.entity_manager', '@app.point.user_factory' ]
|
arguments:
|
||||||
|
- '@app.point.comment_repository'
|
||||||
|
- '@app.point.post_repository'
|
||||||
|
- '@app.point.user_factory'
|
||||||
|
|
||||||
# Tag factory
|
# Tag factory
|
||||||
app.point.tag_factory:
|
app.point.tag_factory:
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
namespace Skobkin\Bundle\PointToolsBundle\Service\Factory\Blogs;
|
namespace Skobkin\Bundle\PointToolsBundle\Service\Factory\Blogs;
|
||||||
|
|
||||||
use Doctrine\ORM\EntityManager;
|
|
||||||
use Doctrine\ORM\EntityRepository;
|
|
||||||
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment;
|
use Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment;
|
||||||
|
use Skobkin\Bundle\PointToolsBundle\Repository\Blogs\CommentRepository;
|
||||||
|
use Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostRepository;
|
||||||
use Skobkin\Bundle\PointToolsBundle\Service\Exceptions\ApiException;
|
use Skobkin\Bundle\PointToolsBundle\Service\Exceptions\ApiException;
|
||||||
use Skobkin\Bundle\PointToolsBundle\Service\Exceptions\InvalidResponseException;
|
use Skobkin\Bundle\PointToolsBundle\Service\Exceptions\InvalidResponseException;
|
||||||
use Skobkin\Bundle\PointToolsBundle\Service\Factory\UserFactory;
|
use Skobkin\Bundle\PointToolsBundle\Service\Factory\UserFactory;
|
||||||
|
@ -12,17 +12,12 @@ use Skobkin\Bundle\PointToolsBundle\Service\Factory\UserFactory;
|
||||||
class CommentFactory
|
class CommentFactory
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var EntityManager
|
* @var CommentRepository
|
||||||
*/
|
|
||||||
private $em;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var EntityRepository
|
|
||||||
*/
|
*/
|
||||||
private $commentRepository;
|
private $commentRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var EntityRepository
|
* @var PostRepository
|
||||||
*/
|
*/
|
||||||
private $postRepository;
|
private $postRepository;
|
||||||
|
|
||||||
|
@ -31,16 +26,12 @@ class CommentFactory
|
||||||
*/
|
*/
|
||||||
private $userFactory;
|
private $userFactory;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param EntityManager $em
|
public function __construct(CommentRepository $commentRepository, PostRepository $postRepository, UserFactory $userFactory)
|
||||||
* @param UserFactory $userFactory
|
|
||||||
*/
|
|
||||||
public function __construct(EntityManager $em, UserFactory $userFactory)
|
|
||||||
{
|
{
|
||||||
$this->em = $em;
|
|
||||||
$this->userFactory = $userFactory;
|
$this->userFactory = $userFactory;
|
||||||
$this->commentRepository = $em->getRepository('SkobkinPointToolsBundle:Blogs\Comment');
|
$this->commentRepository = $commentRepository;
|
||||||
$this->postRepository = $em->getRepository('SkobkinPointToolsBundle:Blogs\Post');
|
$this->postRepository = $postRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +59,7 @@ class CommentFactory
|
||||||
|
|
||||||
$comment = new Comment($data['id'], $post, $author, $toComment, $data['text'], $createdAt, $data['is_rec']);
|
$comment = new Comment($data['id'], $post, $author, $toComment, $data['text'], $createdAt, $data['is_rec']);
|
||||||
|
|
||||||
$this->em->persist($comment);
|
$this->commentRepository->add($comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $comment;
|
return $comment;
|
||||||
|
|
Loading…
Reference in a new issue