laminas / laminas-mvc

Laminas's event-driven MVC layer, including MVC Applications, Controllers, and Plugins
https://docs.laminas.dev/laminas-mvc/
BSD 3-Clause "New" or "Revised" License
144 stars 53 forks source link

Class names for ServiceListenerFactory #23

Open weierophinney opened 4 years ago

weierophinney commented 4 years ago

I noticed that most services defined in the Zend\Mvc\Service\ServiceListenerFactory still use strings for the services names instead of class names.

https://github.com/zendframework/zend-mvc/blob/develop/src/Service/ServiceListenerFactory.php

It looks a little inconsequent in a factory when all services are requested by class names except the very important ViewHelperManager for example. Is there a chance to get this sorted?

Example:

namespace UserFrontend\Authorization;

use Interop\Container\ContainerInterface;
use UserModel\Permissions\UserAcl;
use Zend\Authentication\AuthenticationService;
use Zend\ServiceManager\Factory\FactoryInterface;
use Zend\View\Helper\Navigation;

class AuthorizationListenerFactory implements FactoryInterface
{
    public function __invoke(
        ContainerInterface $container,
        $requestedName,
        array $options = null
    ) {
        $viewHelperManager = $container->get('ViewHelperManager');

        $authService      = $container->get(AuthenticationService::class);
        $userAcl          = $container->get(UserAcl::class);
        $navigationHelper = $viewHelperManager->get(Navigation::class);

        $authorizationListener = new AuthorizationListener(
            $authService, $userAcl, $navigationHelper
        );

        return $authorizationListener;
    }
}

Originally posted by @RalfEggert at https://github.com/zendframework/zend-mvc/issues/186

weierophinney commented 4 years ago

See at #259

https://github.com/zendframework/zend-mvc/blob/bf93aa5e64e688a4f2bc7a50679c152bac289cae/src/ConfigProvider.php#L119


Originally posted by @froschdesign at https://github.com/zendframework/zend-mvc/issues/186#issuecomment-418307280