Skip to content

Commit

Permalink
regexp: \z replaced with D modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Aug 7, 2019
1 parent a33f893 commit fa7e070
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/DI/Config/DefinitionSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/DI/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/DI/Definitions/ServiceDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/DI/Extensions/ServicesExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/DI/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/DI/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down Expand Up @@ -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]]);
Expand Down

0 comments on commit fa7e070

Please sign in to comment.