/**
  * Returns an array of CakeRequest objects. Performs various transformations on the request passed to the constructor,
  * so that the requests match the format expected by CakePHP.
  *
  * @return array Array with CakeRequest objects.
  */
 public function getRequests()
 {
     $requests = array();
     // If the request comes from $HTTP_RAW_POST_DATA it could be a batch request.
     if (strlen($this->rawPostData)) {
         $data = json_decode($this->rawPostData, true);
         // TODO: improve detection (not perfect, but should it should be correct in most cases.)
         if (isset($data['action']) || isset($data['method']) || isset($data['data'])) {
             $data = array($data);
         }
         $data = Set::sort($data, '{n}.tid', 'asc');
     } else {
         if (!empty($this->postData)) {
             // Form requests only contain one request.
             $data = array($this->postData);
         } else {
             // no data passed
             throw new BanchaException('Missing POST Data: The Bancha Dispatcher expected to get all requests in the Ext.Direct format as POST ' . 'parameter, but there is no data in this request. You can not access this site directly!');
         }
     }
     if (count($data) > 0) {
         for ($i = 0; $i < count($data); $i++) {
             $transformer = new BanchaRequestTransformer($data[$i]);
             // CakePHP should think that every Bancha request is a POST request.
             $_SERVER['REQUEST_METHOD'] = 'POST';
             // Create CakeRequest and fill it with values from the transformer.
             $requests[$i] = new CakeRequest($transformer->getUrl());
             // the CakeRequest uses the envirement variable $_POST in his
             // during the startup called _processPost() (currently line 153).
             // This is unclean and adds false data in our case. So delete this data.
             $requests[$i]->data = array();
             // now set params for the request
             $requests[$i]['controller'] = $transformer->getController();
             $requests[$i]['action'] = $transformer->getAction();
             $requests[$i]['named'] = $transformer->getPaging();
             $requests[$i]['plugin'] = null;
             // bancha-specific
             $requests[$i]['tid'] = $transformer->getTid();
             $requests[$i]['extUpload'] = $transformer->getExtUpload();
             $requests[$i]['client_id'] = $transformer->getClientId();
             $requests[$i]['isFormRequest'] = $transformer->isFormRequest();
             $requests[$i]['pass'] = $transformer->getPassParams();
             // additional property for cleaner controller syntax
             $requests[$i]['isBancha'] = true;
             // Handle all other parameters as POST parameters.
             foreach ($transformer->getCleanedDataArray() as $key => $value) {
                 $requests[$i]->data($key, $value);
             }
         }
     }
     return $requests;
 }
 /**
  * For remotable methods the parameter which need to be passed to the method are sent a little bit different than for
  * CRUD actions.
  */
 public function testGetPassParamsRemotable()
 {
     $input = array('data' => array('florian'), 'type' => 'rpc');
     $transformer = new BanchaRequestTransformer($input);
     $this->assertEquals(array('florian'), $transformer->getPassParams());
 }