Skip to content

Commit

Permalink
rename projection into subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Mar 8, 2024
1 parent 5c5ec5a commit 9c338be
Show file tree
Hide file tree
Showing 114 changed files with 4,517 additions and 4,562 deletions.
16 changes: 8 additions & 8 deletions docs/pages/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ $schemaManager = new DoctrineSchemaManager();
$cli->addCommands(array(
new Command\DatabaseCreateCommand($store, $doctrineHelper),
new Command\DatabaseDropCommand($store, $doctrineHelper),
new Command\ProjectionBootCommand($projectionist),
new Command\ProjectionPauseCommand($projectionist),
new Command\ProjectionRunCommand($projectionist),
new Command\ProjectionTeardownCommand($projectionist),
new Command\ProjectionRemoveCommand($projectionist),
new Command\ProjectionReactivateCommand($projectionist),
new Command\ProjectionRebuildCommand($projectionist),
new Command\ProjectionStatusCommand($projectionist),
new Command\SubscriptionBootCommand($projectionist),
new Command\SubscriptionPauseCommand($projectionist),
new Command\SubscriptionRunCommand($projectionist),
new Command\SubscriptionTeardownCommand($projectionist),
new Command\SubscriptionRemoveCommand($projectionist),
new Command\SubscriptionReactivateCommand($projectionist),
new Command\SubscriptionRebuildCommand($projectionist),
new Command\SubscriptionStatusCommand($projectionist),
new Command\SchemaCreateCommand($store, $schemaManager),
new Command\SchemaDropCommand($store, $schemaManager),
new Command\SchemaUpdateCommand($store, $schemaManager),
Expand Down
25 changes: 9 additions & 16 deletions docs/pages/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ use Doctrine\DBAL\Connection;
use Patchlevel\EventSourcing\Attribute\Setup;
use Patchlevel\EventSourcing\Attribute\Teardown;
use Patchlevel\EventSourcing\Attribute\Subscribe;
use Patchlevel\EventSourcing\Attribute\Projector;
use Patchlevel\EventSourcing\Attribute\Subscriber;
use Patchlevel\EventSourcing\EventBus\Message;
use Patchlevel\EventSourcing\Projection\Projection\ProjectionId;
use Patchlevel\EventSourcing\Projection\Projector\ProjectorUtil;
use Patchlevel\EventSourcing\Projection\Subscription\ProjectionId;
use Patchlevel\EventSourcing\Projection\Subscriber\SubscriberUtil;

#[Projector('hotel')]
#[Subscriber('hotel')]
final class HotelProjector
{
use ProjectorUtil;
use SubscriberUtil;

public function __construct(
private readonly Connection $db
Expand Down Expand Up @@ -277,14 +277,7 @@ final class SendCheckInEmailProcessor
After we have defined everything, we still have to plug the whole thing together:

```php
use Doctrine\DBAL\DriverManager;
use Patchlevel\EventSourcing\EventBus\DefaultEventBus;
use Patchlevel\EventSourcing\Projection\Projection\Store\DoctrineStore;
use Patchlevel\EventSourcing\Projection\Projectionist\DefaultProjectionist;
use Patchlevel\EventSourcing\Projection\Projector\MetadataProjectorAccessorRepository;
use Patchlevel\EventSourcing\Repository\DefaultRepositoryManager;
use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;
use Patchlevel\EventSourcing\Store\DoctrineDbalStore;
use Doctrine\DBAL\DriverManager;use Patchlevel\EventSourcing\EventBus\DefaultEventBus;use Patchlevel\EventSourcing\Projection\Engine\DefaultSubscriptionEngine;use Patchlevel\EventSourcing\Projection\Subscriber\MetadataSubscriberAccessorRepository;use Patchlevel\EventSourcing\Projection\Store\DoctrineSubscriptionStore;use Patchlevel\EventSourcing\Repository\DefaultRepositoryManager;use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;use Patchlevel\EventSourcing\Store\DoctrineDbalStore;

$connection = DriverManager::getConnection([
'url' => 'mysql://user:secret@localhost/app'
Expand All @@ -307,13 +300,13 @@ $eventStore = new DoctrineDbalStore(

$hotelProjector = new HotelProjector($projectionConnection);

$projectorRepository = new MetadataProjectorAccessorRepository([
$projectorRepository = new MetadataSubscriberAccessorRepository([
$hotelProjector,
]);

$projectionStore = new DoctrineStore($connection);
$projectionStore = new DoctrineSubscriptionStore($connection);

$projectionist = new DefaultProjectionist(
$projectionist = new DefaultSubscriptionEngine(
$eventStore,
$projectionStore,
$projectorRepository,
Expand Down
74 changes: 37 additions & 37 deletions docs/pages/projection.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ To do this, you can use the `Projector` attribute.

```php
use Doctrine\DBAL\Connection;
use Patchlevel\EventSourcing\Attribute\Projector;
use Patchlevel\EventSourcing\Projection\Projector\ProjectorUtil;
use Patchlevel\EventSourcing\Attribute\Subscriber;
use Patchlevel\EventSourcing\Projection\Subscriber\SubscriberUtil;

#[Projector('profile_1')]
#[Subscriber('profile_1')]
final class ProfileProjector
{
use ProjectorUtil;
use SubscriberUtil;

public function __construct(
private readonly Connection $connection
Expand Down Expand Up @@ -52,14 +52,14 @@ The method name itself doesn't matter.

```php
use Patchlevel\EventSourcing\Attribute\Subscribe;
use Patchlevel\EventSourcing\Attribute\Projector;
use Patchlevel\EventSourcing\Attribute\Subscriber;
use Patchlevel\EventSourcing\EventBus\Message;
use Patchlevel\EventSourcing\Projection\Projector\ProjectorUtil;
use Patchlevel\EventSourcing\Projection\Subscriber\SubscriberUtil;

#[Projector('profile_1')]
#[Subscriber('profile_1')]
final class ProfileProjector
{
use ProjectorUtil;
use SubscriberUtil;

// ...

Expand Down Expand Up @@ -109,13 +109,13 @@ as the target does it automatically, so you can skip this.
```php
use Patchlevel\EventSourcing\Attribute\Setup;
use Patchlevel\EventSourcing\Attribute\Teardown;
use Patchlevel\EventSourcing\Attribute\Projector;
use Patchlevel\EventSourcing\Projection\Projector\ProjectorUtil;
use Patchlevel\EventSourcing\Attribute\Subscriber;
use Patchlevel\EventSourcing\Projection\Subscriber\SubscriberUtil;

#[Projector('profile_1')]
#[Subscriber('profile_1')]
final class ProfileProjector
{
use ProjectorUtil;
use SubscriberUtil;

// ...

Expand Down Expand Up @@ -160,13 +160,13 @@ You can also implement your read model here.
You can offer methods that then read the data and put it into a specific format.

```php
use Patchlevel\EventSourcing\Attribute\Projector;
use Patchlevel\EventSourcing\Projection\Projector\ProjectorUtil;
use Patchlevel\EventSourcing\Attribute\Subscriber;
use Patchlevel\EventSourcing\Projection\Subscriber\SubscriberUtil;

#[Projector('profile_1')]
#[Subscriber('profile_1')]
final class ProfileProjector
{
use ProjectorUtil;
use SubscriberUtil;

// ...

Expand Down Expand Up @@ -198,9 +198,9 @@ Otherwise, the projectionist will not recognize that the projection has changed
To do this, you can add a version to the `projectorId`:

```php
use Patchlevel\EventSourcing\Attribute\Projector;
use Patchlevel\EventSourcing\Attribute\Subscriber;

#[Projector('profile_2')]
#[Subscriber('profile_2')]
final class ProfileProjector
{
// ...
Expand All @@ -218,9 +218,9 @@ You can also group projectors and address these to the projectionist.
This is useful if you want to run projectors in different processes or on different servers.

```php
use Patchlevel\EventSourcing\Attribute\Projector;
use Patchlevel\EventSourcing\Attribute\Subscriber;

#[Projector('profile_1', group: 'a')]
#[Subscriber('profile_1', group: 'a')]
final class ProfileProjector
{
// ...
Expand All @@ -242,10 +242,10 @@ This is the default mode.
The projector will start from the beginning of the event stream and process all events.

```php
use Patchlevel\EventSourcing\Attribute\Projector;
use Patchlevel\EventSourcing\Projection\Projection\RunMode;
use Patchlevel\EventSourcing\Attribute\Subscriber;
use Patchlevel\EventSourcing\Projection\Subscription\RunMode;

#[Projector('welcome_email', runMode: RunMode::FromBeginning)]
#[Subscriber('welcome_email', runMode: RunMode::FromBeginning)]
final class WelcomeEmailProjector
{
// ...
Expand All @@ -259,10 +259,10 @@ This is useful for projectors that are only interested in events that occur afte
As example, a welcome email projector that only wants to send emails to new users.

```php
use Patchlevel\EventSourcing\Attribute\Projector;
use Patchlevel\EventSourcing\Projection\Projection\RunMode;
use Patchlevel\EventSourcing\Attribute\Subscriber;
use Patchlevel\EventSourcing\Projection\Subscription\RunMode;

#[Projector('welcome_email', runMode: RunMode::FromNow)]
#[Subscriber('welcome_email', runMode: RunMode::FromNow)]
final class WelcomeEmailProjector
{
// ...
Expand All @@ -275,10 +275,10 @@ This mode is useful for projectors that only need to run once.
This is useful for projectors to create reports or to migrate data.

```php
use Patchlevel\EventSourcing\Attribute\Projector;
use Patchlevel\EventSourcing\Projection\Projection\RunMode;
use Patchlevel\EventSourcing\Attribute\Subscriber;
use Patchlevel\EventSourcing\Projection\Subscription\RunMode;

#[Projector('migration', runMode: RunMode::Once)]
#[Subscriber('migration', runMode: RunMode::Once)]
final class MigrationProjector
{
// ...
Expand Down Expand Up @@ -419,9 +419,9 @@ The Projectionist uses a projection store to store the status of each projection
We provide a Doctrine implementation of this by default.

```php
use Patchlevel\EventSourcing\Projection\Projection\Store\DoctrineStore;
use Patchlevel\EventSourcing\Projection\Store\DoctrineSubscriptionStore;

$projectionStore = new DoctrineStore($connection);
$projectionStore = new DoctrineSubscriptionStore($connection);
```

So that the schema for the projection store can also be created,
Expand Down Expand Up @@ -475,9 +475,9 @@ The projector accessor is responsible for providing the projectors to the projec
We provide a metadata projector accessor repository by default.

```php
use Patchlevel\EventSourcing\Projection\Projector\MetadataProjectorAccessorRepository;
use Patchlevel\EventSourcing\Projection\Subscriber\MetadataSubscriberAccessorRepository;

$projectorAccessorRepository = new MetadataProjectorAccessorRepository([$projector1, $projector2, $projector3]);
$projectorAccessorRepository = new MetadataSubscriberAccessorRepository([$projector1, $projector2, $projector3]);
```

### Projectionist
Expand All @@ -487,9 +487,9 @@ The event store is needed to load the events, the Projection Store to store the
and the respective projectors. Optionally, we can also pass a retry strategy.

```php
use Patchlevel\EventSourcing\Projection\Projectionist\DefaultProjectionist;
use Patchlevel\EventSourcing\Projection\Engine\DefaultSubscriptionEngine;

$projectionist = new DefaultProjectionist(
$projectionist = new DefaultSubscriptionEngine(
$eventStore,
$projectionStore,
$projectorAccessorRepository,
Expand All @@ -503,9 +503,9 @@ The Projectionist has a few methods needed to use it effectively.
A `ProjectionistCriteria` can be passed to all of these methods to filter the respective projectors.

```php
use Patchlevel\EventSourcing\Projection\Projectionist\ProjectionistCriteria;
use Patchlevel\EventSourcing\Projection\Engine\SubscriptionEngineCriteria;

$criteria = new ProjectionistCriteria(
$criteria = new SubscriptionEngineCriteria(
ids: ['profile_1', 'welcome_email'],
groups: ['default']
);
Expand Down
8 changes: 4 additions & 4 deletions src/Attribute/Projector.php → src/Attribute/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
namespace Patchlevel\EventSourcing\Attribute;

use Attribute;
use Patchlevel\EventSourcing\Projection\Projection\Projection;
use Patchlevel\EventSourcing\Projection\Projection\RunMode;
use Patchlevel\EventSourcing\Subscription\Subscription\RunMode;
use Patchlevel\EventSourcing\Subscription\Subscription\Subscription;

#[Attribute(Attribute::TARGET_CLASS)]
final class Projector
final class Subscriber
{
public function __construct(
public readonly string $id,
public readonly string $group = Projection::DEFAULT_GROUP,
public readonly string $group = Subscription::DEFAULT_GROUP,
public readonly RunMode $runMode = RunMode::FromBeginning,
) {
}
Expand Down
33 changes: 0 additions & 33 deletions src/Console/Command/ProjectionRebuildCommand.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
'event-sourcing:projection:boot',
'Prepare new projections and catch up with the event store',
'event-sourcing:subscription:boot',
'Prepare new subscriptions and catch up with the event store',
)]
final class ProjectionBootCommand extends ProjectionCommand
final class SubscriptionBootCommand extends SubscriptionCommand
{
public function configure(): void
{
Expand All @@ -33,8 +33,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$limit = InputHelper::nullablePositiveInt($input->getOption('limit'));

$criteria = $this->projectionCriteria($input);
$this->projectionist->boot($criteria, $limit);
$criteria = $this->subscriptionEngineCriteria($input);
$this->engine->boot($criteria, $limit);

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
namespace Patchlevel\EventSourcing\Console\Command;

use Patchlevel\EventSourcing\Console\InputHelper;
use Patchlevel\EventSourcing\Projection\Projectionist\Projectionist;
use Patchlevel\EventSourcing\Projection\Projectionist\ProjectionistCriteria;
use Patchlevel\EventSourcing\Subscription\Engine\SubscriptionEngine;
use Patchlevel\EventSourcing\Subscription\Engine\SubscriptionEngineCriteria;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;

/** @interal */
abstract class ProjectionCommand extends Command
abstract class SubscriptionCommand extends Command
{
public function __construct(
protected readonly Projectionist $projectionist,
protected readonly SubscriptionEngine $engine,
) {
parent::__construct();
}
Expand All @@ -27,19 +27,19 @@ protected function configure(): void
'id',
null,
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
'filter by projection id',
'filter by subscription id',
)
->addOption(
'group',
null,
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
'filter by projection group',
'filter by subscription group',
);
}

protected function projectionCriteria(InputInterface $input): ProjectionistCriteria
protected function subscriptionEngineCriteria(InputInterface $input): SubscriptionEngineCriteria
{
return new ProjectionistCriteria(
return new SubscriptionEngineCriteria(
InputHelper::nullableStringList($input->getOption('id')),
InputHelper::nullableStringList($input->getOption('group')),
);
Expand Down
Loading

0 comments on commit 9c338be

Please sign in to comment.