Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Target.php

function Target::parseName

3 calls to Target::parseName()
AutowirePass::autowireMethod in vendor/symfony/dependency-injection/Compiler/AutowirePass.php
Autowires the constructor or a method.
RegisterControllerArgumentLocatorsPass::process in vendor/symfony/http-kernel/DependencyInjection/RegisterControllerArgumentLocatorsPass.php
You can modify the container here before it is dumped to PHP code.
ResolveBindingsPass::processValue in vendor/symfony/dependency-injection/Compiler/ResolveBindingsPass.php
Processes a value found in a definition tree.

File

vendor/symfony/dependency-injection/Attribute/Target.php, line 41

Class

Target
An attribute to tell how a dependency is used and hint named autowiring aliases.

Namespace

Symfony\Component\DependencyInjection\Attribute

Code

public static function parseName(\ReflectionParameter $parameter, ?self &$attribute = null, ?string &$parsedName = null) : string {
    $attribute = null;
    if (!($target = $parameter->getAttributes(self::class)[0] ?? null)) {
        $parsedName = (new self($parameter->name))
            ->getParsedName();
        return $parameter->name;
    }
    $attribute = $target->newInstance();
    $name = $attribute->name ??= $parameter->name;
    $parsedName = $attribute->getParsedName();
    if (!preg_match('/^[a-zA-Z_\\x7f-\\xff]/', $parsedName)) {
        if (($function = $parameter->getDeclaringFunction()) instanceof \ReflectionMethod) {
            $function = $function->class . '::' . $function->name;
        }
        else {
            $function = $function->name;
        }
        throw new InvalidArgumentException(\sprintf('Invalid #[Target] name "%s" on parameter "$%s" of "%s()": the first character must be a letter.', $name, $parameter->name, $function));
    }
    return preg_match('/^[a-zA-Z0-9_\\x7f-\\xff]++$/', $name) ? $name : $parsedName;
}
RSS feed
Powered by Drupal