$this, 'cliInput' => '\FuzeWorks\CLI\Input', 'cliOutput' => '\FuzeWorks\CLI\Output' ]; } public function onAddComponent(Configurator $configurator) { // Add dependencies $configurator->addComponent(new MVCRComponent()); // If the component will handle a request, set the logger to output for CLI if (self::$willHandleRequest) $configurator->call('logger', 'setLoggerTemplate', null, 'logger_cli'); } public function onCreateContainer(Factory $container) { } public function enableComponent() { self::$willHandleRequest = true; } public function disableComponent() { self::$willHandleRequest = false; } protected int $logCount; /** * @return bool * @throws CLIException * @throws FactoryException */ public function routeCliRequest(): bool { if (!self::$willHandleRequest) throw new CLIException("Could not route CLI request. CLIComponent is not configured to handle requests."); // Load dependencies /** @var Router $router */ /** @var Input $input */ /** @var Models $models */ /** @var Views $views */ /** @var Controllers $controllers */ $router = Factory::getInstance('router'); $input = Factory::getInstance('cliInput'); $models = Factory::getInstance('models'); $views = Factory::getInstance('views'); $controllers = Factory::getInstance('controllers'); // Add the directories for Models, Views, Controllers from this Component $srcPath = dirname(__DIR__, 2); $models->addComponentPath($srcPath . DS . 'Models'. Priority::LOW); $views->addComponentPath($srcPath . DS . 'Views', Priority::LOW); $controllers->addComponentPath($srcPath . DS . 'Controllers', Priority::LOW); // Add the default route $router->addRoute('(?P.*?)(| (?P.*?)(| (?P.*?)))', ['category' => 'cli', 'viewType' => 'cli']); // Load the commandProcessor $processor = new CommandProcessor(); Events::addListener([$processor, 'routerCallViewEventListener'], 'routerCallViewEvent', Priority::HIGHEST); // Start logging the request Logger::newLevel("Routing CLI request..."); // Fetch input options $arguments = $input->arguments(); // Prepare commandString and execute array_shift($arguments); $commandString = implode(' ', $arguments); $processor->executeCommand($commandString); // And stop logging the request Logger::stopLevel(); return true; } }