$named * @param array $positional 1 起 */ public function __construct( public array $named = [], public array $positional = [], ) {} public function get(string $name, ?int $position, ?string $default = ''): ?string { if (array_key_exists($name, $this->named)) { return trim($this->named[$name]); } if ($position !== null && array_key_exists($position, $this->positional)) { return trim($this->positional[$position]); } return $default; } /** * 原值(不 trim),给 markdown 参数用。 */ public function raw(string $name, ?int $position): ?string { if (array_key_exists($name, $this->named)) { return $this->named[$name]; } if ($position !== null && array_key_exists($position, $this->positional)) { return $this->positional[$position]; } return null; } public function with(string $name, string $value): self { $copy = clone $this; $copy->named[$name] = $value; return $copy; } /** * 全部参数,命名的用名字、位置的用序号字符串作键(Tpl 模板交给 Mustache 用)。 * * @return array */ public function all(): array { $all = []; foreach ($this->positional as $position => $value) { $all[(string) $position] = trim($value); } foreach ($this->named as $name => $value) { $all[$name] = trim($value); } return $all; } }