Skip to content

Commit

Permalink
Improve config.
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Nov 23, 2023
1 parent 73df35d commit ed418eb
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 81 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ Install `yiisoft/yii-console` package and you are ready to go.

## Usage with Symfony Console

1. Copy configuration file `./vendor/yiisoft/yii-queue/bin/definitions.php` to `root` folder of your project.
1. Copy configuration file `./vendor/yiisoft/yii-queue/bin/QueueContainer.php` to `root` folder of your project.

```shell
cp ./vendor/yiisoft/yii-queue/bin/definitions.php ./
cp ./vendor/yiisoft/yii-queue/bin/QueueContainer.php ./
```

2. Edit `./definitions.php` and add definitions for your logger and queue adapter.
2. Edit `./QueueContainer.php` and add definitions for your logger and queue adapter.

Here's a sample configuration.

Expand Down
83 changes: 83 additions & 0 deletions bin/QueueContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

declare(strict_types=1);

use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
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;

final class QueueContainer
{
public static function definitions(): array
{
return [
Application::class => [
'__construct()' => [
'name' => 'Yii Queue Tool',
'version' => '1.0.0',
],
'addCommands()' => [self::getCommands()],
],
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' => []],
],
LoggerInterface::class => NullLogger::class,
];
}

public static function getCommands(): array
{
return ReferencesArray::from(
[
RunCommand::class,
ListenCommand::class,
]
);
}
}
74 changes: 0 additions & 74 deletions bin/definitions.php

This file was deleted.

6 changes: 2 additions & 4 deletions bin/queue
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ if (!file_exists($autoload)) {
}

require_once $autoload;
require_once 'QueueContainer.php';

/** @var array $definitions */
$definitions = require_once 'definitions.php';

$containerConfig = ContainerConfig::create()->withDefinitions($definitions);
$containerConfig = ContainerConfig::create()->withDefinitions(QueueContainer::definitions());
$container = new Container($containerConfig);

/** @var Application $application */
Expand Down

0 comments on commit ed418eb

Please sign in to comment.