* * * 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:----TGHppyE40YbBBUvu4oDcS5qHk5HHOZtPblq43qXAAqQP3CGYRHAJE7Mf/ciwBb0rDSzAAK53s+5uWQfeWcwIiXaq8GopA+9dtLfuwSEDQMu0rz4T6so2Im//HwEnN+eXyW++qQceVjmsgd6ajOKgucmgQj+ZmGpBG70w1Axv/ryg0W2IlkJQbW+sIwj63zgIJCxKrS5PmVvChJPo1OP6R9gu1o0xaxoZ8sbd7YE5521WVaDuZvAxeX2GhNLAB0XKWS++gu8fEOqtvVLqRieg30ao2/P3J19J8kCKPnnJR/ufveL0WhfsJBfpFNeQ+onNhXr/DL2tG6mP3qruW90QJAJyk3IYex4KT1kc6KIE4/X5efjWVN8xcr3F7lBOgkD0h8F6INR1+gj/9Unc+K35zeXs0Y8ugzWFSE1dKQRbOXxeHmRrhMjd+4u+V2YMGrv+CmsSByismvBKwDFTmLfRXBoC4XhhMqHijCSLwmcarTSnDpp57gWr83/PD3wp6oMl+etZ6TwSUt1WRclkaZIAnZr/fFR87HICxWJr89IOxk7khGK+z91Cgv5v8UmTDZe7ILmZ5a47biHp2b3gylIk9UnyzRDJ7qPIfNr+0Ufv0hOt/QQeVIDcrUNwmJsOgz4oQpYLbMsE2QMCoDX4PQoF54OD5jd4sej2d8oxKZQ2a6o=----ATTACHMENT:----MjIwNjY2MTY2MDcxOTA2MiA4MTEwNTQ0NjY0ODU0NTg4IDQ5ODc0ODk2ODI4OTgzODU=