Esempio n. 1
  * Dispatches a BanchaRequestCollection object. It uses the standard CakePHP dispatcher to dispatch the single
  * CakeRequest objects returned by BanchaRequest. Further it uses BanchaResponseCollection to transform the responses
  * into a single CakeResponse object. If the 'return' option in the $additionalParams argument is TRUE, the body of the
  * response is returned instead of directly sent to the browser.
  * @param BanchaRequestCollection $requests A BanchaRequestCollection can contain multiple CakeRequest objects.
  * @param array $additionalParams If 'return' is TRUE, the body is returned instead of sent to the browser.
  * @return string|void If 'return' is TRUE, the body is returned otherwise void is returned.
 public function dispatch(BanchaRequestCollection $requests, $additionalParams = array())
     $collection = new BanchaResponseCollection();
     // Iterate through all requests, dispatch them and add the response to the transformer object.
     foreach ($requests->getRequests() as $request) {
         $skip_request = false;
         if (!$skip_request) {
             // Call dispatcher for the given CakeRequest.
             // We need to use a sub classes disaptcher, because some parameters are missing in Bancha requests and
             // because we need to full response, not only the body of the response.
             $dispatcher = new BanchaSingleDispatcher();
             try {
                 // dispatch the request
                 $response = new CakeResponse(array('charset' => Configure::read('App.encoding')));
                 $dispatcher->dispatch($request, $response, array('return' => true));
                 // add result to response colection
                 $collection->addResponse($request['tid'], $response, $request);
             } catch (Exception $e) {
                 $collection->addException($request['tid'], $e, $request);
             // try catch
         // if (!$skip_request)
     // foreach
     // Combine the responses and return or output them.
     $responses = $collection->getResponses();
     if (isset($additionalParams['return']) && $additionalParams['return']) {
         return $responses->body();
  * Tests if the extUpload parameter is correctly passed through the CakeRequest.
 public function testGetExtUploadForm()
     $postData = array('extAction' => 'Test', 'extMethod' => 'submit', 'extTID' => 1, 'id' => 42, 'title' => 'Hello World', 'extUpload' => true);
     // Create a new request collection and parse the requests by calling getRequests().
     $collection = new BanchaRequestCollection('', $postData);
     $requests = $collection->getRequests();
     $this->assertEquals(true, $requests[0]['extUpload']);