From e1f76cddafdaed363664dee78c905bea7ba22841 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 22 Nov 2023 07:35:43 -0300 Subject: [PATCH] Remove `yiisoft/config`. --- README.md | 36 +++++++++++++++++++---------------- bin/definitions.php | 46 +++++++++++++++++++++++++++++++++++++++++++++ bin/queue | 9 --------- composer.json | 1 - 4 files changed, 66 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 99443477..61b55228 100644 --- a/README.md +++ b/README.md @@ -43,30 +43,34 @@ Just install `yiisoft/yii-console` package and you are ready to go. ## Usage with Symfony Console -To use this package without the Yii Framework, it is quite simple. You only need to add the configuration of your chosen logger, -example with [yiisoft/log-target-file](https://github.com/yiisoft/log-target-file). +1. Copy configuration file `./vendor/yiisoft/yii-queue/bin/definitions.php` to `root` folder of your project. -./bin/definitions.php +```shell +cp ./vendor/yiisoft/yii-queue/bin/definitions.php ./ +``` + +2. Edit `./definitions.php` and add definitions for your logger and queue adapter. + +Here's a sample configuration. ```php +use Psr\Log\LoggerInterface; +use Yiisoft\Definitions\ReferencesArray; +use Yiisoft\Log\Logger; +use Yiisoft\Log\Target\File\FileTarget; + +return [ LoggerInterface::class => [ 'class' => Logger::class, '__construct()' => [ - 'targets' => ReferencesArray::from([ - FileTarget::class, - ]), - ], - ], -``` - -And in .config/params.php add config for aliases for the logger. - -```php - 'yiisoft/aliases' => [ - 'aliases' => [ - '@runtime' => your_runtime_path, + 'targets' => ReferencesArray::from( + [ + FileTarget::class + ], + ), ], ], +]; ``` ## Ready for yiisoft/config diff --git a/bin/definitions.php b/bin/definitions.php index d92a56ba..ac569fb2 100644 --- a/bin/definitions.php +++ b/bin/definitions.php @@ -2,10 +2,29 @@ declare(strict_types=1); +use Psr\Container\ContainerInterface; use Symfony\Component\Console\Application; use Yiisoft\Definitions\ReferencesArray; +use Yiisoft\Yii\Queue\Cli\LoopInterface; +use Yiisoft\Yii\Queue\Cli\SignalLoop; +use Yiisoft\Yii\Queue\Cli\SimpleLoop; use Yiisoft\Yii\Queue\Command\ListenCommand; use Yiisoft\Yii\Queue\Command\RunCommand; +use Yiisoft\Yii\Queue\Middleware\Consume\ConsumeMiddlewareDispatcher; +use Yiisoft\Yii\Queue\Middleware\Consume\MiddlewareFactoryConsume; +use Yiisoft\Yii\Queue\Middleware\Consume\MiddlewareFactoryConsumeInterface; +use Yiisoft\Yii\Queue\Middleware\FailureHandling\FailureMiddlewareDispatcher; +use Yiisoft\Yii\Queue\Middleware\FailureHandling\MiddlewareFactoryFailure; +use Yiisoft\Yii\Queue\Middleware\FailureHandling\MiddlewareFactoryFailureInterface; +use Yiisoft\Yii\Queue\Middleware\Push\MiddlewareFactoryPush; +use Yiisoft\Yii\Queue\Middleware\Push\MiddlewareFactoryPushInterface; +use Yiisoft\Yii\Queue\Middleware\Push\PushMiddlewareDispatcher; +use Yiisoft\Yii\Queue\Queue; +use Yiisoft\Yii\Queue\QueueFactory; +use Yiisoft\Yii\Queue\QueueFactoryInterface; +use Yiisoft\Yii\Queue\QueueInterface; +use Yiisoft\Yii\Queue\Worker\Worker as QueueWorker; +use Yiisoft\Yii\Queue\Worker\WorkerInterface; return [ Application::class => [ @@ -22,4 +41,31 @@ ), ], ], + QueueWorker::class => [ + 'class' => QueueWorker::class, + '__construct()' => [[]], + ], + WorkerInterface::class => QueueWorker::class, + LoopInterface::class => static function (ContainerInterface $container): LoopInterface { + return extension_loaded('pcntl') + ? $container->get(SignalLoop::class) + : $container->get(SimpleLoop::class); + }, + QueueFactoryInterface::class => QueueFactory::class, + QueueFactory::class => [ + '__construct()' => [[]], + ], + QueueInterface::class => Queue::class, + MiddlewareFactoryPushInterface::class => MiddlewareFactoryPush::class, + MiddlewareFactoryConsumeInterface::class => MiddlewareFactoryConsume::class, + MiddlewareFactoryFailureInterface::class => MiddlewareFactoryFailure::class, + PushMiddlewareDispatcher::class => [ + '__construct()' => ['middlewareDefinitions' => []], + ], + ConsumeMiddlewareDispatcher::class => [ + '__construct()' => ['middlewareDefinitions' => []], + ], + FailureMiddlewareDispatcher::class => [ + '__construct()' => ['middlewareDefinitions' => []], + ], ]; diff --git a/bin/queue b/bin/queue index ca76a7b6..792017f3 100644 --- a/bin/queue +++ b/bin/queue @@ -5,9 +5,6 @@ declare(strict_types=1); use Psr\Log\LoggerInterface; use Symfony\Component\Console\Application; -use Yiisoft\Config\Config; -use Yiisoft\Config\ConfigPaths; -use Yiisoft\Config\Modifier\RecursiveMerge; use Yiisoft\Di\Container; use Yiisoft\Di\ContainerConfig; @@ -16,12 +13,6 @@ require_once './vendor/autoload.php'; /** @var array $definitions */ $definitions = require_once 'definitions.php'; -$config = new Config( - new ConfigPaths('.', 'config', 'vendor'), - modifiers: [RecursiveMerge::groups('di', 'params')], - paramsGroup: 'params', -); -$definitions = array_merge($definitions, $config->get('di')); $containerConfig = ContainerConfig::create()->withDefinitions($definitions); $container = new Container($containerConfig); diff --git a/composer.json b/composer.json index 07718a59..cc3d5911 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,6 @@ "php": "^8.0", "psr/log": "^2.0|^3.0", "psr/container": "^1.0|^2.0", - "yiisoft/config": "^1.4", "yiisoft/definitions": "^1.0|^2.0|^3.0", "yiisoft/friendly-exception": "^1.0", "yiisoft/injector": "^1.0",