Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move un-/register new extensions to the config files #6

Closed
ghost opened this issue Jul 3, 2014 · 4 comments
Closed

Move un-/register new extensions to the config files #6

ghost opened this issue Jul 3, 2014 · 4 comments
Milestone

Comments

@ghost
Copy link

ghost commented Jul 3, 2014

It would be better, if the registering and unregistering of extensions could be achieved with the configuration, instead of using the onBootstrap() hook in every module.

Something like:

return [
    'ldc_user_profile' => [
        'registered_extensions' => [
            'MyModule\UserProfile\Extension' => true,
            'MyOtherModule\UserProfile\Extension' => false,
        ]
    ]
];

Please tell me, if you think this is good. I can try to make a PR for it, if you want to.

@adamlundrigan
Copy link
Owner

That's a very good idea. It should be as simple as adding the registered_extensions key to ModuleOptions and add some code to onBootstrap to pull the ProfileService instance from the SM and register the listed extensions.

My choice would be to use the SM name of the extension's main class (AbstractExtension), so the default set of registered extensions would look like this:

return [
    'ldc_user_profile' => [
        'registered_extensions' => [
            'ldc-user-profile_extension_zfcuser' => true,
        ]
    ]
];

And the onBootstrap code would look something like this:

$sm = $e->getApplication()->getServiceManager();
$extensions = $sm->get('ldc-user-profile_module_options')->getRegisteredExtensions();
$extensionService = $sm->get('ldc-user-profile_service');

foreach ( $extensions as $extension => $isEnabled ) {
    $objExt = $sm->get($extension);
    if ( ! $objExt instanceof AbstractExtension ) {
        continue;
    }
    $isEnabled ? $extensionService->registerExtension($objExt)
                       : $extensionService->unregisterExtension($objExt);
}

If you would like to send a PR for this you're more than welcome to :) If not I'll make some time to implement it in the next few days.

@ghost
Copy link
Author

ghost commented Jul 3, 2014

I will try to make a PR tomorrow, at least until tuesday. Thanks for being open to new ideas.

ghost pushed a commit to JanMalte/LdcUserProfile that referenced this issue Jul 4, 2014
@ghost
Copy link
Author

ghost commented Jul 4, 2014

I decided to move the register and unregister action to the factory. The onBootstrap method can then be removed and the process doesn't have to be done for each request. Instead it will only be executed, if the ProfileService is really needed.

@adamlundrigan
Copy link
Owner

Fixed in #8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant