CLIComponent now uses route categories of MVCR.
This is a safety feature with minimal implementation.
This commit is contained in:
parent
a6b66b9b01
commit
ff2900ae93
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2013-2019 TechFuze
|
||||
Copyright (c) 2013-2021 TechFuze
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -66,7 +66,7 @@ foreach ($autoloaders as $file)
|
|||
$arguments = getopt('', ['bootstrap:']);
|
||||
if (!isset($arguments['bootstrap']) || empty($arguments['bootstrap']))
|
||||
{
|
||||
fwrite(STDERR, "Could not load supervisor. No bootstrap provided.\n");
|
||||
fwrite(STDERR, "Could not load fuzeworks. No bootstrap provided.\n");
|
||||
die(1);
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ if (!isset($arguments['bootstrap']) || empty($arguments['bootstrap']))
|
|||
$bootstrap = $arguments['bootstrap'];
|
||||
if (!file_exists($bootstrap))
|
||||
{
|
||||
fwrite(STDERR, "Could not load supervisor. Provided bootstrap doesn't exist.");
|
||||
fwrite(STDERR, "Could not load fuzeworks. Provided bootstrap doesn't exist.");
|
||||
die(1);
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ $container = require($bootstrap);
|
|||
// Check if container is a Factory
|
||||
if (!$container instanceof Factory)
|
||||
{
|
||||
fwrite(STDERR, "Could not load supervisor. Provided bootstrap is not a valid bootstrap.");
|
||||
fwrite(STDERR, "Could not load fuzeworks. Provided bootstrap is not a valid bootstrap.");
|
||||
die(1);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,11 +14,10 @@
|
|||
],
|
||||
"require": {
|
||||
"php": ">=7.4.0",
|
||||
"fuzeworks/mvcr": "~1.3.1",
|
||||
"fuzeworks/mvcr": "~1.3.2",
|
||||
"fuzeworks/core": "~1.2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9",
|
||||
"fuzeworks/tracycomponent": "~1.2.0"
|
||||
},
|
||||
"autoload": {
|
||||
|
|
|
@ -77,13 +77,6 @@ class CLIComponent implements iComponent
|
|||
// Add dependencies
|
||||
$configurator->addComponent(new MVCRComponent());
|
||||
|
||||
// Add fallback configuration directory
|
||||
$configurator->addDirectory(
|
||||
dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Config',
|
||||
'config',
|
||||
Priority::LOWEST
|
||||
);
|
||||
|
||||
// If the component will handle a request, set the logger to output for CLI
|
||||
if (self::$willHandleRequest)
|
||||
$configurator->call('logger', 'setLoggerTemplate', null, 'logger_cli');
|
||||
|
@ -122,6 +115,7 @@ class CLIComponent implements iComponent
|
|||
/** @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');
|
||||
|
@ -133,6 +127,9 @@ class CLIComponent implements iComponent
|
|||
$views->addComponentPath($srcPath . DS . 'Views', Priority::LOW);
|
||||
$controllers->addComponentPath($srcPath . DS . 'Controllers', Priority::LOW);
|
||||
|
||||
// Add the default route
|
||||
$router->addRoute('(?P<viewName>.*?)(| (?P<viewMethod>.*?)(| (?P<viewParameters>.*?)))', ['category' => 'cli', 'viewType' => 'cli']);
|
||||
|
||||
// Load the commandProcessor
|
||||
$processor = new CommandProcessor();
|
||||
Events::addListener([$processor, 'routerCallViewEventListener'], 'routerCallViewEvent', Priority::HIGHEST);
|
||||
|
|
|
@ -91,13 +91,7 @@ class CommandProcessor
|
|||
$logCount = count(Logger::$logs);
|
||||
|
||||
try {
|
||||
$this->router->route(
|
||||
$commandString, [3 =>
|
||||
[
|
||||
'(?P<viewName>.*?)(| (?P<viewMethod>.*?)(| (?P<viewParameters>.*?)))' => ['viewType' => 'cli']
|
||||
]
|
||||
]
|
||||
);
|
||||
$this->router->route($commandString, 'cli');
|
||||
} catch (NotFoundException $e) {
|
||||
$this->output->warningOut("Requested command '$parts[0]' was not found.");
|
||||
} catch (RouterException $e) {
|
||||
|
@ -115,19 +109,6 @@ class CommandProcessor
|
|||
$this->parseLogs($logs, $verbose);
|
||||
}
|
||||
|
||||
/**
|
||||
* The callable that is used to pick the correct view and controller
|
||||
*
|
||||
* @internal
|
||||
* @param array $matches
|
||||
* @param array $routeData
|
||||
* @param string $route
|
||||
*/
|
||||
public function cliCallable(array $matches, array $routeData, string $route)
|
||||
{
|
||||
dump($this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a commandString and extracts options from it
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue