Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/custom-service-listener' of https://github.com/…
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Jul 24, 2012
9 parents 4244857 + 163015b + aee1ae3 + 412f870 + 9b0f1d4 + e8236b3 + 3e482af + 84d85f9 + c45150b commit 7b83fea
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 10 deletions.
39 changes: 29 additions & 10 deletions src/Listener/ServiceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @package Zend_ModuleManager
* @subpackage Listener
*/
class ServiceListener implements ListenerAggregateInterface
class ServiceListener implements ListenerAggregateInterface, ServiceListenerInterface
{
/**
* @var bool
Expand Down Expand Up @@ -59,12 +59,28 @@ class ServiceListener implements ListenerAggregateInterface
public function __construct(ServiceManager $serviceManager, $configuration = null)
{
$this->defaultServiceManager = $serviceManager;
$this->defaultServiceConfig = $configuration;

if ($configuration !== null) {
$this->setDefaultServiceConfig($configuration);
}
}

/**
* @param array $configuration
* @return ServiceListener
*/
public function setDefaultServiceConfig($configuration)
{
$this->defaultServiceConfig = $configuration;

return $this;
}

/**
* @param string $key
* @param ServiceManager|string $serviceManager
* @param ServiceManager|string $serviceManager Service Manager instance or name
* @param string $key Configuration key
* @param string $moduleInterface FQCN as string
* @param string $method Method name
* @return ServiceListener
*/
public function addServiceManager($serviceManager, $key, $moduleInterface, $method)
Expand Down Expand Up @@ -123,10 +139,13 @@ public function detach(EventManagerInterface $events)
* Retrieve service manager configuration from module, and
* configure the service manager.
*
* If the module does not implement ServiceProviderInterface and does not
* implement the "getServiceConfig()" method, does nothing. Also,
* if the return value of that method is not a ServiceConfig object,
* or not an array or Traversable that can seed one, does nothing.
* If the module does not implement a specific interface and does not
* implement a specific method, does nothing. Also, if the return value
* of that method is not a ServiceConfig object, or not an array or
* Traversable that can seed one, does nothing.
*
* The interface and method name can be set by adding a new service manager
* via the addServiceManager() method.
*
* @param ModuleEvent $e
* @return void
Expand Down Expand Up @@ -161,8 +180,8 @@ public function onLoadModule(ModuleEvent $e)
// We're keeping track of which modules provided which configuration to which serivce managers.
// The actual merging takes place later. Doing it this way will enable us to provide more powerful
// debugging tools for showing which modules overrode what.
$this->serviceManagers[$key]['configuration'][$e->getModuleName() . '::' . $sm['module_class_method'] . '()'] = $config;
}
$fullname = $e->getModuleName() . '::' . $sm['module_class_method'] . '()';
$this->serviceManagers[$key]['configuration'][$fullname] = $config; }
}

/**
Expand Down
34 changes: 34 additions & 0 deletions src/Listener/ServiceListenerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_ModuleManager
*/

namespace Zend\ModuleManager\Listener;

/**
* @category Zend
* @package Zend_ModuleManager
* @subpackage Listener
*/
interface ServiceListenerInterface
{
/**
* @param ServiceManager|string $serviceManager Service Manager instance or name
* @param string $key Configuration key
* @param string $moduleInterface FQCN as string
* @param string $method Method name
* @return ServiceListenerInterface
*/
public function addServiceManager($serviceManager, $key, $moduleInterface, $method);

/**
* @param array $configuration
* @return ServiceListenerInterface
*/
public function setDefaultServiceConfig($configuration);
}

0 comments on commit 7b83fea

Please sign in to comment.