Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monorepo v6 refactoring: EasyActivity #1409

Merged
merged 5 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"autoload": {
"psr-4": {
"EonX\\EasyActivity\\": "packages/EasyActivity/src",
"EonX\\EasyActivity\\Bundle\\": "packages/EasyActivity/bundle",
"EonX\\EasyApiPlatform\\": "packages/EasyApiPlatform/src",
"EonX\\EasyApiToken\\": "packages/EasyApiToken/src",
"EonX\\EasyAsync\\": "packages/EasyAsync/src",
Expand Down Expand Up @@ -126,7 +127,8 @@
"autoload-dev": {
"psr-4": {
"EonX\\EasyActivity\\Tests\\": "packages/EasyActivity/tests",
"EonX\\EasyActivity\\Tests\\Bridge\\Symfony\\Fixtures\\App\\": "packages/EasyActivity/tests/Bridge/Symfony/Fixtures/app/src",
"EonX\\EasyActivity\\Tests\\Fixture\\App\\": "packages/EasyActivity/tests/Fixture/app/src",
"EonX\\EasyActivity\\Tests\\Unit\\": "packages/EasyActivity/tests/Unit/src",
"EonX\\EasyApiPlatform\\Tests\\": "packages/EasyApiPlatform/tests",
"EonX\\EasyApiPlatform\\Tests\\Fixtures\\App\\": "packages/EasyApiPlatform/tests/Fixtures/app/src",
"EonX\\EasyApiToken\\Tests\\": "packages/EasyApiToken/tests",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,42 @@
<?php
declare(strict_types=1);

namespace EonX\EasyActivity\Bridge\Symfony;
namespace EonX\EasyActivity\Bundle;

use EonX\EasyActivity\Bridge\BridgeConstantsInterface;
use EonX\EasyActivity\Bundle\Enum\ConfigParam;
use Symfony\Component\Config\Definition\Configuration;
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;

final class EasyActivitySymfonyBundle extends AbstractBundle
final class EasyActivityBundle extends AbstractBundle
{
private const EASY_ACTIVITY_CONFIG = [
'disallowed_properties' => BridgeConstantsInterface::PARAM_DISALLOWED_PROPERTIES,
'easy_doctrine_subscriber_enabled' => BridgeConstantsInterface::PARAM_EASY_DOCTRINE_SUBSCRIBER_ENABLED,
'subjects' => BridgeConstantsInterface::PARAM_SUBJECTS,
'table_name' => BridgeConstantsInterface::PARAM_TABLE_NAME,
'disallowed_properties' => ConfigParam::DisallowedProperties,
'easy_doctrine_subscriber_enabled' => ConfigParam::EasyDoctrineSubscriberEnabled,
'subjects' => ConfigParam::Subjects,
'table_name' => ConfigParam::TableName,
];

protected string $extensionAlias = 'easy_activity';

public function __construct()
{
$this->path = \realpath(__DIR__);
}

public function configure(DefinitionConfigurator $definition): void
{
$definition->import(__DIR__ . '/Resources/config/definition.php');
$definition->import(__DIR__ . '/config/definition.php');
}

public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
{
foreach (self::EASY_ACTIVITY_CONFIG as $name => $param) {
$container
->parameters()
->set($param, $config[$name]);
->set($param->value, $config[$name]);
}

$container->import(__DIR__ . '/Resources/config/services.php');
$container->import(__DIR__ . '/config/services.php');

if ($this->easyDoctrineBundleIsRegistered($builder)) {
$container->import(__DIR__ . '/Resources/config/easy-doctrine-bridge-services.php');
$container->import(__DIR__ . '/config/easy-doctrine-bridge-services.php');
}
}

Expand Down
15 changes: 15 additions & 0 deletions packages/EasyActivity/bundle/Enum/ConfigParam.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);

namespace EonX\EasyActivity\Bundle\Enum;

enum ConfigParam: string
{
case DisallowedProperties = 'easy_activity.disallowed_properties';

case EasyDoctrineSubscriberEnabled = 'easy_activity.easy_doctrine_subscriber_enabled';

case Subjects = 'easy_activity.subjects';

case TableName = 'easy_activity.table_name';
}
11 changes: 11 additions & 0 deletions packages/EasyActivity/bundle/Enum/ConfigServiceId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);

namespace EonX\EasyActivity\Bundle\Enum;

enum ConfigServiceId: string
{
case CircularReferenceHandler = 'easy_activity.circular_reference_handler';

case Serializer = 'easy_activity.serializer';
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use EonX\EasyActivity\Bridge\BridgeConstantsInterface;
use EonX\EasyActivity\Bridge\EasyDoctrine\EasyDoctrineEntityEventsSubscriber;
use EonX\EasyActivity\Bridge\EasyDoctrine\EasyDoctrineEntityEventsSubscriberInterface;
use EonX\EasyActivity\Bundle\Enum\ConfigParam;
use EonX\EasyActivity\EasyDoctrine\Subscriber\EasyDoctrineEntityEventsSubscriber;
use EonX\EasyActivity\EasyDoctrine\Subscriber\EasyDoctrineEntityEventsSubscriberInterface;

return static function (ContainerConfigurator $container): void {
$services = $container->services();
Expand All @@ -15,6 +15,6 @@

$services
->set(EasyDoctrineEntityEventsSubscriberInterface::class, EasyDoctrineEntityEventsSubscriber::class)
->arg('$enabled', '%' . BridgeConstantsInterface::PARAM_EASY_DOCTRINE_SUBSCRIBER_ENABLED . '%')
->arg('$enabled', param(ConfigParam::EasyDoctrineSubscriberEnabled->value))
->tag('kernel.event_subscriber');
};
74 changes: 74 additions & 0 deletions packages/EasyActivity/bundle/config/services.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use EonX\EasyActivity\Bundle\Enum\ConfigParam;
use EonX\EasyActivity\Bundle\Enum\ConfigServiceId;
use EonX\EasyActivity\Common\CircularReferenceHandler\CircularReferenceHandler;
use EonX\EasyActivity\Common\Dispatcher\AsyncDispatcherInterface;
use EonX\EasyActivity\Common\Factory\ActivityLogEntryFactory;
use EonX\EasyActivity\Common\Factory\ActivityLogEntryFactoryInterface;
use EonX\EasyActivity\Common\Factory\IdFactoryInterface;
use EonX\EasyActivity\Common\Factory\UuidFactory;
use EonX\EasyActivity\Common\Logger\ActivityLoggerInterface;
use EonX\EasyActivity\Common\Logger\AsyncActivityLogger;
use EonX\EasyActivity\Common\Resolver\ActivitySubjectDataResolverInterface;
use EonX\EasyActivity\Common\Resolver\ActivitySubjectResolverInterface;
use EonX\EasyActivity\Common\Resolver\ActorResolverInterface;
use EonX\EasyActivity\Common\Resolver\DefaultActivitySubjectResolver;
use EonX\EasyActivity\Common\Resolver\DefaultActorResolver;
use EonX\EasyActivity\Common\Serializer\ActivitySubjectDataSerializerInterface;
use EonX\EasyActivity\Common\Serializer\SymfonyActivitySubjectDataSerializer;
use EonX\EasyActivity\Common\Store\StoreInterface;
use EonX\EasyActivity\Doctrine\Resolver\DoctrineActivitySubjectDataResolver;
use EonX\EasyActivity\Doctrine\Store\DoctrineDbalStore;
use EonX\EasyActivity\Messenger\Dispatcher\AsyncDispatcher;
use EonX\EasyActivity\Messenger\MessageHandler\ActivityLogEntryMessageHandler;

return static function (ContainerConfigurator $container): void {
$services = $container->services();
$services->defaults()
->autowire()
->autoconfigure();

$services
->set(StoreInterface::class, DoctrineDbalStore::class)
->arg('$table', param(ConfigParam::TableName->value));

$services
->set(IdFactoryInterface::class, UuidFactory::class);

$services
->set(ActorResolverInterface::class, DefaultActorResolver::class);

$services
->set(ActivitySubjectResolverInterface::class, DefaultActivitySubjectResolver::class)
->arg('$subjects', param(ConfigParam::Subjects->value));

$services
->set(ActivitySubjectDataResolverInterface::class, DoctrineActivitySubjectDataResolver::class);

$services
->set(ActivityLoggerInterface::class, AsyncActivityLogger::class);

$services
->alias(ConfigServiceId::Serializer->value, 'serializer');

$services->set(ConfigServiceId::CircularReferenceHandler->value, CircularReferenceHandler::class);

$services
->set(ActivitySubjectDataSerializerInterface::class, SymfonyActivitySubjectDataSerializer::class)
->arg('$serializer', service(ConfigServiceId::Serializer->value))
->arg('$circularReferenceHandler', service(ConfigServiceId::CircularReferenceHandler->value))
->arg('$disallowedProperties', param(ConfigParam::DisallowedProperties->value));

$services
->set(ActivityLogEntryFactoryInterface::class, ActivityLogEntryFactory::class);

$services
->set(ActivityLogEntryMessageHandler::class);

$services
->set(AsyncDispatcherInterface::class, AsyncDispatcher::class);
};
46 changes: 16 additions & 30 deletions packages/EasyActivity/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,39 @@
"type": "library",
"license": "MIT",
"require": {
"doctrine/common": "^3.0",
"nesbot/carbon": "^2.67",
"php": "^8.1",
"symfony/serializer": "^6.4"
},
"require-dev": {
"doctrine/dbal": "^3.0",
"doctrine/doctrine-bundle": "^2.8",
"doctrine/orm": "^2.14",
"doctrine/persistence": "^3.0",
"eonx-com/easy-doctrine": "^5.12",
"eonx-com/easy-event-dispatcher": "^5.12",
"eonx-com/easy-lock": "^5.12",
"nesbot/carbon": "^2.67",
"symfony/config": "^6.4",
"symfony/dependency-injection": "^6.4",
"symfony/event-dispatcher": "^6.4",
"symfony/http-kernel": "^6.4",
"symfony/messenger": "^6.4",
"symfony/serializer": "^6.4",
"symfony/uid": "^6.4"
},
"require-dev": {
"doctrine/doctrine-bundle": "^2.8",
"eonx-com/easy-test": "^5.12",
"eonx-com/easy-webhook": "^5.12",
"phpunit/phpunit": "^10.2",
"psr/log": "^3.0",
"symfony/amazon-sqs-messenger": "^6.4",
"symfony/doctrine-bridge": "^6.4",
"symfony/framework-bundle": "^6.4",
"symfony/monolog-bundle": "^3.8",
"symfony/uid": "^6.4"
"symfony/framework-bundle": "^6.4"
},
"autoload": {
"psr-4": {
"EonX\\EasyActivity\\": "src"
"EonX\\EasyActivity\\": "src",
"EonX\\EasyActivity\\Bundle\\": "bundle"
}
},
"autoload-dev": {
"psr-4": {
"EonX\\EasyActivity\\Tests\\": "tests",
"EonX\\EasyActivity\\Tests\\Bridge\\Symfony\\Fixtures\\App\\": "tests/Bridge/Symfony/Fixtures/app/src"
"EonX\\EasyActivity\\Tests\\Fixture\\App\\": "tests/Fixture/app/src",
"EonX\\EasyActivity\\Tests\\Unit\\": "tests/Unit/src"
}
},
"suggest": {
"doctrine/dbal": "To save log entities to a database",
"doctrine/orm": "To save log entities to a database",
"eonx-com/easy-doctrine": "To create log entries from Doctrine events",
"eonx-com/easy-lock": "To lock async messages",
"symfony/config": "To use this package with Symfony",
"symfony/dependency-injection": "To use this package with Symfony",
"symfony/event-dispatcher": "To subscribe to EasyDoctrine events",
"symfony/http-kernel": "To use this package with Symfony",
"symfony/messenger": "To use this package with Symfony",
"symfony/serializer": "To use this package with Symfony",
"symfony/uid": "To use this package with Symfony"
},
"extra": {
"branch-alias": {
"dev-master": "5.12-dev"
Expand Down
13 changes: 7 additions & 6 deletions packages/EasyActivity/docs/activity-log-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ weight: 1003

# ActivityLogEntry class

The `EonX\EasyActivity\ActivityLogEntry` class defines the data that can be recorded in an activity log entry.
The `EonX\EasyActivity\Common\Entity\ActivityLogEntry` class defines the data that can be recorded in an activity log entry.

## Properties

An ActivityLogEntry object has the following properties:

- `action`: The type of action performed on the subject, which may be one of:
- `ActivityLogEntry::ACTION_CREATE` (i.e. `create`): Create subject
- `ActivityLogEntry::ACTION_DELETE` (i.e. `delete`): Delete subject
- `ActivityLogEntry::ACTION_UPDATE` (i.e. `update`): Update subject
- `ActivityLogEntry::ACTION_CREATE` (i.e. `create`): Create subject
- `ActivityLogEntry::ACTION_DELETE` (i.e. `delete`): Delete subject
- `ActivityLogEntry::ACTION_UPDATE` (i.e. `update`): Update subject
- `actorId`: An optional identifier for an actor in the application.
- `actorName`: An optional name for an actor in the application.
- `actorType`: A mandatory actor type. The actor type could be a `user`, `provider`, `customer`, `jwt:provider`,
Expand All @@ -35,9 +35,10 @@ An ActivityLogEntry object has the following properties:

## ActivityLogEntry creation

The package provides `EonX\EasyActivity\Interfaces\ActivityLogEntryFactoryInterface` that takes care of activity log
entry creation. A default implementation `EonX\EasyActivity\ActivityLogEntryFactory` is also provided by the package.
The package provides `EonX\EasyActivity\Common\Factory\ActivityLogEntryFactoryInterface` that takes care of activity log
entry creation. A default implementation `EonX\EasyActivity\Common\Factory\ActivityLogEntryFactory` is also provided by the package.
See [Usage][2] for more information on using the package.

[1]: config.md

[2]: usage.md
55 changes: 35 additions & 20 deletions packages/EasyActivity/docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,39 @@ The configuration options are as follows:

## Example configuration file

In Symfony, you could have a configuration file called `easy_activity.yaml` that looks like the following:

```yaml
easy_activity:
disallowed_properties:
- updatedAt
subjects:
App\Entity\SomeEntity:
allowed_properties:
- content
- description
disallowed_properties:
- author
nested_object_allowed_properties:
App\Entity\SomeOtherEntity:
- processingDate
type: SomeEntity
table_name: activity_logs
```
In Symfony, you could have a configuration file called `easy_activity.php` that looks like the following:

```php
<?php
declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

[1]: https://flex.symfony.com/
use App\Entity\SomeEntity;
use App\Entity\SomeOtherEntity;
use Symfony\Config\EasyActivityConfig;

return static function (EasyActivityConfig $easyActivityConfig): void {
$easyActivityConfig
->tableName('activity_logs')
->disallowedProperties([
'updatedAt',
]);

$easyActivityConfig->subjects(SomeEntity::class)
->allowedProperties([
'content',
'description',
])
->disallowedProperties([
'author',
])
->nestedObjectAllowedProperties([
SomeOtherEntity::class => [
'processingDate',
]
])
->type('SomeEntity');
};

```
6 changes: 5 additions & 1 deletion packages/EasyActivity/docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ If you're using [Symfony Flex][2], this step has been done automatically for you
return [
// Other bundles ...

EonX\EasyActivity\Bridge\Symfony\EasyActivitySymfonyBundle::class => ['all' => true],
EonX\EasyActivity\Bundle\EasyActivityBundle::class => ['all' => true],
];
```

Expand All @@ -39,7 +39,11 @@ following packages for the following purposes:
- [symfony/messenger][5]: to store entries asynchronously

[1]: https://getcomposer.org/

[2]: https://flex.symfony.com/

[3]: https://github.com/eonx-com/easy-doctrine

[4]: https://github.com/symfony/serializer

[5]: https://github.com/symfony/messenger
Loading