public function index(HTTPRequest $request)
    {
        //check authentication if enabled
        if ($this->authenticator) {
            $policy = $this->config()->authentication_policy;
            $authALL = $policy === true;
            $authMethod = is_array($policy) && in_array($request->httpMethod(), $policy);

            if ($authALL || $authMethod) {
                $authResult = $this->authenticator->authenticate($request);

                if ($authResult instanceof RESTfulAPIError) {
                    //Authentication failed return error to client
                    return $this->error($authResult);
                }
            }
        }

        //pass control to query handler
        $data = $this->queryHandler->handleQuery($request);
        //catch + return errors
        if ($data instanceof RESTfulAPIError) {
            return $this->error($data);
        }

        //serialize response
        $json = $this->serializer->serialize($data);
        //catch + return errors
        if ($json instanceof RESTfulAPIError) {
            return $this->error($json);
        }

        //all is good reply normally
        return $this->answer($json);
    }
public function index(HTTPRequest $request)
    {
        //check authentication if enabled
        if ($this->authenticator) {
            $policy = $this->config()->authentication_policy;
            $authALL = $policy === true;
            $authMethod = is_array($policy) && in_array($request->httpMethod(), $policy);

            if ($authALL || $authMethod) {
                $authResult = $this->authenticator->authenticate($request);

                if ($authResult instanceof RESTfulAPIError) {
                    //Authentication failed return error to client
                    return $this->error($authResult);
                }
            }
        }

        //pass control to query handler
        $data = $this->queryHandler->handleQuery($request);
        //catch + return errors
        if ($data instanceof RESTfulAPIError) {
            return $this->error($data);
        }

        //serialize response
        $json = $this->serializer->serialize($data);
        //catch + return errors
        if ($json instanceof RESTfulAPIError) {
            return $this->error($json);
        }

        //all is good reply normally
        return $this->answer($json);
    }
public function index ( HTTPRequest $ request ) { //check authentication if enabled if ( $ this -> authenticator ) { $ policy = $ this -> config ( ) -> authentication_policy ; $ authALL = $ policy === true ; $ authMethod = is_array ( $ policy ) && in_array ( $ request -> httpMethod ( ) , $ policy ) ; if ( $ authALL || $ authMethod ) { $ authResult = $ this -> authenticator -> authenticate ( $ request ) ; if ( $ authResult instanceof RESTfulAPIError ) { //Authentication failed return error to client return $ this -> error ( $ authResult ) ; } } } //pass control to query handler $ data = $ this -> queryHandler -> handleQuery ( $ request ) ; //catch + return errors if ( $ data instanceof RESTfulAPIError ) { return $ this -> error ( $ data ) ; } //serialize response $ json = $ this -> serializer -> serialize ( $ data ) ; //catch + return errors if ( $ json instanceof RESTfulAPIError ) { return $ this -> error ( $ json ) ; } //all is good reply normally return $ this -> answer ( $ json ) ; }
Main API hub switch
All requests pass through here and are redirected depending on HTTP verb and params

@todo move authentication check to another methode

@param  HTTPRequest      $request    HTTP request
@return string                       json object of the models found
Main API hub switch All requests pass through here and are redirected depending on HTTP verb and params