/**
  * Default implementation for handling an <b>\Phruts\Action\ActionError</b> generated
  * from an Exception during <b>Action</b> delegation.  The default
  * implementation is to set an attribute of the request or session, as
  * defined by the scope provided (the scope from the exception mapping).  An
  * <b>\Phruts\Action\ActionErrors</b> instance is created, the error is added to the collection
  * and the collection is set under the \Phruts\Util\Globals.ERROR_KEY.
  *
  * @param request - The request we are handling
  * @param property  - The property name to use for this error
  * @param error - The error generated from the exception mapping
  * @param forward - The forward generated from the input path (from the form or exception mapping)
  * @param scope - The scope of the exception mapping.
  */
 protected function storeException(\Symfony\Component\HttpFoundation\Request $request, $property, \Phruts\Action\ActionError $error, \Phruts\Config\ForwardConfig $forward, $scope)
 {
     $errors = new \Phruts\Action\ActionErrors();
     $errors->add($property, $error);
     if ($scope == "request") {
         $request->attributes->set(\Phruts\Util\Globals::ERROR_KEY, $errors);
     } else {
         $session = $request->getSession();
         if (!empty($session)) {
             $request->getSession()->set(\Phruts\Util\Globals::ERROR_KEY, $errors);
         }
     }
 }
Beispiel #2
0
 public function testGetErrors()
 {
     $getErrors = self::getMethod('getErrors');
     $errors = $getErrors->invokeArgs($this->action, array($this->request));
     $this->assertEquals(0, $errors->size());
     $errors = new \Phruts\Action\ActionErrors();
     $errors->add('key1', new \Phruts\Action\ActionError('error'));
     $errors->add('key2', new \Phruts\Action\ActionError('error'));
     $saveErrors = self::getMethod('saveErrors');
     $saveErrors->invokeArgs($this->action, array($this->request, $errors));
     $this->assertNotEmpty($this->request->attributes->get(\Phruts\Util\Globals::ERROR_KEY));
     $result = $getErrors->invokeArgs($this->action, array($this->request));
     $this->assertNotEmpty($result);
     $this->assertEquals(2, $result->size());
 }