Ejemplo n.º 1
0
 /**
  * <p>Adds the messages from the given <code>\Phruts\Action\ActionMessages</code> object to
  * this set of messages. The messages are added in the order they are returned from
  * the <code>properties</code> method. If a message's property is already in the current
  * <code>\Phruts\Action\ActionMessages</code> object, it is added to the end of the list for that
  * property. If a message's property is not in the current list it is added to the end
  * of the properties.</p>
  *
  * @param \Phruts\Action\ActionMessages messages The <code>\Phruts\Action\ActionMessages</code> object to
  * be added.  This parameter can be <code>null</code>.
  * @since Struts 1.1
  */
 public function addMessages(\Phruts\Action\ActionMessages $messages)
 {
     // loop over properties
     $properties = $messages->properties();
     foreach ($properties as $property) {
         // loop over messages for each property
         $msgs = $messages->get($property);
         foreach ($msgs as $message) {
             $this->add($property, $message);
         }
     }
 }
Ejemplo n.º 2
0
 public function testCollection()
 {
     $this->assertEquals(0, $this->actionMessages->size());
     $this->assertTrue($this->actionMessages->isEmpty());
     $actionMessage = new ActionMessage('key');
     $this->actionMessages->add('property', $actionMessage);
     $this->assertEquals(1, $this->actionMessages->size());
     $actionMessage2 = new ActionMessage('key');
     $this->actionMessages->add('property', $actionMessage2);
     $this->assertEquals(2, $this->actionMessages->size());
     $this->assertFalse($this->actionMessages->isEmpty());
     $actionMessage3 = new ActionMessage('key');
     $this->actionMessages->add('property2', $actionMessage3);
     $this->assertEquals(1, $this->actionMessages->size('property2'));
     $this->actionMessages->add('property', $actionMessage3);
     $this->assertEquals(3, $this->actionMessages->size('property'));
     $actionMessages = new ActionMessages();
     $actionMessage4 = new ActionMessage('defg');
     $actionMessage5 = new ActionMessage('asdf');
     $actionMessages->add('property', $actionMessage4);
     $actionMessages->add('property2', $actionMessage5);
     $this->actionMessages->addMessages($actionMessages);
     $this->assertEquals(2, $this->actionMessages->size('property2'));
     $this->assertEquals(4, $this->actionMessages->size('property'));
     $this->assertEquals(6, $this->actionMessages->size());
     $this->assertEquals(array('property', 'property2'), $this->actionMessages->properties());
     $this->assertFalse($this->actionMessages->isAccessed());
     $this->assertEquals(0, count($this->actionMessages->get('property3')));
     $this->assertTrue($this->actionMessages->isAccessed());
     $this->assertEquals(6, count($this->actionMessages->get()));
     $this->assertEquals(2, count($this->actionMessages->get('property2')));
     $this->assertEquals(0, count($this->actionMessages->get('property3')));
     $this->actionMessages->clear();
     $this->assertEquals(0, $this->getSize());
     $this->assertTrue($this->actionMessages->isEmpty());
     $actionMessages2 = new ActionMessages();
     $this->assertEquals(0, count($actionMessages2->get()));
     $this->assertEquals(0, $actionMessages2->size('property3'));
 }
Ejemplo n.º 3
0
 /**
  * <p>Save the specified messages keys into the appropriate session
  * attribute for use by the &lt;html:messages&gt; tag (if
  * messages="true" is set), if any messages are required. Otherwise,
  * ensure that the session attribute is not created.</p>
  *
  * @param \Symfony\Component\HttpFoundation\Session\Session session The session to save the messages in.
  * @param \Phruts\Action\ActionMessages messages The messages to save. <code>null</code> or
  * empty messages removes any existing \Phruts\Action\ActionMessages in the session.
  *
  * @since Struts 1.2
  */
 protected function saveMessagesSession(Session $session, ActionMessages $messages = null)
 {
     // Remove any messages attribute if none are required
     if ($messages == null || $messages->isEmpty()) {
         $session->remove(\Phruts\Util\Globals::MESSAGE_KEY);
         return;
     }
     // Save the messages we need
     $session->set(\Phruts\Util\Globals::MESSAGE_KEY, $messages);
 }