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: EasyLock #1430

Merged
merged 7 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
"EonX\\EasyHttpClient\\Bundle\\": "packages/EasyHttpClient/bundle",
"EonX\\EasyHttpClient\\Laravel\\": "packages/EasyHttpClient/laravel",
"EonX\\EasyLock\\": "packages/EasyLock/src",
"EonX\\EasyLock\\Bundle\\": "packages/EasyLock/bundle",
"EonX\\EasyLock\\Laravel\\": "packages/EasyLock/laravel",
"EonX\\EasyLogging\\": "packages/EasyLogging/src",
"EonX\\EasyMonorepo\\": "monorepo",
"EonX\\EasyNotification\\": "packages/EasyNotification/src",
Expand Down Expand Up @@ -167,6 +169,9 @@
"EonX\\EasyHttpClient\\Tests\\Unit\\": "packages/EasyHttpClient/tests/Unit/src",
"EonX\\EasyHttpClient\\Tests\\Unit\\Laravel\\": "packages/EasyHttpClient/tests/Unit/laravel",
"EonX\\EasyLock\\Tests\\": "packages/EasyLock/tests",
"EonX\\EasyLock\\Tests\\Unit\\": "packages/EasyLock/tests/Unit/src",
"EonX\\EasyLock\\Tests\\Unit\\Bundle\\": "packages/EasyLock/tests/Unit/bundle",
"EonX\\EasyLock\\Tests\\Unit\\Laravel\\": "packages/EasyLock/tests/Unit/laravel",
"EonX\\EasyLogging\\Tests\\": "packages/EasyLogging/tests",
"EonX\\EasyNotification\\Tests\\": "packages/EasyNotification/tests",
"EonX\\EasyPagination\\Tests\\": "packages/EasyPagination/tests",
Expand Down
1 change: 1 addition & 0 deletions packages/EasyActivity/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"symfony/event-dispatcher": "^6.4",
"symfony/http-kernel": "^6.4",
"symfony/messenger": "^6.4",
"symfony/property-access": "^6.4",
"symfony/serializer": "^6.4",
"symfony/uid": "^6.4"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
namespace EonX\EasyActivity\Messenger\Message;

use EonX\EasyActivity\Common\Entity\ActivityLogEntry;
use EonX\EasyLock\Interfaces\LockDataInterface;
use EonX\EasyLock\Interfaces\WithLockDataInterface;
use EonX\EasyLock\LockData;
use EonX\EasyLock\Common\ValueObject\LockData;
use EonX\EasyLock\Common\ValueObject\LockDataInterface;
use EonX\EasyLock\Common\ValueObject\WithLockDataInterface;

final class ActivityLogEntryMessage implements WithLockDataInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
namespace EonX\EasyBatch\Bridge\Symfony\Messenger\Lock;

use EonX\EasyBatch\Bridge\Symfony\Messenger\Stamps\BatchItemStamp;
use EonX\EasyLock\Interfaces\LockDataInterface;
use EonX\EasyLock\LockData;
use EonX\EasyLock\Common\ValueObject\LockData;
use EonX\EasyLock\Common\ValueObject\LockDataInterface;
use Symfony\Component\Messenger\Envelope;

final class BatchItemLockFactory implements BatchItemLockFactoryInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace EonX\EasyBatch\Bridge\Symfony\Messenger\Lock;

use EonX\EasyLock\Interfaces\LockDataInterface;
use EonX\EasyLock\Common\ValueObject\LockDataInterface;
use Symfony\Component\Messenger\Envelope;

interface BatchItemLockFactoryInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use EonX\EasyBatch\Interfaces\CurrentBatchObjectsAwareInterface;
use EonX\EasyBatch\Processors\BatchItemProcessor;
use EonX\EasyBatch\Processors\BatchProcessor;
use EonX\EasyLock\Interfaces\LockServiceInterface;
use EonX\EasyLock\Common\Locker\LockerInterface;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
use Symfony\Component\Messenger\Middleware\StackInterface;
Expand All @@ -29,7 +29,7 @@ public function __construct(
private readonly BatchItemProcessor $batchItemProcessor,
private readonly BatchItemLockFactoryInterface $batchItemLockFactory,
private readonly BatchProcessor $batchProcessor,
private readonly LockServiceInterface $lockService,
private readonly LockerInterface $locker,
) {
}

Expand All @@ -56,7 +56,7 @@ public function handle(Envelope $envelope, StackInterface $stack): Envelope
// Since items can be dispatched multiple times to guarantee all items are dispatched
// We must protect the processing logic with a lock to make sure the same item isn't processed
// by multiple workers concurrently
$result = $this->lockService->processWithLock(
$result = $this->locker->processWithLock(
$this->batchItemLockFactory->createFromEnvelope($envelope),
function () use ($batchItemStamp, $message, $func) {
$batchItem = $this->batchItemRepository->findForProcess($batchItemStamp->getBatchItemId());
Expand Down
4 changes: 2 additions & 2 deletions packages/EasyBatch/tests/Bridge/Symfony/Stubs/KernelStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use EonX\EasyBatch\Bridge\Symfony\EasyBatchSymfonyBundle;
use EonX\EasyEncryption\Bridge\Symfony\EasyEncryptionSymfonyBundle;
use EonX\EasyEventDispatcher\Bundle\EasyEventDispatcherBundle;
use EonX\EasyLock\Interfaces\LockServiceInterface;
use EonX\EasyLock\Common\Locker\LockerInterface;
use EonX\EasyRandom\Bridge\Symfony\EasyRandomSymfonyBundle;
use Psr\Container\ContainerInterface;
use stdClass;
Expand All @@ -25,7 +25,7 @@ public function process(ContainerBuilder $container): void
{
$container->setAlias(ContainerInterface::class, 'service_container');
$container->setDefinition(EventDispatcherInterface::class, new Definition(SymfonyEventDispatcherStub::class));
$container->setDefinition(LockServiceInterface::class, new Definition(stdClass::class));
$container->setDefinition(LockerInterface::class, new Definition(stdClass::class));
$container->setDefinition(MessageBusInterface::class, new Definition(MessageBusStub::class));

$container->setDefinition(
Expand Down
4 changes: 2 additions & 2 deletions packages/EasyHttpClient/tests/Fixture/app/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use EonX\EasyEventDispatcher\Bundle\EasyEventDispatcherBundle;
use EonX\EasyHttpClient\Bundle\EasyHttpClientBundle;
use EonX\EasyLock\Bridge\Symfony\EasyLockSymfonyBundle;
use EonX\EasyLock\Bundle\EasyLockBundle;
use EonX\EasyWebhook\Bridge\Symfony\EasyWebhookSymfonyBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;

Expand All @@ -18,7 +18,7 @@
EasyWebhookSymfonyBundle::class => [
'all' => true,
],
EasyLockSymfonyBundle::class => [
EasyLockBundle::class => [
'all' => true,
],
EasyHttpClientBundle::class => [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php
declare(strict_types=1);

namespace EonX\EasyLock\Bridge\Symfony\DependencyInjection\Compiler;
namespace EonX\EasyLock\Bundle\CompilerPass;

use EonX\EasyLock\Bridge\BridgeConstantsInterface;
use EonX\EasyLock\Bundle\Enum\ConfigParam;
use EonX\EasyLock\Bundle\Enum\ConfigServiceId;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Lock\PersistingStoreInterface;
use Symfony\Component\Lock\Store\StoreFactory;

final class RegisterLockStoreServicePass implements CompilerPassInterface
final class RegisterLockStoreServiceCompilerPass implements CompilerPassInterface
{
private const DEFAULT_CONNECTION_ID = 'flock';

Expand All @@ -20,7 +21,7 @@ public function process(ContainerBuilder $container): void
// If connection from config doesn't exist in container, use flock by default
$connectionId = $this->getConnectionId(
$container,
$this->getParameter($container, BridgeConstantsInterface::PARAM_CONNECTION)
$this->getParameter($container, ConfigParam::Connection->value)
);

$arg = $connectionId !== null ? new Reference($connectionId) : self::DEFAULT_CONNECTION_ID;
Expand All @@ -29,7 +30,7 @@ public function process(ContainerBuilder $container): void
->setFactory([StoreFactory::class, 'createStore'])
->setArguments([$arg]);

$container->setDefinition(BridgeConstantsInterface::SERVICE_STORE, $def);
$container->setDefinition(ConfigServiceId::Store->value, $def);
}

private function getConnectionId(ContainerBuilder $container, ?string $param = null): ?string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
declare(strict_types=1);

namespace EonX\EasyLock\Bridge\Symfony\DependencyInjection\Compiler;
namespace EonX\EasyLock\Bundle\CompilerPass;

use EonX\EasyLock\Bridge\BridgeConstantsInterface;
use EonX\EasyLock\Bridge\Symfony\Messenger\ProcessWithLockMiddleware;
use EonX\EasyLock\Bundle\Enum\ConfigParam;
use EonX\EasyLock\Messenger\Middleware\ProcessWithLockMiddleware;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -69,7 +69,7 @@ public function process(ContainerBuilder $container): void

private function isEnabled(ContainerBuilder $container): bool
{
return $container->hasParameter(BridgeConstantsInterface::PARAM_MESSENGER_MIDDLEWARE_AUTO_REGISTER)
&& $container->getParameter(BridgeConstantsInterface::PARAM_MESSENGER_MIDDLEWARE_AUTO_REGISTER);
return $container->hasParameter(ConfigParam::MessengerMiddlewareAutoRegister->value)
&& $container->getParameter(ConfigParam::MessengerMiddlewareAutoRegister->value);
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<?php
declare(strict_types=1);

namespace EonX\EasyLock\Bridge\Symfony;
namespace EonX\EasyLock\Bundle;

use EonX\EasyLock\Bridge\BridgeConstantsInterface;
use EonX\EasyLock\Bridge\Symfony\DependencyInjection\Compiler\RegisterLockStoreServicePass;
use EonX\EasyLock\Bridge\Symfony\DependencyInjection\Compiler\RegisterMessengerMiddlewareCompilerPass;
use EonX\EasyLock\Bundle\CompilerPass\RegisterLockStoreServiceCompilerPass;
use EonX\EasyLock\Bundle\CompilerPass\RegisterMessengerMiddlewareCompilerPass;
use EonX\EasyLock\Bundle\Enum\ConfigParam;
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;
use Symfony\Component\Messenger\DependencyInjection\MessengerPass;

final class EasyLockSymfonyBundle extends AbstractBundle
final class EasyLockBundle extends AbstractBundle
{
protected string $extensionAlias = 'easy_lock';

public function __construct()
{
$this->path = \realpath(__DIR__);
Expand All @@ -24,33 +22,33 @@ public function __construct()
public function build(ContainerBuilder $container): void
{
$container
->addCompilerPass(new RegisterLockStoreServicePass())
->addCompilerPass(new RegisterLockStoreServiceCompilerPass())
// -9 to run before easy-async and easy-batch so middleware is after
->addCompilerPass(new RegisterMessengerMiddlewareCompilerPass(), priority: -9);
}

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

public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
{
$container->import(__DIR__ . '/Resources/config/services.php');
$container->import('config/services.php');

$container
->parameters()
->set(BridgeConstantsInterface::PARAM_CONNECTION, $config['connection']);
->set(ConfigParam::Connection->value, $config['connection']);

if (\class_exists(MessengerPass::class)) {
$container
->parameters()
->set(
BridgeConstantsInterface::PARAM_MESSENGER_MIDDLEWARE_AUTO_REGISTER,
ConfigParam::MessengerMiddlewareAutoRegister->value,
$config['messenger_middleware_auto_register'] ?? true
);

$container->import(__DIR__ . '/Resources/config/messenger_middleware.php');
$container->import('config/messenger_middleware.php');
}
}
}
9 changes: 9 additions & 0 deletions packages/EasyLock/bundle/Enum/BundleParam.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);

namespace EonX\EasyLock\Bundle\Enum;

enum BundleParam: string
{
case LogChannel = 'lock';
}
11 changes: 11 additions & 0 deletions packages/EasyLock/bundle/Enum/ConfigParam.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);

namespace EonX\EasyLock\Bundle\Enum;

enum ConfigParam: string
{
case Connection = 'easy_lock.param.connection';

case MessengerMiddlewareAutoRegister = 'easy_lock.messenger_middleware_auto_register';
}
11 changes: 11 additions & 0 deletions packages/EasyLock/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\EasyLock\Bundle\Enum;

enum ConfigServiceId: string
{
case Connection = 'easy_lock.connection';

case Store = 'easy_lock.store';
}
12 changes: 12 additions & 0 deletions packages/EasyLock/bundle/config/messenger_middleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use EonX\EasyLock\Messenger\Middleware\ProcessWithLockMiddleware;

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

$services->set(ProcessWithLockMiddleware::class);
};
23 changes: 23 additions & 0 deletions packages/EasyLock/bundle/config/services.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use EonX\EasyLock\Bundle\Enum\BundleParam;
use EonX\EasyLock\Bundle\Enum\ConfigServiceId;
use EonX\EasyLock\Common\Locker\Locker;
use EonX\EasyLock\Common\Locker\LockerInterface;
use EonX\EasyLock\Doctrine\Listener\EasyLockDoctrineSchemaListener;

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

$services
->set(LockerInterface::class, Locker::class)
->arg('$store', service(ConfigServiceId::Store->value))
->tag('monolog.logger', ['channel' => BundleParam::LogChannel->value]);

$services
->set(EasyLockDoctrineSchemaListener::class)
->arg('$persistingStore', service(ConfigServiceId::Store->value));
};
27 changes: 21 additions & 6 deletions packages/EasyLock/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,40 @@
"license": "MIT",
"require": {
"php": "^8.2",
"symfony/lock": "^6.4"
"doctrine/dbal": "^3.0",
"doctrine/doctrine-bundle": "^2.8",
"doctrine/orm": "^2.14",
"psr/log": "^3.0",
"symfony/config": "^6.4",
"symfony/dependency-injection": "^6.4",
"symfony/http-kernel": "^6.4",
"symfony/lock": "^6.4",
"symfony/service-contracts": "^3.5"
},
"require-dev": {
"doctrine/orm": "^2.14",
"laravel/lumen-framework": "^9.1",
"phpunit/phpunit": "^10.2",
"symfony/symfony": "^6.4"
"phpunit/phpunit": "^10.2"
},
"autoload": {
"psr-4": {
"EonX\\EasyLock\\": "src",
"EonX\\EasyLock\\Bridge\\Symfony\\": "src/Bridge/Symfony"
"EonX\\EasyLock\\Bundle\\": "bundle",
"EonX\\EasyLock\\Laravel\\": "laravel"
}
},
"autoload-dev": {
"psr-4": {
"EonX\\EasyLock\\Tests\\": "tests"
"EonX\\EasyLock\\Tests\\": "tests",
"EonX\\EasyLock\\Tests\\Unit\\": "tests/Unit/src",
"EonX\\EasyLock\\Tests\\Unit\\Bundle\\": "tests/Unit/bundle",
"EonX\\EasyLock\\Tests\\Unit\\Laravel\\": "tests/Unit/laravel"
}
},
"suggest": {
"eonx-com/easy-async": "For EasyAsync integration",
"eonx-com/easy-logging": "For Laravel and EasyLogging integration",
"symfony/messenger": "For Symfony Messenger integration"
},
"extra": {
"branch-alias": {
"dev-master": "5.12-dev"
Expand Down
4 changes: 2 additions & 2 deletions packages/EasyLock/docs/laravel/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ not familiar with this concept make sure to have a look at the [documentation][1
'providers' => [
// Other Service Providers...

\EonX\EasyLock\Bridge\Laravel\EasyLockServiceProvider::class,
\EonX\EasyLock\Laravel\EasyLockServiceProvider::class,
],
```

Expand All @@ -35,7 +35,7 @@ $app = new Laravel\Lumen\Application(\dirname(__DIR__));

// Other actions...

$app->register(\EonX\EasyLock\Bridge\Laravel\EasyLockServiceProvider::class);
$app->register(\EonX\EasyLock\Laravel\EasyLockServiceProvider::class);
```

[1]: https://laravel.com/docs/5.8/providers
Loading