-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from prooph/develop
Merge v4.6 changes
- Loading branch information
Showing
13 changed files
with
218 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the prooph/service-bus. | ||
* (c) 2014-2015 prooph software GmbH <[email protected]> | ||
|
@@ -11,6 +12,9 @@ | |
|
||
namespace Prooph\ServiceBus\Container; | ||
|
||
use Interop\Config\ConfigurationTrait; | ||
use Interop\Config\RequiresContainerId; | ||
use Interop\Config\ProvidesDefaultOptions; | ||
use Interop\Container\ContainerInterface; | ||
use Prooph\Common\Messaging\MessageFactory; | ||
use Prooph\ServiceBus\Exception\RuntimeException; | ||
|
@@ -24,8 +28,10 @@ | |
* @package Prooph\ServiceBus\Container | ||
* @author Alexander Miertsch <[email protected]> | ||
*/ | ||
abstract class AbstractBusFactory | ||
abstract class AbstractBusFactory implements RequiresContainerId, ProvidesDefaultOptions | ||
{ | ||
use ConfigurationTrait; | ||
|
||
/** | ||
* Returns the FQCN of a bus extending Prooph\ServiceBus\MessageBus | ||
* | ||
|
@@ -34,29 +40,55 @@ abstract class AbstractBusFactory | |
abstract protected function getBusClass(); | ||
|
||
/** | ||
* Returns config key used within the prooph.service_bus config namespace to identify the bus. | ||
* Returns the default router class to use if no one was specified in the config | ||
* | ||
* @return string | ||
*/ | ||
abstract protected function getBusConfigKey(); | ||
abstract protected function getDefaultRouterClass(); | ||
|
||
/** | ||
* Returns the default router class to use if no one was specified in the config | ||
* | ||
* @return string | ||
* @inheritdoc | ||
*/ | ||
abstract protected function getDefaultRouterClass(); | ||
public function vendorName() | ||
{ | ||
return 'prooph'; | ||
} | ||
|
||
/** | ||
* Create service | ||
* @inheritdoc | ||
*/ | ||
public function packageName() | ||
{ | ||
return 'service_bus'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function defaultOptions() | ||
{ | ||
return [ | ||
'enable_handler_location' => true, | ||
'message_factory' => MessageFactory::class, | ||
]; | ||
} | ||
|
||
/** | ||
* Create service. | ||
* | ||
* @param ContainerInterface $container | ||
* @throws RuntimeException | ||
* @return MessageBus | ||
*/ | ||
public function __invoke(ContainerInterface $container) | ||
{ | ||
$busConfig = $this->getBusConfig($container); | ||
$config = []; | ||
|
||
if ($container->has('config')) { | ||
$config = $container->get('config'); | ||
} | ||
|
||
$busConfig = $this->optionsWithFallback($config); | ||
|
||
$busClass = $this->getBusClass(); | ||
|
||
|
@@ -70,58 +102,17 @@ public function __invoke(ContainerInterface $container) | |
$this->attachRouter($bus, $busConfig['router']); | ||
} | ||
|
||
if (!isset($busConfig['enable_handler_location']) || (bool)$busConfig['enable_handler_location']) { | ||
if ((bool) $busConfig['enable_handler_location']) { | ||
$bus->utilize(new ServiceLocatorPlugin($container)); | ||
} | ||
|
||
$messageFactoryServiceId = isset($busConfig['message_factory']) | ||
? $busConfig['message_factory'] | ||
: MessageFactory::class; | ||
|
||
if ($container->has($messageFactoryServiceId)) { | ||
$bus->utilize(new MessageFactoryPlugin($container->get($messageFactoryServiceId))); | ||
if ($container->has($busConfig['message_factory'])) { | ||
$bus->utilize(new MessageFactoryPlugin($container->get($busConfig['message_factory']))); | ||
} | ||
|
||
return $bus; | ||
} | ||
|
||
/** | ||
* @param ContainerInterface $container | ||
* @return array | ||
* @throws RuntimeException | ||
*/ | ||
private function getBusConfig(ContainerInterface $container) | ||
{ | ||
if (! $container->has('config')) { | ||
return []; | ||
} | ||
|
||
$config = $container->get('config'); | ||
|
||
if (!is_array($config) && !$config instanceof \ArrayAccess) { | ||
throw new RuntimeException(sprintf( | ||
'Application config registered in the container %s must be either of type array or implement \ArrayAccess. Otherwise it is not compatible with %s', | ||
get_class($container), | ||
get_called_class() | ||
)); | ||
} | ||
|
||
if (!isset($config['prooph']['service_bus'][$this->getBusConfigKey()])) { | ||
return []; | ||
} | ||
|
||
$busConfig = $config['prooph']['service_bus'][$this->getBusConfigKey()]; | ||
|
||
if (!is_array($busConfig) && !$busConfig instanceof \ArrayAccess) { | ||
throw new RuntimeException(sprintf( | ||
'Config prooph.service_bus.%s must either be of type array or implement \ArrayAccess.', | ||
$this->getBusConfigKey() | ||
)); | ||
} | ||
|
||
return $busConfig; | ||
} | ||
|
||
/** | ||
* @param MessageBus $bus | ||
* @param array $utils | ||
|
@@ -134,7 +125,7 @@ private function attachPlugins(MessageBus $bus, array &$utils, ContainerInterfac | |
if (! is_string($util) || ! $container->has($util)) { | ||
throw new RuntimeException(sprintf( | ||
'Wrong message bus utility configured at %s. Either it is not a string or unknown by the container.', | ||
'prooph.service_bus.' . $this->getBusConfigKey() . '.' . $index | ||
'prooph.service_bus.' . $this->containerId() . '.' . $index | ||
)); | ||
} | ||
|
||
|
@@ -148,9 +139,9 @@ private function attachPlugins(MessageBus $bus, array &$utils, ContainerInterfac | |
*/ | ||
private function attachRouter(MessageBus $bus, array &$routerConfig) | ||
{ | ||
$routerClass = isset($routerConfig['type'])? (string)$routerConfig['type'] : $this->getDefaultRouterClass(); | ||
$routerClass = isset($routerConfig['type']) ? (string)$routerConfig['type'] : $this->getDefaultRouterClass(); | ||
|
||
$routes = isset($routerConfig['routes'])? $routerConfig['routes'] : []; | ||
$routes = isset($routerConfig['routes']) ? $routerConfig['routes'] : []; | ||
|
||
$router = new $routerClass($routes); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the prooph/service-bus. | ||
* (c) 2014-2015 prooph software GmbH <[email protected]> | ||
|
@@ -22,21 +23,20 @@ | |
*/ | ||
class CommandBusFactory extends AbstractBusFactory | ||
{ | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getBusClass() | ||
public function containerId() | ||
{ | ||
return CommandBus::class; | ||
return 'command_bus'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getBusConfigKey() | ||
protected function getBusClass() | ||
{ | ||
return 'command_bus'; | ||
return CommandBus::class; | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the prooph/service-bus. | ||
* (c) 2014-2015 prooph software GmbH <[email protected]> | ||
|
@@ -22,21 +23,20 @@ | |
*/ | ||
class EventBusFactory extends AbstractBusFactory | ||
{ | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getBusClass() | ||
public function containerId() | ||
{ | ||
return EventBus::class; | ||
return 'event_bus'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getBusConfigKey() | ||
protected function getBusClass() | ||
{ | ||
return 'event_bus'; | ||
return EventBus::class; | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the prooph/service-bus. | ||
* (c) 2014-2015 prooph software GmbH <[email protected]> | ||
|
@@ -24,17 +25,17 @@ class QueryBusFactory extends AbstractBusFactory | |
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getBusClass() | ||
public function containerId() | ||
{ | ||
return QueryBus::class; | ||
return 'query_bus'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getBusConfigKey() | ||
protected function getBusClass() | ||
{ | ||
return 'query_bus'; | ||
return QueryBus::class; | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.