/** * {@inheritdoc} * @throws MethodDefinitionAlreadyExistsException * @throws MethodDefinitionNotFoundException */ public function analyze(DefinitionAnalyzer $analyzer, ClassDefinition $classDefinition, \ReflectionMethod $reflectionMethod) { $methodName = $reflectionMethod->getName(); // Constructor definition is required if ($methodName === '__construct' && !$classDefinition->hasMethod('__construct')) { $classDefinition->defineConstructor()->end(); } // Set method metadata if ($classDefinition->hasMethod($methodName)) { $classDefinition->getMethod($methodName)->setModifiers($reflectionMethod->getModifiers())->setIsPublic($reflectionMethod->isPublic()); } }
/** * Resolve constructor * * @param ClassDefinition $classDefinition * @param array $constructorArray * @throws MethodDefinitionAlreadyExistsException * @throws \InvalidArgumentException * @throws ParameterDefinitionAlreadyExistsException * @throws ReferenceNotImplementsException */ protected function resolveConstructor(ClassDefinition $classDefinition, array $constructorArray) { $methodDefinition = $classDefinition->defineConstructor(); if (array_key_exists('arguments', $constructorArray)) { $this->resolveArguments($methodDefinition, $constructorArray['arguments']); } }
/** * Define constructor * * @param ClassDefinition $classDefinition * @param $path * @throws MethodDefinitionAlreadyExistsException */ protected function defineConstructor(ClassDefinition $classDefinition, $path) { $classDefinition->defineConstructor()->defineParameter('path')->defineDependency(new StringReference($path))->end()->end(); }