Skip to content

Commit

Permalink
Binding options renamed for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Bakulin committed Nov 21, 2017
1 parent 011a00b commit 54b48c4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
12 changes: 6 additions & 6 deletions Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class Configuration extends Component
[
'exchange' => null,
'queue' => null,
'toExchange' => null,
'routingKeys' => [],
'to_exchange' => null,
'routing_keys' => [],
],
],
'producers' => [
Expand Down Expand Up @@ -287,11 +287,11 @@ protected function validateRequired()
if (!$this->isNameExist($this->exchanges, $binding['exchange'])) {
throw new InvalidConfigException("`{$binding['exchange']}` defined in binding doesn't configured in exchanges.");
}
if (isset($binding['routingKeys']) && !is_array($binding['routingKeys'])) {
throw new InvalidConfigException('Option `routingKeys` should be an array.');
if (isset($binding['routing_keys']) && !is_array($binding['routing_keys'])) {
throw new InvalidConfigException('Option `routing_keys` should be an array.');
}
if ((!isset($binding['queue']) && !isset($binding['toExchange'])) || isset($binding['queue'], $binding['toExchange'])) {
throw new InvalidConfigException('Either `queue` or `toExchange` options should be specified to create binding.');
if ((!isset($binding['queue']) && !isset($binding['to_exchange'])) || isset($binding['queue'], $binding['to_exchange'])) {
throw new InvalidConfigException('Either `queue` or `to_exchange` options should be specified to create binding.');
}
if (isset($binding['queue']) && !$this->isNameExist($this->queues, $binding['queue'])) {
throw new InvalidConfigException("`{$binding['queue']}` defined in binding doesn't configured in queues.");
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ return [
[
'queue' => 'YOUR_QUEUE_NAME',
'exchange' => 'YOUR_EXCHANGE_NAME',
'routingKeys' => ['YOUR_ROUTING_KEY'],
'routing_keys' => ['YOUR_ROUTING_KEY'],
],
],
'producers' => [
Expand Down Expand Up @@ -290,8 +290,8 @@ $rabbitmq_defaults = [
[
'exchange' => null,
'queue' => null,
'toExchange' => null,
'routingKeys' => [],
'to_exchange' => null,
'routing_keys' => [],
],
],
'producers' => [
Expand Down
12 changes: 6 additions & 6 deletions components/Routing.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ public function declareBindings()
*/
public function bindExchangeToQueue(array $binding)
{
if (isset($binding['routingKeys']) && count($binding['routingKeys']) > 0) {
foreach ($binding['routingKeys'] as $routingKey) {
if (isset($binding['routing_keys']) && count($binding['routing_keys']) > 0) {
foreach ($binding['routing_keys'] as $routingKey) {
// queue binding is not permitted on the default exchange
if ('' !== $binding['exchange']) {
$this->conn->channel()->queue_bind($binding['queue'], $binding['exchange'], $routingKey);
Expand All @@ -157,17 +157,17 @@ public function bindExchangeToQueue(array $binding)
*/
public function bindExchangeToExchange(array $binding)
{
if (isset($binding['routingKeys']) && count($binding['routingKeys']) > 0) {
foreach ($binding['routingKeys'] as $routingKey) {
if (isset($binding['routing_keys']) && count($binding['routing_keys']) > 0) {
foreach ($binding['routing_keys'] as $routingKey) {
// queue binding is not permitted on the default exchange
if ('' !== $binding['exchange']) {
$this->conn->channel()->exchange_bind($binding['toExchange'], $binding['exchange'], $routingKey);
$this->conn->channel()->exchange_bind($binding['to_exchange'], $binding['exchange'], $routingKey);
}
}
} else {
// queue binding is not permitted on the default exchange
if ('' !== $binding['exchange']) {
$this->conn->channel()->exchange_bind($binding['toExchange'], $binding['exchange']);
$this->conn->channel()->exchange_bind($binding['to_exchange'], $binding['exchange']);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public function invalidConfig()
['Queue wrong field', array_merge($required, ['queues' => [['wrong' => 'wrong']]]), InvalidConfigException::class],
['Exchange name is required for binding', array_merge($required, ['bindings' => [[]]]), InvalidConfigException::class],
['Routing key is required for binding', array_merge($required, ['bindings' => [['exchange' => 'smth']]]), InvalidConfigException::class],
['Either `queue` or `toExchange` options should be specified to create binding', array_merge($required, ['bindings' => [['exchange' => 'smth', 'routingKey' => 'smth',]]]), InvalidConfigException::class],
['Exchanges and queues should be configured in corresponding sections', array_merge($required, ['bindings' => [['exchange' => 'smth', 'routingKey' => 'smth', 'queue' => 'smth',]]]), InvalidConfigException::class],
['Either `queue` or `to_exchange` options should be specified to create binding', array_merge($required, ['bindings' => [['exchange' => 'smth', 'routing_keys' => ['smth'],]]]), InvalidConfigException::class],
['Exchanges and queues should be configured in corresponding sections', array_merge($required, ['bindings' => [['exchange' => 'smth', 'routing_keys' => ['smth'], 'queue' => 'smth',]]]), InvalidConfigException::class],
['Binding wrong field', array_merge($required, ['bindings' => [['wrong' => 'wrong']]]), InvalidConfigException::class],
['Producer wrong field', array_merge($required, ['producers' => [['wrong' => 'wrong']]]), InvalidConfigException::class],
['Producer name is required', array_merge($required, ['producers' => [[]]]), InvalidConfigException::class],
Expand Down
2 changes: 1 addition & 1 deletion tests/DependencyInjectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testBootstrap()
[
'queue' => $name,
'exchange' => $name,
'routingKeys' => [$name],
'routing_keys' => [$name],
],
],
'producers' => [
Expand Down
8 changes: 4 additions & 4 deletions tests/components/RoutingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ public function testRouting()
[
'queue' => $name,
'exchange' => $name,
'routingKeys' => [$name],
'routing_keys' => [$name],
],
[
'exchange' => $name,
'toExchange' => $name,
'routingKeys' => [$name],
'to_exchange' => $name,
'routing_keys' => [$name],
],
[
'queue' => $name,
'exchange' => $name,
],
[
'exchange' => $name,
'toExchange' => $name,
'to_exchange' => $name,
],
[
'queue' => '',
Expand Down

0 comments on commit 54b48c4

Please sign in to comment.