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\Router\RouteStackInterface
;
14 use Zend\ServiceManager\FactoryInterface
;
15 use Zend\ServiceManager\ServiceLocatorInterface
;
17 class HttpRouterFactory
implements FactoryInterface
19 use RouterConfigTrait
;
22 * Create and return the HTTP router
24 * Retrieves the "router" key of the Config service, and uses it
25 * to instantiate the router. Uses the TreeRouteStack implementation by
28 * @param ContainerInterface $container
30 * @param null|array $options
31 * @return RouteStackInterface
33 public function __invoke(ContainerInterface
$container, $name, array $options = null)
35 $config = $container->has('config') ?
$container->get('config') : [];
38 $class = 'Zend\Mvc\Router\Http\TreeRouteStack';
39 $config = isset($config['router']) ?
$config['router'] : [];
41 return $this->createRouter($class, $config, $container);
45 * Create and return RouteStackInterface instance
47 * For use with zend-servicemanager v2; proxies to __invoke().
49 * @param ServiceLocatorInterface $container
50 * @return RouteStackInterface
52 public function createService(ServiceLocatorInterface
$container)
54 return $this($container, RouteStackInterface
::class);