Completed
Branch EDTR/master (2c3e96)
by
unknown
19:06 queued 09:20
created

Router   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 200
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 200
rs 10
c 0
b 0
f 0
wmc 17
lcom 1
cbo 3

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A loadPrimaryRoutes() 0 15 1
A registerShortcodesModulesAndWidgets() 0 12 3
A brewEspresso() 0 21 3
A loadControllers() 0 39 3
A coreLoadedAndReady() 0 15 3
A initializeLast() 0 12 3
1
<?php
2
3
namespace EventEspresso\core\services\routing;
4
5
use EE_Dependency_Map;
6
use EventEspresso\core\services\loaders\LoaderInterface;
7
use Exception;
8
9
/**
10
 * Class RoutingSwitch
11
 *
12
 * @package EventEspresso\core\services\routing
13
 * @since   $VID:$
14
 */
15
class Router
16
{
17
18
    /**
19
     * @var EE_Dependency_Map $dependency_map
20
     */
21
    protected $dependency_map;
22
23
    /**
24
     * @var LoaderInterface $loader
25
     */
26
    protected $loader;
27
28
    /**
29
     * @var RouteHandler $route_handler
30
     */
31
    protected $route_handler;
32
33
    /**
34
     * @var string $route_request_type
35
     */
36
    protected $route_request_type;
37
38
39
    /**
40
     * RoutingSwitch constructor.
41
     *
42
     * @param EE_Dependency_Map $dependency_map
43
     * @param LoaderInterface   $loader
44
     * @param RouteHandler      $router
45
     */
46
    public function __construct(EE_Dependency_Map $dependency_map, LoaderInterface $loader, RouteHandler $router)
47
    {
48
        $this->dependency_map = $dependency_map;
49
        $this->loader         = $loader;
50
        $this->route_handler  = $router;
51
    }
52
53
54
    /**
55
     * @throws Exception
56
     */
57
    public function loadPrimaryRoutes()
58
    {
59
        $this->dependency_map->registerDependencies(
60
            'EventEspresso\core\domain\entities\routing\handlers\admin\ActivationRequests',
61
            Route::getFullDependencies()
62
        );
63
        $this->dependency_map->registerDependencies(
64
            'EventEspresso\core\domain\entities\routing\handlers\shared\RegularRequests',
65
            Route::getFullDependencies()
66
        );
67
        // now load and prep all primary Routes
68
        $this->route_handler->addRoute('EventEspresso\core\domain\entities\routing\handlers\admin\ActivationRequests');
69
        $this->route_handler->addRoute('EventEspresso\core\domain\entities\routing\handlers\shared\RegularRequests');
70
        $this->route_request_type = $this->route_handler->getRouteRequestType();
71
    }
72
73
74
    /**
75
     *
76
     * @throws Exception
77
     */
78
    public function registerShortcodesModulesAndWidgets()
79
    {
80
        switch ($this->route_request_type) {
81
            case PrimaryRoute::ROUTE_REQUEST_TYPE_ACTIVATION:
82
                break;
83
            case PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR:
84
                $this->route_handler->addRoute(
85
                    'EventEspresso\core\domain\entities\routing\handlers\frontend\ShortcodeRequests'
86
                );
87
                break;
88
        }
89
    }
90
91
92
    /**
93
     *
94
     * @throws Exception
95
     * @throws Exception
96
     * @throws Exception
97
     * @throws Exception
98
     */
99
    public function brewEspresso()
100
    {
101
        switch ($this->route_request_type) {
102
            case PrimaryRoute::ROUTE_REQUEST_TYPE_ACTIVATION:
103
                $this->route_handler->addRoute(
104
                    'EventEspresso\core\domain\entities\routing\handlers\admin\PueRequests'
105
                );
106
                break;
107
            case PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR:
108
                $this->route_handler->addRoute(
109
                    'EventEspresso\core\domain\entities\routing\handlers\shared\GQLRequests'
110
                );
111
                $this->route_handler->addRoute(
112
                    'EventEspresso\core\domain\entities\routing\handlers\admin\PueRequests'
113
                );
114
                $this->route_handler->addRoute(
115
                    'EventEspresso\core\domain\entities\routing\handlers\shared\RestApiRequests'
116
                );
117
                break;
118
        }
119
    }
120
121
122
    /**
123
     *
124
     * @throws Exception
125
     * @throws Exception
126
     * @throws Exception
127
     * @throws Exception
128
     * @throws Exception
129
     * @throws Exception
130
     * @throws Exception
131
     * @throws Exception
132
     * @throws Exception
133
     * @throws Exception
134
     */
135
    public function loadControllers()
136
    {
137
        switch ($this->route_request_type) {
138
            case PrimaryRoute::ROUTE_REQUEST_TYPE_ACTIVATION:
139
                $this->route_handler->addRoute(
140
                    'EventEspresso\core\domain\entities\routing\handlers\admin\AdminRoute'
141
                );
142
                $this->route_handler->addRoute(
143
                    'EventEspresso\core\domain\entities\routing\handlers\admin\WordPressPluginsPage'
144
                );
145
                break;
146
            case PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR:
147
                $this->route_handler->addRoute(
148
                    'EventEspresso\core\domain\entities\routing\handlers\frontend\FrontendRequests'
149
                );
150
                $this->route_handler->addRoute(
151
                    'EventEspresso\core\domain\entities\routing\handlers\admin\AdminRoute'
152
                );
153
                $this->route_handler->addRoute(
154
                    'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoLegacyAdmin'
155
                );
156
                $this->route_handler->addRoute(
157
                    'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventsAdmin'
158
                );
159
                $this->route_handler->addRoute(
160
                    'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventEditor'
161
                );
162
                $this->route_handler->addRoute(
163
                    'EventEspresso\core\domain\entities\routing\handlers\admin\GutenbergEditor'
164
                );
165
                $this->route_handler->addRoute(
166
                    'EventEspresso\core\domain\entities\routing\handlers\admin\WordPressPluginsPage'
167
                );
168
                $this->route_handler->addRoute(
169
                    'EventEspresso\core\domain\entities\routing\handlers\shared\WordPressHeartbeat'
170
                );
171
                break;
172
        }
173
    }
174
175
176
    /**
177
     *
178
     * @throws Exception
179
     * @throws Exception
180
     */
181
    public function coreLoadedAndReady()
182
    {
183
        switch ($this->route_request_type) {
184
            case PrimaryRoute::ROUTE_REQUEST_TYPE_ACTIVATION:
185
                break;
186
            case PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR:
187
                $this->route_handler->addRoute(
188
                    'EventEspresso\core\domain\entities\routing\handlers\shared\AssetRequests'
189
                );
190
                $this->route_handler->addRoute(
191
                    'EventEspresso\core\domain\entities\routing\handlers\shared\SessionRequests'
192
                );
193
                break;
194
        }
195
    }
196
197
198
    /**
199
     *
200
     * @throws Exception
201
     */
202
    public function initializeLast()
203
    {
204
        switch ($this->route_request_type) {
205
            case PrimaryRoute::ROUTE_REQUEST_TYPE_ACTIVATION:
206
                break;
207
            case PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR:
208
                $this->route_handler->addRoute(
209
                    'EventEspresso\core\domain\entities\routing\handlers\admin\PersonalDataRequests'
210
                );
211
                break;
212
        }
213
    }
214
}
215