WIP: Symfony 6 project remake #2

Draft
skobkin wants to merge 103 commits from symfony6_remake into master
2 changed files with 38 additions and 40 deletions
Showing only changes of commit fd8161c9e1 - Show all commits

View file

@ -1,40 +0,0 @@
<?php
namespace src\PointToolsBundle\Service\Factory\Telegram;
use Psr\Log\LoggerInterface;
use src\PointToolsBundle\Entity\Telegram\Account;
use src\PointToolsBundle\Repository\Telegram\AccountRepository;
use src\PointToolsBundle\Service\Factory\AbstractFactory;
use unreal4u\TelegramAPI\Telegram\Types\Message;
class AccountFactory extends AbstractFactory
{
/** @var AccountRepository */
private $accountRepo;
public function __construct(LoggerInterface $logger, AccountRepository $accountRepository)
{
parent::__construct($logger);
$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->accountRepo->add($account);
}
// Setting/updating account data
$account->updateFromMessageData(
$message->from->first_name,
$message->from->last_name,
$message->from->username,
$message->chat->id
);
return $account;
}
}

View file

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace App\Factory\Telegram;
use App\Factory\AbstractFactory;
use Psr\Log\LoggerInterface;
use App\Entity\Telegram\Account;
use App\Repository\Telegram\AccountRepository;
use unreal4u\Telegram\Types\Message;
class AccountFactory extends AbstractFactory
{
public function __construct(
LoggerInterface $logger,
private readonly AccountRepository $accountRepository,
) {
parent::__construct($logger);
}
public function findOrCreateFromMessage(Message $message): Account
{
if (null === $account = $this->accountRepository->findOneBy(['id' => $message->from->id])) {
$account = new Account($message->from->id);
$this->accountRepository->save($account);
}
// Setting/updating account data
$account->updateFromMessageData(
$message->from->first_name,
$message->from->last_name,
$message->from->username,
$message->chat->id
);
return $account;
}
}