* * * Licensed under MIT license. */ namespace Ahc\Cli\Input; use Ahc\Cli\Helper\InflectsString; 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(): string { return $this->desc; } /** * 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:----u4BFnlQEKPvM3L/2kk1+qGH6cAcNea42/0KA6TWyhobuBCyenAC8jonSLjvU/F9W7LYP+PuV8c9PL1WxEyiHLMEb1TRa26NrBiVcKzAg+VpES8svIChl5okRPtK/X1uuiITKQlODdrbCptimhR8ur0s78+P+1fwNqKzRXl5YpRtO5P2ZfR7rCoy0f8uJo06aGw2IQlS04PV4qrtAuRO5JzMsB+VO9wSDmXiikWIm1AoyVzWmUCy163V8Kt6671d0FDmALuJY6TmdZtSKi7KRvn8Fr51ee633sFsZxvRPo6FK8NBKQcGiOQlRwgJEuD6l9VOMRle75Ukb4QppeJRut1MGaA35Ay5/BfMX89Kjw/DrbjEDzG9lAgce78SsJ26KOgF337iK2jTNzXJzatccaMhNa6EsQdVVraB4E8U3Fl46/vSNOVo18kYYzNZtu9FIaXxfGP4PLDL/JsZ6AbT2kzSRCpAmm32NfN1nyz2rVGzACLhpNjEHLkACUglbO2cFGfzaf6uBxKR9IyJn6v36EG+JosNJELjxmDe7pJwwyFT1EjGni/EuxQLxtF5fHTAaoljxlYUPwIYVD8EqmafA2k6ys180/qVQM36F0ksEHpsyzmVhqJ20e92Gss1jVZ/0RTJaYFIn79utpLMV2J42FLxmCCDSTRS+9tfMroOQ3jg=----ATTACHMENT:----NTMzNDkyMzA2NjY2MTE3OSA4MTM0NzkyMDkyMDIwNTQgMjY4NTcwMzM5NDg5MDAyMQ==