/**
  * Set correct order of arguments
  *
  * @param MethodDefinition $methodDefinition
  * @param \ReflectionFunctionAbstract $reflectionMethod
  * @throws \InvalidArgumentException
  */
 public function setOrderArguments(MethodDefinition $methodDefinition, \ReflectionFunctionAbstract $reflectionMethod)
 {
     $parameters = [];
     // Get parameter names
     foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
         $parameters[] = $reflectionParameter->getName();
     }
     $methodDefinition->setParametersCollectionOrder($parameters);
 }
Пример #2
0
 /** {@inheritdoc} */
 public function defineMethod(string $methodName) : MethodBuilderInterface
 {
     if (array_key_exists($methodName, $this->methodsCollection)) {
         throw new MethodDefinitionAlreadyExistsException();
     }
     $methodDefinition = new MethodDefinition($this, $methodName);
     $methodDefinition->setMethodName($methodName);
     $this->methodsCollection[$methodName] = $methodDefinition;
     return $methodDefinition;
 }
 /**
  * Generate setters for class
  *
  * @param ClassDefinition $classDefinition
  * @param MethodDefinition $methodDefinition
  * @return string
  * @throws ReferenceNotImplementsException
  */
 protected function generateSetters(ClassDefinition $classDefinition, MethodDefinition $methodDefinition) : string
 {
     $className = $classDefinition->getClassName();
     $methodName = $methodDefinition->getMethodName();
     $arguments = $this->generateArguments($methodDefinition);
     // Call method by reflection
     if (!$methodDefinition->isPublic()) {
         $isEmptyArguments = count($methodDefinition->getParametersCollection()) === 0;
         return "\t\$method = (new \\ReflectionClass('{$className}'))->getMethod('{$methodName}');" . "\n\t\t\t\$method->setAccessible(true);" . "\n\t\t\t\$method->invoke(\$temp" . ($isEmptyArguments ? '' : ", {$arguments}") . ');' . "\n\t\t\t\$method->setAccessible(false);";
     } else {
         return "\t\$temp->{$methodName}({$arguments});";
     }
 }
Пример #4
0
 /**
  * Resolve method/constructor arguments
  *
  * @param MethodDefinition $methodDefinition
  * @param array $arguments
  * @throws ParameterDefinitionAlreadyExistsException
  * @throws \InvalidArgumentException
  * @throws ReferenceNotImplementsException
  */
 protected function resolveArguments(MethodDefinition $methodDefinition, array $arguments)
 {
     foreach ($arguments as $argumentName => $argumentValue) {
         $methodDefinition->defineParameter($argumentName)->defineDependency($this->resolveDependency($argumentValue));
     }
 }