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

52 lines
1.5 KiB
PHP
Raw Normal View History

2024-04-04 16:26:22 +04:00
<?php
namespace nur\mapper\item;
use nur\mapper\base\mappers_command;
use nur\mapper\base\Tparams_command;
/**
* Class SchemaMapper_command: classe de support pour construire une instance de
* mapper pour une application recevant des commandes utilisateurs
*/
class SchemaMapper_command {
use Tparams_command;
const NAME = "schema";
const DEF = [self::NAME,
"help" => "appliquer un schéma",
"action" => [self::class, "create_command"],
"cmd_args" => [
"usage" => self::NAME,
["-r", "--run-code", "args" => "value",
"action" => [self::class, "set_schema_from_code"],
"help" => "exécuter le code et utiliser sa valeur de retour comme schéma",
],
["-f", "--run-file", "args" => "file",
"action" => [self::class, "set_schema_from_file"],
"help" => "exécuter le fichier et utiliser sa valeur de retour comme schéma",
],
["-o", "--param", "args" => "value",
"action" => [self::class, "add_params"],
"help" => "spécifier une option générique",
],
],
];
/** @var SchemaMapper */
protected static $command;
static function create_command() {
self::$command = mappers_command::add(new SchemaMapper());
}
static function set_schema_from_code(string $code) {
$schema = eval($code);
self::get()->setFsvSchema($schema);
}
static function set_schema_from_file(string $file) {
$schema = require($file);
self::get()->setFsvSchema($schema);
}
}