3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Mvc\Service
;
12 use Interop\Container\ContainerInterface
;
13 use Zend\Mvc\HttpMethodListener
;
14 use Zend\ServiceManager\FactoryInterface
;
15 use Zend\ServiceManager\ServiceLocatorInterface
;
17 class HttpMethodListenerFactory
implements FactoryInterface
21 * @return HttpMethodListener
23 public function __invoke(ContainerInterface
$container, $name, array $options = null)
25 $config = $container->get('config');
27 if (! isset($config['http_methods_listener'])) {
28 return new HttpMethodListener();
31 $listenerConfig = $config['http_methods_listener'];
32 $enabled = array_key_exists('enabled', $listenerConfig)
33 ?
$listenerConfig['enabled']
35 $allowedMethods = (isset($listenerConfig['allowed_methods']) && is_array($listenerConfig['allowed_methods']))
36 ?
$listenerConfig['allowed_methods']
39 return new HttpMethodListener($enabled, $allowedMethods);
43 * Create and return HttpMethodListener instance
45 * For use with zend-servicemanager v2; proxies to __invoke().
47 * @param ServiceLocatorInterface $container
48 * @return HttpMethodListener
50 public function createService(ServiceLocatorInterface
$container)
52 return $this($container, HttpMethodListener
::class);