Skip to content
Permalink
Browse files

Container: added const NAME_REGEXP

  • Loading branch information...
dg committed Nov 1, 2019
1 parent 7446938 commit 6ba5e7e84ba46eec5afccf2b906b6e718d397014
Showing with 4 additions and 2 deletions.
  1. +4 −2 src/ComponentModel/Container.php
@@ -19,6 +19,8 @@
*/
class Container extends Component implements IContainer
{
private const NAME_REGEXP = '#^[a-zA-Z0-9_]+$#D';
/** @var IComponent[] */
private $components = [];
@@ -40,7 +42,7 @@ public function addComponent(IComponent $component, ?string $name, string $inser
$name = $component->getName();
}
if (!preg_match('#^[a-zA-Z0-9_]+$#D', $name)) {
if (!preg_match(self::NAME_REGEXP, $name)) {
throw new Nette\InvalidArgumentException("Component name must be non-empty alphanumeric string, '$name' given.");
}
@@ -107,7 +109,7 @@ public function removeComponent(IComponent $component): void
[$name] = $parts = explode(self::NAME_SEPARATOR, $name, 2);
if (!isset($this->components[$name])) {
if (!preg_match('#^[a-zA-Z0-9_]+$#D', $name)) {
if (!preg_match(self::NAME_REGEXP, $name)) {
if ($throw) {
throw new Nette\InvalidArgumentException("Component name must be non-empty alphanumeric string, '$name' given.");
}

0 comments on commit 6ba5e7e

Please sign in to comment.
You can’t perform that action at this time.