59 lines
1.7 KiB
PHP
59 lines
1.7 KiB
PHP
<?php
|
|
namespace nur\mapper\base;
|
|
|
|
/**
|
|
* Class FuncMapper_command: classe de support pour construire une instance de
|
|
* mapper pour une application recevant des commandes utilisateurs
|
|
*/
|
|
class FuncMapper_command {
|
|
use Tparams_command;
|
|
|
|
const NAME = "func";
|
|
const DEF = [self::NAME,
|
|
"help" => "appliquer une fonction",
|
|
"action" => [self::class, "create_command"],
|
|
"cmd_args" => [
|
|
"usage" => self::NAME,
|
|
["-r", "--run-code", "args" => "value",
|
|
"action" => [self::class, "set_run_code"],
|
|
"help" => "exécuter le code avec eval() pour chaque élément du flux",
|
|
],
|
|
["-f", "--run-file", "args" => "file",
|
|
"action" => [self::class, "set_run_file"],
|
|
"help" => "exécuter le fichier avec require() pour chaque élément du flux",
|
|
],
|
|
["--mo", "--marked-only", "args" => "value", "type" => "bool",
|
|
"action" => [self::class, "set_marked_only"],
|
|
"help" => "indiquer si la fonction ne doit être appelée que pour les éléments marqués",
|
|
],
|
|
["-o", "--param", "args" => "value",
|
|
"action" => [self::class, "add_params"],
|
|
"help" => "spécifier une option générique",
|
|
],
|
|
],
|
|
];
|
|
|
|
/** @var FuncMapper */
|
|
protected static $command;
|
|
|
|
static function create_command() {
|
|
self::$command = mappers_command::add(new FuncMapper());
|
|
}
|
|
|
|
static function set_run_code(string $code) {
|
|
self::get()->setFunc(function() use($code) {
|
|
return eval($code);
|
|
});
|
|
}
|
|
|
|
static function set_run_file(string $file) {
|
|
self::get()->setFunc(function() use($file) {
|
|
return require($file);
|
|
});
|
|
}
|
|
|
|
static function set_marked_only(?bool $marked_only) {
|
|
self::get()->setMarkedOnly($marked_only);
|
|
}
|
|
}
|