AsTaggedItem.php
2 years ago
Autoconfigure.php
2 years ago
AutoconfigureTag.php
2 years ago
TaggedIterator.php
2 years ago
TaggedLocator.php
2 years ago
Target.php
4 years ago
When.php
2 years ago
index.php
3 years ago
Target.php
30 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\DependencyInjection\Attribute; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; |
| 5 | #[\Attribute(\Attribute::TARGET_PARAMETER)] |
| 6 | final class Target |
| 7 | { |
| 8 | public $name; |
| 9 | public function __construct(string $name) |
| 10 | { |
| 11 | $this->name = \lcfirst(\str_replace(' ', '', \ucwords(\preg_replace('/[^a-zA-Z0-9\\x7f-\\xff]++/', ' ', $name)))); |
| 12 | } |
| 13 | public static function parseName(\ReflectionParameter $parameter) : string |
| 14 | { |
| 15 | if (80000 > \PHP_VERSION_ID || !($target = $parameter->getAttributes(self::class)[0] ?? null)) { |
| 16 | return $parameter->name; |
| 17 | } |
| 18 | $name = $target->newInstance()->name; |
| 19 | if (!\preg_match('/^[a-zA-Z_\\x7f-\\xff]/', $name)) { |
| 20 | if (($function = $parameter->getDeclaringFunction()) instanceof \ReflectionMethod) { |
| 21 | $function = $function->class . '::' . $function->name; |
| 22 | } else { |
| 23 | $function = $function->name; |
| 24 | } |
| 25 | throw new InvalidArgumentException(\sprintf('Invalid #[Target] name "%s" on parameter "$%s" of "%s()": the first character must be a letter.', $name, $parameter->name, $function)); |
| 26 | } |
| 27 | return $name; |
| 28 | } |
| 29 | } |
| 30 |