Remove orm and db occurrences from code

This commit is contained in:
Claudio Zizza
2023-08-26 22:32:55 +02:00
parent 4912b461ac
commit 74bcb6c470
9 changed files with 8 additions and 143 deletions

View File

@@ -1,9 +1,6 @@
imports:
- { resource: config.yml }
parameters:
doctrine.website.mysql.host: '127.0.0.1'
services:
Doctrine\Website\Github\GithubProjectContributors:
alias: Doctrine\Website\Github\TestGithubProjectContributors

View File

@@ -2,4 +2,3 @@ parameters:
doctrine.website.algolia.admin_api_key: 'abcd'
doctrine.website.projects_dir: '%doctrine.website.root_dir%/projects'
doctrine.website.github.http_token: 'abcd'
doctrine.website.mysql.password: 'MyDBPassword'

View File

@@ -8,12 +8,6 @@
<import resource="services/rst-parser.xml"/>
</imports>
<parameters>
<parameter key="doctrine.website.mysql.user">root</parameter>
<parameter key="doctrine.website.mysql.host">localhost</parameter>
<parameter key="doctrine.website.mysql.version">5.7</parameter>
</parameters>
<services>
<defaults autowire="true" autoconfigure="true" public="false">
<bind key="$rootDir">%doctrine.website.root_dir%</bind>
@@ -307,7 +301,6 @@
<argument type="service">
<service class="Doctrine\Website\Hydrators\EventHydrator">
<argument type="service" id="Doctrine\SkeletonMapper\ObjectManager" />
<argument type="service" id="Doctrine\Website\Model\Entity\EventParticipantRepository" />
<argument>%doctrine.website.env%</argument>
</service>
</argument>
@@ -374,36 +367,5 @@
<argument type="service" id="Doctrine\SkeletonMapper\Mapping\ClassMetadataFactory" />
<argument type="service" id="Doctrine\Common\EventManager" />
</service>
<service id="Doctrine\ORM\Configuration">
<factory class="Doctrine\ORM\ORMSetup" method="createAttributeMetadataConfiguration" />
<argument type="collection">
<argument>%doctrine.website.root_dir%/lib/Model/Entity</argument>
</argument>
<argument>%doctrine.website.debug%</argument>
</service>
<service id="Doctrine\ORM\EntityManager">
<factory class="Doctrine\ORM\EntityManager" method="create" />
<argument type="service" id="Doctrine\DBAL\Connection" />
<argument type="service" id="Doctrine\ORM\Configuration" />
</service>
<service id="Doctrine\Website\Model\Entity\EventParticipantRepository">
<factory service="Doctrine\ORM\EntityManager" method="getRepository" />
<argument>Doctrine\Website\Model\Entity\EventParticipant</argument>
</service>
<service id="Doctrine\DBAL\Connection">
<factory class="Doctrine\DBAL\DriverManager" method="getConnection" />
<argument type="collection">
<argument key="dbname">doctrine_website_%doctrine.website.env%</argument>
<argument key="user">%doctrine.website.mysql.user%</argument>
<argument key="password">%doctrine.website.mysql.password%</argument>
<argument key="host">%doctrine.website.mysql.host%</argument>
<argument key="driver">pdo_mysql</argument>
<argument key="serverVersion">%doctrine.website.mysql.version%</argument>
</argument>
</service>
</services>
</container>

View File

@@ -4,12 +4,6 @@ declare(strict_types=1);
namespace Doctrine\Website;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Tools\Console\Command as DBALCommand;
use Doctrine\DBAL\Tools\Console\ConnectionProvider\SingleConnectionProvider;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Console\Command as ORMCommand;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Doctrine\Website\Commands\BuildAllCommand;
use Doctrine\Website\Commands\BuildDocsCommand;
use Doctrine\Website\Commands\BuildWebsiteCommand;
@@ -43,8 +37,6 @@ class Application
public function __construct(
private BaseApplication $application,
EntityManager $em,
Connection $connection,
BuildAllCommand $buildAllCommand,
BuildDocsCommand $buildDocsCommand,
BuildWebsiteCommand $buildWebsiteCommand,
@@ -63,35 +55,7 @@ class Application
$this->application->setHelperSet(new HelperSet([
'question' => new QuestionHelper(),
//'db' => new ConnectionHelper($connection),
'em' => new EntityManagerHelper($em),
//'configuration' => new ConfigurationHelper($connection, $migrationsConfiguration),
]));
$connectionProvider = new SingleConnectionProvider($connection);
$this->application->addCommands([
// DBAL Commands
new DBALCommand\ReservedWordsCommand($connectionProvider),
new DBALCommand\RunSqlCommand($connectionProvider),
// ORM Commands
new ORMCommand\ClearCache\CollectionRegionCommand(),
new ORMCommand\ClearCache\EntityRegionCommand(),
new ORMCommand\ClearCache\MetadataCommand(),
new ORMCommand\ClearCache\QueryCommand(),
new ORMCommand\ClearCache\QueryRegionCommand(),
new ORMCommand\ClearCache\ResultCommand(),
new ORMCommand\SchemaTool\CreateCommand(),
new ORMCommand\SchemaTool\UpdateCommand(),
new ORMCommand\SchemaTool\DropCommand(),
new ORMCommand\EnsureProductionSettingsCommand(),
new ORMCommand\GenerateProxiesCommand(),
new ORMCommand\RunDqlCommand(),
new ORMCommand\ValidateSchemaCommand(),
new ORMCommand\InfoCommand(),
new ORMCommand\MappingDescribeCommand(),
]);
}
public function run(InputInterface $input): int
@@ -122,7 +86,6 @@ class Application
$container->setParameter('doctrine.website.config_dir', realpath(__DIR__ . '/../config'));
$container->setParameter('doctrine.website.cache_dir', realpath(__DIR__ . '/../cache'));
$container->setParameter('doctrine.website.github.http_token', getenv('doctrine_website_github_http_token'));
$container->setParameter('doctrine.website.mysql.password', getenv('doctrine_website_mysql_password'));
$container->setParameter('doctrine.website.algolia.admin_api_key', getenv('doctrine_website_algolia_admin_api_key') ?: '1234');
$container->setParameter('doctrine.website.stripe.secret_key', getenv('doctrine_website_stripe_secret_key') ?: '');
$container->setParameter('doctrine.website.send_grid.api_key', getenv('doctrine_website_send_grid_api_key') ?: '');

View File

@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Doctrine\Website\Commands;
use Doctrine\ORM\EntityManager;
use Doctrine\Website\Event\EmailParticipants;
use Doctrine\Website\Event\GetStripeEventParticipants;
use Doctrine\Website\Model\Entity\EventParticipant;
@@ -36,7 +35,6 @@ class EventParticipantsCommand extends Command
private EventParticipantRepository $eventParticipantRepository,
private GetStripeEventParticipants $getStripeEventParticipants,
private EmailParticipants $emailParticipants,
private EntityManager $entityManager,
) {
parent::__construct();
}
@@ -142,11 +140,6 @@ class EventParticipantsCommand extends Command
/** @param EventParticipant[] $eventParticipants */
private function saveEventParticipants(array $eventParticipants): void
{
foreach ($eventParticipants as $eventParticipant) {
$this->entityManager->persist($eventParticipant);
}
$this->entityManager->flush();
}
/** @param EventParticipant[] $eventParticipants */

View File

@@ -9,8 +9,6 @@ use Doctrine\SkeletonMapper\ObjectManagerInterface;
use Doctrine\Website\Application;
use Doctrine\Website\Model\Address;
use Doctrine\Website\Model\DateTimeRange;
use Doctrine\Website\Model\Entity\EventParticipant;
use Doctrine\Website\Model\Entity\EventParticipantRepository;
use Doctrine\Website\Model\Event;
use Doctrine\Website\Model\EventCfp;
use Doctrine\Website\Model\EventLocation;
@@ -53,10 +51,8 @@ final class EventHydrator extends ModelHydrator
'test' => 'test',
];
/** @param EventParticipantRepository<EventParticipant> $eventParticipantRepository */
public function __construct(
ObjectManagerInterface $objectManager,
private EventParticipantRepository $eventParticipantRepository,
private string $env,
) {
parent::__construct($objectManager);
@@ -156,9 +152,6 @@ final class EventHydrator extends ModelHydrator
$this->price = (float) ($data['price'] ?? 0.00);
$this->participants = new EventParticipants(
$data['id'],
$this->eventParticipantRepository,
);
$this->participants = new EventParticipants();
}
}

View File

@@ -4,36 +4,17 @@ declare(strict_types=1);
namespace Doctrine\Website\Model\Entity;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\Table;
use Doctrine\Website\Model\Event;
#[Entity(repositoryClass: EventParticipantRepository::class)]
#[Table(name: 'event_participants')]
final class EventParticipant
{
#[Id]
#[Column(type: 'integer')]
#[GeneratedValue]
private int|null $id = null;
#[Column(type: 'string')]
private string $email;
#[Column(type: 'integer')]
private int $quantity;
#[Column(type: 'integer')]
private int $eventId;
public function __construct(Event $event, string $email, int $quantity)
public function __construct(Event $event, private string $email, private int $quantity)
{
$this->eventId = $event->getId();
$this->email = $email;
$this->quantity = $quantity;
$this->eventId = $event->getId();
}
public function getId(): int|null

View File

@@ -4,30 +4,17 @@ declare(strict_types=1);
namespace Doctrine\Website\Model\Entity;
use Doctrine\ORM\EntityRepository;
use function assert;
/**
* @template T of EventParticipant
* @template-extends EntityRepository<T>
*/
final class EventParticipantRepository extends EntityRepository
/** @template T of EventParticipant */
final class EventParticipantRepository
{
public function findOneByEmail(string $email): EventParticipant|null
{
$eventParticipant = $this->findOneBy(['email' => $email]);
assert($eventParticipant instanceof EventParticipant);
return $eventParticipant;
return null;
}
/** @return EventParticipant[] */
public function findByEventId(int $eventId): array
{
/** @var EventParticipant[] $eventParticipants */
$eventParticipants = $this->findBy(['eventId' => $eventId]);
return $eventParticipants;
return [];
}
}

View File

@@ -7,22 +7,12 @@ namespace Doctrine\Website\Model;
use Doctrine\Common\Collections\AbstractLazyCollection;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Website\Model\Entity\EventParticipant;
use Doctrine\Website\Model\Entity\EventParticipantRepository;
/** @template-extends AbstractLazyCollection<int, EventParticipant> */
final class EventParticipants extends AbstractLazyCollection
{
/** @param EventParticipantRepository<EventParticipant> $eventParticipantRepository */
public function __construct(private int $eventId, private EventParticipantRepository $eventParticipantRepository)
{
}
protected function doInitialize(): void
{
/** @var EventParticipant[] $eventParticipants */
$eventParticipants = $this->eventParticipantRepository
->findByEventId($this->eventId);
$this->collection = new ArrayCollection($eventParticipants);
$this->collection = new ArrayCollection();
}
}