6c02459dda5c16192f09d28e0bbbb838df31906d
[GitHub/Stricted/Domain-Control-Panel.git] / vendor / Zend / Mvc / Service / ConsoleExceptionStrategyFactory.php
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
4 *
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
8 */
9
10 namespace Zend\Mvc\Service;
11
12 use Interop\Container\ContainerInterface;
13 use Zend\Mvc\View\Console\ExceptionStrategy;
14 use Zend\ServiceManager\FactoryInterface;
15 use Zend\ServiceManager\ServiceLocatorInterface;
16
17 class ConsoleExceptionStrategyFactory implements FactoryInterface
18 {
19 use ConsoleViewManagerConfigTrait;
20
21 /**
22 * @param ContainerInterface $container
23 * @param string $name
24 * @param null|array $options
25 * @return ExceptionStrategy
26 */
27 public function __invoke(ContainerInterface $container, $name, array $options = null)
28 {
29 $strategy = new ExceptionStrategy();
30 $config = $this->getConfig($container);
31
32 $this->injectDisplayExceptions($strategy, $config);
33 $this->injectExceptionMessage($strategy, $config);
34
35 return $strategy;
36 }
37
38 /**
39 * Create and return ExceptionStrategy instance
40 *
41 * For use with zend-servicemanager v2; proxies to __invoke().
42 *
43 * @param ServiceLocatorInterface $container
44 * @return ExceptionStrategy
45 */
46 public function createService(ServiceLocatorInterface $container)
47 {
48 return $this($container, ExceptionStrategy::class);
49 }
50
51 /**
52 * Inject strategy with configured display_exceptions flag.
53 *
54 * @param ExceptionStrategy $strategy
55 * @param array $config
56 */
57 private function injectDisplayExceptions(ExceptionStrategy $strategy, array $config)
58 {
59 $flag = array_key_exists('display_exceptions', $config) ? $config['display_exceptions'] : true;
60 $strategy->setDisplayExceptions($flag);
61 }
62
63 /**
64 * Inject strategy with configured exception_message
65 *
66 * @param ExceptionStrategy $strategy
67 * @param array $config
68 */
69 private function injectExceptionMessage(ExceptionStrategy $strategy, array $config)
70 {
71 if (isset($config['exception_message'])) {
72 $strategy->setMessage($config['exception_message']);
73 }
74 }
75 }