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\ExceptionStrategy
;
14 use Zend\ServiceManager\FactoryInterface
;
15 use Zend\ServiceManager\ServiceLocatorInterface
;
17 class HttpExceptionStrategyFactory
implements FactoryInterface
19 use HttpViewManagerConfigTrait
;
22 * @param ContainerInterface $container
24 * @param null|array $options
25 * @return ExceptionStrategy
27 public function __invoke(ContainerInterface
$container, $name, array $options = null)
29 $strategy = new ExceptionStrategy();
30 $config = $this->getConfig($container);
32 $this->injectDisplayExceptions($strategy, $config);
33 $this->injectExceptionTemplate($strategy, $config);
39 * Create and return ExceptionStrategy instance
41 * For use with zend-servicemanager v2; proxies to __invoke().
43 * @param ServiceLocatorInterface $container
44 * @return ExceptionStrategy
46 public function createService(ServiceLocatorInterface
$container)
48 return $this($container, ExceptionStrategy
::class);
52 * Inject strategy with configured display_exceptions flag.
54 * @param ExceptionStrategy $strategy
55 * @param array $config
57 private function injectDisplayExceptions(ExceptionStrategy
$strategy, array $config)
59 $flag = isset($config['display_exceptions']) ?
$config['display_exceptions'] : false;
60 $strategy->setDisplayExceptions($flag);
64 * Inject strategy with configured exception_template
66 * @param ExceptionStrategy $strategy
67 * @param array $config
69 private function injectExceptionTemplate(ExceptionStrategy
$strategy, array $config)
71 $template = isset($config['exception_template']) ?
$config['exception_template'] : 'error';
72 $strategy->setExceptionTemplate($template);