| @@ 28-78 (lines=51) @@ | ||
| 25 | * |
|
| 26 | * @Annotation |
|
| 27 | */ |
|
| 28 | class InjectParameter implements ResolvePropertyInterface, ResolveMethodInterface |
|
| 29 | { |
|
| 30 | /** @var mixed */ |
|
| 31 | protected $value; |
|
| 32 | ||
| 33 | /** |
|
| 34 | * Inject constructor. |
|
| 35 | * |
|
| 36 | * @param $value |
|
| 37 | */ |
|
| 38 | public function __construct($value) |
|
| 39 | { |
|
| 40 | $this->value = $value; |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * {@inheritdoc} |
|
| 45 | * @throws PropertyDefinitionNotFoundException |
|
| 46 | */ |
|
| 47 | public function resolveProperty( |
|
| 48 | DefinitionAnalyzer $analyzer, |
|
| 49 | ClassDefinition $classDefinition, |
|
| 50 | \ReflectionProperty $reflectionProperty |
|
| 51 | ) { |
|
| 52 | $propertyName = $reflectionProperty->getName(); |
|
| 53 | if ($classDefinition->hasProperty($propertyName)) { |
|
| 54 | $classDefinition->getProperty($propertyName) |
|
| 55 | ->defineDependency(new ParameterReference($this->value['value'])); |
|
| 56 | } |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * {@inheritdoc} |
|
| 61 | * @throws WrongAnnotationConstructorException |
|
| 62 | * @throws MethodDefinitionNotFoundException |
|
| 63 | * @throws ParameterDefinitionAlreadyExistsException |
|
| 64 | * @throws MethodDefinitionAlreadyExistsException |
|
| 65 | */ |
|
| 66 | public function resolveMethod( |
|
| 67 | DefinitionAnalyzer $analyzer, |
|
| 68 | ClassDefinition $classDefinition, |
|
| 69 | \ReflectionMethod $reflectionMethod |
|
| 70 | ) { |
|
| 71 | // Get parameter key |
|
| 72 | $key = array_keys($this->value)[0]; |
|
| 73 | $classDefinition->setupMethod($reflectionMethod->getName()) |
|
| 74 | ->defineParameter($key) |
|
| 75 | ->defineDependency(new ParameterReference($this->value[$key])) |
|
| 76 | ->end(); |
|
| 77 | } |
|
| 78 | } |
|
| 79 | ||
| @@ 27-76 (lines=50) @@ | ||
| 24 | * |
|
| 25 | * @Annotation |
|
| 26 | */ |
|
| 27 | class InjectService implements ResolvePropertyInterface, ResolveMethodInterface |
|
| 28 | { |
|
| 29 | /** @var mixed */ |
|
| 30 | protected $value; |
|
| 31 | ||
| 32 | /** |
|
| 33 | * Inject constructor. |
|
| 34 | * |
|
| 35 | * @param $value |
|
| 36 | */ |
|
| 37 | public function __construct($value) |
|
| 38 | { |
|
| 39 | $this->value = $value; |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * {@inheritdoc} |
|
| 44 | * @throws PropertyDefinitionNotFoundException |
|
| 45 | */ |
|
| 46 | public function resolveProperty( |
|
| 47 | DefinitionAnalyzer $analyzer, |
|
| 48 | ClassDefinition $classDefinition, |
|
| 49 | \ReflectionProperty $reflectionProperty |
|
| 50 | ) { |
|
| 51 | $propertyName = $reflectionProperty->getName(); |
|
| 52 | if ($classDefinition->hasProperty($propertyName)) { |
|
| 53 | $classDefinition->getProperty($propertyName) |
|
| 54 | ->defineDependency(new ServiceReference($this->value['value'])); |
|
| 55 | } |
|
| 56 | } |
|
| 57 | ||
| 58 | /** |
|
| 59 | * {@inheritdoc} |
|
| 60 | * @throws WrongAnnotationConstructorException |
|
| 61 | * @throws MethodDefinitionNotFoundException |
|
| 62 | * @throws ParameterDefinitionAlreadyExistsException |
|
| 63 | * @throws MethodDefinitionAlreadyExistsException |
|
| 64 | */ |
|
| 65 | public function resolveMethod( |
|
| 66 | DefinitionAnalyzer $analyzer, |
|
| 67 | ClassDefinition $classDefinition, |
|
| 68 | \ReflectionMethod $reflectionMethod |
|
| 69 | ) { |
|
| 70 | // Get parameter key |
|
| 71 | $key = array_keys($this->value)[0]; |
|
| 72 | $classDefinition->setupMethod($reflectionMethod->getName()) |
|
| 73 | ->defineParameter($key) |
|
| 74 | ->defineDependency(new ServiceReference($this->value[$key]))->end(); |
|
| 75 | } |
|
| 76 | } |
|
| 77 | ||