| @@ 12-34 (lines=23) @@ | ||
| 9 | ||
| 10 | class ExtensionDefinition extends AbstractDefinition |
|
| 11 | { |
|
| 12 | public function __construct(ReflectionMethod $reflectionMethod, Extension $annotation) |
|
| 13 | { |
|
| 14 | if (!$reflectionMethod->isPublic()) { |
|
| 15 | throw BadModifierException::mustBePublic($reflectionMethod, '@Extension'); |
|
| 16 | } |
|
| 17 | if (!$reflectionMethod->isStatic()) { |
|
| 18 | throw BadModifierException::mustBeStatic($reflectionMethod, '@Extension'); |
|
| 19 | } |
|
| 20 | ||
| 21 | if ($annotation->isFromMethodName()) { |
|
| 22 | $this->name = $reflectionMethod->getName(); |
|
| 23 | } elseif ($annotation->isFromType()) { |
|
| 24 | $returnType = $reflectionMethod->getReturnType(); |
|
| 25 | if ($returnType === null) { |
|
| 26 | throw UnknownTypeException::create($reflectionMethod); |
|
| 27 | } |
|
| 28 | $this->name = (string) $returnType; |
|
| 29 | } else { |
|
| 30 | $this->name = (string) $annotation->getName(); |
|
| 31 | } |
|
| 32 | ||
| 33 | parent::__construct($reflectionMethod); |
|
| 34 | } |
|
| 35 | ||
| 36 | public function buildExtensionCode(string $functionName) : string |
|
| 37 | { |
|
| @@ 15-38 (lines=24) @@ | ||
| 12 | { |
|
| 13 | private $aliases; |
|
| 14 | ||
| 15 | public function __construct(ReflectionMethod $reflectionMethod, Factory $annotation) |
|
| 16 | { |
|
| 17 | if (!$reflectionMethod->isPublic()) { |
|
| 18 | throw BadModifierException::mustBePublic($reflectionMethod, '@Factory'); |
|
| 19 | } |
|
| 20 | if (!$reflectionMethod->isStatic()) { |
|
| 21 | throw BadModifierException::mustBeStatic($reflectionMethod, '@Factory'); |
|
| 22 | } |
|
| 23 | ||
| 24 | if ($annotation->isFromMethodName()) { |
|
| 25 | $this->name = $reflectionMethod->getName(); |
|
| 26 | } elseif ($annotation->isFromType()) { |
|
| 27 | $returnType = $reflectionMethod->getReturnType(); |
|
| 28 | if ($returnType === null) { |
|
| 29 | throw UnknownTypeException::create($reflectionMethod); |
|
| 30 | } |
|
| 31 | $this->name = (string) $returnType; |
|
| 32 | } else { |
|
| 33 | $this->name = (string) $annotation->getName(); |
|
| 34 | } |
|
| 35 | ||
| 36 | parent::__construct($reflectionMethod); |
|
| 37 | $this->aliases = $annotation->getAliases(); |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * Returns true if the signature of the reflection method is compatible with container-interop/service-provider |
|