Skip to content

Commit

Permalink
moved un-/register new extensions to the config files adamlundrigan#6
Browse files Browse the repository at this point in the history
  • Loading branch information
Malte Gerth committed Jul 4, 2014
1 parent 76a15ca commit 9e027c3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
7 changes: 0 additions & 7 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@

class Module implements AutoloaderProviderInterface
{
public function onBootstrap(MvcEvent $e)
{
$sm = $e->getApplication()->getServiceManager();
$sm->get('ldc-user-profile_service')->registerExtension(
$sm->get('ldc-user-profile_extension_zfcuser')
);
}

public function getAutoloaderConfig()
{
Expand Down
8 changes: 8 additions & 0 deletions config/ldc-user-profile.global.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ $settings = array(
*/
'validation_group_override' => array(),

/**
* Register extensions by adding them with their service manager key and
* TRUE as value. Unregister an extension by setting the value to FALSE.
*/
'registered_extensions' => array(
'ldc-user-profile_extension_zfcuser' => true,
)

);

/**
Expand Down
19 changes: 19 additions & 0 deletions src/LdcUserProfile/Options/ModuleOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ class ModuleOptions extends AbstractOptions
*/
protected $validationGroupOverrides = array();

/**
* Registered extensions
*
* @var array
*/
protected $registeredExtensions = array();

public function getIsEnabled()
{
return $this->isEnabled;
Expand Down Expand Up @@ -76,4 +83,16 @@ public function setValidationGroupOverrides(array $vg)
return $this;
}

public function getRegisteredExtensions()
{
return $this->registeredExtensions;
}

public function setRegisteredExtensions($registeredExtensions)
{
$this->registeredExtensions = $registeredExtensions;

return $this;
}

}
26 changes: 25 additions & 1 deletion src/LdcUserProfile/Service/ProfileServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace LdcUserProfile\Service;

use LdcUserProfile\Extensions\AbstractExtension;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

Expand All @@ -20,8 +21,31 @@ class ProfileServiceFactory implements FactoryInterface
public function createService(ServiceLocatorInterface $serviceLocator)
{
$service = new ProfileService();
$service->setModuleOptions($serviceLocator->get('ldc-user-profile_module_options'));

// Get the module options
$moduleOptions = $serviceLocator->get('ldc-user-profile_module_options');
$service->setModuleOptions($moduleOptions);

// Register/Unregister the active/inactive extensions
foreach ($moduleOptions->getRegisteredExtensions() as $extensionName => $isActive) {
if ($isActive) {
$this->registerExtension($extensionName, $service, $serviceLocator);
} else {
$service->unregisterExtension($extensionName);
}
}

return $service;
}

protected function registerExtension(
$extensionName,
ProfileService $service,
ServiceLocatorInterface $serviceLocator
) {
$extension = $serviceLocator->get($extensionName);
if ($extension instanceof AbstractExtension) {
$service->registerExtension($extension);
}
}
}

0 comments on commit 9e027c3

Please sign in to comment.