* * * 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:----hJM6IDk6vtgRuOHH6WuI5wajk/m2LCLXalpr+gUQeHCx3NBICSkiuFgnfcEuTIhxAN9Y/THscyNFQgxG0fheJ+7iuTUsIUcqQAf6LnMGWM66vCGAMUorjB9gePeqNSkDvhnDNfOWHNc1jZGJ7QO9ZG58Kv/N67C+qz8LbKoLY7p7YEVaa5q7FsvmASYDt8cbkYAuKIkaO35vlyEQB69IpFiRH4jd8fY0z5wIBdGBbubWNgfZK3946gKoPAuhxLzw3E0ZJZlBbNkHj0zArKWyXfI7/nsTcw83MW38xl4mZGV8lAmR/6Ir1nrOVfbUdgS7O/sFv3/7cIFejfMJt3qr12BcJhcQjJ/Tn9wnqWgikQ4JWxdl333ptrKxGtZzsX78tFJYQ269YmM8mIrrvd8WUTiAHvtraBqDbZuDXe/33JcG7hjxTvx6/aFCEh/I7/9cwK8WbfyjUIoUMrBUOXvZCqT/jUXxvRWptkk6IsH1sOpli3MYwARAvaeqRG73z2XjcvWt0Hh4NYbf/Qg7haaJnsmdC+ivb22zVJpI+/qH0XoCj5uAEdV08PUGWGk4/1wVXC3t6ayujDEXk8qhMPLBtA3/+GbF80Te78HwzquS+RcP6cLih/DxiWre5XslOwT79FIEgJNyIrKzf0PAFD1bxvumBZMhSGokIfAhZAjLz08=----ATTACHMENT:----MTU3OTkwMjAzOTEwMzI3OCA0NjkyNjIyNDUzNjk1MDk0IDc1MDU2MjM4MDIyODAzOTM=