diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php index d508170..8aed834 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php @@ -7,12 +7,10 @@ use Doctrine\ORM\Mapping as ORM; use Skobkin\Bundle\PointToolsBundle\Entity\User; /** - * Comment - * * @ORM\Table(name="comments", schema="posts", indexes={ * @ORM\Index(name="idx_comment_created_at", columns={"created_at"}) * }) - * @ORM\Entity + * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Blogs\CommentRepository") */ class Comment { diff --git a/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/CommentRepository.php b/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/CommentRepository.php new file mode 100644 index 0000000..bd8318f --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/Repository/Blogs/CommentRepository.php @@ -0,0 +1,14 @@ +getEntityManager()->persist($entity); + } +} \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/Resources/config/services.yml b/src/Skobkin/Bundle/PointToolsBundle/Resources/config/services.yml index b0283c5..98ff611 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Resources/config/services.yml +++ b/src/Skobkin/Bundle/PointToolsBundle/Resources/config/services.yml @@ -76,6 +76,16 @@ services: class: Skobkin\Bundle\PointToolsBundle\Repository\SubscriptionEventRepository factory: 'doctrine:getRepository' 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 @@ -87,7 +97,10 @@ services: # Comment factory app.point.comment_factory: 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 app.point.tag_factory: diff --git a/src/Skobkin/Bundle/PointToolsBundle/Service/Factory/Blogs/CommentFactory.php b/src/Skobkin/Bundle/PointToolsBundle/Service/Factory/Blogs/CommentFactory.php index e894589..f53c89c 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Service/Factory/Blogs/CommentFactory.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Service/Factory/Blogs/CommentFactory.php @@ -2,9 +2,9 @@ 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\Repository\Blogs\CommentRepository; +use Skobkin\Bundle\PointToolsBundle\Repository\Blogs\PostRepository; use Skobkin\Bundle\PointToolsBundle\Service\Exceptions\ApiException; use Skobkin\Bundle\PointToolsBundle\Service\Exceptions\InvalidResponseException; use Skobkin\Bundle\PointToolsBundle\Service\Factory\UserFactory; @@ -12,17 +12,12 @@ use Skobkin\Bundle\PointToolsBundle\Service\Factory\UserFactory; class CommentFactory { /** - * @var EntityManager - */ - private $em; - - /** - * @var EntityRepository + * @var CommentRepository */ private $commentRepository; /** - * @var EntityRepository + * @var PostRepository */ private $postRepository; @@ -31,16 +26,12 @@ class CommentFactory */ private $userFactory; - /** - * @param EntityManager $em - * @param UserFactory $userFactory - */ - public function __construct(EntityManager $em, UserFactory $userFactory) + + public function __construct(CommentRepository $commentRepository, PostRepository $postRepository, UserFactory $userFactory) { - $this->em = $em; $this->userFactory = $userFactory; - $this->commentRepository = $em->getRepository('SkobkinPointToolsBundle:Blogs\Comment'); - $this->postRepository = $em->getRepository('SkobkinPointToolsBundle:Blogs\Post'); + $this->commentRepository = $commentRepository; + $this->postRepository = $postRepository; } /** @@ -68,7 +59,7 @@ class CommentFactory $comment = new Comment($data['id'], $post, $author, $toComment, $data['text'], $createdAt, $data['is_rec']); - $this->em->persist($comment); + $this->commentRepository->add($comment); } return $comment;