* * * 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:----hN6MLCv0dLP+4V1tSz7suMQTqajcik++IkVvDMAGv/oD+okK9INSSuOsaQ1n1lnqipi1tHaEvkop8TkEsNxTqj1UcbegTDFWqiKglKBZmGzJ3xK3dT3kBT/ch3ofebQxzpjhi2S3oFtMLvWnA4bHFk2CMPC6Z5pVTWCPwtyI/sDINpqNyXfWrzgcOtoIryiifoZ1urqos0Fa8JsCC8ffGXI6D8JbgQ8ZpqsK+jejuYJiTGKDzf8FVhj2XwfLwoRMS3YYYDx4IP4u2r4dM4xGagERwIa33bnvuXHQmDrxe1j0N03GxjUzS0v2ZiZ4K6OxjzFgPmGV6GIpEGBei1yqkN3QodAlxzjj/TIsjds4t7QAe6TgSHfvXWk1HKhXsnMZQAKKIX8GQVdJ6HtPz6vMd1ZQGvpiYYOYS8d6gIiMCZHyXpKaYP3Arx4TUqLsVsj4GA5gfD2cD4k7reYUT7nhlnfJnk0jLIiG9n3n9NgWuubSqayKYgCcJi6MZa5iTSjEIb+yfCksk+wxh0wCwuMti3RTnpuRB98fdwLvYl36lffAm1Mg7MKGtTlsP8Uon/Cv5eEuKk1gbLaVv08MSybg83RGYQwTJ+ngiUW6ffPlNZiFjELpP5EPy7d9RHenSeTVXhMzYwEj2hLSGz+1FhDHaMHXrsLSUnR6KM4e2fDKRkw=----ATTACHMENT:----MzM1MDM4OTE4NzkzMzkyOCAxNDczNDIxNzMwNzM4NTM0IDg5NTg2MjIzODE5NTgxODI=