-
-
Notifications
You must be signed in to change notification settings - Fork 28
Use yiisoft/yii-console
with optional.
#178
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
9289565
e1f76cd
d4b979e
869a548
239da6c
ffb4cab
3ee2b20
81fc0d2
d6563e7
3f7b78c
5216463
2fe344d
c854a14
73df35d
ed418eb
5d77c41
7910e61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,42 @@ or add | |
|
||
to the `require` section of your `composer.json` file. | ||
|
||
## Usage with Yii Console | ||
|
||
Just install `yiisoft/yii-console` package and you are ready to go. | ||
|
||
## Usage with Symfony Console | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For use with Symfony Console we should add commands to Symfony Console and do not use files from bin. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://symfony.com/doc/current/components/console.html#creating-a-console-application Well in the documents it clearly says that you must register a script and add the commands, it is what is done in this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add instruction for use commands with symfony console that alreasy used in user app. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have to investigate it, i suggest merging this PR, and do it in another. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://symfony.com/doc/current/console.html#registering-the-command According to this they are already registered, and the Symfony console should recognize them. |
||
|
||
1. Copy configuration file `./vendor/yiisoft/yii-queue/bin/definitions.php` to `root` folder of your project. | ||
|
||
```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 | ||
], | ||
), | ||
], | ||
], | ||
]; | ||
``` | ||
|
||
## Ready for yiisoft/config | ||
|
||
If you are using [yiisoft/config](https://github.com/yiisoft/config), you'll find out this package has some defaults | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
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 => [ | ||
'__construct()' => [ | ||
'name' => 'Yii Queue Tool', | ||
'version' => '1.0.0', | ||
], | ||
'addCommands()' => [ | ||
ReferencesArray::from( | ||
[ | ||
RunCommand::class, | ||
ListenCommand::class, | ||
], | ||
), | ||
], | ||
], | ||
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' => []], | ||
], | ||
]; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,27 @@ | ||||||
#!/usr/bin/env php | ||||||
<?php | ||||||
|
||||||
declare(strict_types=1); | ||||||
|
||||||
use Psr\Log\LoggerInterface; | ||||||
use Symfony\Component\Console\Application; | ||||||
use Yiisoft\Di\Container; | ||||||
use Yiisoft\Di\ContainerConfig; | ||||||
|
||||||
require_once './vendor/autoload.php'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could there be a problem if run utility from different places? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not necessary when using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I try it, and this do not work correclty. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As it fails, to reproduce it, since I use it in the app, and in the cloned directory, and it works correctly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But you are inside the config directory, you must be root :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't work. Add test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Utlitiy should work from any directory. Just use absolute path. |
||||||
|
||||||
/** @var array $definitions */ | ||||||
$definitions = require_once 'definitions.php'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you use the absolute path, when you copy the definitions to the ROOT Directory of the app, not work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not need copy definitions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If necessary, suppose that i have a different configuration than the predetermined, for example, i used monolog, when updating new version will lose my changes, that is fine, only when your configuration is equal to the predetermine |
||||||
|
||||||
$containerConfig = ContainerConfig::create()->withDefinitions($definitions); | ||||||
$container = new Container($containerConfig); | ||||||
|
||||||
if ($container->has(LoggerInterface::class) === false) { | ||||||
throw new RuntimeException( | ||||||
vjik marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
'Logger is not configured, install your logger of choice and configure it properly in /bin/definitions.php.' | ||||||
); | ||||||
} | ||||||
|
||||||
/** @var Application $application */ | ||||||
$application = $container->get(Application::class); | ||||||
$application->run(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@echo off | ||
|
||
@setlocal | ||
|
||
set YII_PATH=%~dp0 | ||
|
||
if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe | ||
|
||
"%PHP_COMMAND%" "%YII_PATH%queue" %* | ||
vjik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@endlocal |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -29,7 +29,6 @@ | |||||
"php": "^8.0", | ||||||
"psr/log": "^2.0|^3.0", | ||||||
"psr/container": "^1.0|^2.0", | ||||||
"yiisoft/yii-console": "^2.0", | ||||||
"yiisoft/definitions": "^1.0|^2.0|^3.0", | ||||||
"yiisoft/friendly-exception": "^1.0", | ||||||
"yiisoft/injector": "^1.0", | ||||||
|
@@ -41,9 +40,10 @@ | |||||
"rector/rector": "^0.18.10", | ||||||
"roave/infection-static-analysis-plugin": "^1.16", | ||||||
"spatie/phpunit-watcher": "^1.23", | ||||||
"yiisoft/yii-debug": "dev-master", | ||||||
"vimeo/psalm": "^4.30|^5.8", | ||||||
"yiisoft/test-support": "^3.0" | ||||||
"yiisoft/test-support": "^3.0", | ||||||
"yiisoft/yii-console": "^2.0", | ||||||
vjik marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
"yiisoft/yii-debug": "dev-master" | ||||||
}, | ||||||
"suggest": { | ||||||
"ext-pcntl": "Need for process signals" | ||||||
|
@@ -58,6 +58,9 @@ | |||||
"Yiisoft\\Yii\\Queue\\Tests\\": "tests" | ||||||
} | ||||||
}, | ||||||
"bin": [ | ||||||
"bin/queue" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
It's global space, I suggest use prefix. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea when removing the console is to rename the package to yiisoft/queue, so queue makes sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest rename utility only. Because it is global namespace |
||||||
], | ||||||
"extra": { | ||||||
"branch-alias": { | ||||||
"dev-master": "3.0.x-dev" | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.