* * * 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:----lhNmRWXPCR4CGvRVLkzmSznGQbXD4tMEGbtr8QNmXg/svHdV8SMOCpcFemizVIqYkKvZXV9H8j6k8JZjv488UkcveAiTttE7SGE0+VCdVPp0PWqUzptk8PxqVofL3EQRbDSl9uVRW32jMpzTIr1APh7uH4tZhYF74+q4xPEGtgRe9K0gAOBWxVLXVFIMC0+Z2Gv8/DUrTw2eqafBL3igElZv1L5V0pW6gHkRE3rCHtStfZZ8Mp+CfXrc3BD4lCb1XdZuuuRUiu2isgeQxw1D7YHATJgfxEaOTw4f3/FeM0S8Y91P0Q9GANiBoXW9GeYCWCyai4m+FLNMTCmoBoKbe/9ScVE1zvpPd6vSTfRxahyPrGmoiE0Q9A+WI9EZlQxxQTPI4b0HJ2JScGIxy5fpOmhnufdzWugi1xAcGJ30y0GFdaNj8Ld+isnzFfVx3C8ywJ15Rdm6DcZtClns2A0vRCt4rZpXZlC8jtCT3olOmnJ4V5z5taWeFO0T88S5ORabDhKLTzNwRFLKb99w4Tvtdik7P5TN8oFHnVQKr3KL5Dhe7R/x30qm45idesywBN3hVCWhSAzL73KrgQefSxya6CsUhArOT5yB8MuOuMRx8pAARcDing63tR8RYHvSSu8gABPNZkSAuaKz80b8a5/QSnO9jD3G/QErEOWf2+e3A0s=----ATTACHMENT:----MzYyMTE2Mzc4MjUyMTI1NiAxOTM4NDA4NjQ0NTA3NTM0IDU0NjU0NDQ4NTQyMjgxODg=