private function bindRequestParamsToClass(ServerRequestInterface $request, \ReflectionClass $reflectClass)
    {
        try {
            $object = $reflectClass->newInstance();
            $queryParams = $request->getQueryParams();
            // Get request body, auto decode when content type is json format
            if (StringHelper::startsWith($request->getHeaderLine('Content-Type'), 'application/json')) {
                $requestBody = JsonHelper::decode($request->getBody()->getContents(), true);
            } else {
                $requestBody = $request->getParsedBody();
            }
            // Merge query params and request body
            $requestParams = array_merge($queryParams, $requestBody);
            // Binding request params to target object
            $properties = $reflectClass->getProperties();
            foreach ($properties as $property) {
                $name = $property->getName();
                if (!isset($requestParams[$name])) {
                    continue;
                }
                if (!$property->isPublic()) {
                    $property->setAccessible(true);
                }
                $property->setValue($object, $requestParams[$name]);
            }
        } catch (\Exception $e) {
            $object = null;
        }
        return $object;
    }
private function bindRequestParamsToClass(ServerRequestInterface $request, \ReflectionClass $reflectClass)
    {
        try {
            $object = $reflectClass->newInstance();
            $queryParams = $request->getQueryParams();
            // Get request body, auto decode when content type is json format
            if (StringHelper::startsWith($request->getHeaderLine('Content-Type'), 'application/json')) {
                $requestBody = JsonHelper::decode($request->getBody()->getContents(), true);
            } else {
                $requestBody = $request->getParsedBody();
            }
            // Merge query params and request body
            $requestParams = array_merge($queryParams, $requestBody);
            // Binding request params to target object
            $properties = $reflectClass->getProperties();
            foreach ($properties as $property) {
                $name = $property->getName();
                if (!isset($requestParams[$name])) {
                    continue;
                }
                if (!$property->isPublic()) {
                    $property->setAccessible(true);
                }
                $property->setValue($object, $requestParams[$name]);
            }
        } catch (\Exception $e) {
            $object = null;
        }
        return $object;
    }
private function bindRequestParamsToClass ( ServerRequestInterface $ request , \ ReflectionClass $ reflectClass ) { try { $ object = $ reflectClass -> newInstance ( ) ; $ queryParams = $ request -> getQueryParams ( ) ; // Get request body, auto decode when content type is json format if ( StringHelper :: startsWith ( $ request -> getHeaderLine ( 'Content-Type' ) , 'application/json' ) ) { $ requestBody = JsonHelper :: decode ( $ request -> getBody ( ) -> getContents ( ) , true ) ; } else { $ requestBody = $ request -> getParsedBody ( ) ; } // Merge query params and request body $ requestParams = array_merge ( $ queryParams , $ requestBody ) ; // Binding request params to target object $ properties = $ reflectClass -> getProperties ( ) ; foreach ( $ properties as $ property ) { $ name = $ property -> getName ( ) ; if ( ! isset ( $ requestParams [ $ name ] ) ) { continue ; } if ( ! $ property -> isPublic ( ) ) { $ property -> setAccessible ( true ) ; } $ property -> setValue ( $ object , $ requestParams [ $ name ] ) ; } } catch ( \ Exception $ e ) { $ object = null ; } return $ object ; }
Bind request parameters to instance of ReflectClass

@param ServerRequestInterface $request
@param \ReflectionClass $reflectClass
@return Object
Bind request parameters to instance of ReflectClass