for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\NotificationBundle\Iterator;
use Interop\Amqp\AmqpConsumer;
use Interop\Amqp\AmqpMessage;
use Sonata\NotificationBundle\Model\Message;
class AMQPMessageIterator implements MessageIteratorInterface
{
/**
* @var mixed
protected $message;
* @var AmqpMessage
protected $AMQMessage;
* @var int
protected $counter;
protected $timeout;
* @var AmqpConsumer
protected $consumer;
* @var bool
protected $isValid;
* @param AmqpConsumer $consumer
public function __construct(AmqpConsumer $consumer)
$this->consumer = $consumer;
$this->counter = 0;
$this->timeout = 0;
$this->isValid = true;
}
* {@inheritdoc}
public function current()
return $this->message;
public function next()
if ($amqpMessage = $this->consumer->receive($this->timeout)) {
$this->AMQMessage = $amqpMessage;
$data = json_decode($this->AMQMessage->getBody(), true);
$data['body']['AMQMessage'] = $amqpMessage;
$message = new Message();
$message->setBody($data['body']);
$message->setType($data['type']);
$message->setState($data['state']);
$this->message = $message;
++$this->counter;
} else {
$this->isValid = false;
public function key()
$this->counter;
public function valid()
return $this->isValid;
public function rewind()