rcrowe\Hippy\Queue::add PHP Method

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.
    public function add(MessageInterface $message)
    {
        // Get the next index in the container that we can insert into
        if (count($this->container) > 0) {
            $keys = array_keys($this->container);
            $index = $keys[count($keys) - 1] + 1;
        } else {
            $index = 0;
        }
        $this->container[$index] = $message;
        return $index;
    }

Usage Example

Example #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);
 }
All Usage Examples Of rcrowe\Hippy\Queue::add