2021-05-05 09:57:54 +02:00
|
|
|
#!/usr/bin/env php
|
2019-12-06 22:56:15 +01:00
|
|
|
<?php
|
2021-05-05 09:57:54 +02:00
|
|
|
/**
|
|
|
|
* Controlleur central du lancement des commandes
|
|
|
|
* Package MVC\Command
|
|
|
|
* @author Emmanuel ROY
|
|
|
|
* @todo protect by chosen licence between an CC-licensed or MIT-licenced (open source)
|
|
|
|
* @version 3.5
|
|
|
|
* @uses \Command SAND Console-Script of commands
|
|
|
|
*/
|
2020-12-08 09:28:12 +01:00
|
|
|
global $argv;
|
|
|
|
|
2021-05-05 09:57:54 +02:00
|
|
|
require dirname(__FILE__) . DIRECTORY_SEPARATOR . "vendor" . DIRECTORY_SEPARATOR . "autoload.php";
|
2020-12-08 09:28:12 +01:00
|
|
|
|
2021-05-05 09:57:54 +02:00
|
|
|
\MVC\Command\Component\Debug::setPHPvalues();
|
2019-12-06 22:56:15 +01:00
|
|
|
|
2020-12-08 09:28:12 +01:00
|
|
|
if (isset($argv[1])) {
|
2019-12-06 22:56:15 +01:00
|
|
|
$option = explode(':', $argv[1]);
|
2021-05-05 09:57:54 +02:00
|
|
|
$command_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . "command" . DIRECTORY_SEPARATOR . lcfirst($option[0]) . ".php";
|
2019-12-06 22:56:15 +01:00
|
|
|
if (is_file($command_file)) {
|
2021-05-05 09:57:54 +02:00
|
|
|
$class = "Command\\" . lcfirst($option[0]);
|
2020-12-08 09:28:12 +01:00
|
|
|
|
2021-05-05 09:57:54 +02:00
|
|
|
if(isset($option[1]) && $option[1] !== '') {
|
|
|
|
$static_method = $option[1];
|
|
|
|
appel_cmd($class,$static_method);
|
|
|
|
|
|
|
|
}else{
|
|
|
|
$static_method = 'help';
|
|
|
|
$class::$static_method();
|
2020-12-08 09:28:12 +01:00
|
|
|
}
|
2019-12-06 22:56:15 +01:00
|
|
|
} else {
|
2021-05-05 09:57:54 +02:00
|
|
|
$command_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . "command" . DIRECTORY_SEPARATOR . "app" . DIRECTORY_SEPARATOR . lcfirst($option[0]) . ".php";
|
2021-04-19 16:23:22 +02:00
|
|
|
if (is_file($command_file)) {
|
2021-05-05 09:57:54 +02:00
|
|
|
$class = "Command\\App\\" . lcfirst($option[0]);
|
|
|
|
|
|
|
|
if(isset($option[1]) && $option[1] !== '') {
|
|
|
|
$static_method = $option[1];
|
|
|
|
appel_cmd($class,$static_method);
|
2021-04-19 16:23:22 +02:00
|
|
|
|
2021-05-05 09:57:54 +02:00
|
|
|
}else{
|
|
|
|
$static_method = 'help';
|
|
|
|
$class::$static_method();
|
2021-04-19 16:23:22 +02:00
|
|
|
}
|
2021-05-05 09:57:54 +02:00
|
|
|
} else {
|
|
|
|
$command_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . "command" . DIRECTORY_SEPARATOR . "sand" . DIRECTORY_SEPARATOR . lcfirst($option[0]) . ".php";
|
2021-04-19 16:23:22 +02:00
|
|
|
if (is_file($command_file)) {
|
2021-05-05 09:57:54 +02:00
|
|
|
$class = "Command\\Sand\\" . lcfirst($option[0]);
|
|
|
|
|
|
|
|
if(isset($option[1]) && $option[1] !== '') {
|
|
|
|
$static_method = $option[1];
|
|
|
|
appel_cmd($class,$static_method);
|
2021-04-19 16:23:22 +02:00
|
|
|
|
2021-05-05 09:57:54 +02:00
|
|
|
}else{
|
|
|
|
$static_method = 'help';
|
|
|
|
$class::$static_method();
|
2021-04-19 16:23:22 +02:00
|
|
|
}
|
2021-05-05 09:57:54 +02:00
|
|
|
} else {
|
|
|
|
print "SAND Command not found !\n";
|
|
|
|
$class = "Command\\Help";
|
|
|
|
$static_method = 'help';
|
|
|
|
$class::$static_method();
|
2021-04-19 16:23:22 +02:00
|
|
|
}
|
|
|
|
}
|
2019-12-06 22:56:15 +01:00
|
|
|
}
|
2020-12-08 09:28:12 +01:00
|
|
|
} else {
|
2019-12-06 22:56:15 +01:00
|
|
|
print "No command was specified !\n";
|
2021-05-05 09:57:54 +02:00
|
|
|
$class = "Command\\Help";
|
|
|
|
$static_method = 'help';
|
|
|
|
$class::$static_method();
|
|
|
|
|
2020-12-09 10:26:26 +01:00
|
|
|
}
|
2021-05-05 09:57:54 +02:00
|
|
|
|
|
|
|
function appel_cmd($class,$static_method){
|
|
|
|
if(method_exists($class,$static_method)) {
|
|
|
|
|
|
|
|
//récupération des arguments de la commande pour passage en paramètre de la méthode
|
|
|
|
$arguments = array();
|
|
|
|
if (isset($argv[2])) {
|
|
|
|
for ($i = 2; $i < count($argv); $i++) {
|
|
|
|
$arguments[] = $argv[$i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//récupération des arguments maitres "--env=????????????? ou --debug-aff=TRUEor????????"
|
|
|
|
$i = 0;
|
|
|
|
foreach ($arguments as $master_arg) {
|
|
|
|
if (preg_match("/--env=([A-Z]*)/", $master_arg, $matches)) {
|
|
|
|
define("ENV", $matches[1]);
|
|
|
|
unset($arguments[$i]);
|
|
|
|
}
|
|
|
|
if (preg_match("/--debug-aff=([A-Z]*)/", $master_arg, $matches)) {
|
|
|
|
if ($matches[1] === 'TRUE') {
|
|
|
|
define("LOG_AFF_ERROR", true);
|
|
|
|
} else {
|
|
|
|
define("LOG_AFF_ERROR", false);
|
|
|
|
}
|
|
|
|
unset($arguments[$i]);
|
|
|
|
}
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
//appel de la commande avec les paramètres spécifiés et récupération des erreurs
|
|
|
|
$errors = $class::$static_method(...$arguments);
|
|
|
|
|
|
|
|
if ($errors !== null) {
|
|
|
|
MVC\Command\Component\Error::logErrors($errors);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$static_method = 'help';
|
|
|
|
$class::$static_method();
|
|
|
|
}
|
|
|
|
}
|