nur-sery/nur_src/mapper/item/Seq2AssocMapper_command.php

50 lines
1.3 KiB
PHP
Raw Normal View History

2024-04-04 16:26:22 +04:00
<?php
namespace nur\mapper\item;
use nur\A;
use nur\mapper\base\mappers_command;
use nur\mapper\base\Tparams_command;
/**
* Class Seq2AssocMapper_command: classe de support pour construire une instance
* de mapper pour une application recevant des commandes utilisateurs
*/
class Seq2AssocMapper_command {
use Tparams_command;
const NAME = "seq2assoc";
const DEF = [self::NAME,
"help" => "convertir en tableaux associatifs",
"action" => [self::class, "create_command"],
"cmd_args" => [
"usage" => self::NAME,
["-k", "--parse-keys", "type" => "bool",
"action" => [self::class, "set_parse_keys", true],
],
["-o", "--param", "args" => "value",
"action" => [self::class, "add_params"],
"help" => "spécifier une option générique",
],
["args" => [["value", null]], "type" => "array",
"action" => [self::class, "set_keys"],
],
],
];
/** @var Seq2AssocMapper */
protected static $command;
static function create_command() {
self::$command = mappers_command::add(new Seq2AssocMapper());
}
static function set_parse_keys(bool $parseKeys) {
self::get()->setParseKeys($parseKeys);
}
static function set_keys(array $args) {
A::merge($keys, ...$args);
if ($keys) self::get()->setKeys($keys);
}
}