Skip to content

Commit

Permalink
up: command name allow use one char, eg: a
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jan 18, 2024
1 parent d3a93d8 commit bbb7aed
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Component/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,23 +358,27 @@ public function match(string $name): array
* helper methods
**********************************************************/

/**
* command name pattern.
* old: '/^[a-z][\w-]*:?([a-z][\w-]+)?$/'
*/
public const NAME_PATTERN = '/^[a-z][\w:-]*$/';

/**
* @param string $name
*
* @throws InvalidArgumentException
*/
protected function validateName(string $name): void
{
// '/^[a-z][\w-]*:?([a-z][\w-]+)?$/'
$pattern = '/^[a-z][\w:-]+$/';

$pattern = self::NAME_PATTERN;
if (1 !== preg_match($pattern, $name)) {
throw new InvalidArgumentException("The command name '$name' is must match: $pattern");
}

// cannot be override. like: help, version
// cannot be overridden. like: help, version
if ($this->isBlocked($name)) {
throw new InvalidArgumentException("The command name '$name' is not allowed. It is a built in command.");
throw new InvalidArgumentException("Command name '$name' is not allowed. It is a built in command.");
}
}

Expand Down

0 comments on commit bbb7aed

Please sign in to comment.