-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
143 additions
and
35 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/Prooph/ServiceBus/Command/AbstractCommandFactoryFactory.php
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/* | ||
* This file is part of the prooph/service-bus. | ||
* (c) Alexander Miertsch <contact@prooph.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* Date: 05.07.14 - 22:51 | ||
*/ | ||
|
||
namespace Prooph\ServiceBus\Command; | ||
|
||
use Prooph\ServiceBus\Service\CommandFactoryLoader; | ||
use Zend\ServiceManager\AbstractFactoryInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
/** | ||
* Class AbstractCommandFactoryFactory | ||
* | ||
* @package Prooph\ServiceBus\Command | ||
* @author Alexander Miertsch <kontakt@codeliner.ws> | ||
*/ | ||
class AbstractCommandFactoryFactory implements AbstractFactoryInterface | ||
{ | ||
protected $commandFactory; | ||
|
||
/** | ||
* Determine if we can create a service with name | ||
* | ||
* @param ServiceLocatorInterface $serviceLocator | ||
* @param $name | ||
* @param $requestedName | ||
* @return bool | ||
*/ | ||
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) | ||
{ | ||
if ($serviceLocator instanceof CommandFactoryLoader) { | ||
return true; | ||
} | ||
} | ||
|
||
/** | ||
* Create service with name | ||
* | ||
* @param ServiceLocatorInterface $serviceLocator | ||
* @param $name | ||
* @param $requestedName | ||
* @return mixed | ||
*/ | ||
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) | ||
{ | ||
if (is_null($this->commandFactory)) { | ||
$this->commandFactory = new CommandFactory(); | ||
} | ||
return $this->commandFactory; | ||
} | ||
} | ||
|
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/* | ||
* This file is part of the prooph/service-bus. | ||
* (c) Alexander Miertsch <contact@prooph.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* Date: 05.07.14 - 22:30 | ||
*/ | ||
|
||
namespace Prooph\ServiceBus\Service; | ||
|
||
use Prooph\ServiceBus\Command\AbstractCommandFactoryFactory; | ||
use Prooph\ServiceBus\Command\CommandFactoryInterface; | ||
use Zend\ServiceManager\AbstractPluginManager; | ||
use Zend\ServiceManager\ConfigInterface; | ||
use Zend\ServiceManager\Exception; | ||
|
||
/** | ||
* Class CommandFactoryLoader | ||
* | ||
* @package Prooph\ServiceBus\Service | ||
* @author Alexander Miertsch <kontakt@codeliner.ws> | ||
*/ | ||
class CommandFactoryLoader extends AbstractPluginManager | ||
{ | ||
/** | ||
* @param ConfigInterface $aConfig | ||
*/ | ||
public function __construct(ConfigInterface $aConfig = null) | ||
{ | ||
parent::__construct($aConfig); | ||
|
||
$this->abstractFactories[] = new AbstractCommandFactoryFactory(); | ||
} | ||
|
||
/** | ||
* Validate the plugin | ||
* | ||
* Checks that the filter loaded is either a valid callback or an instance | ||
* of FilterInterface. | ||
* | ||
* @param mixed $plugin | ||
* @throws Exception\RuntimeException | ||
* @return void | ||
*/ | ||
public function validatePlugin($plugin) | ||
{ | ||
if (! $plugin instanceof CommandFactoryInterface) { | ||
throw new Exception\RuntimeException(sprintf( | ||
'CommandFactory must be instance of Prooph\ServiceBus\Command\CommandFactoryInterface,' | ||
. 'instance of type %s given', | ||
((is_object($plugin)? get_class($plugin) : gettype($plugin))) | ||
)); | ||
} | ||
} | ||
} | ||
|
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
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