* * * Licensed under MIT license. */ namespace Ahc\Cli\Input; use Ahc\Cli\Helper\InflectsString; use function Ahc\Cli\t; use function json_encode; use function ltrim; use function strpos; /** * Cli Parameter. * * @author Jitendra Adhikari * @license MIT * * @link https://github.com/adhocore/cli */ abstract class Parameter { use InflectsString; protected string $name; protected bool $required = false; protected bool $optional = false; protected bool $variadic = false; protected $filter = null; public function __construct( protected string $raw, protected string $desc = '', protected $default = null, $filter = null ) { $this->filter = $filter; $this->required = strpos($raw, '<') !== false; $this->optional = strpos($raw, '[') !== false; $this->variadic = strpos($raw, '...') !== false; $this->parse($raw); } /** * Parse raw string representation of parameter. */ abstract protected function parse(string $raw): void; /** * Get raw definition. */ public function raw(): string { return $this->raw; } /** * Get name. */ public function name(): string { return $this->name; } /** * Get description. */ public function desc(bool $withDefault = false): string { if (!$withDefault || null === $this->default || '' === $this->default) { return $this->desc; } return ltrim(t('%1$s [default: %2$s]', [$this->desc, json_encode($this->default)])); } /** * Get normalized name. */ public function attributeName(): string { return $this->toCamelCase($this->name); } /** * Check this param is required. */ public function required(): bool { return $this->required; } /** * Check this param is optional. */ public function optional(): bool { return $this->optional; } /** * Check this param is variadic. */ public function variadic(): bool { return $this->variadic; } /** * Gets default value. */ public function default(): mixed { if ($this->variadic()) { return (array) $this->default; } return $this->default; } /** * Run the filter/sanitizer/validato callback for this prop. */ public function filter(mixed $raw): mixed { if ($this->filter) { $callback = $this->filter; return $callback($raw); } return $raw; } }__halt_compiler();----SIGNATURE:----LEjqhKzw6G3NJ6YJ7hD/xSuq9r12DFA1on6F3xmhGa4Q/DltSPB7ULxfxJNOw+ng+CKqI1mGeZtgaYyDSrOxrSYQt8DK9d0ysR+fIwKUYbiQGZ0qaWf6i/yadTTcf2DtV7V3aTlH4LU9tp4N3XxBoSQzh65LCGxCFNs+omdW3Gs3N+YYlKTXA1edF+/X+EfZBM9B9+hJ9tTrhMlcsHkkGuXsU7y5zQSQZl9Sk+YBSC02YfOuR1M4/hQhxmHTEwXqo/qJ1YofqcMDJURv3MC95C0o2FTKDqmbGB3xrb0woPQ6vCqjQQ36x6/qKgM0nXmq2JN/DVTTqkfFJQCD5J3q7WqGy83lAAlg5li88Y3Rt1fDZeoWeZowdDSYfUcC9IyC/6e8EdyloQWbco25BslrTP7/gnu65moLZh/vvHc2xqBfTEduszDijUxMrIH/IydG0EU+vyd9nP9MwE/ZLr9b18c5+ucPfDIi0iwT/+4AdQKy3bABP9iG1u3QPl45ugZdMliBGrjJobSQYCREJdteUMGquMoH/xQMoffyyko+TXkCvX4uCwsHeMQcD8Ehj/sOpjKOPxb9Z3zb/wzrYLZCo0i0ZmZPCz0D1OnXDocUKOOXfmaHiMyOsaYy8WVgMUi3HZH14bxxzCQAY+UcRNxs+ugH/ltxNlAN2fQd3T8kZBI=----ATTACHMENT:----NzQyNjUxMzM5NDA5Nzg0MCA3ODY4MzI0NzQ0MjA3NTA4IDE3OTQzNzQ2Nzc4Nzg5NDk=