Skip to content

Commit

Permalink
Use adapter's addMessages method
Browse files Browse the repository at this point in the history
Instead of iterating through each message, we can call the
method addMessages of the adapter which can now be
overridden by each adapter as it inherits from AbstractAdapter.
  • Loading branch information
neverdane committed Jan 25, 2016
1 parent 373aa24 commit 248288a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
31 changes: 31 additions & 0 deletions src/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@

namespace ReputationVIP\QueueClient\Adapter;

use ReputationVIP\QueueClient\QueueClientInterface;

class AbstractAdapter
{

/**
* @param string $queueName
* @param array $messages
* @param string $priority
*
* @return QueueClientInterface
*/
public function addMessages($queueName, $messages, $priority = null)
{
foreach ($messages as $message) {
$this->addMessage($queueName, $message, $priority);
}

return $this;
}

/**
* @param string $queueName
* @param mixed $message
* @param string $priority
*
* @return AdapterInterface
*/
public function addMessage($queueName, $message, $priority = null)
{
return $this;
}

}
8 changes: 0 additions & 8 deletions src/Adapter/NullAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ public function __construct(PriorityHandlerInterface $priorityHandler = null)
$this->priorityHandler = $priorityHandler;
}

/**
* @inheritdoc
*/
public function addMessage($queueName, $message, $priority = null)
{
return $this;
}

/**
* @inheritdoc
*/
Expand Down
4 changes: 1 addition & 3 deletions src/QueueClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ public function addMessages($queueName, $messages, $priority = null)
$queues = (array) $this->resolveAliasQueueName($queueName);

foreach ($queues as $queue) {
foreach ($messages as $message) {
$this->adapter->addMessage($queue, $message, $priority);
}
$this->adapter->addMessages($queue, $messages, $priority);
}

return $this;
Expand Down

0 comments on commit 248288a

Please sign in to comment.