From 7efbc4a8456678b2b53e6fae862dee8550de0600 Mon Sep 17 00:00:00 2001 From: Nik Samokhvalov Date: Fri, 18 Mar 2016 17:22:02 +0300 Subject: [PATCH] New structure --- bin/jedi | 2 +- .../Agent => Agent/Command}/OnCronCommand.php | 4 +- .../Agent => Agent/Command}/RunCommand.php | 4 +- src/{Console => Application}/Application.php | 134 ++++++++++-------- .../Command/BitrixCommand.php | 2 +- .../Command/Command.php | 4 +- .../Command/InitCommand.php | 2 +- .../Cache => Cache/Command}/ClearCommand.php | 4 +- .../Command}/InitCommand.php | 4 +- tests/bootstrap.php | 2 +- 10 files changed, 87 insertions(+), 75 deletions(-) rename src/{Console/Command/Agent => Agent/Command}/OnCronCommand.php (89%) rename src/{Console/Command/Agent => Agent/Command}/RunCommand.php (90%) rename src/{Console => Application}/Application.php (89%) rename src/{Console => Application}/Command/BitrixCommand.php (90%) rename src/{Console => Application}/Command/Command.php (78%) rename src/{Console => Application}/Command/InitCommand.php (99%) rename src/{Console/Command/Cache => Cache/Command}/ClearCommand.php (94%) rename src/{Console/Command/Environment => Environment/Command}/InitCommand.php (98%) diff --git a/bin/jedi b/bin/jedi index 8d353ae..f0c8137 100644 --- a/bin/jedi +++ b/bin/jedi @@ -7,5 +7,5 @@ require_once __DIR__ . '/../../../autoload.php'; -$app = new \Notamedia\ConsoleJedi\Console\Application(); +$app = new \Notamedia\ConsoleJedi\Application\Application(); $app->run(); \ No newline at end of file diff --git a/src/Console/Command/Agent/OnCronCommand.php b/src/Agent/Command/OnCronCommand.php similarity index 89% rename from src/Console/Command/Agent/OnCronCommand.php rename to src/Agent/Command/OnCronCommand.php index 50f17e4..64dc094 100644 --- a/src/Console/Command/Agent/OnCronCommand.php +++ b/src/Agent/Command/OnCronCommand.php @@ -4,10 +4,10 @@ * file that was distributed with this source code. */ -namespace Notamedia\ConsoleJedi\Console\Command\Agent; +namespace Notamedia\ConsoleJedi\Agent\Command; use Bitrix\Main\Config\Option; -use Notamedia\ConsoleJedi\Console\Command\BitrixCommand; +use Notamedia\ConsoleJedi\Application\Command\BitrixCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; diff --git a/src/Console/Command/Agent/RunCommand.php b/src/Agent/Command/RunCommand.php similarity index 90% rename from src/Console/Command/Agent/RunCommand.php rename to src/Agent/Command/RunCommand.php index ac17342..ccfb433 100644 --- a/src/Console/Command/Agent/RunCommand.php +++ b/src/Agent/Command/RunCommand.php @@ -4,9 +4,9 @@ * file that was distributed with this source code. */ -namespace Notamedia\ConsoleJedi\Console\Command\Agent; +namespace Notamedia\ConsoleJedi\Agent\Command; -use Notamedia\ConsoleJedi\Console\Command\BitrixCommand; +use Notamedia\ConsoleJedi\Application\Command\BitrixCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; diff --git a/src/Console/Application.php b/src/Application/Application.php similarity index 89% rename from src/Console/Application.php rename to src/Application/Application.php index 68b18c4..70ac241 100644 --- a/src/Console/Application.php +++ b/src/Application/Application.php @@ -4,15 +4,16 @@ * file that was distributed with this source code. */ -namespace Notamedia\ConsoleJedi\Console; +namespace Notamedia\ConsoleJedi\Application; use Bitrix\Main\DB\ConnectionException; use Bitrix\Main\Loader; use Bitrix\Main\ModuleManager; -use Notamedia\ConsoleJedi\Console\Command\Agent; -use Notamedia\ConsoleJedi\Console\Command\Cache; -use Notamedia\ConsoleJedi\Console\Command\Environment; -use Notamedia\ConsoleJedi\Console\Command\InitCommand; +use Notamedia\ConsoleJedi\Agent\Command\OnCronCommand; +use Notamedia\ConsoleJedi\Agent\Command\RunCommand; +use Notamedia\ConsoleJedi\Cache\Command\ClearCommand; +use Notamedia\ConsoleJedi\Environment\Command\InitCommand; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Filesystem\Filesystem; @@ -82,19 +83,15 @@ public function doRun(InputInterface $input, OutputInterface $output) if ($this->getConfiguration()) { - $this->addCommands([ - new Agent\OnCronCommand(), - new Agent\RunCommand(), - new Cache\ClearCommand(), - new Environment\InitCommand() - ]); + foreach ($this->getBitrixCommands() as $bitrixCommand) + { + $this->add($bitrixCommand); + } } if ($this->isBitrixLoaded() && $this->getConfiguration()['useModules'] === true) { - $moduleCommands = $this->getModulesCommands(); - - foreach ($moduleCommands as $moduleCommand) + foreach ($this->getModulesCommands() as $moduleCommand) { $this->add($moduleCommand); } @@ -139,11 +136,72 @@ public function doRun(InputInterface $input, OutputInterface $output) protected function getDefaultCommands() { $commands = parent::getDefaultCommands(); - $commands[] = new InitCommand(); + $commands[] = new \Notamedia\ConsoleJedi\Application\Command\InitCommand(); return $commands; } + /** + * Gets Bitrix console commands from this package. + * + * @return Command[] + */ + protected function getBitrixCommands() + { + return [ + new OnCronCommand(), + new RunCommand(), + new ClearCommand(), + new InitCommand() + ]; + } + + /** + * Gets console commands from modules. + * + * @return Command[] + * + * @throws \Bitrix\Main\LoaderException + */ + protected function getModulesCommands() + { + $commands = []; + + foreach (ModuleManager::getInstalledModules() as $module) + { + $moduleBitrixDir = $_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/modules/' . $module['ID']; + $moduleLocalDir = $_SERVER['DOCUMENT_ROOT'] . '/local/modules/' . $module['ID']; + $cliFile = '/cli.php'; + + if (is_file($moduleBitrixDir . $cliFile)) + { + $cliFile = $moduleBitrixDir . $cliFile; + } + elseif (is_file($moduleLocalDir . $cliFile)) + { + $cliFile = $moduleLocalDir . $cliFile; + } + else + { + continue; + } + + if (!Loader::includeModule($module['ID'])) + { + continue; + } + + $config = include_once $cliFile; + + if (isset($config['commands']) && is_array($config['commands'])) + { + $commands = array_merge($commands, $config['commands']); + } + } + + return $commands; + } + /** * Loading application configuration. * @@ -196,52 +254,6 @@ public function getConfiguration() return $this->configuration; } - /** - * Gets console commands from modules. - * - * @return array - * - * @throws \Bitrix\Main\LoaderException - */ - protected function getModulesCommands() - { - $commands = []; - - foreach (ModuleManager::getInstalledModules() as $module) - { - $moduleBitrixDir = $_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/modules/' . $module['ID']; - $moduleLocalDir = $_SERVER['DOCUMENT_ROOT'] . '/local/modules/' . $module['ID']; - $cliFile = '/cli.php'; - - if (is_file($moduleBitrixDir . $cliFile)) - { - $cliFile = $moduleBitrixDir . $cliFile; - } - elseif (is_file($moduleLocalDir . $cliFile)) - { - $cliFile = $moduleLocalDir . $cliFile; - } - else - { - continue; - } - - if (!Loader::includeModule($module['ID'])) - { - continue; - } - - $config = include_once $cliFile; - - if (isset($config['commands']) && is_array($config['commands'])) - { - $commands = array_merge($commands, $config['commands']); - } - } - - return $commands; - } - /** * Initialize kernel of Bitrix. * diff --git a/src/Console/Command/BitrixCommand.php b/src/Application/Command/BitrixCommand.php similarity index 90% rename from src/Console/Command/BitrixCommand.php rename to src/Application/Command/BitrixCommand.php index be96c9f..ea912f3 100644 --- a/src/Console/Command/BitrixCommand.php +++ b/src/Application/Command/BitrixCommand.php @@ -4,7 +4,7 @@ * file that was distributed with this source code. */ -namespace Notamedia\ConsoleJedi\Console\Command; +namespace Notamedia\ConsoleJedi\Application\Command; /** * Base class for Bitrix console command. diff --git a/src/Console/Command/Command.php b/src/Application/Command/Command.php similarity index 78% rename from src/Console/Command/Command.php rename to src/Application/Command/Command.php index 43f5dfa..3170d0f 100644 --- a/src/Console/Command/Command.php +++ b/src/Application/Command/Command.php @@ -4,7 +4,7 @@ * file that was distributed with this source code. */ -namespace Notamedia\ConsoleJedi\Console\Command; +namespace Notamedia\ConsoleJedi\Application\Command; /** * Base class for console command. @@ -14,7 +14,7 @@ class Command extends \Symfony\Component\Console\Command\Command { /** - * @return \Notamedia\ConsoleJedi\Console\Application + * @return \Notamedia\ConsoleJedi\Application\Application */ public function getApplication() { diff --git a/src/Console/Command/InitCommand.php b/src/Application/Command/InitCommand.php similarity index 99% rename from src/Console/Command/InitCommand.php rename to src/Application/Command/InitCommand.php index d666e00..cbb9d58 100644 --- a/src/Console/Command/InitCommand.php +++ b/src/Application/Command/InitCommand.php @@ -4,7 +4,7 @@ * file that was distributed with this source code. */ -namespace Notamedia\ConsoleJedi\Console\Command; +namespace Notamedia\ConsoleJedi\Application\Command; use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputInterface; diff --git a/src/Console/Command/Cache/ClearCommand.php b/src/Cache/Command/ClearCommand.php similarity index 94% rename from src/Console/Command/Cache/ClearCommand.php rename to src/Cache/Command/ClearCommand.php index 90563bf..b712971 100644 --- a/src/Console/Command/Cache/ClearCommand.php +++ b/src/Cache/Command/ClearCommand.php @@ -4,12 +4,12 @@ * file that was distributed with this source code. */ -namespace Notamedia\ConsoleJedi\Console\Command\Cache; +namespace Notamedia\ConsoleJedi\Cache\Command; use Bitrix\Main\Application; use Bitrix\Main\Data\Cache; use Bitrix\Main\Data\StaticHtmlCache; -use Notamedia\ConsoleJedi\Console\Command\BitrixCommand; +use Notamedia\ConsoleJedi\Application\Command\BitrixCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; diff --git a/src/Console/Command/Environment/InitCommand.php b/src/Environment/Command/InitCommand.php similarity index 98% rename from src/Console/Command/Environment/InitCommand.php rename to src/Environment/Command/InitCommand.php index ec1af05..410d5ce 100644 --- a/src/Console/Command/Environment/InitCommand.php +++ b/src/Environment/Command/InitCommand.php @@ -4,7 +4,7 @@ * file that was distributed with this source code. */ -namespace Notamedia\ConsoleJedi\Console\Command\Environment; +namespace Notamedia\ConsoleJedi\Environment\Command; use Bitrix\Main\Application; use Bitrix\Main\Config\Configuration; @@ -13,7 +13,7 @@ use Bitrix\Main\Loader; use Bitrix\Main\LoaderException; use Bitrix\Main\ModuleManager; -use Notamedia\ConsoleJedi\Console\Command\Command; +use Notamedia\ConsoleJedi\Application\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 4db2f97..286c6f3 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -6,7 +6,7 @@ require_once __DIR__ . '/../../../autoload.php'; -$app = new \Notamedia\ConsoleJedi\Console\Application(); +$app = new \Notamedia\ConsoleJedi\Application\Application(); $app->loadConfiguration(); $app->initializeBitrix();