Skip to content
Permalink
Browse files

regexp: \z replaced with D modifier

  • Loading branch information...
dg committed Jul 11, 2019
1 parent 1010cee commit 2f52649fa508f2fbb90549b2bdf28af02907ff9c
@@ -130,7 +130,7 @@ public function completeDefault(Context $context)
private function sniffType($key, array $def): string
{
if (is_string($key)) {
$name = preg_match('#^@[\w\\\\]+\z#', $key)
$name = preg_match('#^@[\w\\\\]+$#D', $key)
? $this->builder->getByType(substr($key, 1), false)
: $key;
@@ -64,7 +64,7 @@ public function addDefinition(?string $name, Definition $definition = null): Def
for ($i = 1; isset($this->definitions['0' . $i]) || isset($this->aliases['0' . $i]); $i++);
$name = '0' . $i; // prevents converting to integer in array key
} elseif (is_int(key([$name => 1])) || !preg_match('#^\w+(\.\w+)*\z#', $name)) {
} elseif (is_int(key([$name => 1])) || !preg_match('#^\w+(\.\w+)*$#D', $name)) {
throw new Nette\InvalidArgumentException(sprintf('Service name must be a alpha-numeric string and not a number, %s given.', gettype($name)));
} else {
@@ -244,7 +244,7 @@ public function generateMethod(Nette\PhpGenerator\Method $method, Nette\DI\PhpGe
$this->setup
&& $type !== $entity
&& !(is_array($entity) && $entity[0] instanceof Reference && $entity[0]->getValue() === Nette\DI\ContainerBuilder::THIS_CONTAINER)
&& !(is_string($entity) && preg_match('#^[\w\\\\]+\z#', $entity) && is_subclass_of($entity, $type))
&& !(is_string($entity) && preg_match('#^[\w\\\\]+$#D', $entity) && is_subclass_of($entity, $type))
) {
$code .= PhpHelpers::formatArgs("if (!\$service instanceof $type) {\n"
. "\tthrow new Nette\\UnexpectedValueException(?);\n}\n",
@@ -223,7 +223,7 @@ private function convertKeyToName($key): ?string
{
if (is_int($key)) {
return null;
} elseif (preg_match('#^@[\w\\\\]+\z#', $key)) {
} elseif (preg_match('#^@[\w\\\\]+$#D', $key)) {
return $this->getContainerBuilder()->getByType(substr($key, 1), true);
}
return $key;
@@ -101,9 +101,9 @@ public static function filterArguments(array $args): array
foreach ($args as $k => $v) {
if ($v === '...') {
unset($args[$k]);
} elseif (is_string($v) && preg_match('#^[\w\\\\]*::[A-Z][A-Z0-9_]*\z#', $v, $m)) {
} elseif (is_string($v) && preg_match('#^[\w\\\\]*::[A-Z][A-Z0-9_]*$#D', $v, $m)) {
$args[$k] = constant(ltrim($v, ':'));
} elseif (is_string($v) && preg_match('#^@[\w\\\\]+\z#', $v)) {
} elseif (is_string($v) && preg_match('#^@[\w\\\\]+$#D', $v)) {
$args[$k] = new Reference(substr($v, 1));
} elseif (is_array($v)) {
$args[$k] = self::filterArguments($v);
@@ -195,7 +195,7 @@ public function completeStatement(Statement $statement, bool $currentServiceAllo
break;
case is_array($entity):
if (!preg_match('#^\$?(\\\\?' . PhpHelpers::PHP_IDENT . ')+(\[\])?\z#', $entity[1])) {
if (!preg_match('#^\$?(\\\\?' . PhpHelpers::PHP_IDENT . ')+(\[\])?$#D', $entity[1])) {
throw new ServiceCreationException("Expected function, method or property name, '$entity[1]' given.");
}
@@ -432,7 +432,7 @@ private function convertReferences(array $arguments): array
$pair = explode('::', substr($val, 1), 2);
if (!isset($pair[1])) { // @service
$val = new Reference($pair[0]);
} elseif (preg_match('#^[A-Z][A-Z0-9_]*\z#', $pair[1], $m)) { // @service::CONSTANT
} elseif (preg_match('#^[A-Z][A-Z0-9_]*$#D', $pair[1], $m)) { // @service::CONSTANT
$val = ContainerBuilder::literal($this->resolveReferenceType(new Reference($pair[0])) . '::' . $pair[1]);
} else { // @service::property
$val = new Statement([new Reference($pair[0]), '$' . $pair[1]]);

0 comments on commit 2f52649

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