Prepares the parameters for the given constructor

@param \ReflectionMethod $constructor
@param array $additionalParameters
@return array

@throws \Zepi\Turbo\Exception Cannot find correct value for parameter "{parameterName}" in class "{className}".
516842
protected function prepareParameters(ReflectionMethod $constructor, $additionalParameters)
    {
        $parameters = array();
        foreach ($constructor->getParameters() as $parameter) {
            $parameterValue = null;
        
            if (isset($additionalParameters[$parameter->name])) {
                $parameterValue = $additionalParameters[$parameter->name];
            } else if ($parameter->getClass() !== null) {
                $parameterValue = $this->getInstance($parameter->getClass());
            }
        
            if ($parameterValue === null) {
                throw new Exception('Cannot find correct value for parameter "' . $parameter->name . '" in class "' . $constructor->class . '".');
            }
        
            $parameters[] = $parameterValue;
        }
        
        return $parameters;
    }
841821
public function setAdditionalCondition($additionalCondition, $additionalConditionSql)
	{
		if ( ! empty($additionalCondition)) {
			$additionalCondition = '(' . $additionalCondition . ')';
		}
		$this->additionalCondition = $additionalCondition;

		if ( ! empty($additionalConditionSql)) {
			$additionalConditionSql = '(' . $additionalConditionSql . ')';
		}
		$this->additionalConditionSql = $additionalConditionSql;
	}
713447
public function initConstructorArgs()
    {
        $constructor = $this->reflected->getConstructor();

        if (!is_null($constructor)) {
            // Index parameters by their names
            foreach ($constructor->getParameters() as $param) {
                $name = Util::snakeToCamelCase($param->getName());
                $this->constructorArgs[$name] = $param;
            }
        }
    }
1042246
public function additionalClass($additionalClass)
    {
        $additionalClasses = $this->getAdditionalClasses();
        
        if (($key = array_search($additionalClass, $additionalClasses)) !== false) {
            unset($additionalClasses[$key]);
        }
        
        $additionalClasses[] = $additionalClass;
        $this->setAdditionalClasses($additionalClasses);
    }
960048
public function createParameterConverters(?InterfaceToCall $relatedClassInterface, array $parameterConverterAnnotations): array
    {
        $parameterConverters = [];

        foreach ($parameterConverterAnnotations as $parameterConverterAnnotation) {
            if ($parameterConverterAnnotation instanceof Header) {
                if ($parameterConverterAnnotation->isRequired) {
                    $parameterConverters[] = HeaderBuilder::create($parameterConverterAnnotation->parameterName, $parameterConverterAnnotation->headerName);
                } else {
                    $parameterConverters[] = HeaderBuilder::createOptional($parameterConverterAnnotation->parameterName, $parameterConverterAnnotation->headerName);
                }
            } else if ($parameterConverterAnnotation instanceof Payload) {
                $parameterConverters[] = PayloadBuilder::create($parameterConverterAnnotation->parameterName);
            } else if ($parameterConverterAnnotation instanceof MessageParameter) {
                $parameterConverters[] = MessageConverterBuilder::create($parameterConverterAnnotation->parameterName);
            } else if ($parameterConverterAnnotation instanceof Reference) {
                if ($parameterConverterAnnotation->referenceName) {
                    $parameterConverters[] = ReferenceBuilder::create($parameterConverterAnnotation->parameterName, $parameterConverterAnnotation->referenceName);
                }elseif ($relatedClassInterface) {
                    $parameterConverters[] = ReferenceBuilder::createFromParameterTypeHint($parameterConverterAnnotation->parameterName, $relatedClassInterface);
                }else {
                    $parameterConverters[] = ReferenceBuilder::createWithDynamicResolve($parameterConverterAnnotation->parameterName);
                }
            } else if ($parameterConverterAnnotation instanceof Expression) {
                $parameterConverters[] = ExpressionBuilder::create(
                    $parameterConverterAnnotation->parameterName, $parameterConverterAnnotation->expression
                );
            } else if ($parameterConverterAnnotation instanceof Value) {
                $parameterConverters[] = ValueBuilder::create($parameterConverterAnnotation->parameterName, $parameterConverterAnnotation->value);
            }
        }

        return $parameterConverters;
    }
429149
public function parse($value, $providers, $references = [], $additional = [])
    {
        preg_match_all(self::REGEX, $value, $matches);

        foreach ($matches[0] as $pattern) {
            preg_match_all('/[^,\(\)<>]+/', $pattern, $arguments);
            $arguments = $arguments[0];
            $method = array_shift($arguments);
            $arguments = array_map(function ($arg) {
                return trim(trim($arg), '\'""');
            }, $arguments);

            foreach ($providers as $provider) {
                /*
                 * Call method from provider with/without arguments
                 * 1: Arguments are passed through from fixture
                 * 2: Search if method needs arguments en find them through typehint and additional params
                 * 3: Magic methods without arguments
                 */
                if (method_exists($provider, $method)) {
                    $refl = new \ReflectionMethod($provider, $method);

                    if (count($arguments) < $refl->getNumberOfRequiredParameters()) {
                        $parameters = $refl->getParameters();
                        $parametersNeeded = array_slice($parameters, count($arguments));
                        $arguments = array_merge($arguments, $this->findArguments($parametersNeeded, $additional));

                        if (count($parameters) !== count($arguments)) {
                            throw new \Exception('Can not match all arguments for provider ' . get_class($provider));
                        }
                    }

                    $value = $this->processValue($pattern, $refl->invokeArgs($provider, $arguments), $value, $matches[0]);

                    break;
                } elseif (is_callable([$provider, $method])) {
                    $value = $this->processValue($pattern, call_user_func_array(array($provider, $method), $arguments), $value, $matches[0]);

                    break;
                }
            }
        }

        return $value;
    }
232016
public function resolveCallDependencies(array $parameters, ReflectionFunctionAbstract $reflector)
    {
        foreach ($reflector->getParameters() as $key => $parameter) {
            if ($key === 0) {
                // The first parameter is always the authenticated User instance.
                continue;
            }

            $instance = $this->transformDependency($parameter, $parameters);

            if (! is_null($instance)) {
                array_splice($parameters, $key, 0, array($instance));
            }
        }

        return $parameters;
    }
336210
public function loadExtraOptions($extraOptions, $instance)
    {
        foreach ($extraOptions as $name => $value) {
            if ($this->reflected->hasMethod($name)) {
                // There is a method to handle this option
                call_user_func_array(
                    array($instance, $name),
                    is_array($value) ? $value : array($value)
                );
                continue;
            }
            if ($this->reflected->hasProperty($name) &&
                $this->reflected->getProperty($name)->isPublic()
            ) {
                // There is a public member we can set for this option
                $instance->$name = $value;
                continue;
            }

            if ($this->canHandle($name)) {
                // There is a custom handler for that option
                $closure = $this->getExtraOptionsHandler($name);
                $closure($instance, $value);
            }
        }
    }
260909
private function prepareFilterParams($filtersOrConfigurationKey, array $extraFilters = [])
    {
        if (is_array($filtersOrConfigurationKey)) {
            return array_merge($filtersOrConfigurationKey, $extraFilters);
        }

        if (false !== strpos($filtersOrConfigurationKey, '.')) {
            list($configurationKey, $attribute) = explode('.', $filtersOrConfigurationKey);
        } else {
            $configurationKey = $filtersOrConfigurationKey;
            $attribute = null;
        }

        if (!isset($this->filtersConfigurations[$configurationKey])) {
            throw new ConfigurationException(sprintf('Unable to find filter configuration "%s"', $configurationKey));
        }

        if (null !== $attribute) {
            if (!isset($this->filtersConfigurations[$configurationKey][$attribute])) {
                throw new ConfigurationException(sprintf('Unable to find attribute "%s" in filter configuration "%s"', $attribute, $configurationKey));
            }

            return is_array($this->filtersConfigurations[$configurationKey][$attribute])
                ? array_merge($this->filtersConfigurations[$configurationKey][$attribute], $extraFilters)
                : $this->filtersConfigurations[$configurationKey][$attribute]
                ;
        }

        return is_array($this->filtersConfigurations[$configurationKey])
            ? array_merge($this->filtersConfigurations[$configurationKey], $extraFilters)
            : $this->filtersConfigurations[$configurationKey]
            ;
    }
609340
public function loadContainer(array $additionalConfigsToLoad)
    {
        $containerConfigCache = new ConfigCache($this->cacheFile->getPathname(), (bool)($this->isDebugMode));

        if (!$containerConfigCache->isFresh()) {
            $containerBuilder = $this->loader->loadContainer($additionalConfigsToLoad);

            $dumper = new PhpDumper($containerBuilder);
            $containerConfigCache->write(
                $dumper->dump(),
                $containerBuilder->getResources()
            );
        }

        require_once $this->cacheFile->getPathname();

        return new ProjectServiceContainer();
    }
912370
public function resolveMethodDependencies(array $parameters, ReflectionFunctionAbstract $reflector)
    {
        foreach ($reflector->getParameters() as $key => $parameter) {
            $instance = $this->transformDependency($parameter, $parameters);

            if (!is_null($instance)) {
                $this->spliceIntoParameters($parameters, $key, $instance);
            }
        }

        return $parameters;
    }
20904
private function resolveMethodDependencies(\ReflectionFunctionAbstract $reflector)
    {
        $parameters = [];
        foreach ($reflector->getParameters() as $key => $parameter) {
            $class = $parameter->getClass();
            if ($class) {
                //Request
                $instance = app()->make($class->name);

                if ($instance instanceof FormRequest) {
                    if ($instance->authorize()) {
                        $instance->validate();
                    } else {
                        $instance->forbiddenResponse();
                    }
                }

                array_splice(
                    $parameters, $key, 0, [$instance]
                );
            }
        }

        return $parameters;
    }
486382
protected final void addAdditionalParameters(List<ContentPart<?>> contentList)
    {
        //add additional parameters
        if(this.additionalParameters!=null)
        {
            Iterator<Entry<String,String>> iterator=this.additionalParameters.entrySet().iterator();
            Entry<String,String> entry=null;
            String key=null;
            String value=null;
            while(iterator.hasNext())
            {
                //get next entry
                entry=iterator.next();
                
                //get next key/value
                key=entry.getKey();
                value=entry.getValue();
                
                if((key!=null)&&(value!=null))
                {
                    this.addContentPart(contentList,key,value);
                }
            }
        }
    }
106027
private String[] extractConstructorParameters(Key<?> factoryKey, TypeLiteral<?> implementation,
      Constructor constructor, List<Key<?>> methodParams, Errors errors,
      Set<Dependency> dependencyCollector) throws ErrorsException {

    // Get parameters with annotations.
    List<TypeLiteral<?>> ctorParams = implementation.getParameterTypes(constructor);
    Annotation[][] ctorParamAnnotations = constructor.getParameterAnnotations();

    int p = 0;
    String[] parameterNames = new String[ctorParams.size()];
    Set<Key<?>> keySet = new LinkedHashSet<Key<?>>();
    for (TypeLiteral<?> ctorParam : ctorParams) {
      Key<?> ctorParamKey = getKey(ctorParam, constructor, ctorParamAnnotations[p], errors);

      if (ctorParamKey.getAnnotationType() == Assisted.class) {
        if (!keySet.add(ctorParamKey)) {
          errors.addMessage(PrettyPrinter.format(
              "%s has more than one parameter of type %s annotated with @Assisted(\"%s\").  " +
              "Please specify a unique value with the annotation to avoid confusion.",
              implementation, ctorParamKey.getTypeLiteral().getType(), 
              ((Assisted) ctorParamKey.getAnnotation()).value()));
        }
        
        int location = methodParams.indexOf(ctorParamKey);

        // This should never happen since the constructor was already checked
        // in #[inject]constructorHasMatchingParams(..).
        Preconditions.checkState(location != -1);

        parameterNames[p] = ReflectUtil.formatParameterName(location);
      } else {
        dependencyCollector.add(new Dependency(factoryKey, ctorParamKey, false, true,
            constructor.toString()));
      }

      p++;
    }

    return parameterNames;
  }
828975
public function resolveMethodDependencies(array $parameters, ReflectionFunctionAbstract $reflector)
	{
		foreach ($reflector->getParameters() as $key => $parameter)
		{
			// If the parameter has a type-hinted class, we will check to see if it is already in
			// the list of parameters. If it is we will just skip it as it is probably a model
			// binding and we do not want to mess with those; otherwise, we resolve it here.
			$class = $parameter->getClass();

			if ($class && ! $this->alreadyInParameters($class->name, $parameters))
			{
				array_splice(
					$parameters, $key, 0, [$this->container->make($class->name)]
				);
			}
		}

		return $parameters;
	}
1080408
private function prepareMethodParameters(\ReflectionMethod $refMethod, array $args, $removeUnknownArguments = true): array
    {
        $normalizedArguments = $this->normalizeArguments($args);
        if (!$removeUnknownArguments) {
            $normalizedArguments = array_merge($args, $normalizedArguments);
        }
        $normalizedArguments['args'] = $normalizedArguments;
        $indexedArguments = $this->resolveMethodArguments($refMethod, $normalizedArguments);
        ksort($indexedArguments);

        return $indexedArguments;
    }
891728
protected function getQueryParams(array $additionalParams = [])
    {
        $params = parent::getQueryParams($additionalParams);

        if (empty($params['where'])) {
            return $params;
        }

        foreach (explode('&', $params['where']) as $where) {
            list($key, $value) = explode('=', $where);
            $params[$key] = $value;
        }

        unset($params['where']);

        return $params;
    }