Resolves function arguments.

@param array $parameters

@throws UnresolvableArgumentException
@throws \ReflectionException

@return array
331208
public function resolve(array $parameters) : array
    {
        if (!$number = $this->reflection->getNumberOfParameters()) {
            return [];
        }

        $arguments = \array_fill(0, $number, null);

        foreach ($this->getParameters() as $pos => $parameter) {
            $result = $this->match($parameter, $parameters);

            if ($result) {
                $arguments[$pos] = $result[1];
                unset($parameters[$result[0]]);
                continue;
            }

            if ($parameter->isDefaultValueAvailable()) {
                $arguments[$pos] = $parameter->getDefaultValue();
                continue;
            }

            throw UnresolvableArgumentException::fromParameter($parameter);
        }

        return $arguments;
    }
609993
public function all(array $parameters = [])
    {
        $resolver = $this->createOptionsResolver();
        $resolver->setDefined('search');

        return $this->get('namespaces', $resolver->resolve($parameters));
    }
669569
protected function normalizeRouteParameters(array $parameters): array
    {
        $factoryWasGiven = array_key_exists(RouteInterface::PARAM_REQUEST_FACTORY, $parameters);
        $useGroupFactory =
            $parameters[RouteInterface::PARAM_FACTORY_FROM_GROUP] ?? self::USE_FACTORY_FROM_GROUP_DEFAULT;

        return [
            $parameters[RouteInterface::PARAM_MIDDLEWARE_LIST] ?? [],
            $parameters[RouteInterface::PARAM_CONTAINER_CONFIGURATORS] ?? [],
            $parameters[RouteInterface::PARAM_REQUEST_FACTORY] ?? null,
            $factoryWasGiven === true ? false : $useGroupFactory,
            $parameters[RouteInterface::PARAM_NAME] ?? null,
        ];
    }
378980
protected function resolveHeaders(array $parameters)
    {
        $headers = [];
        foreach ($parameters as $key => $value) {
            if (strpos($key, 'HTTP_') === 0) {
                $headers[substr($key, 5)] = $value;
            } elseif (in_array($key, array('CONTENT_LENGTH', 'CONTENT_MD5', 'CONTENT_TYPE'))) {
                $headers[$key] = $value;
            }
        }

        return $headers;
    }
534243
public function resolveTargets($name, array $parameters)
    {
        $definitionsGrouped = [[]];

        foreach ($parameters as $target => $params) {
            $definitionsGrouped[] = $this->resolveForTarget($name, $target, $params);
        }

        return array_merge(...$definitionsGrouped);
    }
883331
public function resolveClauses(array &$parameters)
    {
        $parameters = array_merge($parameters, $this->parameters);

        $filter = function($clause) use ($parameters) {
            $is_exist = true;
            
            if (preg_match_all('/@(?P<type>.):(?P<name>.+?)@/', $clause, $match) > 0) {
                foreach ($match['name'] as $name) {
                    if (!($is_exist = isset($parameters[$name]))) {
                        // all fields must be available
                        break;
                    }
                }
            }

            return $is_exist;
        };

        $clauses = [
            true => array_filter($this->clauses[true], $filter),
            false => array_filter($this->clauses[false], $filter)
        ];

        if (count($clauses[true]) > 0) {
            $snippet = $this->prefix . implode(
                $this->joiner,
                array_merge(
                    $clauses[false],
                    [
                        ' ( ' . implode(' OR ', $clauses[true]) . ' ) '
                    ]
                )
            ) . $this->postfix;
        } elseif (count($clauses[false]) > 0) {
            $snippet = $this->prefix . implode($this->joiner, $clauses[false]) . $this->postfix;
        } else {
            $snippet = '';
        }

        return $snippet;
    }
1355287
protected function resolveParameters($parameters)
    {
        $resolver = new OptionsResolver();

        $this->configureOptionResolver($resolver);

        try {
            return $resolver->resolve($parameters);
        } catch (OptionsResolverException\MissingOptionsException $e) {
            throw new SocialFeedException\MissingOptionsException($e->getMessage(), $e->getCode(), $e);
        }
    }
1271933
public static function parameters(array $parameters)
    {
        $args = array();
        foreach ($parameters as $param) {
            $arg = '';

            if ($param->isPassedByReference()) {
                $arg .= '&';
            }

            $arg .= '$' . $param->getName();

            if ($param->isOptional()) {
                $arg .= ' = ';

                switch (true) {
                    case null === $param->getDefaultValue():
                        $arg .= 'null';
                        break;
                    case is_array($param->getDefaultValue()):
                        $arg .= 'array()';
                        break;
                    case is_bool($param->getDefaultValue()):
                        $arg .= $param->getDefaultValue() ? 'true' : 'false';
                        break;
                    case is_int($param->getDefaultValue()):
                        $arg .= $param->getDefaultValue();
                        break;
                    default:
                        $arg .= '\'' . str_replace('\'', '\\\'', $param->getDefaultValue()) . '\'';
                        break;
                }
            }

            $args[] = $arg;
        }

        return $args;
    }
1365584
private function resolveParameters(?array $params = [], ?array $definitions = null) : array
    {
        $parameters = [];

        //method doesn't exist so there's no parameters
        if(!isset($params) || empty($params)) {
            return $parameters;
        }

        /** @var \ReflectionParameter $parameter */
        foreach($params as $parameter) {

            //handle definitions
            if(isset($definitions, $definitions[$parameter->name])
                && is_a($definitions[$parameter->name], Definition::class)) {

                /** @var Definition $definition */
                $definition = $definitions[$parameter->name];
                $parameters[] = $definition->getType() == Definition::CONTAINER
                    ? $this->container->get($definition->getValue()) : $definition->getValue();

            } elseif($parameter->isDefaultValueAvailable()) {
                $parameters[] = $parameter->getDefaultValue();
            } elseif($parameter->allowsNull() || $parameter->isOptional() || !$parameter->hasType()) {
                $parameters[] = null;
            } elseif($parameter->getClass() !== null) {

                $parameter_class = $parameter->getClass();
                $parameter_class_name = $parameter_class->getName();

                try {
                    $parameters[] = $this->container->get($parameter_class_name);
                } catch(\Exception $e) {
                    $parameters[] = null;
                }

            } elseif($parameter->isCallable()) {
                $parameters[] = function(){};
            } elseif($parameter->isArray()) {
                $parameters[] = [];
            } else {
                $parameters[] = $this->resolveDefaultType($parameter->getType());
            }
        }

        return $parameters;
    }
344195
static function resolveCallableWithArgs(callable $callable, $parameters)
    {
        if ($parameters instanceof \Traversable)
            $parameters = \Poirot\Std\cast($parameters)->toArray();


        $reflection       = self::makeReflectFromCallable($callable);
        $matchedArguments = self::resolveArgsForReflection($reflection, $parameters);

        if (!empty($parameters) && empty($matchedArguments))
            // In Case That Fun Has No Any Argument.
            // exp. func() { $args = func_get_args() ..
            $matchedArguments = $parameters;

        $callbackResolved = function() use ($callable, $matchedArguments) {
            return call_user_func_array($callable, $matchedArguments);
        };

        return $callbackResolved;
    }
898291
protected function resolveArguments(
        ReflectionMethod $method,
        array $arguments
    ) {
        $params = $method->getParameters();
        $result = [];

        foreach ($params as $param) {
            /** @var ReflectionParameter $param */
            if (isset($arguments[$param->name])) {
                $result[$param->name] = $arguments[$param->name];
                continue;
            }

            $class = $param->getClass();
            if ($class) {
                $className = $class->getName();
                if ($this->isShared($className)) {
                    $result[$className] = isset($this->sharedInstances[$className])
                        ? $this->sharedInstances[$className]
                        : $this->get($className);
                } else {
                    $result[$className] = $this->create($className);
                }
            }
        }

        return $result;
    }
1034121
protected function normalizeGroupParameters(array $parameters): array
    {
        $factoryWasGiven = array_key_exists(GroupInterface::PARAM_REQUEST_FACTORY, $parameters);

        return [
            $parameters[GroupInterface::PARAM_MIDDLEWARE_LIST] ?? [],
            $parameters[GroupInterface::PARAM_CONTAINER_CONFIGURATORS] ?? [],
            $factoryWasGiven,
            $parameters[GroupInterface::PARAM_REQUEST_FACTORY] ?? null,
            $parameters[GroupInterface::PARAM_NAME_PREFIX] ?? null,
        ];
    }
775637
protected function flattenParameters(array $parameters)
	{
		$flattened = array();

		foreach($parameters as $parameter) {
			array_walk($parameter, function($value, $key) use (&$flattened) {
				$flattened[$key] = $value;
			});
		}

		return $flattened;
	}
47200
protected function replaceDefaults(array $parameters)
    {
        foreach ($parameters as $key => &$value) {
            if (! isset($value)) {
                $value = Arr::get($this->defaults, $key);
            }
        }

        return $parameters;
    }
680693
public function resolver($definition, array $args = [])
    {
        if ($definition instanceof Closure) {
            $resolvedDefinition = call_user_func_array($definition, $args);
        } elseif (is_object($definition)) {
            $resolvedDefinition = $definition;
        } elseif (is_string($definition)) {
            if (class_exists($definition)) {
                $reflectionObj = new ReflectionClass($definition);
                $resolvedDefinition = $reflectionObj->newInstanceArgs($args);
            } else {
                throw new Exception(sprintf('Class "%s" does not exist.', $definition));
            }
        } elseif (is_array($definition)) {
            $resolvedDefinition = self::fromArray($definition);
        } else {
            throw new Exception(sprintf('Definition type "%s" does not support.', gettype($definition)));
        }

        return $resolvedDefinition;
    }
517680
protected function matchArguments(
        array $reflectionParameters,
        array $providedArguments
    )/*# : array */ {
        // result
        $resolvedArguments = [];
        foreach ($reflectionParameters as $i => $param) {
            $class = $param->getClass();

            if ($this->isTypeMatched($class, $providedArguments)) {
                $resolvedArguments[$i] = array_shift($providedArguments);
            } elseif ($this->isRequiredClass($param, $providedArguments)) {
                $resolvedArguments[$i] = $this->getObjectByClass($class->getName());
            }
        }
        return array_merge($resolvedArguments, $providedArguments);
    }
1134323
private function resolveFilterCriteria(array $parameters)
    {
        $baseCriteria = $this->buildBaseCriteria($parameters);
        $registeredCriteria = $this->buildRegisteredCriteria($parameters);
        $filterCriteria = $this->getFilterCriteria($parameters);

        if (null === $filterCriteria) {
            $filterCriteria = [];
        }

        if ($filterCriteria instanceof Criterion) {
            $filterCriteria = [$filterCriteria];
        }

        $criteria = array_merge($baseCriteria, $registeredCriteria, $filterCriteria);

        if (empty($criteria)) {
            return null;
        }

        if (1 === count($criteria)) {
            return $criteria[0];
        }

        return new LogicalAnd($criteria);
    }