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;
    }
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;
    }
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 ; }
Binding params of action method

@param ServerRequestInterface $request request object
@param mixed $handler handler
@param array $matches route params info
@return array
@throws \ReflectionException
Binding params of action method