-
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
9 changed files
with
129 additions
and
23 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/Prooph/ServiceBus/Event/AbstractEventFactoryFactory.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,58 @@ | ||
<?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 - 23:00 | ||
*/ | ||
|
||
namespace Prooph\ServiceBus\Event; | ||
|
||
use Prooph\ServiceBus\Service\EventFactoryLoader; | ||
use Zend\ServiceManager\AbstractFactoryInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
/** | ||
* Class AbstractEventFactoryFactory | ||
* | ||
* @package Prooph\ServiceBus\Event | ||
* @author Alexander Miertsch <kontakt@codeliner.ws> | ||
*/ | ||
class AbstractEventFactoryFactory implements AbstractFactoryInterface | ||
{ | ||
protected $eventFactory; | ||
|
||
/** | ||
* 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) | ||
{ | ||
return $serviceLocator instanceof EventFactoryLoader; | ||
} | ||
|
||
/** | ||
* Create service with name | ||
* | ||
* @param ServiceLocatorInterface $serviceLocator | ||
* @param $name | ||
* @param $requestedName | ||
* @return mixed | ||
*/ | ||
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) | ||
{ | ||
if (is_null($this->eventFactory)) { | ||
$this->eventFactory = new EventFactory(); | ||
} | ||
|
||
return $this->eventFactory; | ||
} | ||
} | ||
|
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?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:58 | ||
*/ | ||
|
||
namespace Prooph\ServiceBus\Service; | ||
|
||
use Prooph\ServiceBus\Event\AbstractEventFactoryFactory; | ||
use Prooph\ServiceBus\Event\EventFactoryInterface; | ||
use Zend\ServiceManager\AbstractPluginManager; | ||
use Zend\ServiceManager\ConfigInterface; | ||
use Zend\ServiceManager\Exception; | ||
|
||
class EventFactoryLoader extends AbstractPluginManager | ||
{ | ||
/** | ||
* @param ConfigInterface $aConfig | ||
*/ | ||
public function __construct(ConfigInterface $aConfig = null) | ||
{ | ||
parent::__construct($aConfig); | ||
|
||
$this->abstractFactories[] = new AbstractEventFactoryFactory(); | ||
} | ||
|
||
/** | ||
* 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 EventFactoryInterface) { | ||
throw new Exception\RuntimeException(sprintf( | ||
'EventFactory must be instance of Prooph\ServiceBus\Event\EventFactoryInterface,' | ||
. '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