-
Notifications
You must be signed in to change notification settings - Fork 0
/
eea-router.php
148 lines (135 loc) · 4.57 KB
/
eea-router.php
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/*
Plugin Name: Espresso Router
Plugin URI: https://eventespresso.com
Description: Espresso Router - is a configuration based router for WordPress plugins, that connects
Controllers with Views, using a completely decoupled system that promotes reusability.
Version: 1.0.1.rc.002
Author: Event Espresso
Author URI: https://eventespresso.com
Copyright 2015 Event Espresso (email : [email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA02110-1301USA
*
* ------------------------------------------------------------------------
*
* Event Espresso
*
* Event Registration and Management Plugin for WordPress
*
* @ package Event Espresso
* @ author Event Espresso
* @ copyright (c) 2008-2015 Event Espresso All Rights Reserved.
* @ license https://eventespresso.com/support/terms-conditions/ * see Plugin Licensing *
* @ link https://eventespresso.com
* @ version EE4
*
* ------------------------------------------------------------------------
*/
use EspressoRouter\application\entities\routes\ExampleRouteConfig;
use EspressoRouter\application\services\routers\Router;
use EventEspresso\core\exceptions\ExceptionStackTraceDisplay;
use EventEspresso\core\services\container\CoffeeMaker;
use EventEspresso\core\services\container\CoffeeShop;
/*
* ************** IMPORTANT **************
*
* There are two minor changes that need to happen in core
* before you can use the following examples/demonstrations.
* These issues would be corrected before merging this to core.
*
* 1) in EE_Load_Espresso_Core::handle_request() around line 84
* change:
* // $CoffeeShop = $OpenCoffeeShop->CoffeeShop();
* to
* global $CoffeeShop;
* $CoffeeShop = $OpenCoffeeShop->CoffeeShop();
*
* 2) in EE_Request::__construct() around line 78
* change:
* $this->_get = (array)$get;
* to
* $this->_get = ! empty($get) ? (array)$get : $_GET;
*/
define('EE_ROUTER_BASE_PATH', plugin_dir_path(__FILE__));
add_action(
'AHEE__EE_System__construct__begin',
function() {
EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EspressoRouter', EE_ROUTER_BASE_PATH);
}
);
add_action(
'AHEE__EE_System__load_controllers__start',
function() {
global /** @var CoffeeShop $CoffeeShop */
$CoffeeShop;
if (!$CoffeeShop instanceof CoffeeShop) {
return;
}
try {
/** @var Router $router */
$router = $CoffeeShop->brew(
'EspressoRouter\application\services\routers\Router',
array(
$CoffeeShop,
$CoffeeShop->brew('EE_Request'),
),
CoffeeMaker::BREW_SHARED
);
/** @var ExampleRouteConfig $route_config */
$route_config = $CoffeeShop->brew(
'\EspressoRouter\application\entities\routes\ExampleRouteConfig'
);
$route_config->addRoutes();
$router->dispatch();
} catch (Exception $exception) {
new ExceptionStackTraceDisplay($exception);
}
}
);
add_filter(
'the_content',
function($the_content){
if (has_action('AHEE__Router__before_the_content')){
ob_start();
do_action('AHEE__Router__before_the_content');
return ob_get_clean() . $the_content;
}
return $the_content;
},
999
);
add_filter(
'the_content',
function($the_content){
if (has_action('AHEE__Router__replace_the_content')) {
ob_start();
do_action('AHEE__Router__replace_the_content');
return ob_get_clean();
}
return $the_content;
},
999
);
add_filter(
'the_content',
function($the_content){
if (has_action('AHEE__Router__after_the_content')) {
ob_start();
do_action('AHEE__Router__after_the_content');
return $the_content . ob_get_clean();
}
return $the_content;
},
999
);
// End of file: eea-router.php
// Location: eea-router.php