add() public method

The benefit of using the add function over using the queue as an array is that you are given back an index of the new item in the queue. This index allows you to remove it at a later stage if you choose.
See also: rcrowe\Hippy\Message\Queue::offsetSet()
public add ( rcrowe\Hippy\Message\MessageInterface $message ) : integer
$message rcrowe\Hippy\Message\MessageInterface
return integer Index of the new item in the queue.
Beispiel #1
0
 public function testQueuedMessages()
 {
     $entity = m::mock('Guzzle\\Http\\Message\\EntityEnclosingRequest');
     $entity->shouldReceive('send')->twice();
     $http = m::mock('Guzzle\\Http\\Client');
     $http->shouldReceive('post')->andReturn($entity)->twice();
     $transport = new Guzzle('123', 'cog', 'vivalacrowe');
     $transport->setHttp($http);
     $hippy = new Hippy($transport);
     $queue = new Queue();
     $queue->add(new Message(true, 'red'));
     $queue->add(new Message(false, 'random'));
     $hippy->send($queue);
 }
Beispiel #2
0
 /**
  * Add a html message to the queue.
  *
  * @param string $msg
  * @param bool   $notify
  * @param string $background
  * @throws RuntimeException When Facade::init() has not been called.
  * @return void
  */
 public static function addHtml($msg, $notify = false, $background = Message::BACKGROUND_YELLOW)
 {
     if (static::$client === null) {
         throw new RuntimeException('Must call init first');
     }
     $message = new Message($notify, $background);
     $message->setHtml($msg);
     static::$queue->add($message);
 }