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\View\Http\RouteNotFoundStrategy
;
14 use Zend\ServiceManager\FactoryInterface
;
15 use Zend\ServiceManager\ServiceLocatorInterface
;
17 class HttpRouteNotFoundStrategyFactory
implements FactoryInterface
19 use HttpViewManagerConfigTrait
;
22 * @param ContainerInterface $container
24 * @param null|array $options
25 * @return RouteNotFoundStrategy
27 public function __invoke(ContainerInterface
$container, $name, array $options = null)
29 $strategy = new RouteNotFoundStrategy();
30 $config = $this->getConfig($container);
32 $this->injectDisplayExceptions($strategy, $config);
33 $this->injectDisplayNotFoundReason($strategy, $config);
34 $this->injectNotFoundTemplate($strategy, $config);
40 * Create and return RouteNotFoundStrategy instance
42 * For use with zend-servicemanager v2; proxies to __invoke().
44 * @param ServiceLocatorInterface $container
45 * @return RouteNotFoundStrategy
47 public function createService(ServiceLocatorInterface
$container)
49 return $this($container, RouteNotFoundStrategy
::class);
53 * Inject strategy with configured display_exceptions flag.
55 * @param RouteNotFoundStrategy $strategy
56 * @param array $config
58 private function injectDisplayExceptions(RouteNotFoundStrategy
$strategy, array $config)
60 $flag = isset($config['display_exceptions']) ?
$config['display_exceptions'] : false;
61 $strategy->setDisplayExceptions($flag);
65 * Inject strategy with configured display_not_found_reason flag.
67 * @param RouteNotFoundStrategy $strategy
68 * @param array $config
70 private function injectDisplayNotFoundReason(RouteNotFoundStrategy
$strategy, array $config)
72 $flag = isset($config['display_not_found_reason']) ?
$config['display_not_found_reason'] : false;
73 $strategy->setDisplayNotFoundReason($flag);
77 * Inject strategy with configured not_found_template.
79 * @param RouteNotFoundStrategy $strategy
80 * @param array $config
82 private function injectNotFoundTemplate(RouteNotFoundStrategy
$strategy, array $config)
84 $template = isset($config['not_found_template']) ?
$config['not_found_template'] : '404';
85 $strategy->setNotFoundTemplate($template);