Пример #1
0
 /**
  * Maps the supplied request with the appropiate method to run on this controller, for example
  * GET to doGET(), POST to doPOST() etc.  Returns the response generated by the method called.
  *
  * @param Alpha\Util\Http\Request $request
  *
  * @return Alpha\Util\Http\Response
  *
  * @since 2.0
  */
 public function process($request)
 {
     if (!$request instanceof Request) {
         throw new IllegalArguementException('The request passed to process is not a valid Request object');
     }
     $config = ConfigProvider::getInstance();
     $method = $request->getMethod();
     if (in_array($method, array('POST', 'PUT', 'PATCH'))) {
         if ($config->get('security.encrypt.http.fieldnames')) {
             $decryptedParams = $this->decryptFieldNames($request->getParams());
             $request->addParams($decryptedParams);
             if ($request->getParam('_METHOD') != null) {
                 $request->setMethod($request->getParam('_METHOD'));
                 $method = $request->getMethod();
             }
         }
     }
     $ProviderClassName = $config->get('app.renderer.provider.name');
     if ($ProviderClassName == 'auto' && $request->getAccept() != null) {
         View::setProvider('auto', $request->getAccept());
     }
     $this->request = $request;
     // check the current user's rights on access to the page controller
     if (!$this->checkRights()) {
         return $this->accessError();
     }
     switch ($method) {
         case 'HEAD':
             $response = $this->doHEAD($request);
             break;
         case 'GET':
             $response = $this->doGET($request);
             break;
         case 'POST':
             $response = $this->doPOST($request);
             break;
         case 'PUT':
             $response = $this->doPUT($request);
             break;
         case 'PATCH':
             $response = $this->doPATCH($request);
             break;
         case 'DELETE':
             $response = $this->doDELETE($request);
             break;
         case 'OPTIONS':
             $response = $this->doOPTIONS($request);
             break;
         case 'TRACE':
             $response = $this->doTRACE($request);
             break;
     }
     return $response;
 }
Пример #2
0
 /**
  * Testing that we can override the HTTP method via X-HTTP-Method-Override or _METHOD.
  */
 public function testHTTPMethodOverride()
 {
     $_POST['_METHOD'] = 'HEAD';
     $request = new Request();
     $this->assertEquals('HEAD', $request->getMethod(), 'Testing that we can override the HTTP method via _METHOD');
     $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'HEAD';
     $request = new Request();
     $this->assertEquals('HEAD', $request->getMethod(), 'Testing that we can override the HTTP method via X-HTTP-Method-Override');
 }