Skip to content

Commit bbb7aed

Browse files
committed
up: command name allow use one char, eg: a
1 parent d3a93d8 commit bbb7aed

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Component/Router.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,23 +358,27 @@ public function match(string $name): array
358358
* helper methods
359359
**********************************************************/
360360

361+
/**
362+
* command name pattern.
363+
* old: '/^[a-z][\w-]*:?([a-z][\w-]+)?$/'
364+
*/
365+
public const NAME_PATTERN = '/^[a-z][\w:-]*$/';
366+
361367
/**
362368
* @param string $name
363369
*
364370
* @throws InvalidArgumentException
365371
*/
366372
protected function validateName(string $name): void
367373
{
368-
// '/^[a-z][\w-]*:?([a-z][\w-]+)?$/'
369-
$pattern = '/^[a-z][\w:-]+$/';
370-
374+
$pattern = self::NAME_PATTERN;
371375
if (1 !== preg_match($pattern, $name)) {
372376
throw new InvalidArgumentException("The command name '$name' is must match: $pattern");
373377
}
374378

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

0 commit comments

Comments
 (0)