-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
412 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
use Bitrix\Main\Loader; | ||
use Proklung\RabbitMq\Integration\CLI\CommandsSetup; | ||
use Proklung\RabbitMq\Integration\CLI\ConsoleCommandConfigurator; | ||
use Proklung\RabbitMq\Integration\CLI\LoaderBitrix; | ||
use Proklung\RabbitMq\Integration\DI\Services; | ||
use Symfony\Component\Console\Application; | ||
|
||
@set_time_limit(0); | ||
|
||
$_SERVER['DOCUMENT_ROOT'] = __DIR__. DIRECTORY_SEPARATOR . '..'; | ||
$GLOBALS['DOCUMENT_ROOT'] = $_SERVER['DOCUMENT_ROOT']; | ||
|
||
$autoloadPath = $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php'; | ||
|
||
/** @noinspection PhpIncludeInspection */ | ||
require_once $autoloadPath; | ||
|
||
/** | ||
* Загрузить Битрикс. | ||
*/ | ||
$loaderBitrix = new LoaderBitrix(); | ||
$loaderBitrix->setDocumentRoot($_SERVER['DOCUMENT_ROOT']); | ||
$loaderBitrix->initializeBitrix(); | ||
|
||
if (!$loaderBitrix->isBitrixLoaded()) { | ||
exit('Bitrix not initialized.'); | ||
} | ||
|
||
Loader::includeModule('proklung.rabbitmq'); | ||
|
||
$application = new ConsoleCommandConfigurator( | ||
new Application(), | ||
CommandsSetup::load(Services::getInstance()) | ||
); | ||
|
||
$application->init(); | ||
$application->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Proklung\RabbitMq\Integration\CLI; | ||
|
||
use Proklung\RabbitMq\Command; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* Class CommandsSetup | ||
* @package Proklung\RabbitMq\CLI | ||
*/ | ||
class CommandsSetup | ||
{ | ||
/** | ||
* @param ContainerInterface $container | ||
* | ||
* @return array | ||
*/ | ||
public static function load(ContainerInterface $container) | ||
{ | ||
$commands = [ | ||
new Command\ConsumerCommand(), | ||
new Command\DeleteCommand(), | ||
new Command\PurgeConsumerCommand(), | ||
new Command\SetupFabricCommand(), | ||
new Command\StdInProducerCommand(), | ||
]; | ||
|
||
foreach ($commands as $command) { | ||
if (!$command instanceof Command\BaseRabbitMqCommand) { | ||
continue; | ||
} | ||
|
||
$command->setContainer($container); | ||
} | ||
|
||
return $commands; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
namespace Proklung\RabbitMq\Integration\CLI; | ||
|
||
use Exception; | ||
use IteratorAggregate; | ||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Command\Command; | ||
|
||
/** | ||
* Class ConsoleCommandConfigurator | ||
* @package Proklung\RabbitMq\Integration\CLI | ||
* | ||
*/ | ||
class ConsoleCommandConfigurator | ||
{ | ||
/** | ||
* @var Application $application Конфигуратор консольных команд. | ||
*/ | ||
private $application; | ||
|
||
/** | ||
* @var Command[] $commands Команды. | ||
*/ | ||
private $commands; | ||
|
||
/** | ||
* ConsoleCommandConfigurator constructor. | ||
* | ||
* @param Application $application Конфигуратор консольных команд. | ||
* @param Command ...$commands Команды. | ||
*/ | ||
public function __construct( | ||
Application $application, | ||
Command ...$commands | ||
) { | ||
$this->application = $application; | ||
$this->commands = $commands; | ||
} | ||
|
||
/** | ||
* Инициализация команд. | ||
* | ||
* @return $this | ||
*/ | ||
public function init() : self | ||
{ | ||
foreach ($this->commands as $command) { | ||
$this->application->add($command); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Запуск команд. | ||
* | ||
* @throws Exception | ||
*/ | ||
public function run() : void | ||
{ | ||
$this->application->run(); | ||
} | ||
|
||
/** | ||
* Добавить команды. | ||
* | ||
* @param mixed $commands Команды | ||
* | ||
* @return void | ||
* | ||
* @throws Exception | ||
* @since 24.12.2020 Рефакторинг. | ||
*/ | ||
public function add(...$commands) : void | ||
{ | ||
$result = []; | ||
|
||
foreach ($commands as $command) { | ||
$array = $command; | ||
if ($command instanceof IteratorAggregate) { | ||
$iterator = $command->getIterator(); | ||
$array = iterator_to_array($iterator); | ||
} | ||
|
||
$result[] = $array; | ||
} | ||
|
||
/** @psalm-suppress InvalidPropertyAssignmentValue */ | ||
$this->commands = array_merge($this->commands, $result); | ||
} | ||
} |
Oops, something went wrong.