Skip to content

Commit

Permalink
Remove yiisoft/config.
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Nov 22, 2023
1 parent 9289565 commit e1f76cd
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 26 deletions.
36 changes: 20 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions bin/definitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 => [
Expand All @@ -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' => []],
],
];
9 changes: 0 additions & 9 deletions bin/queue
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit e1f76cd

Please sign in to comment.