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

RegularRequests::initialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 54
rs 9.0036
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace EventEspresso\core\domain\entities\routing\handlers\shared;
4
5
use EE_Dependency_Map;
6
use EventEspresso\core\services\routing\PrimaryRoute;
7
use EventEspresso\core\services\routing\Route;
8
use EventEspresso\core\services\routing\Router;
9
10
/**
11
 * Class RoutingRequests
12
 * registers dependencies for all other Routes as long as this is not an activation request
13
 *
14
 * @package EventEspresso\core\domain\entities\routing\handlers\shared
15
 * @author  Brent Christensen
16
 * @since   $VID:$
17
 */
18
class RegularRequests extends PrimaryRoute
19
{
20
21
    /**
22
     * called just before matchesCurrentRequest()
23
     * and allows Route to perform any setup required such as calling setSpecification()
24
     *
25
     * @since $VID:$
26
     */
27
    public function initialize()
28
    {
29
        $basic_nodes = [
30
            'EventEspresso\core\domain\entities\routing\data_nodes\core\Api',
31
            'EventEspresso\core\domain\entities\routing\data_nodes\core\CurrentUser',
32
            'EventEspresso\core\domain\entities\routing\data_nodes\core\GeneralSettings',
33
            'EventEspresso\core\domain\entities\routing\data_nodes\core\Locale',
34
            'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteUrls',
35
        ];
36
        foreach ($basic_nodes as $basic_node) {
37
            $this->dependency_map->registerDependencies(
38
                $basic_node,
39
                ['EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache]
40
            );
41
        }
42
        $this->dependency_map->registerDependencies(
43
            'EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData',
44
            [
45
                'EventEspresso\core\domain\entities\routing\data_nodes\core\Api'    => EE_Dependency_Map::load_from_cache,
46
                'EventEspresso\core\domain\entities\routing\data_nodes\core\Config' => EE_Dependency_Map::load_from_cache,
47
                'EventEspresso\core\services\assets\JedLocaleData'                  => EE_Dependency_Map::load_from_cache,
48
                'EventEspresso\core\services\json\JsonDataNodeValidator'            => EE_Dependency_Map::load_from_cache,
49
            ]
50
        );
51
        $this->dependency_map->registerDependencies(
52
            'EventEspresso\core\domain\entities\routing\data_nodes\core\Config',
53
            [
54
                'EventEspresso\core\domain\entities\routing\data_nodes\core\CurrentUser'        => EE_Dependency_Map::load_from_cache,
55
                'EventEspresso\core\domain\entities\routing\data_nodes\core\EspressoCoreDomain' => EE_Dependency_Map::load_from_cache,
56
                'EventEspresso\core\domain\entities\routing\data_nodes\core\GeneralSettings'    => EE_Dependency_Map::load_from_cache,
57
                'EventEspresso\core\domain\entities\routing\data_nodes\core\Locale'             => EE_Dependency_Map::load_from_cache,
58
                'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteCurrency'       => EE_Dependency_Map::load_from_cache,
59
                'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteUrls'           => EE_Dependency_Map::load_from_cache,
60
                'EventEspresso\core\services\json\JsonDataNodeValidator'                        => EE_Dependency_Map::load_from_cache,
61
            ]
62
        );
63
        $this->dependency_map->registerDependencies(
64
            'EventEspresso\core\domain\entities\routing\data_nodes\core\EspressoCoreDomain',
65
            [
66
                'EventEspresso\core\domain\Domain'                       => EE_Dependency_Map::load_from_cache,
67
                'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache,
68
            ]
69
        );
70
        $this->dependency_map->registerDependencies(
71
            'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteCurrency',
72
            [
73
                'EE_Currency_Config'                                     => EE_Dependency_Map::load_from_cache,
74
                'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache,
75
            ]
76
        );
77
        $this->setDataNode(
78
            $this->loader->getShared('EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData')
79
        );
80
    }
81
82
83
    /**
84
     * returns true if the current request matches this route
85
     *
86
     * @return bool
87
     * @since   $VID:$
88
     */
89
    public function matchesCurrentRequest()
90
    {
91
        return ! $this->request->isActivation() || $this->request->isUnitTesting();
92
    }
93
94
95
    /**
96
     * @since $VID:$
97
     */
98
    protected function registerDependencies()
99
    {
100
        $admin = ['EE_Admin_Config' => EE_Dependency_Map::load_from_cache] + Route::$default_dependencies;
101
        $public = ['EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache] + Route::$default_dependencies;
102
        $default_routes = [
103
            // default dependencies
104
            'EventEspresso\core\domain\entities\routing\handlers\admin\PueRequests'          => Route::$default_dependencies,
105
            'EventEspresso\core\domain\entities\routing\handlers\admin\WordPressPluginsPage' => Route::$default_dependencies,
106
            'EventEspresso\core\domain\entities\routing\handlers\frontend\ShortcodeRequests' => Route::$default_dependencies,
107
            'EventEspresso\core\domain\entities\routing\handlers\shared\AssetRequests'       => Route::$default_dependencies,
108
            'EventEspresso\core\domain\entities\routing\handlers\shared\GQLRequests'         => Route::$default_dependencies,
109
            'EventEspresso\core\domain\entities\routing\handlers\shared\RestApiRequests'     => Route::$default_dependencies,
110
            'EventEspresso\core\domain\entities\routing\handlers\shared\SessionRequests'     => Route::$default_dependencies,
111
            'EventEspresso\core\domain\entities\routing\handlers\shared\WordPressHeartbeat'  => Route::$default_dependencies,
112
            // admin dependencies
113
            'EventEspresso\core\domain\entities\routing\handlers\admin\AdminRoute'           => $admin,
114
            'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventsAdmin'  => $admin,
115
            'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventEditor'  => $admin,
116
            'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoLegacyAdmin'  => $admin,
117
            'EventEspresso\core\domain\entities\routing\handlers\admin\GutenbergEditor'  => $admin,
118
            // public dependencies
119
            'EventEspresso\core\domain\entities\routing\handlers\admin\PersonalDataRequests' => $public,
120
            'EventEspresso\core\domain\entities\routing\handlers\frontend\FrontendRequests'  => $public,
121
        ];
122
        foreach ($default_routes as $route => $dependencies) {
123
            $this->dependency_map->registerDependencies($route, $dependencies);
124
        }
125
    }
126
127
128
    /**
129
     * implements logic required to run during request
130
     *
131
     * @return bool
132
     * @since   $VID:$
133
     */
134
    protected function requestHandler()
135
    {
136
        $this->setRouteRequestType(PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR);
137
        return true;
138
    }
139
}
140