Binding params of action method

@param ServerRequestInterface $request request object
@param mixed $handler handler
@param array $matches route params info
@return array
@throws \ReflectionException
511987
private function bindParams(ServerRequestInterface $request, $handler, array $matches): array
    {
        if (\is_array($handler)) {
            list($controller, $method) = $handler;
            $reflectMethod = new \ReflectionMethod($controller, $method);
            $reflectParams = $reflectMethod->getParameters();
        } else {
            $reflectMethod = new \ReflectionFunction($handler);
            $reflectParams = $reflectMethod->getParameters();
        }

        $bindParams = [];

        // Binding params
        foreach ($reflectParams as $key => $reflectParam) {
            $reflectType = $reflectParam->getType();
            $name        = $reflectParam->getName();

            // undefined type of the param
            if ($reflectType === null) {
                if (isset($matches[$name])) {
                    $bindParams[$key] = $matches[$name];
                } else {
                    $bindParams[$key] = null;
                }
                continue;
            }

            /**
             * Defined type of the param
             * @notice \ReflectType::getName() is not supported in PHP 7.0, that is why use __toString()
             */
            $type = $reflectType->__toString();
            if ($type === Request::class) {
                // Current Request Object
                $bindParams[$key] = $request;
            } elseif ($type === Response::class) {
                // Current Response Object
                $bindParams[$key] = RequestContext::getResponse();
            } elseif (isset($matches[$name])) {
                // Request parameters
                $bindParams[$key] = $this->parserParamType($type, $matches[$name]);
            } elseif (App::hasBean($type)) {
                // Bean
                $bindParams[$key] = App::getBean($type);
            } elseif (\class_exists($type)) {
                // Class
                $bindParams[$key] = $this->bindRequestParamsToClass($request, new \ReflectionClass($type));
            } else {
                $bindParams[$key] = $this->getDefaultValue($type);
            }
        }

        return $bindParams;
    }
1266885
protected function methodDispatcher($handler, $params)
    {
        /**
         *  call when pass closure as handler
         **/
        if (is_callable($handler)) {
            $resolving = $this->container->resolveCallback($handler, $params);

            $this->validateForm($resolving);

            return call_user_func_array($handler, $resolving);
        }

        /**
         * call when pass controller as handler
         **/
        list($controller, $method) = explode('@', $handler);

        return $this->invoke($controller, $method, $params);
    }
331786
private function getActionFromMatch($match = array())
    {
        $target = explode("#", $match["target"]);

        if (count($target) > 1) {
            return $target[1];
        }

        if (array_key_exists("action", $match["params"])) {
            return $this->getActionFromParam($match["params"]["action"]);
        }

        $this->controller->request = new Request();
        if (is_admin() && $this->controller->request->hasGet('page')) {
            return $this->controller->request->get('page');
            // When no method is sent, guesstimate from the action post value (ex: basic ajax)
        } elseif ($this->controller->request->hasPost('action')) {
            return $this->controller->request->post('action');
        }
    }
15640
private function mapQueryToActionParameters(RouteEndpoint $route, RequestInterface $request) : array
    {
        $reflection = new ReflectionClass($route->getFullyQualifiedName());
        $method = $reflection->getMethod($route->getAction(true));
        $query = $request->getQuery();

        $mapper = [];
        foreach ($method->getParameters() as $parameter) {
            $defaultValue = null;
            if ($parameter->isDefaultValueAvailable()) {
                $defaultValue = $parameter->getDefaultValue();
            }

            $value = $query->get($parameter->getName(), $defaultValue);

            // We are missing a required parameter, so this is a bad request
            if ($value === null && !$parameter->allowsNull()) {
                throw HttpException::badRequest();
            }

            $mapper[$parameter->getName()] = $value;
        }

        return $mapper;
    }
792365
public RouteMatcher all(String pattern, Handler<HttpServerRequest> handler) {
		addPattern(pattern, handler, getBindings);
		addPattern(pattern, handler, putBindings);
		addPattern(pattern, handler, postBindings);
		addPattern(pattern, handler, deleteBindings);
		addPattern(pattern, handler, optionsBindings);
		addPattern(pattern, handler, headBindings);
		addPattern(pattern, handler, traceBindings);
		addPattern(pattern, handler, connectBindings);
		addPattern(pattern, handler, patchBindings);
		return this;
	}
118523
private function validateField($request, array $matches, string $type, array $validatorAry)
    {
        $get = $request->getQueryParams();
        $post = $request->getParsedBody();
        $contentType = $request->getHeader('content-type');
        $isPostJson = false;

        if (isset($contentType[0]) && StringHelper::startsWith($contentType[0], 'application/json')) {
            $isPostJson = true;
            $post = $request->json();
        }

        foreach ($validatorAry as $name => $info) {
            $default = array_pop($info['params']);
            if ($type === ValidatorFrom::GET) {
                if (!isset($get[$name])) {
                    $request = $request->addQueryParam($name, $default);
                    $this->doValidation($name, $default, $info);
                    continue;
                }
                $this->doValidation($name, $get[$name], $info);

                continue;
            }
            if ($type === ValidatorFrom::POST && \is_array($post)) {
                if (! ArrayHelper::has($post, $name)) {
                    ArrayHelper::set($post, $name, $default);
                    if ($isPostJson) {
                        $request = $request->withBody(new SwooleStream(JsonHelper::encode($post)));
                    } else {
                        $request = $request->addParserBody($name, $default);
                    }

                    $this->doValidation($name, $default, $info);
                    continue;
                }
                $this->doValidation($name, ArrayHelper::get($post, $name), $info);
                continue;
            }
            if ($type === ValidatorFrom::PATH) {
                if (!isset($matches[$name])) {
                    continue;
                }
                $this->doValidation($name, $matches[$name], $info);
                continue;
            }
        }

        return $request;
    }
539976
public function get($request, $match)
    { // Set the default
        $model = $this->internalGet($request, $match);
        if (! isset($model)) {
            throw new Pluf_Exception_DoesNotExist('Setting not found');
        }
        return $model;
    }
292015
public static function get($request, $match)
    {
        $perm = Pluf_Shortcuts_GetObjectOr404('User_Role', $match['role_id']);
        $userModel = new User_Account();
        $param = array(
            'view' => 'join_role',
            'filter' => array(
                'id=' . $match['user_id'],
                'role_id=' . $perm->id
            )
        );
        $users = $userModel->getList($param);
        if ($users->count() == 0) {
            throw new Pluf_Exception_DoesNotExist('User has not such role');
        }
        return $users[0];
    }
1183570
public function match(ServerRequestInterface $request, $path)
	{
	    if(isset($this->properties['method'])) {
	        if(!in_array(strtolower($request->getMethod()), $this->properties['method']))
	            return array(
	                'route' => false,
                    'parameter' => false,
                    'continue' => false
                );
        }

        if(isset($this->properties['path'])) {
            $result = $this->matchPath($path);

            if(!$result['matched'])
                return array(
                    'route' =>false,
                    'parameter' => $result['parameter'],
                    'continue' => $result['continue']
                );

            if($this->properties['validators']) {
                $flag = $this->matchValidators($request, $path, $result['parameter']);

                if($flag === false)
                    return array(
                        'route' => false,
                        'parameter' => false,
                        'continue' => false
                    );
            }

            return array(
                'route' => $this,
                'parameter' => $result['parameter'],
                'continue' => $result['continue']
            );
        }

        return array(
            'route'=>false,
            'parameter'=> array(),
            'continue'=> false
        );
	}
200730
public function bindParameters(Request $request)
    {
        // If the route has a regular expression for the host part of the URI, we will
        // compile that and get the parameter matches for this domain. We will then
        // merge them into this parameters array so that this array is completed.
        $params = $this->matchToKeys(
            array_slice($this->bindPathParameters($request), 1)
        );

        // If the route has a regular expression for the host part of the URI, we will
        // compile that and get the parameter matches for this domain. We will then
        // merge them into this parameters array so that this array is completed.
        if (! is_null($this->compiled->getHostRegex())) {
            $params = $this->bindHostParameters($request, $params);
        }

        return $this->parameters = $this->replaceDefaults($params);
    }
309267
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        try {
            return $this->route($request, $handler);
        } catch (BadRequestException $e) {
            if ($this->http400Handler !== null) {
                return $this->http400Handler->badRequest($e, $request);
            } else {
                throw $e;
            }
        } catch (PageNotFoundException $e) {
            return $handler->handle($request);
        }
    }
350349
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        /* @var ValidatorInterface $validator */
        $serviceHandler = $request->getAttribute(RouterMiddleware::ATTRIBUTE);
        $serviceData    = $request->getAttribute(PackerMiddleware::ATTRIBUTE_DATA);
        $validator      = App::getBean(ServiceValidator::class);

        list($className, $validatorKey) = $serviceHandler;
        $collector = ValidatorCollector::getCollector();
        if (isset($collector[$className][$validatorKey]['validator'])) {
            $validators = $collector[$className][$validatorKey]['validator'];
            $validator->validate($validators, $serviceHandler, $serviceData);
        }

        return $handler->handle($request);
    }
313788
protected function createResult(Route $route, ServerRequestInterface $request, array $matches): Match
    {
        $attributes = $route->getAttributes();

        foreach ($attributes as $index => $attribute) {
            $name = $attribute->getName();

            if (array_key_exists($index, $matches)) {
                $request = $request->withAttribute($name, $matches[$index]);
            }
        }

        return new Match($route, $request);
    }
1286786
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $serviceHandler = $request->getAttribute(RouterMiddleware::ATTRIBUTE);
        list($className, $funcName) = $serviceHandler;

        $middlewares         = [];
        $collector           = MiddlewareCollector::getCollector();
        $middlewareCollector = $collector[$className]['middlewares']??[];
        $groupMiddlewares    = $middlewareCollector['group'] ?? [];
        $funcMiddlewares     = $middlewareCollector['actions'][$funcName]??[];
        $middlewares = array_merge($middlewares, $groupMiddlewares, $funcMiddlewares);
        if (!empty($middlewares) && $handler instanceof RequestHandler) {
            $handler->insertMiddlewares($middlewares);
        }

        return $handler->handle($request);
    }
86826
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $frontendController = $GLOBALS['TSFE'];
        if (!$frontendController->isGeneratePage() || !isset($request->getQueryParams()[self::argumentNamespace])) {
            return $handler->handle($request);
        }
        $this->ensureRequiredEnvironment();

        $frontendController->config['config']['disableAllHeaderCode'] = 1;
        $frontendController->pSetup = [
            '10' => 'TYPOSCRIPT_RENDERING',
            '10.' => [
                'request' => $request->getQueryParams()[self::argumentNamespace],
            ],
        ];

        return $handler->handle($request);
    }
444807
public final function match(ServerRequestInterface &$request): RouteInterface
   {
       foreach ($this->route as $value) {
           if ($this->matcher->match($request, $value)) {
               return $value;
           }
       }
       throw new RouterException(
           "Can't match "
         . $request->getMethod() . " "
         . $request->getUri()->getPath());
   }
441060
private function resolveControlerAction($matches, $parameters, $handler)
    {
        $controler = $handler['controler'];
        $action    = $handler['action'];
        $namespace = $this->resolveNamespace($parameters, $handler, $matches);

        if ($this->isPlaceholder($action)) {
            $transformed = $this->transformHandler($matches, $parameters, $handler);
            if ($this->isPlaceholder($controler)) {
                $controler = $namespace.'\\'.$transformed['controler'];
            } else {
                $controler = $namespace.'\\'.$controler;
            }

            return [
                $controler,
                $transformed['action']
            ];
        }

        return [
            $namespace.'\\'.$controler,
            $action
        ];
    }