Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
 * ZF2 Integration for Whoops
 * @author Balázs Németh <zsilbi@zsilbi.hu>
 *
 * The Whoops directory should be added as a module to ZF2 (/vendor/Whoops)
 *
 * Whoops must be added as the first module
 * For example:
 *   'modules' => array(
 *       'Whoops',
 *       'Application',
 *   ),
 *
 * This file should be moved next to Whoops/Run.php (/vendor/Whoops/Module.php)
 *
 */

namespace Whoops;

use Whoops\Handler\JsonResponseHandler;
use Whoops\Handler\PrettyPageHandler;
use Whoops\Provider\Zend\ExceptionStrategy;
use Whoops\Provider\Zend\RouteNotFoundStrategy;
use Zend\Console\Request as ConsoleRequest;
use Zend\EventManager\EventInterface;

/**
 * @deprecated Use https://github.com/ghislainf/zf2-whoops
 */
class Module
{
    protected $run;

    public function onBootstrap(EventInterface $event)
    {
        $prettyPageHandler = new PrettyPageHandler();

        // Set editor
        $config = $event->getApplication()->getServiceManager()->get('Config');
        if (isset($config['view_manager']['editor'])) {
            $prettyPageHandler->setEditor($config['view_manager']['editor']);
        }

        $this->run = new Run();
        $this->run->register();
        $this->run->pushHandler($prettyPageHandler);

        $this->attachListeners($event);
    }

    public function getAutoloaderConfig()
    {
        return array(
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                ),
            ),
        );
    }

    private function attachListeners(EventInterface $event)
    {
        $request = $event->getRequest();
        $application = $event->getApplication();
        $services = $application->getServiceManager();
        $events = $application->getEventManager();
        $config = $services->get('Config');

        //Display exceptions based on configuration and console mode
        if ($request instanceof ConsoleRequest || empty($config['view_manager']['display_exceptions'])) {
            return;
        }

        $jsonHandler = new JsonResponseHandler();

        if (!empty($config['view_manager']['json_exceptions']['show_trace'])) {
            //Add trace to the JSON output
            $jsonHandler->addTraceToOutput(true);
        }

        if (!empty($config['view_manager']['json_exceptions']['ajax_only'])) {
            //Only return JSON response for AJAX requests
            $jsonHandler->onlyForAjaxRequests(true);
        }

        if (!empty($config['view_manager']['json_exceptions']['display'])) {
            //Turn on JSON handler
            $this->run->pushHandler($jsonHandler);
        }

        //Attach the Whoops ExceptionStrategy
        $exceptionStrategy = new ExceptionStrategy($this->run);
        $exceptionStrategy->attach($events);

        //Attach the Whoops RouteNotFoundStrategy
        $routeNotFoundStrategy = new RouteNotFoundStrategy($this->run);
        $routeNotFoundStrategy->attach($events);

        //Detach default ExceptionStrategy
        $services->get('Zend\Mvc\View\Http\ExceptionStrategy')->detach($events);

        //Detach default RouteNotFoundStrategy
        $services->get('Zend\Mvc\View\Http\RouteNotFoundStrategy')->detach($events);
    }
}

Commits for Nextrek/Aiba_backup/vendor/filp/whoops/src/deprecated/Zend/Module.php

Diff revisions: vs.
Revision Author Commited Message
1464 MOliva picture MOliva Tue 13 Oct, 2020 11:16:56 +0000