diff --git a/src/Skobkin/Bundle/PointToolsBundle/Repository/Telegram/AccountRepository.php b/src/Skobkin/Bundle/PointToolsBundle/Repository/Telegram/AccountRepository.php index e82a484..cfeb05b 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Repository/Telegram/AccountRepository.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Repository/Telegram/AccountRepository.php @@ -3,9 +3,15 @@ namespace Skobkin\Bundle\PointToolsBundle\Repository\Telegram; use Doctrine\ORM\EntityRepository; +use Skobkin\Bundle\PointToolsBundle\Entity\Telegram\Account; class AccountRepository extends EntityRepository { + public function add(Account $entity) + { + $this->getEntityManager()->persist($entity); + } + /** * @todo remove if not used * @@ -14,7 +20,7 @@ class AccountRepository extends EntityRepository * @param int|null $limit * @param int|null $offset * - * @return array + * @return Account[] */ public function findLinkedAccountsBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null): array { diff --git a/src/Skobkin/Bundle/PointToolsBundle/Resources/config/services.yml b/src/Skobkin/Bundle/PointToolsBundle/Resources/config/services.yml index f94252f..6f62571 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Resources/config/services.yml +++ b/src/Skobkin/Bundle/PointToolsBundle/Resources/config/services.yml @@ -96,6 +96,11 @@ services: class: Skobkin\Bundle\PointToolsBundle\Repository\Blogs\FileRepository factory: 'doctrine:getRepository' arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\Blogs\File'] + # Telegram Account repository + app.point.telegram_account_repository: + class: Skobkin\Bundle\PointToolsBundle\Repository\Telegram\AccountRepository + factory: 'doctrine:getRepository' + arguments: ['Skobkin\Bundle\PointToolsBundle\Entity\Telegram\Account'] # Factories @@ -137,7 +142,7 @@ services: # Telegram accounts factory app.telegram.telegram_account_factory: class: Skobkin\Bundle\PointToolsBundle\Service\Factory\Telegram\AccountFactory - arguments: ['@doctrine.orm.entity_manager'] + arguments: ['@app.point.telegram_account_repository'] # Custom Markdown parser diff --git a/src/Skobkin/Bundle/PointToolsBundle/Service/Factory/Telegram/AccountFactory.php b/src/Skobkin/Bundle/PointToolsBundle/Service/Factory/Telegram/AccountFactory.php index 8cb3e38..7a47505 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Service/Factory/Telegram/AccountFactory.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Service/Factory/Telegram/AccountFactory.php @@ -2,35 +2,28 @@ namespace Skobkin\Bundle\PointToolsBundle\Service\Factory\Telegram; -use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\EntityRepository; use Skobkin\Bundle\PointToolsBundle\Entity\Telegram\Account; +use Skobkin\Bundle\PointToolsBundle\Repository\Telegram\AccountRepository; use unreal4u\TelegramAPI\Telegram\Types\Message; class AccountFactory { /** - * @var EntityManagerInterface - */ - private $em; - - /** - * @var EntityRepository + * @var AccountRepository */ private $accountRepo; - public function __construct(EntityManagerInterface $em) + public function __construct(AccountRepository $accountRepository) { - $this->em = $em; - $this->accountRepo = $em->getRepository('SkobkinPointToolsBundle:Telegram\Account'); + $this->accountRepo = $accountRepository; } public function findOrCreateFromMessage(Message $message): Account { if (null === $account = $this->accountRepo->findOneBy(['id' => $message->from->id])) { $account = new Account($message->from->id); - $this->em->persist($account); + $this->accountRepo->add($account); } // Setting/updating account data