-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Use yiisoft/yii-console
with optional.
#178
base: master
Are you sure you want to change the base?
Changes from all 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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?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. Emm, why do we need it? |
||
|
||
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, | ||
] | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Symfony\Component\Console\Application; | ||
use Yiisoft\Di\Container; | ||
use Yiisoft\Di\ContainerConfig; | ||
|
||
$autoload = $_composer_autoload_path ?? './vendor/autoload.php'; | ||
|
||
if (!file_exists($autoload)) { | ||
throw new RuntimeException( | ||
vjik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'Please run "composer install" in your project root to install the required dependencies.' | ||
); | ||
} | ||
|
||
require_once $autoload; | ||
require_once 'QueueContainer.php'; | ||
|
||
$containerConfig = ContainerConfig::create()->withDefinitions(QueueContainer::definitions()); | ||
$container = new Container($containerConfig); | ||
|
||
/** @var Application $application */ | ||
$application = $container->get(Application::class); | ||
$application->run(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@echo off | ||
|
||
@setlocal | ||
|
||
if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe | ||
|
||
"%PHP_COMMAND%" "%~dp0queue" %* | ||
|
||
@endlocal |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -40,9 +40,9 @@ | |||||
"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-debug": "dev-master" | ||||||
}, | ||||||
"suggest": { | ||||||
"ext-pcntl": "Need for process signals" | ||||||
|
@@ -57,6 +57,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" | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Yii\Queue\Tests\Unit; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
final class ConsoleQueueTest extends TestCase | ||
{ | ||
public function testQueueRunsSuccessfully(): void | ||
{ | ||
$output = shell_exec('php ./bin/queue'); | ||
|
||
$this->assertStringContainsString('Yii Queue Tool 1.0.0', $output); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest require the user to create
yii-queue-params.php
in root directory with queue params only and don't require copy full container configuration. It's more cleary...