Completed
Branch BUG/pantheon-session-fatal-2 (dc6a1f)
by
unknown
199:51 queued 131:59
created
core/services/request/LegacyRequestInterface.php 1 patch
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -15,125 +15,125 @@
 block discarded – undo
15 15
 interface LegacyRequestInterface
16 16
 {
17 17
 
18
-    /**
19
-     * @return array
20
-     */
21
-    public function get_params();
18
+	/**
19
+	 * @return array
20
+	 */
21
+	public function get_params();
22 22
 
23 23
 
24
-    /**
25
-     * @return array
26
-     */
27
-    public function post_params();
24
+	/**
25
+	 * @return array
26
+	 */
27
+	public function post_params();
28 28
 
29 29
 
30
-    /**
31
-     * @return array
32
-     */
33
-    public function cookie_params();
30
+	/**
31
+	 * @return array
32
+	 */
33
+	public function cookie_params();
34 34
 
35 35
 
36
-    /**
37
-     * @return array
38
-     */
39
-    public function server_params();
36
+	/**
37
+	 * @return array
38
+	 */
39
+	public function server_params();
40 40
 
41 41
 
42
-    /**
43
-     * returns contents of $_REQUEST
44
-     *
45
-     * @return array
46
-     */
47
-    public function params();
42
+	/**
43
+	 * returns contents of $_REQUEST
44
+	 *
45
+	 * @return array
46
+	 */
47
+	public function params();
48 48
 
49 49
 
50
-    /**
51
-     * @param      $key
52
-     * @param      $value
53
-     * @param bool $override_ee
54
-     * @return    void
55
-     */
56
-    public function set($key, $value, $override_ee = false);
50
+	/**
51
+	 * @param      $key
52
+	 * @param      $value
53
+	 * @param bool $override_ee
54
+	 * @return    void
55
+	 */
56
+	public function set($key, $value, $override_ee = false);
57 57
 
58 58
 
59
-    /**
60
-     * returns   the value for a request param if the given key exists
61
-     *
62
-     * @param       $key
63
-     * @param null  $default
64
-     * @return mixed
65
-     */
66
-    public function get($key, $default = null);
59
+	/**
60
+	 * returns   the value for a request param if the given key exists
61
+	 *
62
+	 * @param       $key
63
+	 * @param null  $default
64
+	 * @return mixed
65
+	 */
66
+	public function get($key, $default = null);
67 67
 
68 68
 
69
-    /**
70
-     * check if param exists
71
-     *
72
-     * @param       $key
73
-     * @return bool
74
-     */
75
-    public function is_set($key);
69
+	/**
70
+	 * check if param exists
71
+	 *
72
+	 * @param       $key
73
+	 * @return bool
74
+	 */
75
+	public function is_set($key);
76 76
 
77 77
 
78
-    /**
79
-     * remove param
80
-     *
81
-     * @param      $key
82
-     * @param bool $unset_from_global_too
83
-     */
84
-    public function un_set($key, $unset_from_global_too = false);
78
+	/**
79
+	 * remove param
80
+	 *
81
+	 * @param      $key
82
+	 * @param bool $unset_from_global_too
83
+	 */
84
+	public function un_set($key, $unset_from_global_too = false);
85 85
 
86 86
 
87
-    /**
88
-     * @return string
89
-     */
90
-    public function ip_address();
87
+	/**
88
+	 * @return string
89
+	 */
90
+	public function ip_address();
91 91
 
92 92
 
93
-    /**
94
-     * @return bool
95
-     */
96
-    public function isAdmin();
93
+	/**
94
+	 * @return bool
95
+	 */
96
+	public function isAdmin();
97 97
 
98 98
 
99
-    /**
100
-     * @return mixed
101
-     */
102
-    public function isAjax();
99
+	/**
100
+	 * @return mixed
101
+	 */
102
+	public function isAjax();
103 103
 
104 104
 
105
-    /**
106
-     * @return mixed
107
-     */
108
-    public function isFrontAjax();
105
+	/**
106
+	 * @return mixed
107
+	 */
108
+	public function isFrontAjax();
109 109
 
110 110
 
111
-    /**
112
-     * @return mixed|string
113
-     */
114
-    public function requestUri();
111
+	/**
112
+	 * @return mixed|string
113
+	 */
114
+	public function requestUri();
115 115
 
116 116
 
117
-    /**
118
-     * @return string
119
-     */
120
-    public function userAgent();
117
+	/**
118
+	 * @return string
119
+	 */
120
+	public function userAgent();
121 121
 
122 122
 
123
-    /**
124
-     * @param string $user_agent
125
-     */
126
-    public function setUserAgent($user_agent = '');
123
+	/**
124
+	 * @param string $user_agent
125
+	 */
126
+	public function setUserAgent($user_agent = '');
127 127
 
128 128
 
129
-    /**
130
-     * @return bool
131
-     */
132
-    public function isBot();
129
+	/**
130
+	 * @return bool
131
+	 */
132
+	public function isBot();
133 133
 
134 134
 
135
-    /**
136
-     * @param bool $is_bot
137
-     */
138
-    public function setIsBot($is_bot);
135
+	/**
136
+	 * @param bool $is_bot
137
+	 */
138
+	public function setIsBot($is_bot);
139 139
 }
Please login to merge, or discard this patch.
core/services/request/Response.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
      */
59 59
     public function setNotice($key, $value)
60 60
     {
61
-        $this->notice[ $key ] = $value;
61
+        $this->notice[$key] = $value;
62 62
     }
63 63
 
64 64
 
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      */
70 70
     public function getNotice($key)
71 71
     {
72
-        return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null;
72
+        return isset($this->notice[$key]) ? $this->notice[$key] : null;
73 73
     }
74 74
 
75 75
 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
      */
91 91
     public function addOutput($string, $append = true)
92 92
     {
93
-        $this->output = $append ? $this->output . $string : $string . $this->output;
93
+        $this->output = $append ? $this->output.$string : $string.$this->output;
94 94
     }
95 95
 
96 96
 
Please login to merge, or discard this patch.
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -16,119 +16,119 @@
 block discarded – undo
16 16
 class Response implements ResponseInterface, ReservedInstanceInterface
17 17
 {
18 18
 
19
-    /**
20
-     * @var array $notice
21
-     */
22
-    protected $notice = array();
23
-
24
-    /**
25
-     * rendered output to be returned to WP
26
-     *
27
-     * @var string $output
28
-     */
29
-    protected $output = '';
30
-
31
-    /**
32
-     * @var bool
33
-     */
34
-    protected $request_terminated = false;
35
-
36
-    /**
37
-     * @var bool $deactivate_plugin
38
-     */
39
-    protected $deactivate_plugin = false;
40
-
41
-
42
-    /**
43
-     * EE_Response constructor.
44
-     */
45
-    public function __construct()
46
-    {
47
-        $this->terminateRequest(false);
48
-    }
49
-
50
-
51
-    /**
52
-     * @param $key
53
-     * @param $value
54
-     * @return    void
55
-     */
56
-    public function setNotice($key, $value)
57
-    {
58
-        $this->notice[ $key ] = $value;
59
-    }
60
-
61
-
62
-    /**
63
-     * @param $key
64
-     * @return    mixed
65
-     */
66
-    public function getNotice($key)
67
-    {
68
-        return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null;
69
-    }
70
-
71
-
72
-    /**
73
-     * @return array
74
-     */
75
-    public function getNotices()
76
-    {
77
-        return $this->notice;
78
-    }
79
-
80
-
81
-    /**
82
-     * @param string $string
83
-     * @param bool   $append
84
-     */
85
-    public function addOutput($string, $append = true)
86
-    {
87
-        $this->output = $append ? $this->output . $string : $string . $this->output;
88
-    }
89
-
90
-
91
-    /**
92
-     * @return string
93
-     */
94
-    public function getOutput()
95
-    {
96
-        return $this->output;
97
-    }
98
-
99
-
100
-    /**
101
-     * @return boolean
102
-     */
103
-    public function requestTerminated()
104
-    {
105
-        return $this->request_terminated;
106
-    }
107
-
108
-
109
-    /**
110
-     * @param boolean $request_terminated
111
-     */
112
-    public function terminateRequest($request_terminated = true)
113
-    {
114
-        $this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN);
115
-    }
116
-
117
-
118
-    /**
119
-     * @return boolean
120
-     */
121
-    public function pluginDeactivated()
122
-    {
123
-        return $this->deactivate_plugin;
124
-    }
125
-
126
-
127
-    /**
128
-     * sets $deactivate_plugin to true
129
-     */
130
-    public function deactivatePlugin()
131
-    {
132
-        $this->deactivate_plugin = true;
133
-    }
19
+	/**
20
+	 * @var array $notice
21
+	 */
22
+	protected $notice = array();
23
+
24
+	/**
25
+	 * rendered output to be returned to WP
26
+	 *
27
+	 * @var string $output
28
+	 */
29
+	protected $output = '';
30
+
31
+	/**
32
+	 * @var bool
33
+	 */
34
+	protected $request_terminated = false;
35
+
36
+	/**
37
+	 * @var bool $deactivate_plugin
38
+	 */
39
+	protected $deactivate_plugin = false;
40
+
41
+
42
+	/**
43
+	 * EE_Response constructor.
44
+	 */
45
+	public function __construct()
46
+	{
47
+		$this->terminateRequest(false);
48
+	}
49
+
50
+
51
+	/**
52
+	 * @param $key
53
+	 * @param $value
54
+	 * @return    void
55
+	 */
56
+	public function setNotice($key, $value)
57
+	{
58
+		$this->notice[ $key ] = $value;
59
+	}
60
+
61
+
62
+	/**
63
+	 * @param $key
64
+	 * @return    mixed
65
+	 */
66
+	public function getNotice($key)
67
+	{
68
+		return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null;
69
+	}
70
+
71
+
72
+	/**
73
+	 * @return array
74
+	 */
75
+	public function getNotices()
76
+	{
77
+		return $this->notice;
78
+	}
79
+
80
+
81
+	/**
82
+	 * @param string $string
83
+	 * @param bool   $append
84
+	 */
85
+	public function addOutput($string, $append = true)
86
+	{
87
+		$this->output = $append ? $this->output . $string : $string . $this->output;
88
+	}
89
+
90
+
91
+	/**
92
+	 * @return string
93
+	 */
94
+	public function getOutput()
95
+	{
96
+		return $this->output;
97
+	}
98
+
99
+
100
+	/**
101
+	 * @return boolean
102
+	 */
103
+	public function requestTerminated()
104
+	{
105
+		return $this->request_terminated;
106
+	}
107
+
108
+
109
+	/**
110
+	 * @param boolean $request_terminated
111
+	 */
112
+	public function terminateRequest($request_terminated = true)
113
+	{
114
+		$this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN);
115
+	}
116
+
117
+
118
+	/**
119
+	 * @return boolean
120
+	 */
121
+	public function pluginDeactivated()
122
+	{
123
+		return $this->deactivate_plugin;
124
+	}
125
+
126
+
127
+	/**
128
+	 * sets $deactivate_plugin to true
129
+	 */
130
+	public function deactivatePlugin()
131
+	{
132
+		$this->deactivate_plugin = true;
133
+	}
134 134
 }
Please login to merge, or discard this patch.
core/services/request/middleware/PreProductionVersionWarning.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@
 block discarded – undo
78 78
     public function preProductionVersionAdminNotice()
79 79
     {
80 80
         new PersistentAdminNotice(
81
-            'preProductionVersionAdminNotice_' . EVENT_ESPRESSO_VERSION,
81
+            'preProductionVersionAdminNotice_'.EVENT_ESPRESSO_VERSION,
82 82
             $this->warningNotice()
83 83
         );
84 84
     }
Please login to merge, or discard this patch.
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -18,91 +18,91 @@
 block discarded – undo
18 18
 class PreProductionVersionWarning extends Middleware
19 19
 {
20 20
 
21
-    /**
22
-     * converts a Request to a Response
23
-     *
24
-     * @param RequestInterface  $request
25
-     * @param ResponseInterface $response
26
-     * @return ResponseInterface
27
-     */
28
-    public function handleRequest(RequestInterface $request, ResponseInterface $response)
29
-    {
30
-        $this->request = $request;
31
-        $this->response = $response;
32
-        $this->displayPreProductionVersionWarning();
33
-        $this->response = $this->processRequestStack($this->request, $this->response);
34
-        return $this->response;
35
-    }
21
+	/**
22
+	 * converts a Request to a Response
23
+	 *
24
+	 * @param RequestInterface  $request
25
+	 * @param ResponseInterface $response
26
+	 * @return ResponseInterface
27
+	 */
28
+	public function handleRequest(RequestInterface $request, ResponseInterface $response)
29
+	{
30
+		$this->request = $request;
31
+		$this->response = $response;
32
+		$this->displayPreProductionVersionWarning();
33
+		$this->response = $this->processRequestStack($this->request, $this->response);
34
+		return $this->response;
35
+	}
36 36
 
37 37
 
38
-    /**
39
-     * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode
40
-     *
41
-     * @return void
42
-     */
43
-    public function displayPreProductionVersionWarning()
44
-    {
45
-        // skip AJAX requests
46
-        if ($this->request->isAjax()) {
47
-            return;
48
-        }
49
-        // skip stable releases
50
-        if (substr(EVENT_ESPRESSO_VERSION, -5) !== '.beta') {
51
-            return;
52
-        }
53
-        // site admin has authorized use of non-stable release candidate for production
54
-        if (defined('ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE') && ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE) {
55
-            return;
56
-        }
57
-        // post release candidate warning
58
-        if ($this->request->isAdmin()) {
59
-            add_action('admin_notices', array($this, 'preProductionVersionAdminNotice'), -999);
60
-        } else {
61
-            add_action('shutdown', array($this, 'preProductionVersionWarningNotice'), 10);
62
-        }
63
-    }
38
+	/**
39
+	 * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode
40
+	 *
41
+	 * @return void
42
+	 */
43
+	public function displayPreProductionVersionWarning()
44
+	{
45
+		// skip AJAX requests
46
+		if ($this->request->isAjax()) {
47
+			return;
48
+		}
49
+		// skip stable releases
50
+		if (substr(EVENT_ESPRESSO_VERSION, -5) !== '.beta') {
51
+			return;
52
+		}
53
+		// site admin has authorized use of non-stable release candidate for production
54
+		if (defined('ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE') && ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE) {
55
+			return;
56
+		}
57
+		// post release candidate warning
58
+		if ($this->request->isAdmin()) {
59
+			add_action('admin_notices', array($this, 'preProductionVersionAdminNotice'), -999);
60
+		} else {
61
+			add_action('shutdown', array($this, 'preProductionVersionWarningNotice'), 10);
62
+		}
63
+	}
64 64
 
65 65
 
66
-    /**
67
-     * displays admin notice that current version of EE is not a stable release
68
-     *
69
-     * @return void
70
-     * @throws InvalidDataTypeException
71
-     */
72
-    public function preProductionVersionAdminNotice()
73
-    {
74
-        new PersistentAdminNotice(
75
-            'preProductionVersionAdminNotice_' . EVENT_ESPRESSO_VERSION,
76
-            $this->warningNotice()
77
-        );
78
-    }
66
+	/**
67
+	 * displays admin notice that current version of EE is not a stable release
68
+	 *
69
+	 * @return void
70
+	 * @throws InvalidDataTypeException
71
+	 */
72
+	public function preProductionVersionAdminNotice()
73
+	{
74
+		new PersistentAdminNotice(
75
+			'preProductionVersionAdminNotice_' . EVENT_ESPRESSO_VERSION,
76
+			$this->warningNotice()
77
+		);
78
+	}
79 79
 
80 80
 
81
-    /**
82
-     * displays message on frontend of site notifying admin that current version of EE is not a stable release
83
-     *
84
-     * @return void
85
-     */
86
-    public function preProductionVersionWarningNotice()
87
-    {
88
-        echo '<div id="ee-release-candidate-notice-dv" class="ee-really-important-notice-dv"><p>';
89
-        echo $this->warningNotice();
90
-        echo '</p></div>';
91
-    }
81
+	/**
82
+	 * displays message on frontend of site notifying admin that current version of EE is not a stable release
83
+	 *
84
+	 * @return void
85
+	 */
86
+	public function preProductionVersionWarningNotice()
87
+	{
88
+		echo '<div id="ee-release-candidate-notice-dv" class="ee-really-important-notice-dv"><p>';
89
+		echo $this->warningNotice();
90
+		echo '</p></div>';
91
+	}
92 92
 
93 93
 
94
-    /**
95
-     * @return string
96
-     */
97
-    private function warningNotice()
98
-    {
99
-        return sprintf(
100
-            esc_html__(
101
-                'This version of Event Espresso is for testing and/or evaluation purposes only. It is %1$snot%2$s considered a stable release and should therefore %1$snot%2$s be activated on a live or production website.',
102
-                'event_espresso'
103
-            ),
104
-            '<strong>',
105
-            '</strong>'
106
-        );
107
-    }
94
+	/**
95
+	 * @return string
96
+	 */
97
+	private function warningNotice()
98
+	{
99
+		return sprintf(
100
+			esc_html__(
101
+				'This version of Event Espresso is for testing and/or evaluation purposes only. It is %1$snot%2$s considered a stable release and should therefore %1$snot%2$s be activated on a live or production website.',
102
+				'event_espresso'
103
+			),
104
+			'<strong>',
105
+			'</strong>'
106
+		);
107
+	}
108 108
 }
Please login to merge, or discard this patch.
core/services/bootstrap/BootstrapRequestResponseObjects.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@
 block discarded – undo
83 83
     {
84 84
         espresso_load_required(
85 85
             'EE_Request',
86
-            EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
86
+            EE_CORE.'request_stack'.DS.'EE_Request.core.php'
87 87
         );
88 88
         $this->legacy_request = new EE_Request($_GET, $_POST, $_COOKIE, $_SERVER);
89 89
         $this->legacy_request->setRequest($this->request);
Please login to merge, or discard this patch.
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -25,80 +25,80 @@
 block discarded – undo
25 25
 class BootstrapRequestResponseObjects
26 26
 {
27 27
 
28
-    /**
29
-     * @type LegacyRequestInterface $legacy_request
30
-     */
31
-    protected $legacy_request;
28
+	/**
29
+	 * @type LegacyRequestInterface $legacy_request
30
+	 */
31
+	protected $legacy_request;
32 32
 
33
-    /**
34
-     * @type LoaderInterface $loader
35
-     */
36
-    protected $loader;
33
+	/**
34
+	 * @type LoaderInterface $loader
35
+	 */
36
+	protected $loader;
37 37
 
38
-    /**
39
-     * @var RequestInterface $request
40
-     */
41
-    protected $request;
38
+	/**
39
+	 * @var RequestInterface $request
40
+	 */
41
+	protected $request;
42 42
 
43
-    /**
44
-     * @var ResponseInterface $response
45
-     */
46
-    protected $response;
43
+	/**
44
+	 * @var ResponseInterface $response
45
+	 */
46
+	protected $response;
47 47
 
48 48
 
49
-    /**
50
-     * BootstrapRequestResponseObjects constructor.
51
-     *
52
-     * @param LoaderInterface $loader
53
-     */
54
-    public function __construct(LoaderInterface $loader)
55
-    {
56
-        $this->loader = $loader;
57
-    }
49
+	/**
50
+	 * BootstrapRequestResponseObjects constructor.
51
+	 *
52
+	 * @param LoaderInterface $loader
53
+	 */
54
+	public function __construct(LoaderInterface $loader)
55
+	{
56
+		$this->loader = $loader;
57
+	}
58 58
 
59 59
 
60
-    /**
61
-     * @return void
62
-     */
63
-    public function buildRequestResponse()
64
-    {
65
-        // load our Request and Response objects
66
-        $this->request = new Request($_GET, $_POST, $_COOKIE, $_SERVER);
67
-        $this->response = new Response();
68
-    }
60
+	/**
61
+	 * @return void
62
+	 */
63
+	public function buildRequestResponse()
64
+	{
65
+		// load our Request and Response objects
66
+		$this->request = new Request($_GET, $_POST, $_COOKIE, $_SERVER);
67
+		$this->response = new Response();
68
+	}
69 69
 
70 70
 
71
-    /**
72
-     * @return void
73
-     * @throws InvalidArgumentException
74
-     */
75
-    public function shareRequestResponse()
76
-    {
77
-        $this->loader->share('EventEspresso\core\services\request\Request', $this->request);
78
-        $this->loader->share('EventEspresso\core\services\request\Response', $this->response);
79
-        EE_Dependency_Map::instance()->setRequest($this->request);
80
-        EE_Dependency_Map::instance()->setResponse($this->response);
81
-    }
71
+	/**
72
+	 * @return void
73
+	 * @throws InvalidArgumentException
74
+	 */
75
+	public function shareRequestResponse()
76
+	{
77
+		$this->loader->share('EventEspresso\core\services\request\Request', $this->request);
78
+		$this->loader->share('EventEspresso\core\services\request\Response', $this->response);
79
+		EE_Dependency_Map::instance()->setRequest($this->request);
80
+		EE_Dependency_Map::instance()->setResponse($this->response);
81
+	}
82 82
 
83 83
 
84
-    /**
85
-     * @return void
86
-     * @throws InvalidArgumentException
87
-     * @throws EE_Error
88
-     */
89
-    public function setupLegacyRequest()
90
-    {
91
-        espresso_load_required(
92
-            'EE_Request',
93
-            EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
94
-        );
95
-        $this->legacy_request = new EE_Request($_GET, $_POST, $_COOKIE, $_SERVER);
96
-        $this->legacy_request->setRequest($this->request);
97
-        $this->legacy_request->admin = $this->request->isAdmin();
98
-        $this->legacy_request->ajax = $this->request->isAjax();
99
-        $this->legacy_request->front_ajax = $this->request->isFrontAjax();
100
-        EE_Dependency_Map::instance()->setLegacyRequest($this->legacy_request);
101
-        $this->loader->share('EE_Request', $this->legacy_request);
102
-        $this->loader->share('EventEspresso\core\services\request\LegacyRequestInterface', $this->legacy_request);
103
-    }
84
+	/**
85
+	 * @return void
86
+	 * @throws InvalidArgumentException
87
+	 * @throws EE_Error
88
+	 */
89
+	public function setupLegacyRequest()
90
+	{
91
+		espresso_load_required(
92
+			'EE_Request',
93
+			EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
94
+		);
95
+		$this->legacy_request = new EE_Request($_GET, $_POST, $_COOKIE, $_SERVER);
96
+		$this->legacy_request->setRequest($this->request);
97
+		$this->legacy_request->admin = $this->request->isAdmin();
98
+		$this->legacy_request->ajax = $this->request->isAjax();
99
+		$this->legacy_request->front_ajax = $this->request->isFrontAjax();
100
+		EE_Dependency_Map::instance()->setLegacyRequest($this->legacy_request);
101
+		$this->loader->share('EE_Request', $this->legacy_request);
102
+		$this->loader->share('EventEspresso\core\services\request\LegacyRequestInterface', $this->legacy_request);
103
+	}
104 104
 }
Please login to merge, or discard this patch.
core/request_stack/EE_Request.core.php 2 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
      *
182 182
      * @deprecated 4.9.53
183 183
      * @param      $key
184
-     * @param null $default
184
+     * @param null|string $default
185 185
      * @return mixed
186 186
      * @throws InvalidArgumentException
187 187
      * @throws InvalidDataTypeException
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 
257 257
     /**
258 258
      * @deprecated 4.9.53
259
-     * @return mixed
259
+     * @return boolean
260 260
      * @throws InvalidArgumentException
261 261
      * @throws InvalidDataTypeException
262 262
      * @throws InvalidInterfaceException
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 
270 270
     /**
271 271
      * @deprecated 4.9.53
272
-     * @return mixed
272
+     * @return boolean
273 273
      * @throws InvalidArgumentException
274 274
      * @throws InvalidDataTypeException
275 275
      * @throws InvalidInterfaceException
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 
283 283
     /**
284 284
      * @deprecated 4.9.53
285
-     * @return mixed|string
285
+     * @return string
286 286
      * @throws InvalidArgumentException
287 287
      * @throws InvalidDataTypeException
288 288
      * @throws InvalidInterfaceException
Please login to merge, or discard this patch.
Indentation   +355 added lines, -355 removed lines patch added patch discarded remove patch
@@ -18,359 +18,359 @@
 block discarded – undo
18 18
 class EE_Request implements LegacyRequestInterface, InterminableInterface
19 19
 {
20 20
 
21
-    /**
22
-     * @var RequestInterface $request
23
-     */
24
-    private $request;
25
-
26
-    /**
27
-     * whether current request is for the admin but NOT via AJAX
28
-     *
29
-     * @var boolean $admin
30
-     */
31
-    public $admin = false;
32
-
33
-    /**
34
-     * whether current request is via AJAX
35
-     *
36
-     * @var boolean $ajax
37
-     */
38
-    public $ajax = false;
39
-
40
-    /**
41
-     * whether current request is via AJAX from the frontend of the site
42
-     *
43
-     * @var boolean $front_ajax
44
-     */
45
-    public $front_ajax = false;
46
-
47
-
48
-    /**
49
-     * @deprecated 4.9.53
50
-     * @param array $get
51
-     * @param array $post
52
-     * @param array $cookie
53
-     * @param array $server
54
-     */
55
-    public function __construct(
56
-        array $get = array(),
57
-        array $post = array(),
58
-        array $cookie = array(),
59
-        array $server = array()
60
-    ) {
61
-    }
62
-
63
-
64
-    /**
65
-     * @return RequestInterface
66
-     * @throws InvalidArgumentException
67
-     * @throws InvalidInterfaceException
68
-     * @throws InvalidDataTypeException
69
-     */
70
-    private function request()
71
-    {
72
-        if ($this->request instanceof RequestInterface) {
73
-            return $this->request;
74
-        }
75
-        $loader = LoaderFactory::getLoader();
76
-        $this->request = $loader->getShared('EventEspresso\core\services\request\RequestInterface');
77
-        return $this->request;
78
-    }
79
-
80
-
81
-    /**
82
-     * @param RequestInterface $request
83
-     */
84
-    public function setRequest(RequestInterface $request)
85
-    {
86
-        $this->request = $request;
87
-    }
88
-
89
-
90
-    /**
91
-     * @deprecated 4.9.53
92
-     * @return array
93
-     * @throws InvalidArgumentException
94
-     * @throws InvalidDataTypeException
95
-     * @throws InvalidInterfaceException
96
-     */
97
-    public function get_params()
98
-    {
99
-        return $this->request()->getParams();
100
-    }
101
-
102
-
103
-    /**
104
-     * @deprecated 4.9.53
105
-     * @return array
106
-     * @throws InvalidArgumentException
107
-     * @throws InvalidDataTypeException
108
-     * @throws InvalidInterfaceException
109
-     */
110
-    public function post_params()
111
-    {
112
-        return $this->request()->postParams();
113
-    }
114
-
115
-
116
-    /**
117
-     * @deprecated 4.9.53
118
-     * @return array
119
-     * @throws InvalidArgumentException
120
-     * @throws InvalidDataTypeException
121
-     * @throws InvalidInterfaceException
122
-     */
123
-    public function cookie_params()
124
-    {
125
-        return $this->request()->cookieParams();
126
-    }
127
-
128
-
129
-    /**
130
-     * @deprecated 4.9.53
131
-     * @return array
132
-     * @throws InvalidArgumentException
133
-     * @throws InvalidDataTypeException
134
-     * @throws InvalidInterfaceException
135
-     */
136
-    public function server_params()
137
-    {
138
-        return $this->request()->serverParams();
139
-    }
140
-
141
-
142
-    /**
143
-     * returns contents of $_REQUEST
144
-     *
145
-     * @deprecated 4.9.53
146
-     * @return array
147
-     * @throws InvalidArgumentException
148
-     * @throws InvalidDataTypeException
149
-     * @throws InvalidInterfaceException
150
-     */
151
-    public function params()
152
-    {
153
-        return $this->request()->requestParams();
154
-    }
155
-
156
-
157
-    /**
158
-     * @deprecated 4.9.53
159
-     * @param      $key
160
-     * @param      $value
161
-     * @param bool $override_ee
162
-     * @return void
163
-     * @throws InvalidArgumentException
164
-     * @throws InvalidDataTypeException
165
-     * @throws InvalidInterfaceException
166
-     */
167
-    public function set($key, $value, $override_ee = false)
168
-    {
169
-        $this->request()->setRequestParam($key, $value, $override_ee);
170
-    }
171
-
172
-
173
-    /**
174
-     * returns   the value for a request param if the given key exists
175
-     *
176
-     * @deprecated 4.9.53
177
-     * @param      $key
178
-     * @param null $default
179
-     * @return mixed
180
-     * @throws InvalidArgumentException
181
-     * @throws InvalidDataTypeException
182
-     * @throws InvalidInterfaceException
183
-     */
184
-    public function get($key, $default = null)
185
-    {
186
-        return $this->request()->getRequestParam($key, $default);
187
-    }
188
-
189
-
190
-    /**
191
-     * check if param exists
192
-     *
193
-     * @deprecated 4.9.53
194
-     * @param $key
195
-     * @return bool
196
-     * @throws InvalidArgumentException
197
-     * @throws InvalidDataTypeException
198
-     * @throws InvalidInterfaceException
199
-     */
200
-    public function is_set($key)
201
-    {
202
-        return $this->request()->requestParamIsSet($key);
203
-    }
204
-
205
-
206
-    /**
207
-     * remove param
208
-     *
209
-     * @deprecated 4.9.53
210
-     * @param      $key
211
-     * @param bool $unset_from_global_too
212
-     * @throws InvalidArgumentException
213
-     * @throws InvalidDataTypeException
214
-     * @throws InvalidInterfaceException
215
-     */
216
-    public function un_set($key, $unset_from_global_too = false)
217
-    {
218
-        $this->request()->unSetRequestParam($key, $unset_from_global_too);
219
-    }
220
-
221
-
222
-    /**
223
-     * @deprecated 4.9.53
224
-     * @return string
225
-     * @throws InvalidArgumentException
226
-     * @throws InvalidDataTypeException
227
-     * @throws InvalidInterfaceException
228
-     */
229
-    public function ip_address()
230
-    {
231
-        return $this->request()->ipAddress();
232
-    }
233
-
234
-
235
-    /**
236
-     * @deprecated 4.9.53
237
-     * @return bool
238
-     * @throws InvalidArgumentException
239
-     * @throws InvalidDataTypeException
240
-     * @throws InvalidInterfaceException
241
-     */
242
-    public function isAdmin()
243
-    {
244
-        return $this->request()->isAdmin();
245
-    }
246
-
247
-
248
-    /**
249
-     * @deprecated 4.9.53
250
-     * @return mixed
251
-     * @throws InvalidArgumentException
252
-     * @throws InvalidDataTypeException
253
-     * @throws InvalidInterfaceException
254
-     */
255
-    public function isAjax()
256
-    {
257
-        return $this->request()->isAjax();
258
-    }
259
-
260
-
261
-    /**
262
-     * @deprecated 4.9.53
263
-     * @return mixed
264
-     * @throws InvalidArgumentException
265
-     * @throws InvalidDataTypeException
266
-     * @throws InvalidInterfaceException
267
-     */
268
-    public function isFrontAjax()
269
-    {
270
-        return $this->request()->isFrontAjax();
271
-    }
272
-
273
-
274
-    /**
275
-     * @deprecated 4.9.53
276
-     * @return mixed|string
277
-     * @throws InvalidArgumentException
278
-     * @throws InvalidDataTypeException
279
-     * @throws InvalidInterfaceException
280
-     */
281
-    public function requestUri()
282
-    {
283
-        return $this->request()->requestUri();
284
-    }
285
-
286
-
287
-    /**
288
-     * @deprecated 4.9.53
289
-     * @return string
290
-     * @throws InvalidArgumentException
291
-     * @throws InvalidDataTypeException
292
-     * @throws InvalidInterfaceException
293
-     */
294
-    public function userAgent()
295
-    {
296
-        return $this->request()->userAgent();
297
-    }
298
-
299
-
300
-    /**
301
-     * @deprecated 4.9.53
302
-     * @param string $user_agent
303
-     * @throws InvalidArgumentException
304
-     * @throws InvalidDataTypeException
305
-     * @throws InvalidInterfaceException
306
-     */
307
-    public function setUserAgent($user_agent = '')
308
-    {
309
-        $this->request()->setUserAgent($user_agent);
310
-    }
311
-
312
-
313
-    /**
314
-     * @deprecated 4.9.53
315
-     * @return bool
316
-     * @throws InvalidArgumentException
317
-     * @throws InvalidDataTypeException
318
-     * @throws InvalidInterfaceException
319
-     */
320
-    public function isBot()
321
-    {
322
-        return $this->request()->isBot();
323
-    }
324
-
325
-
326
-    /**
327
-     * @deprecated 4.9.53
328
-     * @param bool $is_bot
329
-     * @throws InvalidArgumentException
330
-     * @throws InvalidDataTypeException
331
-     * @throws InvalidInterfaceException
332
-     */
333
-    public function setIsBot($is_bot)
334
-    {
335
-        $this->request()->setIsBot($is_bot);
336
-    }
337
-
338
-
339
-    /**
340
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
341
-     * and return the value for the first match found
342
-     * wildcards can be either of the following:
343
-     *      ? to represent a single character of any type
344
-     *      * to represent one or more characters of any type
345
-     *
346
-     * @param string     $pattern
347
-     * @param null|mixed $default
348
-     * @return false|int
349
-     * @throws InvalidArgumentException
350
-     * @throws InvalidInterfaceException
351
-     * @throws InvalidDataTypeException
352
-     */
353
-    public function getMatch($pattern, $default = null)
354
-    {
355
-        return $this->request()->getMatch($pattern, $default);
356
-    }
357
-
358
-
359
-    /**
360
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
361
-     * wildcards can be either of the following:
362
-     *      ? to represent a single character of any type
363
-     *      * to represent one or more characters of any type
364
-     * returns true if a match is found or false if not
365
-     *
366
-     * @param string $pattern
367
-     * @return false|int
368
-     * @throws InvalidArgumentException
369
-     * @throws InvalidInterfaceException
370
-     * @throws InvalidDataTypeException
371
-     */
372
-    public function matches($pattern)
373
-    {
374
-        return $this->request()->matches($pattern);
375
-    }
21
+	/**
22
+	 * @var RequestInterface $request
23
+	 */
24
+	private $request;
25
+
26
+	/**
27
+	 * whether current request is for the admin but NOT via AJAX
28
+	 *
29
+	 * @var boolean $admin
30
+	 */
31
+	public $admin = false;
32
+
33
+	/**
34
+	 * whether current request is via AJAX
35
+	 *
36
+	 * @var boolean $ajax
37
+	 */
38
+	public $ajax = false;
39
+
40
+	/**
41
+	 * whether current request is via AJAX from the frontend of the site
42
+	 *
43
+	 * @var boolean $front_ajax
44
+	 */
45
+	public $front_ajax = false;
46
+
47
+
48
+	/**
49
+	 * @deprecated 4.9.53
50
+	 * @param array $get
51
+	 * @param array $post
52
+	 * @param array $cookie
53
+	 * @param array $server
54
+	 */
55
+	public function __construct(
56
+		array $get = array(),
57
+		array $post = array(),
58
+		array $cookie = array(),
59
+		array $server = array()
60
+	) {
61
+	}
62
+
63
+
64
+	/**
65
+	 * @return RequestInterface
66
+	 * @throws InvalidArgumentException
67
+	 * @throws InvalidInterfaceException
68
+	 * @throws InvalidDataTypeException
69
+	 */
70
+	private function request()
71
+	{
72
+		if ($this->request instanceof RequestInterface) {
73
+			return $this->request;
74
+		}
75
+		$loader = LoaderFactory::getLoader();
76
+		$this->request = $loader->getShared('EventEspresso\core\services\request\RequestInterface');
77
+		return $this->request;
78
+	}
79
+
80
+
81
+	/**
82
+	 * @param RequestInterface $request
83
+	 */
84
+	public function setRequest(RequestInterface $request)
85
+	{
86
+		$this->request = $request;
87
+	}
88
+
89
+
90
+	/**
91
+	 * @deprecated 4.9.53
92
+	 * @return array
93
+	 * @throws InvalidArgumentException
94
+	 * @throws InvalidDataTypeException
95
+	 * @throws InvalidInterfaceException
96
+	 */
97
+	public function get_params()
98
+	{
99
+		return $this->request()->getParams();
100
+	}
101
+
102
+
103
+	/**
104
+	 * @deprecated 4.9.53
105
+	 * @return array
106
+	 * @throws InvalidArgumentException
107
+	 * @throws InvalidDataTypeException
108
+	 * @throws InvalidInterfaceException
109
+	 */
110
+	public function post_params()
111
+	{
112
+		return $this->request()->postParams();
113
+	}
114
+
115
+
116
+	/**
117
+	 * @deprecated 4.9.53
118
+	 * @return array
119
+	 * @throws InvalidArgumentException
120
+	 * @throws InvalidDataTypeException
121
+	 * @throws InvalidInterfaceException
122
+	 */
123
+	public function cookie_params()
124
+	{
125
+		return $this->request()->cookieParams();
126
+	}
127
+
128
+
129
+	/**
130
+	 * @deprecated 4.9.53
131
+	 * @return array
132
+	 * @throws InvalidArgumentException
133
+	 * @throws InvalidDataTypeException
134
+	 * @throws InvalidInterfaceException
135
+	 */
136
+	public function server_params()
137
+	{
138
+		return $this->request()->serverParams();
139
+	}
140
+
141
+
142
+	/**
143
+	 * returns contents of $_REQUEST
144
+	 *
145
+	 * @deprecated 4.9.53
146
+	 * @return array
147
+	 * @throws InvalidArgumentException
148
+	 * @throws InvalidDataTypeException
149
+	 * @throws InvalidInterfaceException
150
+	 */
151
+	public function params()
152
+	{
153
+		return $this->request()->requestParams();
154
+	}
155
+
156
+
157
+	/**
158
+	 * @deprecated 4.9.53
159
+	 * @param      $key
160
+	 * @param      $value
161
+	 * @param bool $override_ee
162
+	 * @return void
163
+	 * @throws InvalidArgumentException
164
+	 * @throws InvalidDataTypeException
165
+	 * @throws InvalidInterfaceException
166
+	 */
167
+	public function set($key, $value, $override_ee = false)
168
+	{
169
+		$this->request()->setRequestParam($key, $value, $override_ee);
170
+	}
171
+
172
+
173
+	/**
174
+	 * returns   the value for a request param if the given key exists
175
+	 *
176
+	 * @deprecated 4.9.53
177
+	 * @param      $key
178
+	 * @param null $default
179
+	 * @return mixed
180
+	 * @throws InvalidArgumentException
181
+	 * @throws InvalidDataTypeException
182
+	 * @throws InvalidInterfaceException
183
+	 */
184
+	public function get($key, $default = null)
185
+	{
186
+		return $this->request()->getRequestParam($key, $default);
187
+	}
188
+
189
+
190
+	/**
191
+	 * check if param exists
192
+	 *
193
+	 * @deprecated 4.9.53
194
+	 * @param $key
195
+	 * @return bool
196
+	 * @throws InvalidArgumentException
197
+	 * @throws InvalidDataTypeException
198
+	 * @throws InvalidInterfaceException
199
+	 */
200
+	public function is_set($key)
201
+	{
202
+		return $this->request()->requestParamIsSet($key);
203
+	}
204
+
205
+
206
+	/**
207
+	 * remove param
208
+	 *
209
+	 * @deprecated 4.9.53
210
+	 * @param      $key
211
+	 * @param bool $unset_from_global_too
212
+	 * @throws InvalidArgumentException
213
+	 * @throws InvalidDataTypeException
214
+	 * @throws InvalidInterfaceException
215
+	 */
216
+	public function un_set($key, $unset_from_global_too = false)
217
+	{
218
+		$this->request()->unSetRequestParam($key, $unset_from_global_too);
219
+	}
220
+
221
+
222
+	/**
223
+	 * @deprecated 4.9.53
224
+	 * @return string
225
+	 * @throws InvalidArgumentException
226
+	 * @throws InvalidDataTypeException
227
+	 * @throws InvalidInterfaceException
228
+	 */
229
+	public function ip_address()
230
+	{
231
+		return $this->request()->ipAddress();
232
+	}
233
+
234
+
235
+	/**
236
+	 * @deprecated 4.9.53
237
+	 * @return bool
238
+	 * @throws InvalidArgumentException
239
+	 * @throws InvalidDataTypeException
240
+	 * @throws InvalidInterfaceException
241
+	 */
242
+	public function isAdmin()
243
+	{
244
+		return $this->request()->isAdmin();
245
+	}
246
+
247
+
248
+	/**
249
+	 * @deprecated 4.9.53
250
+	 * @return mixed
251
+	 * @throws InvalidArgumentException
252
+	 * @throws InvalidDataTypeException
253
+	 * @throws InvalidInterfaceException
254
+	 */
255
+	public function isAjax()
256
+	{
257
+		return $this->request()->isAjax();
258
+	}
259
+
260
+
261
+	/**
262
+	 * @deprecated 4.9.53
263
+	 * @return mixed
264
+	 * @throws InvalidArgumentException
265
+	 * @throws InvalidDataTypeException
266
+	 * @throws InvalidInterfaceException
267
+	 */
268
+	public function isFrontAjax()
269
+	{
270
+		return $this->request()->isFrontAjax();
271
+	}
272
+
273
+
274
+	/**
275
+	 * @deprecated 4.9.53
276
+	 * @return mixed|string
277
+	 * @throws InvalidArgumentException
278
+	 * @throws InvalidDataTypeException
279
+	 * @throws InvalidInterfaceException
280
+	 */
281
+	public function requestUri()
282
+	{
283
+		return $this->request()->requestUri();
284
+	}
285
+
286
+
287
+	/**
288
+	 * @deprecated 4.9.53
289
+	 * @return string
290
+	 * @throws InvalidArgumentException
291
+	 * @throws InvalidDataTypeException
292
+	 * @throws InvalidInterfaceException
293
+	 */
294
+	public function userAgent()
295
+	{
296
+		return $this->request()->userAgent();
297
+	}
298
+
299
+
300
+	/**
301
+	 * @deprecated 4.9.53
302
+	 * @param string $user_agent
303
+	 * @throws InvalidArgumentException
304
+	 * @throws InvalidDataTypeException
305
+	 * @throws InvalidInterfaceException
306
+	 */
307
+	public function setUserAgent($user_agent = '')
308
+	{
309
+		$this->request()->setUserAgent($user_agent);
310
+	}
311
+
312
+
313
+	/**
314
+	 * @deprecated 4.9.53
315
+	 * @return bool
316
+	 * @throws InvalidArgumentException
317
+	 * @throws InvalidDataTypeException
318
+	 * @throws InvalidInterfaceException
319
+	 */
320
+	public function isBot()
321
+	{
322
+		return $this->request()->isBot();
323
+	}
324
+
325
+
326
+	/**
327
+	 * @deprecated 4.9.53
328
+	 * @param bool $is_bot
329
+	 * @throws InvalidArgumentException
330
+	 * @throws InvalidDataTypeException
331
+	 * @throws InvalidInterfaceException
332
+	 */
333
+	public function setIsBot($is_bot)
334
+	{
335
+		$this->request()->setIsBot($is_bot);
336
+	}
337
+
338
+
339
+	/**
340
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
341
+	 * and return the value for the first match found
342
+	 * wildcards can be either of the following:
343
+	 *      ? to represent a single character of any type
344
+	 *      * to represent one or more characters of any type
345
+	 *
346
+	 * @param string     $pattern
347
+	 * @param null|mixed $default
348
+	 * @return false|int
349
+	 * @throws InvalidArgumentException
350
+	 * @throws InvalidInterfaceException
351
+	 * @throws InvalidDataTypeException
352
+	 */
353
+	public function getMatch($pattern, $default = null)
354
+	{
355
+		return $this->request()->getMatch($pattern, $default);
356
+	}
357
+
358
+
359
+	/**
360
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
361
+	 * wildcards can be either of the following:
362
+	 *      ? to represent a single character of any type
363
+	 *      * to represent one or more characters of any type
364
+	 * returns true if a match is found or false if not
365
+	 *
366
+	 * @param string $pattern
367
+	 * @return false|int
368
+	 * @throws InvalidArgumentException
369
+	 * @throws InvalidInterfaceException
370
+	 * @throws InvalidDataTypeException
371
+	 */
372
+	public function matches($pattern)
373
+	{
374
+		return $this->request()->matches($pattern);
375
+	}
376 376
 }
Please login to merge, or discard this patch.
core/services/request/RequestStack.php 2 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -19,59 +19,59 @@
 block discarded – undo
19 19
 class RequestStack
20 20
 {
21 21
 
22
-    /**
23
-     * @var RequestDecoratorInterface $request_stack_app
24
-     */
25
-    protected $request_stack_app;
22
+	/**
23
+	 * @var RequestDecoratorInterface $request_stack_app
24
+	 */
25
+	protected $request_stack_app;
26 26
 
27
-    /**
28
-     * @var RequestStackCoreAppInterface $core_app
29
-     */
30
-    protected $core_app;
27
+	/**
28
+	 * @var RequestStackCoreAppInterface $core_app
29
+	 */
30
+	protected $core_app;
31 31
 
32
-    /**
33
-     * @var RequestInterface $request
34
-     */
35
-    protected $request;
32
+	/**
33
+	 * @var RequestInterface $request
34
+	 */
35
+	protected $request;
36 36
 
37
-    /**
38
-     * @var ResponseInterface $response
39
-     */
40
-    protected $response;
37
+	/**
38
+	 * @var ResponseInterface $response
39
+	 */
40
+	protected $response;
41 41
 
42 42
 
43
-    /**
44
-     * @param RequestDecoratorInterface    $request_stack_app
45
-     * @param RequestStackCoreAppInterface $core_app
46
-     */
47
-    public function __construct(RequestDecoratorInterface $request_stack_app, RequestStackCoreAppInterface $core_app)
48
-    {
49
-        $this->request_stack_app = $request_stack_app;
50
-        $this->core_app      = $core_app;
51
-    }
43
+	/**
44
+	 * @param RequestDecoratorInterface    $request_stack_app
45
+	 * @param RequestStackCoreAppInterface $core_app
46
+	 */
47
+	public function __construct(RequestDecoratorInterface $request_stack_app, RequestStackCoreAppInterface $core_app)
48
+	{
49
+		$this->request_stack_app = $request_stack_app;
50
+		$this->core_app      = $core_app;
51
+	}
52 52
 
53 53
 
54
-    /**
55
-     * @param RequestInterface  $request
56
-     * @param ResponseInterface $response
57
-     * @return ResponseInterface
58
-     */
59
-    public function handleRequest(RequestInterface $request, ResponseInterface $response)
60
-    {
61
-        $this->request  = $request;
62
-        $this->response = $response;
63
-        return $this->request_stack_app->handleRequest($request, $response);
64
-    }
54
+	/**
55
+	 * @param RequestInterface  $request
56
+	 * @param ResponseInterface $response
57
+	 * @return ResponseInterface
58
+	 */
59
+	public function handleRequest(RequestInterface $request, ResponseInterface $response)
60
+	{
61
+		$this->request  = $request;
62
+		$this->response = $response;
63
+		return $this->request_stack_app->handleRequest($request, $response);
64
+	}
65 65
 
66 66
 
67
-    /**
68
-     * handle_response
69
-     * executes the handle_response() method on the RequestStackCoreAppInterface object
70
-     * after the request stack has been fully processed
71
-     */
72
-    public function handleResponse()
73
-    {
74
-        $this->core_app->handleResponse($this->request, $this->response);
75
-    }
67
+	/**
68
+	 * handle_response
69
+	 * executes the handle_response() method on the RequestStackCoreAppInterface object
70
+	 * after the request stack has been fully processed
71
+	 */
72
+	public function handleResponse()
73
+	{
74
+		$this->core_app->handleResponse($this->request, $this->response);
75
+	}
76 76
 }
77 77
 // Location: RequestStack.php
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
     public function __construct(RequestDecoratorInterface $request_stack_app, RequestStackCoreAppInterface $core_app)
48 48
     {
49 49
         $this->request_stack_app = $request_stack_app;
50
-        $this->core_app      = $core_app;
50
+        $this->core_app = $core_app;
51 51
     }
52 52
 
53 53
 
Please login to merge, or discard this patch.
core/services/request/middleware/SetRequestTypeContextChecker.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -22,36 +22,36 @@
 block discarded – undo
22 22
 class SetRequestTypeContextChecker extends Middleware
23 23
 {
24 24
 
25
-    /**
26
-     * converts a Request to a Response
27
-     *
28
-     * @param RequestInterface  $request
29
-     * @param ResponseInterface $response
30
-     * @return ResponseInterface
31
-     * @throws InvalidArgumentException
32
-     */
33
-    public function handleRequest(RequestInterface $request, ResponseInterface $response)
34
-    {
35
-        $this->request  = $request;
36
-        $this->response = $response;
37
-        /** @var RequestTypeContextDetector $request_type_context_detector */
38
-        $request_type_context_detector = $this->loader->getShared(
39
-            'EventEspresso\core\domain\services\contexts\RequestTypeContextDetector',
40
-            array(
41
-                $this->request,
42
-                $this->loader->getShared(
43
-                    'EventEspresso\core\domain\services\contexts\RequestTypeContextFactory',
44
-                    array($this->loader)
45
-                ),
46
-            )
47
-        );
48
-        $request_type_context          = $request_type_context_detector->detectRequestTypeContext();
49
-        $request_type_context_checker  = $this->loader->getShared(
50
-            'EventEspresso\core\domain\services\contexts\RequestTypeContextChecker',
51
-            array($request_type_context)
52
-        );
53
-        $this->request->setRequestTypeContextChecker($request_type_context_checker);
54
-        $this->response = $this->processRequestStack($this->request, $this->response);
55
-        return $this->response;
56
-    }
25
+	/**
26
+	 * converts a Request to a Response
27
+	 *
28
+	 * @param RequestInterface  $request
29
+	 * @param ResponseInterface $response
30
+	 * @return ResponseInterface
31
+	 * @throws InvalidArgumentException
32
+	 */
33
+	public function handleRequest(RequestInterface $request, ResponseInterface $response)
34
+	{
35
+		$this->request  = $request;
36
+		$this->response = $response;
37
+		/** @var RequestTypeContextDetector $request_type_context_detector */
38
+		$request_type_context_detector = $this->loader->getShared(
39
+			'EventEspresso\core\domain\services\contexts\RequestTypeContextDetector',
40
+			array(
41
+				$this->request,
42
+				$this->loader->getShared(
43
+					'EventEspresso\core\domain\services\contexts\RequestTypeContextFactory',
44
+					array($this->loader)
45
+				),
46
+			)
47
+		);
48
+		$request_type_context          = $request_type_context_detector->detectRequestTypeContext();
49
+		$request_type_context_checker  = $this->loader->getShared(
50
+			'EventEspresso\core\domain\services\contexts\RequestTypeContextChecker',
51
+			array($request_type_context)
52
+		);
53
+		$this->request->setRequestTypeContextChecker($request_type_context_checker);
54
+		$this->response = $this->processRequestStack($this->request, $this->response);
55
+		return $this->response;
56
+	}
57 57
 }
Please login to merge, or discard this patch.
modules/core_rest_api/EED_Core_Rest_Api.module.php 4 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 use EventEspresso\core\domain\Domain;
4
-use EventEspresso\core\domain\entities\notifications\PersistentAdminNotice;
5 4
 use EventEspresso\core\domain\services\factories\EmailAddressFactory;
6 5
 use EventEspresso\core\domain\services\validation\email\EmailValidationException;
7 6
 use EventEspresso\core\exceptions\InvalidDataTypeException;
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -408,7 +408,7 @@
 block discarded – undo
408 408
      * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`)
409 409
      * in this versioned namespace of EE4
410 410
      *
411
-     * @param $version
411
+     * @param string $version
412 412
      * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event')
413 413
      */
414 414
     public static function model_names_with_plural_routes($version)
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
      */
123 123
     protected static function _set_hooks_for_changes()
124 124
     {
125
-        $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false);
125
+        $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES.'rest_api'.DS.'changes'), false);
126 126
         foreach ($folder_contents as $classname_in_namespace => $filepath) {
127 127
             // ignore the base parent class
128 128
             // and legacy named classes
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
             ) {
132 132
                 continue;
133 133
             }
134
-            $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
134
+            $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\'.$classname_in_namespace;
135 135
             if (class_exists($full_classname)) {
136 136
                 $instance_of_class = new $full_classname;
137 137
                 if ($instance_of_class instanceof ChangesInBase) {
@@ -176,10 +176,10 @@  discard block
 block discarded – undo
176 176
                      * }
177 177
                      */
178 178
                     // skip route options
179
-                    if (! is_numeric($endpoint_key)) {
179
+                    if ( ! is_numeric($endpoint_key)) {
180 180
                         continue;
181 181
                     }
182
-                    if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) {
182
+                    if ( ! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) {
183 183
                         throw new EE_Error(
184 184
                             esc_html__(
185 185
                             // @codingStandardsIgnoreStart
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
                     }
201 201
                     if (isset($data_for_single_endpoint['callback_args'])) {
202 202
                         $callback_args = $data_for_single_endpoint['callback_args'];
203
-                        $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use (
203
+                        $single_endpoint_args['callback'] = function(\WP_REST_Request $request) use (
204 204
                             $callback,
205 205
                             $callback_args
206 206
                         ) {
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
                     $schema_route_data = $data_for_multiple_endpoints['schema'];
220 220
                     $schema_callback = $schema_route_data['schema_callback'];
221 221
                     $callback_args = $schema_route_data['callback_args'];
222
-                    $multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) {
222
+                    $multiple_endpoint_args['schema'] = function() use ($schema_callback, $callback_args) {
223 223
                         return call_user_func_array(
224 224
                             $schema_callback,
225 225
                             $callback_args
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
     {
262 262
         // delete the saved EE REST API routes
263 263
         foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
264
-            delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
264
+            delete_option(EED_Core_Rest_Api::saved_routes_option_names.$version);
265 265
         }
266 266
     }
267 267
 
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
     {
281 281
         $ee_routes = array();
282 282
         foreach (self::versions_served() as $version => $hidden_endpoints) {
283
-            $ee_routes[ self::ee_api_namespace . $version ] = self::_get_ee_route_data_for_version(
283
+            $ee_routes[self::ee_api_namespace.$version] = self::_get_ee_route_data_for_version(
284 284
                 $version,
285 285
                 $hidden_endpoints
286 286
             );
@@ -300,8 +300,8 @@  discard block
 block discarded – undo
300 300
      */
301 301
     protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
302 302
     {
303
-        $ee_routes = get_option(self::saved_routes_option_names . $version, null);
304
-        if (! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
303
+        $ee_routes = get_option(self::saved_routes_option_names.$version, null);
304
+        if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
305 305
             $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
306 306
         }
307 307
         return $ee_routes;
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
                 $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
329 329
             )
330 330
         );
331
-        $option_name = self::saved_routes_option_names . $version;
331
+        $option_name = self::saved_routes_option_names.$version;
332 332
         if (get_option($option_name)) {
333 333
             update_option($option_name, $routes, true);
334 334
         } else {
@@ -373,8 +373,8 @@  discard block
 block discarded – undo
373 373
     {
374 374
         $model_routes = array();
375 375
         foreach (self::versions_served() as $version => $hidden_endpoint) {
376
-            $model_routes[ EED_Core_Rest_Api::ee_api_namespace
377
-                           . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
376
+            $model_routes[EED_Core_Rest_Api::ee_api_namespace
377
+                           . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
378 378
         }
379 379
         return $model_routes;
380 380
     }
@@ -443,13 +443,13 @@  discard block
 block discarded – undo
443 443
         foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) {
444 444
             $model = \EE_Registry::instance()->load_model($model_name);
445 445
             // if this isn't a valid model then let's skip iterate to the next item in the loop.
446
-            if (! $model instanceof EEM_Base) {
446
+            if ( ! $model instanceof EEM_Base) {
447 447
                 continue;
448 448
             }
449 449
             // yes we could just register one route for ALL models, but then they wouldn't show up in the index
450 450
             $plural_model_route = EED_Core_Rest_Api::get_collection_route($model);
451 451
             $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)');
452
-            $model_routes[ $plural_model_route ] = array(
452
+            $model_routes[$plural_model_route] = array(
453 453
                 array(
454 454
                     'callback'        => array(
455 455
                         'EventEspresso\core\libraries\rest_api\controllers\model\Read',
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
                     'hidden_endpoint' => $hidden_endpoint,
461 461
                     'args'            => $this->_get_read_query_params($model, $version),
462 462
                     '_links'          => array(
463
-                        'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
463
+                        'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace.$version.$singular_model_route),
464 464
                     ),
465 465
                 ),
466 466
                 'schema' => array(
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
                     'callback_args'   => array($version, $model_name),
472 472
                 ),
473 473
             );
474
-            $model_routes[ $singular_model_route ] = array(
474
+            $model_routes[$singular_model_route] = array(
475 475
                 array(
476 476
                     'callback'        => array(
477 477
                         'EventEspresso\core\libraries\rest_api\controllers\model\Read',
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
                 EED_Core_Rest_Api::should_have_write_endpoints($model),
489 489
                 $model
490 490
             )) {
491
-                $model_routes[ $plural_model_route ][] = array(
491
+                $model_routes[$plural_model_route][] = array(
492 492
                     'callback'        => array(
493 493
                         'EventEspresso\core\libraries\rest_api\controllers\model\Write',
494 494
                         'handleRequestInsert',
@@ -498,8 +498,8 @@  discard block
 block discarded – undo
498 498
                     'hidden_endpoint' => $hidden_endpoint,
499 499
                     'args'            => $this->_get_write_params($model_name, $model_version_info, true),
500 500
                 );
501
-                $model_routes[ $singular_model_route ] = array_merge(
502
-                    $model_routes[ $singular_model_route ],
501
+                $model_routes[$singular_model_route] = array_merge(
502
+                    $model_routes[$singular_model_route],
503 503
                     array(
504 504
                         array(
505 505
                             'callback'        => array(
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
                         'args'            => $this->_get_read_query_params($relation_obj->get_other_model(), $version),
543 543
                     ),
544 544
                 );
545
-                $model_routes[ $related_route ] = $endpoints;
545
+                $model_routes[$related_route] = $endpoints;
546 546
             }
547 547
         }
548 548
         return $model_routes;
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
      */
575 575
     public static function get_entity_route($model, $id)
576 576
     {
577
-        return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id;
577
+        return EED_Core_Rest_Api::get_collection_route($model).'/'.$id;
578 578
     }
579 579
 
580 580
 
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
             $relation_obj->get_other_model()->get_this_model_name(),
595 595
             $relation_obj
596 596
         );
597
-        return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part;
597
+        return EED_Core_Rest_Api::get_entity_route($model, $id).'/'.$related_model_name_endpoint_part;
598 598
     }
599 599
 
600 600
 
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
      */
609 609
     public static function get_versioned_route_to($relative_route, $version = '4.8.36')
610 610
     {
611
-        return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route;
611
+        return '/'.EED_Core_Rest_Api::ee_api_namespace.$version.'/'.$relative_route;
612 612
     }
613 613
 
614 614
 
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
     {
623 623
         $routes = array();
624 624
         foreach (self::versions_served() as $version => $hidden_endpoint) {
625
-            $routes[ self::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version(
625
+            $routes[self::ee_api_namespace.$version] = $this->_get_rpc_route_data_for_version(
626 626
                 $version,
627 627
                 $hidden_endpoint
628 628
             );
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
     {
749 749
         $default_orderby = array();
750 750
         foreach ($model->get_combined_primary_key_fields() as $key_field) {
751
-            $default_orderby[ $key_field->get_name() ] = 'ASC';
751
+            $default_orderby[$key_field->get_name()] = 'ASC';
752 752
         }
753 753
         return array_merge(
754 754
             $this->_get_response_selection_query_params($model, $version),
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
                     'type'              => array(
783 783
                         'object',
784 784
                         'string',
785
-                    ),// because we accept a variety of types, WP core validation and sanitization
785
+                    ), // because we accept a variety of types, WP core validation and sanitization
786 786
                     // freaks out. We'll just validate this argument while handling the request
787 787
                     'validate_callback' => null,
788 788
                     'sanitize_callback' => null,
@@ -880,7 +880,7 @@  discard block
 block discarded – undo
880 880
                 $sanitize_callback = null;
881 881
             }
882 882
             $arg_info['sanitize_callback'] = $sanitize_callback;
883
-            $args_info[ $field_name ] = $arg_info;
883
+            $args_info[$field_name] = $arg_info;
884 884
             if ($field_obj instanceof EE_Datetime_Field) {
885 885
                 $gmt_arg_info = $arg_info;
886 886
                 $gmt_arg_info['description'] = sprintf(
@@ -891,7 +891,7 @@  discard block
 block discarded – undo
891 891
                     $field_obj->get_nicename(),
892 892
                     $field_name
893 893
                 );
894
-                $args_info[ $field_name . '_gmt' ] = $gmt_arg_info;
894
+                $args_info[$field_name.'_gmt'] = $gmt_arg_info;
895 895
             }
896 896
         }
897 897
         return $args_info;
@@ -914,16 +914,16 @@  discard block
 block discarded – undo
914 914
     public static function default_sanitize_callback($value, WP_REST_Request $request, $param)
915 915
     {
916 916
         $attributes = $request->get_attributes();
917
-        if (! isset($attributes['args'][ $param ])
918
-            || ! is_array($attributes['args'][ $param ])) {
917
+        if ( ! isset($attributes['args'][$param])
918
+            || ! is_array($attributes['args'][$param])) {
919 919
             $validation_result = true;
920 920
         } else {
921
-            $args = $attributes['args'][ $param ];
921
+            $args = $attributes['args'][$param];
922 922
             if ((
923 923
                     $value === ''
924 924
                     || $value === null
925 925
                 )
926
-                && (! isset($args['required'])
926
+                && ( ! isset($args['required'])
927 927
                     || $args['required'] === false
928 928
                 )
929 929
             ) {
@@ -933,7 +933,7 @@  discard block
 block discarded – undo
933 933
                       && $args['format'] === 'email'
934 934
             ) {
935 935
                 $validation_result = true;
936
-                if (! self::_validate_email($value)) {
936
+                if ( ! self::_validate_email($value)) {
937 937
                     $validation_result = new WP_Error(
938 938
                         'rest_invalid_param',
939 939
                         esc_html__(
@@ -983,7 +983,7 @@  discard block
 block discarded – undo
983 983
     {
984 984
         $config_routes = array();
985 985
         foreach (self::versions_served() as $version => $hidden_endpoint) {
986
-            $config_routes[ self::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version(
986
+            $config_routes[self::ee_api_namespace.$version] = $this->_get_config_route_data_for_version(
987 987
                 $version,
988 988
                 $hidden_endpoint
989 989
             );
@@ -1038,7 +1038,7 @@  discard block
 block discarded – undo
1038 1038
     {
1039 1039
         $meta_routes = array();
1040 1040
         foreach (self::versions_served() as $version => $hidden_endpoint) {
1041
-            $meta_routes[ self::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version(
1041
+            $meta_routes[self::ee_api_namespace.$version] = $this->_get_meta_route_data_for_version(
1042 1042
                 $version,
1043 1043
                 $hidden_endpoint
1044 1044
             );
@@ -1090,7 +1090,7 @@  discard block
 block discarded – undo
1090 1090
             foreach ($relative_urls as $resource_name => $endpoints) {
1091 1091
                 foreach ($endpoints as $key => $endpoint) {
1092 1092
                     // skip schema and other route options
1093
-                    if (! is_numeric($key)) {
1093
+                    if ( ! is_numeric($key)) {
1094 1094
                         continue;
1095 1095
                     }
1096 1096
                     // by default, hide "hidden_endpoint"s, unless the request indicates
@@ -1099,9 +1099,9 @@  discard block
 block discarded – undo
1099 1099
                     if (($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
1100 1100
                         || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '')
1101 1101
                     ) {
1102
-                        $full_route = '/' . ltrim($namespace, '/');
1103
-                        $full_route .= '/' . ltrim($resource_name, '/');
1104
-                        unset($route_data[ $full_route ]);
1102
+                        $full_route = '/'.ltrim($namespace, '/');
1103
+                        $full_route .= '/'.ltrim($resource_name, '/');
1104
+                        unset($route_data[$full_route]);
1105 1105
                     }
1106 1106
                 }
1107 1107
             }
@@ -1174,19 +1174,19 @@  discard block
 block discarded – undo
1174 1174
             // if it's not above the current core version, and it's compatible with the current version of core
1175 1175
             if ($key_versioned_endpoint === $latest_version) {
1176 1176
                 // don't hide the latest version in the index
1177
-                $versions_served[ $key_versioned_endpoint ] = false;
1177
+                $versions_served[$key_versioned_endpoint] = false;
1178 1178
             } elseif ($key_versioned_endpoint >= $lowest_compatible_version
1179 1179
                 && $key_versioned_endpoint < EED_Core_Rest_Api::core_version()
1180 1180
             ) {
1181 1181
                 // include, but hide, previous versions which are still supported
1182
-                $versions_served[ $key_versioned_endpoint ] = true;
1182
+                $versions_served[$key_versioned_endpoint] = true;
1183 1183
             } elseif (apply_filters(
1184 1184
                 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions',
1185 1185
                 false,
1186 1186
                 $possibly_served_versions
1187 1187
             )) {
1188 1188
                 // if a version is no longer supported, don't include it in index or list of versions served
1189
-                $versions_served[ $key_versioned_endpoint ] = true;
1189
+                $versions_served[$key_versioned_endpoint] = true;
1190 1190
             }
1191 1191
         }
1192 1192
         return $versions_served;
Please login to merge, or discard this patch.
Indentation   +1221 added lines, -1221 removed lines patch added patch discarded remove patch
@@ -23,1225 +23,1225 @@
 block discarded – undo
23 23
 class EED_Core_Rest_Api extends \EED_Module
24 24
 {
25 25
 
26
-    const ee_api_namespace = Domain::API_NAMESPACE;
27
-
28
-    const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/';
29
-
30
-    const saved_routes_option_names = 'ee_core_routes';
31
-
32
-    /**
33
-     * string used in _links response bodies to make them globally unique.
34
-     *
35
-     * @see http://v2.wp-api.org/extending/linking/
36
-     */
37
-    const ee_api_link_namespace = 'https://api.eventespresso.com/';
38
-
39
-    /**
40
-     * @var CalculatedModelFields
41
-     */
42
-    protected static $_field_calculator;
43
-
44
-
45
-    /**
46
-     * @return EED_Core_Rest_Api|EED_Module
47
-     */
48
-    public static function instance()
49
-    {
50
-        self::$_field_calculator = LoaderFactory::getLoader()->load('EventEspresso\core\libraries\rest_api\CalculatedModelFields');
51
-        return parent::get_instance(__CLASS__);
52
-    }
53
-
54
-
55
-    /**
56
-     *    set_hooks - for hooking into EE Core, other modules, etc
57
-     *
58
-     * @access    public
59
-     * @return    void
60
-     */
61
-    public static function set_hooks()
62
-    {
63
-        self::set_hooks_both();
64
-    }
65
-
66
-
67
-    /**
68
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
69
-     *
70
-     * @access    public
71
-     * @return    void
72
-     */
73
-    public static function set_hooks_admin()
74
-    {
75
-        self::set_hooks_both();
76
-    }
77
-
78
-
79
-    public static function set_hooks_both()
80
-    {
81
-        add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10);
82
-        add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5);
83
-        add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2);
84
-        add_filter(
85
-            'rest_index',
86
-            array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex')
87
-        );
88
-        EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change();
89
-    }
90
-
91
-
92
-    /**
93
-     * sets up hooks which only need to be included as part of REST API requests;
94
-     * other requests like to the frontend or admin etc don't need them
95
-     *
96
-     * @throws \EE_Error
97
-     */
98
-    public static function set_hooks_rest_api()
99
-    {
100
-        // set hooks which account for changes made to the API
101
-        EED_Core_Rest_Api::_set_hooks_for_changes();
102
-    }
103
-
104
-
105
-    /**
106
-     * public wrapper of _set_hooks_for_changes.
107
-     * Loads all the hooks which make requests to old versions of the API
108
-     * appear the same as they always did
109
-     *
110
-     * @throws EE_Error
111
-     */
112
-    public static function set_hooks_for_changes()
113
-    {
114
-        self::_set_hooks_for_changes();
115
-    }
116
-
117
-
118
-    /**
119
-     * Loads all the hooks which make requests to old versions of the API
120
-     * appear the same as they always did
121
-     *
122
-     * @throws EE_Error
123
-     */
124
-    protected static function _set_hooks_for_changes()
125
-    {
126
-        $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false);
127
-        foreach ($folder_contents as $classname_in_namespace => $filepath) {
128
-            // ignore the base parent class
129
-            // and legacy named classes
130
-            if ($classname_in_namespace === 'ChangesInBase'
131
-                || strpos($classname_in_namespace, 'Changes_In_') === 0
132
-            ) {
133
-                continue;
134
-            }
135
-            $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
136
-            if (class_exists($full_classname)) {
137
-                $instance_of_class = new $full_classname;
138
-                if ($instance_of_class instanceof ChangesInBase) {
139
-                    $instance_of_class->setHooks();
140
-                }
141
-            }
142
-        }
143
-    }
144
-
145
-
146
-    /**
147
-     * Filters the WP routes to add our EE-related ones. This takes a bit of time
148
-     * so we actually prefer to only do it when an EE plugin is activated or upgraded
149
-     *
150
-     * @throws \EE_Error
151
-     */
152
-    public static function register_routes()
153
-    {
154
-        foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) {
155
-            foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) {
156
-                /**
157
-                 * @var array     $data_for_multiple_endpoints numerically indexed array
158
-                 *                                         but can also contain route options like {
159
-                 * @type array    $schema                      {
160
-                 * @type callable $schema_callback
161
-                 * @type array    $callback_args               arguments that will be passed to the callback, after the
162
-                 * WP_REST_Request of course
163
-                 * }
164
-                 * }
165
-                 */
166
-                // when registering routes, register all the endpoints' data at the same time
167
-                $multiple_endpoint_args = array();
168
-                foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) {
169
-                    /**
170
-                     * @var array     $data_for_single_endpoint {
171
-                     * @type callable $callback
172
-                     * @type string methods
173
-                     * @type array args
174
-                     * @type array _links
175
-                     * @type array    $callback_args            arguments that will be passed to the callback, after the
176
-                     * WP_REST_Request of course
177
-                     * }
178
-                     */
179
-                    // skip route options
180
-                    if (! is_numeric($endpoint_key)) {
181
-                        continue;
182
-                    }
183
-                    if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) {
184
-                        throw new EE_Error(
185
-                            esc_html__(
186
-                            // @codingStandardsIgnoreStart
187
-                                'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).',
188
-                                // @codingStandardsIgnoreEnd
189
-                                'event_espresso'
190
-                            )
191
-                        );
192
-                    }
193
-                    $callback = $data_for_single_endpoint['callback'];
194
-                    $single_endpoint_args = array(
195
-                        'methods' => $data_for_single_endpoint['methods'],
196
-                        'args'    => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args']
197
-                            : array(),
198
-                    );
199
-                    if (isset($data_for_single_endpoint['_links'])) {
200
-                        $single_endpoint_args['_links'] = $data_for_single_endpoint['_links'];
201
-                    }
202
-                    if (isset($data_for_single_endpoint['callback_args'])) {
203
-                        $callback_args = $data_for_single_endpoint['callback_args'];
204
-                        $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use (
205
-                            $callback,
206
-                            $callback_args
207
-                        ) {
208
-                            array_unshift($callback_args, $request);
209
-                            return call_user_func_array(
210
-                                $callback,
211
-                                $callback_args
212
-                            );
213
-                        };
214
-                    } else {
215
-                        $single_endpoint_args['callback'] = $data_for_single_endpoint['callback'];
216
-                    }
217
-                    $multiple_endpoint_args[] = $single_endpoint_args;
218
-                }
219
-                if (isset($data_for_multiple_endpoints['schema'])) {
220
-                    $schema_route_data = $data_for_multiple_endpoints['schema'];
221
-                    $schema_callback = $schema_route_data['schema_callback'];
222
-                    $callback_args = $schema_route_data['callback_args'];
223
-                    $multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) {
224
-                        return call_user_func_array(
225
-                            $schema_callback,
226
-                            $callback_args
227
-                        );
228
-                    };
229
-                }
230
-                register_rest_route(
231
-                    $namespace,
232
-                    $relative_route,
233
-                    $multiple_endpoint_args
234
-                );
235
-            }
236
-        }
237
-    }
238
-
239
-
240
-    /**
241
-     * Checks if there was a version change or something that merits invalidating the cached
242
-     * route data. If so, invalidates the cached route data so that it gets refreshed
243
-     * next time the WP API is used
244
-     */
245
-    public static function invalidate_cached_route_data_on_version_change()
246
-    {
247
-        if (EE_System::instance()->detect_req_type() !== EE_System::req_type_normal) {
248
-            EED_Core_Rest_Api::invalidate_cached_route_data();
249
-        }
250
-        foreach (EE_Registry::instance()->addons as $addon) {
251
-            if ($addon instanceof EE_Addon && $addon->detect_req_type() !== EE_System::req_type_normal) {
252
-                EED_Core_Rest_Api::invalidate_cached_route_data();
253
-            }
254
-        }
255
-    }
256
-
257
-
258
-    /**
259
-     * Removes the cached route data so it will get refreshed next time the WP API is used
260
-     */
261
-    public static function invalidate_cached_route_data()
262
-    {
263
-        // delete the saved EE REST API routes
264
-        foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
265
-            delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
266
-        }
267
-    }
268
-
269
-
270
-    /**
271
-     * Gets the EE route data
272
-     *
273
-     * @return array top-level key is the namespace, next-level key is the route and its value is array{
274
-     * @throws \EE_Error
275
-     * @type string|array $callback
276
-     * @type string       $methods
277
-     * @type boolean      $hidden_endpoint
278
-     * }
279
-     */
280
-    public static function get_ee_route_data()
281
-    {
282
-        $ee_routes = array();
283
-        foreach (self::versions_served() as $version => $hidden_endpoints) {
284
-            $ee_routes[ self::ee_api_namespace . $version ] = self::_get_ee_route_data_for_version(
285
-                $version,
286
-                $hidden_endpoints
287
-            );
288
-        }
289
-        return $ee_routes;
290
-    }
291
-
292
-
293
-    /**
294
-     * Gets the EE route data from the wp options if it exists already,
295
-     * otherwise re-generates it and saves it to the option
296
-     *
297
-     * @param string  $version
298
-     * @param boolean $hidden_endpoints
299
-     * @return array
300
-     * @throws \EE_Error
301
-     */
302
-    protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
303
-    {
304
-        $ee_routes = get_option(self::saved_routes_option_names . $version, null);
305
-        if (! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
306
-            $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
307
-        }
308
-        return $ee_routes;
309
-    }
310
-
311
-
312
-    /**
313
-     * Saves the EE REST API route data to a wp option and returns it
314
-     *
315
-     * @param string  $version
316
-     * @param boolean $hidden_endpoints
317
-     * @return mixed|null
318
-     * @throws \EE_Error
319
-     */
320
-    protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false)
321
-    {
322
-        $instance = self::instance();
323
-        $routes = apply_filters(
324
-            'EED_Core_Rest_Api__save_ee_route_data_for_version__routes',
325
-            array_replace_recursive(
326
-                $instance->_get_config_route_data_for_version($version, $hidden_endpoints),
327
-                $instance->_get_meta_route_data_for_version($version, $hidden_endpoints),
328
-                $instance->_get_model_route_data_for_version($version, $hidden_endpoints),
329
-                $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
330
-            )
331
-        );
332
-        $option_name = self::saved_routes_option_names . $version;
333
-        if (get_option($option_name)) {
334
-            update_option($option_name, $routes, true);
335
-        } else {
336
-            add_option($option_name, $routes, null, 'no');
337
-        }
338
-        return $routes;
339
-    }
340
-
341
-
342
-    /**
343
-     * Calculates all the EE routes and saves it to a WordPress option so we don't
344
-     * need to calculate it on every request
345
-     *
346
-     * @deprecated since version 4.9.1
347
-     * @return void
348
-     */
349
-    public static function save_ee_routes()
350
-    {
351
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
352
-            $instance = self::instance();
353
-            $routes = apply_filters(
354
-                'EED_Core_Rest_Api__save_ee_routes__routes',
355
-                array_replace_recursive(
356
-                    $instance->_register_config_routes(),
357
-                    $instance->_register_meta_routes(),
358
-                    $instance->_register_model_routes(),
359
-                    $instance->_register_rpc_routes()
360
-                )
361
-            );
362
-            update_option(self::saved_routes_option_names, $routes, true);
363
-        }
364
-    }
365
-
366
-
367
-    /**
368
-     * Gets all the route information relating to EE models
369
-     *
370
-     * @return array @see get_ee_route_data
371
-     * @deprecated since version 4.9.1
372
-     */
373
-    protected function _register_model_routes()
374
-    {
375
-        $model_routes = array();
376
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
377
-            $model_routes[ EED_Core_Rest_Api::ee_api_namespace
378
-                           . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
379
-        }
380
-        return $model_routes;
381
-    }
382
-
383
-
384
-    /**
385
-     * Decides whether or not to add write endpoints for this model.
386
-     *
387
-     * Currently, this defaults to exclude all global tables and models
388
-     * which would allow inserting WP core data (we don't want to duplicate
389
-     * what WP API does, as it's unnecessary, extra work, and potentially extra bugs)
390
-     *
391
-     * @param EEM_Base $model
392
-     * @return bool
393
-     */
394
-    public static function should_have_write_endpoints(EEM_Base $model)
395
-    {
396
-        if ($model->is_wp_core_model()) {
397
-            return false;
398
-        }
399
-        foreach ($model->get_tables() as $table) {
400
-            if ($table->is_global()) {
401
-                return false;
402
-            }
403
-        }
404
-        return true;
405
-    }
406
-
407
-
408
-    /**
409
-     * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`)
410
-     * in this versioned namespace of EE4
411
-     *
412
-     * @param $version
413
-     * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event')
414
-     */
415
-    public static function model_names_with_plural_routes($version)
416
-    {
417
-        $model_version_info = new ModelVersionInfo($version);
418
-        $models_to_register = $model_version_info->modelsForRequestedVersion();
419
-        // let's not bother having endpoints for extra metas
420
-        unset(
421
-            $models_to_register['Extra_Meta'],
422
-            $models_to_register['Extra_Join'],
423
-            $models_to_register['Post_Meta']
424
-        );
425
-        return apply_filters(
426
-            'FHEE__EED_Core_REST_API___register_model_routes',
427
-            $models_to_register
428
-        );
429
-    }
430
-
431
-
432
-    /**
433
-     * Gets the route data for EE models in the specified version
434
-     *
435
-     * @param string  $version
436
-     * @param boolean $hidden_endpoint
437
-     * @return array
438
-     * @throws EE_Error
439
-     */
440
-    protected function _get_model_route_data_for_version($version, $hidden_endpoint = false)
441
-    {
442
-        $model_routes = array();
443
-        $model_version_info = new ModelVersionInfo($version);
444
-        foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) {
445
-            $model = \EE_Registry::instance()->load_model($model_name);
446
-            // if this isn't a valid model then let's skip iterate to the next item in the loop.
447
-            if (! $model instanceof EEM_Base) {
448
-                continue;
449
-            }
450
-            // yes we could just register one route for ALL models, but then they wouldn't show up in the index
451
-            $plural_model_route = EED_Core_Rest_Api::get_collection_route($model);
452
-            $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)');
453
-            $model_routes[ $plural_model_route ] = array(
454
-                array(
455
-                    'callback'        => array(
456
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
457
-                        'handleRequestGetAll',
458
-                    ),
459
-                    'callback_args'   => array($version, $model_name),
460
-                    'methods'         => WP_REST_Server::READABLE,
461
-                    'hidden_endpoint' => $hidden_endpoint,
462
-                    'args'            => $this->_get_read_query_params($model, $version),
463
-                    '_links'          => array(
464
-                        'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
465
-                    ),
466
-                ),
467
-                'schema' => array(
468
-                    'schema_callback' => array(
469
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
470
-                        'handleSchemaRequest',
471
-                    ),
472
-                    'callback_args'   => array($version, $model_name),
473
-                ),
474
-            );
475
-            $model_routes[ $singular_model_route ] = array(
476
-                array(
477
-                    'callback'        => array(
478
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
479
-                        'handleRequestGetOne',
480
-                    ),
481
-                    'callback_args'   => array($version, $model_name),
482
-                    'methods'         => WP_REST_Server::READABLE,
483
-                    'hidden_endpoint' => $hidden_endpoint,
484
-                    'args'            => $this->_get_response_selection_query_params($model, $version),
485
-                ),
486
-            );
487
-            if (apply_filters(
488
-                'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints',
489
-                EED_Core_Rest_Api::should_have_write_endpoints($model),
490
-                $model
491
-            )) {
492
-                $model_routes[ $plural_model_route ][] = array(
493
-                    'callback'        => array(
494
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Write',
495
-                        'handleRequestInsert',
496
-                    ),
497
-                    'callback_args'   => array($version, $model_name),
498
-                    'methods'         => WP_REST_Server::CREATABLE,
499
-                    'hidden_endpoint' => $hidden_endpoint,
500
-                    'args'            => $this->_get_write_params($model_name, $model_version_info, true),
501
-                );
502
-                $model_routes[ $singular_model_route ] = array_merge(
503
-                    $model_routes[ $singular_model_route ],
504
-                    array(
505
-                        array(
506
-                            'callback'        => array(
507
-                                'EventEspresso\core\libraries\rest_api\controllers\model\Write',
508
-                                'handleRequestUpdate',
509
-                            ),
510
-                            'callback_args'   => array($version, $model_name),
511
-                            'methods'         => WP_REST_Server::EDITABLE,
512
-                            'hidden_endpoint' => $hidden_endpoint,
513
-                            'args'            => $this->_get_write_params($model_name, $model_version_info),
514
-                        ),
515
-                        array(
516
-                            'callback'        => array(
517
-                                'EventEspresso\core\libraries\rest_api\controllers\model\Write',
518
-                                'handleRequestDelete',
519
-                            ),
520
-                            'callback_args'   => array($version, $model_name),
521
-                            'methods'         => WP_REST_Server::DELETABLE,
522
-                            'hidden_endpoint' => $hidden_endpoint,
523
-                            'args'            => $this->_get_delete_query_params($model, $version),
524
-                        ),
525
-                    )
526
-                );
527
-            }
528
-            foreach ($model->relation_settings() as $relation_name => $relation_obj) {
529
-                $related_route = EED_Core_Rest_Api::get_relation_route_via(
530
-                    $model,
531
-                    '(?P<id>[^\/]+)',
532
-                    $relation_obj
533
-                );
534
-                $endpoints = array(
535
-                    array(
536
-                        'callback'        => array(
537
-                            'EventEspresso\core\libraries\rest_api\controllers\model\Read',
538
-                            'handleRequestGetRelated',
539
-                        ),
540
-                        'callback_args'   => array($version, $model_name, $relation_name),
541
-                        'methods'         => WP_REST_Server::READABLE,
542
-                        'hidden_endpoint' => $hidden_endpoint,
543
-                        'args'            => $this->_get_read_query_params($relation_obj->get_other_model(), $version),
544
-                    ),
545
-                );
546
-                $model_routes[ $related_route ] = $endpoints;
547
-            }
548
-        }
549
-        return $model_routes;
550
-    }
551
-
552
-
553
-    /**
554
-     * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace,
555
-     * excluding the preceding slash.
556
-     * Eg you pass get_plural_route_to('Event') = 'events'
557
-     *
558
-     * @param EEM_Base $model
559
-     * @return string
560
-     */
561
-    public static function get_collection_route(EEM_Base $model)
562
-    {
563
-        return EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
564
-    }
565
-
566
-
567
-    /**
568
-     * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace,
569
-     * excluding the preceding slash.
570
-     * Eg you pass get_plural_route_to('Event', 12) = 'events/12'
571
-     *
572
-     * @param EEM_Base $model eg Event or Venue
573
-     * @param string   $id
574
-     * @return string
575
-     */
576
-    public static function get_entity_route($model, $id)
577
-    {
578
-        return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id;
579
-    }
580
-
581
-
582
-    /**
583
-     * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace,
584
-     * excluding the preceding slash.
585
-     * Eg you pass get_plural_route_to('Event', 12) = 'events/12'
586
-     *
587
-     * @param EEM_Base               $model eg Event or Venue
588
-     * @param string                 $id
589
-     * @param EE_Model_Relation_Base $relation_obj
590
-     * @return string
591
-     */
592
-    public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj)
593
-    {
594
-        $related_model_name_endpoint_part = ModelRead::getRelatedEntityName(
595
-            $relation_obj->get_other_model()->get_this_model_name(),
596
-            $relation_obj
597
-        );
598
-        return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part;
599
-    }
600
-
601
-
602
-    /**
603
-     * Adds onto the $relative_route the EE4 REST API versioned namespace.
604
-     * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events'
605
-     *
606
-     * @param string $relative_route
607
-     * @param string $version
608
-     * @return string
609
-     */
610
-    public static function get_versioned_route_to($relative_route, $version = '4.8.36')
611
-    {
612
-        return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route;
613
-    }
614
-
615
-
616
-    /**
617
-     * Adds all the RPC-style routes (remote procedure call-like routes, ie
618
-     * routes that don't conform to the traditional REST CRUD-style).
619
-     *
620
-     * @deprecated since 4.9.1
621
-     */
622
-    protected function _register_rpc_routes()
623
-    {
624
-        $routes = array();
625
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
626
-            $routes[ self::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version(
627
-                $version,
628
-                $hidden_endpoint
629
-            );
630
-        }
631
-        return $routes;
632
-    }
633
-
634
-
635
-    /**
636
-     * @param string  $version
637
-     * @param boolean $hidden_endpoint
638
-     * @return array
639
-     */
640
-    protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false)
641
-    {
642
-        $this_versions_routes = array();
643
-        // checkin endpoint
644
-        $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array(
645
-            array(
646
-                'callback'        => array(
647
-                    'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin',
648
-                    'handleRequestToggleCheckin',
649
-                ),
650
-                'methods'         => WP_REST_Server::CREATABLE,
651
-                'hidden_endpoint' => $hidden_endpoint,
652
-                'args'            => array(
653
-                    'force' => array(
654
-                        'required'    => false,
655
-                        'default'     => false,
656
-                        'description' => __(
657
-                        // @codingStandardsIgnoreStart
658
-                            'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses',
659
-                            // @codingStandardsIgnoreEnd
660
-                            'event_espresso'
661
-                        ),
662
-                    ),
663
-                ),
664
-                'callback_args'   => array($version),
665
-            ),
666
-        );
667
-        return apply_filters(
668
-            'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes',
669
-            $this_versions_routes,
670
-            $version,
671
-            $hidden_endpoint
672
-        );
673
-    }
674
-
675
-
676
-    /**
677
-     * Gets the query params that can be used when request one or many
678
-     *
679
-     * @param EEM_Base $model
680
-     * @param string   $version
681
-     * @return array
682
-     */
683
-    protected function _get_response_selection_query_params(\EEM_Base $model, $version)
684
-    {
685
-        return apply_filters(
686
-            'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
687
-            array(
688
-                'include'   => array(
689
-                    'required' => false,
690
-                    'default'  => '*',
691
-                    'type'     => 'string',
692
-                ),
693
-                'calculate' => array(
694
-                    'required'          => false,
695
-                    'default'           => '',
696
-                    'enum'              => self::$_field_calculator->retrieveCalculatedFieldsForModel($model),
697
-                    'type'              => 'string',
698
-                    // because we accept a CSV'd list of the enumerated strings, WP core validation and sanitization
699
-                    // freaks out. We'll just validate this argument while handling the request
700
-                    'validate_callback' => null,
701
-                    'sanitize_callback' => null,
702
-                ),
703
-            ),
704
-            $model,
705
-            $version
706
-        );
707
-    }
708
-
709
-
710
-    /**
711
-     * Gets the parameters acceptable for delete requests
712
-     *
713
-     * @param \EEM_Base $model
714
-     * @param string    $version
715
-     * @return array
716
-     */
717
-    protected function _get_delete_query_params(\EEM_Base $model, $version)
718
-    {
719
-        $params_for_delete = array(
720
-            'allow_blocking' => array(
721
-                'required' => false,
722
-                'default'  => true,
723
-                'type'     => 'boolean',
724
-            ),
725
-        );
726
-        $params_for_delete['force'] = array(
727
-            'required' => false,
728
-            'default'  => false,
729
-            'type'     => 'boolean',
730
-        );
731
-        return apply_filters(
732
-            'FHEE__EED_Core_Rest_Api___get_delete_query_params',
733
-            $params_for_delete,
734
-            $model,
735
-            $version
736
-        );
737
-    }
738
-
739
-
740
-    /**
741
-     * Gets info about reading query params that are acceptable
742
-     *
743
-     * @param \EEM_Base $model eg 'Event' or 'Venue'
744
-     * @param  string   $version
745
-     * @return array    describing the args acceptable when querying this model
746
-     * @throws EE_Error
747
-     */
748
-    protected function _get_read_query_params(\EEM_Base $model, $version)
749
-    {
750
-        $default_orderby = array();
751
-        foreach ($model->get_combined_primary_key_fields() as $key_field) {
752
-            $default_orderby[ $key_field->get_name() ] = 'ASC';
753
-        }
754
-        return array_merge(
755
-            $this->_get_response_selection_query_params($model, $version),
756
-            array(
757
-                'where'    => array(
758
-                    'required'          => false,
759
-                    'default'           => array(),
760
-                    'type'              => 'object',
761
-                    // because we accept an almost infinite list of possible where conditions, WP
762
-                    // core validation and sanitization freaks out. We'll just validate this argument
763
-                    // while handling the request
764
-                    'validate_callback' => null,
765
-                    'sanitize_callback' => null,
766
-                ),
767
-                'limit'    => array(
768
-                    'required'          => false,
769
-                    'default'           => EED_Core_Rest_Api::get_default_query_limit(),
770
-                    'type'              => array(
771
-                        'array',
772
-                        'string',
773
-                        'integer',
774
-                    ),
775
-                    // because we accept a variety of types, WP core validation and sanitization
776
-                    // freaks out. We'll just validate this argument while handling the request
777
-                    'validate_callback' => null,
778
-                    'sanitize_callback' => null,
779
-                ),
780
-                'order_by' => array(
781
-                    'required'          => false,
782
-                    'default'           => $default_orderby,
783
-                    'type'              => array(
784
-                        'object',
785
-                        'string',
786
-                    ),// because we accept a variety of types, WP core validation and sanitization
787
-                    // freaks out. We'll just validate this argument while handling the request
788
-                    'validate_callback' => null,
789
-                    'sanitize_callback' => null,
790
-                ),
791
-                'group_by' => array(
792
-                    'required'          => false,
793
-                    'default'           => null,
794
-                    'type'              => array(
795
-                        'object',
796
-                        'string',
797
-                    ),
798
-                    // because we accept  an almost infinite list of possible groupings,
799
-                    // WP core validation and sanitization
800
-                    // freaks out. We'll just validate this argument while handling the request
801
-                    'validate_callback' => null,
802
-                    'sanitize_callback' => null,
803
-                ),
804
-                'having'   => array(
805
-                    'required'          => false,
806
-                    'default'           => null,
807
-                    'type'              => 'object',
808
-                    // because we accept an almost infinite list of possible where conditions, WP
809
-                    // core validation and sanitization freaks out. We'll just validate this argument
810
-                    // while handling the request
811
-                    'validate_callback' => null,
812
-                    'sanitize_callback' => null,
813
-                ),
814
-                'caps'     => array(
815
-                    'required' => false,
816
-                    'default'  => EEM_Base::caps_read,
817
-                    'type'     => 'string',
818
-                    'enum'     => array(
819
-                        EEM_Base::caps_read,
820
-                        EEM_Base::caps_read_admin,
821
-                        EEM_Base::caps_edit,
822
-                        EEM_Base::caps_delete,
823
-                    ),
824
-                ),
825
-            )
826
-        );
827
-    }
828
-
829
-
830
-    /**
831
-     * Gets parameter information for a model regarding writing data
832
-     *
833
-     * @param string           $model_name
834
-     * @param ModelVersionInfo $model_version_info
835
-     * @param boolean          $create                                       whether this is for request to create (in
836
-     *                                                                       which case we need all required params) or
837
-     *                                                                       just to update (in which case we don't
838
-     *                                                                       need those on every request)
839
-     * @return array
840
-     */
841
-    protected function _get_write_params(
842
-        $model_name,
843
-        ModelVersionInfo $model_version_info,
844
-        $create = false
845
-    ) {
846
-        $model = EE_Registry::instance()->load_model($model_name);
847
-        $fields = $model_version_info->fieldsOnModelInThisVersion($model);
848
-        $args_info = array();
849
-        foreach ($fields as $field_name => $field_obj) {
850
-            if ($field_obj->is_auto_increment()) {
851
-                // totally ignore auto increment IDs
852
-                continue;
853
-            }
854
-            $arg_info = $field_obj->getSchema();
855
-            $required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null;
856
-            $arg_info['required'] = $required;
857
-            // remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right?
858
-            unset($arg_info['readonly']);
859
-            $schema_properties = $field_obj->getSchemaProperties();
860
-            if (isset($schema_properties['raw'])
861
-                && $field_obj->getSchemaType() === 'object'
862
-            ) {
863
-                // if there's a "raw" form of this argument, use those properties instead
864
-                $arg_info = array_replace(
865
-                    $arg_info,
866
-                    $schema_properties['raw']
867
-                );
868
-            }
869
-            $arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson(
870
-                $field_obj,
871
-                $field_obj->get_default_value(),
872
-                $model_version_info->requestedVersion()
873
-            );
874
-            // we do our own validation and sanitization within the controller
875
-            if (function_exists('rest_validate_value_from_schema')) {
876
-                $sanitize_callback = array(
877
-                    'EED_Core_Rest_Api',
878
-                    'default_sanitize_callback',
879
-                );
880
-            } else {
881
-                $sanitize_callback = null;
882
-            }
883
-            $arg_info['sanitize_callback'] = $sanitize_callback;
884
-            $args_info[ $field_name ] = $arg_info;
885
-            if ($field_obj instanceof EE_Datetime_Field) {
886
-                $gmt_arg_info = $arg_info;
887
-                $gmt_arg_info['description'] = sprintf(
888
-                    esc_html__(
889
-                        '%1$s - the value for this field in UTC. Ignored if %2$s is provided.',
890
-                        'event_espresso'
891
-                    ),
892
-                    $field_obj->get_nicename(),
893
-                    $field_name
894
-                );
895
-                $args_info[ $field_name . '_gmt' ] = $gmt_arg_info;
896
-            }
897
-        }
898
-        return $args_info;
899
-    }
900
-
901
-
902
-    /**
903
-     * Replacement for WP API's 'rest_parse_request_arg'.
904
-     * If the value is blank but not required, don't bother validating it.
905
-     * Also, it uses our email validation instead of WP API's default.
906
-     *
907
-     * @param                 $value
908
-     * @param WP_REST_Request $request
909
-     * @param                 $param
910
-     * @return bool|true|WP_Error
911
-     * @throws InvalidArgumentException
912
-     * @throws InvalidInterfaceException
913
-     * @throws InvalidDataTypeException
914
-     */
915
-    public static function default_sanitize_callback($value, WP_REST_Request $request, $param)
916
-    {
917
-        $attributes = $request->get_attributes();
918
-        if (! isset($attributes['args'][ $param ])
919
-            || ! is_array($attributes['args'][ $param ])) {
920
-            $validation_result = true;
921
-        } else {
922
-            $args = $attributes['args'][ $param ];
923
-            if ((
924
-                    $value === ''
925
-                    || $value === null
926
-                )
927
-                && (! isset($args['required'])
928
-                    || $args['required'] === false
929
-                )
930
-            ) {
931
-                // not required and not provided? that's cool
932
-                $validation_result = true;
933
-            } elseif (isset($args['format'])
934
-                      && $args['format'] === 'email'
935
-            ) {
936
-                $validation_result = true;
937
-                if (! self::_validate_email($value)) {
938
-                    $validation_result = new WP_Error(
939
-                        'rest_invalid_param',
940
-                        esc_html__(
941
-                            'The email address is not valid or does not exist.',
942
-                            'event_espresso'
943
-                        )
944
-                    );
945
-                }
946
-            } else {
947
-                $validation_result = rest_validate_value_from_schema($value, $args, $param);
948
-            }
949
-        }
950
-        if (is_wp_error($validation_result)) {
951
-            return $validation_result;
952
-        }
953
-        return rest_sanitize_request_arg($value, $request, $param);
954
-    }
955
-
956
-
957
-    /**
958
-     * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email()
959
-     *
960
-     * @param $email
961
-     * @return bool
962
-     * @throws InvalidArgumentException
963
-     * @throws InvalidInterfaceException
964
-     * @throws InvalidDataTypeException
965
-     */
966
-    protected static function _validate_email($email)
967
-    {
968
-        try {
969
-            EmailAddressFactory::create($email);
970
-            return true;
971
-        } catch (EmailValidationException $e) {
972
-            return false;
973
-        }
974
-    }
975
-
976
-
977
-    /**
978
-     * Gets routes for the config
979
-     *
980
-     * @return array @see _register_model_routes
981
-     * @deprecated since version 4.9.1
982
-     */
983
-    protected function _register_config_routes()
984
-    {
985
-        $config_routes = array();
986
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
987
-            $config_routes[ self::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version(
988
-                $version,
989
-                $hidden_endpoint
990
-            );
991
-        }
992
-        return $config_routes;
993
-    }
994
-
995
-
996
-    /**
997
-     * Gets routes for the config for the specified version
998
-     *
999
-     * @param string  $version
1000
-     * @param boolean $hidden_endpoint
1001
-     * @return array
1002
-     */
1003
-    protected function _get_config_route_data_for_version($version, $hidden_endpoint)
1004
-    {
1005
-        return array(
1006
-            'config'    => array(
1007
-                array(
1008
-                    'callback'        => array(
1009
-                        'EventEspresso\core\libraries\rest_api\controllers\config\Read',
1010
-                        'handleRequest',
1011
-                    ),
1012
-                    'methods'         => WP_REST_Server::READABLE,
1013
-                    'hidden_endpoint' => $hidden_endpoint,
1014
-                    'callback_args'   => array($version),
1015
-                ),
1016
-            ),
1017
-            'site_info' => array(
1018
-                array(
1019
-                    'callback'        => array(
1020
-                        'EventEspresso\core\libraries\rest_api\controllers\config\Read',
1021
-                        'handleRequestSiteInfo',
1022
-                    ),
1023
-                    'methods'         => WP_REST_Server::READABLE,
1024
-                    'hidden_endpoint' => $hidden_endpoint,
1025
-                    'callback_args'   => array($version),
1026
-                ),
1027
-            ),
1028
-        );
1029
-    }
1030
-
1031
-
1032
-    /**
1033
-     * Gets the meta info routes
1034
-     *
1035
-     * @return array @see _register_model_routes
1036
-     * @deprecated since version 4.9.1
1037
-     */
1038
-    protected function _register_meta_routes()
1039
-    {
1040
-        $meta_routes = array();
1041
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
1042
-            $meta_routes[ self::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version(
1043
-                $version,
1044
-                $hidden_endpoint
1045
-            );
1046
-        }
1047
-        return $meta_routes;
1048
-    }
1049
-
1050
-
1051
-    /**
1052
-     * @param string  $version
1053
-     * @param boolean $hidden_endpoint
1054
-     * @return array
1055
-     */
1056
-    protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false)
1057
-    {
1058
-        return array(
1059
-            'resources' => array(
1060
-                array(
1061
-                    'callback'        => array(
1062
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Meta',
1063
-                        'handleRequestModelsMeta',
1064
-                    ),
1065
-                    'methods'         => WP_REST_Server::READABLE,
1066
-                    'hidden_endpoint' => $hidden_endpoint,
1067
-                    'callback_args'   => array($version),
1068
-                ),
1069
-            ),
1070
-        );
1071
-    }
1072
-
1073
-
1074
-    /**
1075
-     * Tries to hide old 4.6 endpoints from the
1076
-     *
1077
-     * @param array $route_data
1078
-     * @return array
1079
-     * @throws \EE_Error
1080
-     */
1081
-    public static function hide_old_endpoints($route_data)
1082
-    {
1083
-        // allow API clients to override which endpoints get hidden, in case
1084
-        // they want to discover particular endpoints
1085
-        // also, we don't have access to the request so we have to just grab it from the superglobal
1086
-        $force_show_ee_namespace = ltrim(
1087
-            EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''),
1088
-            '/'
1089
-        );
1090
-        foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
1091
-            foreach ($relative_urls as $resource_name => $endpoints) {
1092
-                foreach ($endpoints as $key => $endpoint) {
1093
-                    // skip schema and other route options
1094
-                    if (! is_numeric($key)) {
1095
-                        continue;
1096
-                    }
1097
-                    // by default, hide "hidden_endpoint"s, unless the request indicates
1098
-                    // to $force_show_ee_namespace, in which case only show that one
1099
-                    // namespace's endpoints (and hide all others)
1100
-                    if (($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
1101
-                        || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '')
1102
-                    ) {
1103
-                        $full_route = '/' . ltrim($namespace, '/');
1104
-                        $full_route .= '/' . ltrim($resource_name, '/');
1105
-                        unset($route_data[ $full_route ]);
1106
-                    }
1107
-                }
1108
-            }
1109
-        }
1110
-        return $route_data;
1111
-    }
1112
-
1113
-
1114
-    /**
1115
-     * Returns an array describing which versions of core support serving requests for.
1116
-     * Keys are core versions' major and minor version, and values are the
1117
-     * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like
1118
-     * data by just removing a few models and fields from the responses. However, 4.15 might remove
1119
-     * the answers table entirely, in which case it would be very difficult for
1120
-     * it to serve 4.6-style responses.
1121
-     * Versions of core that are missing from this array are unknowns.
1122
-     * previous ver
1123
-     *
1124
-     * @return array
1125
-     */
1126
-    public static function version_compatibilities()
1127
-    {
1128
-        return apply_filters(
1129
-            'FHEE__EED_Core_REST_API__version_compatibilities',
1130
-            array(
1131
-                '4.8.29' => '4.8.29',
1132
-                '4.8.33' => '4.8.29',
1133
-                '4.8.34' => '4.8.29',
1134
-                '4.8.36' => '4.8.29',
1135
-            )
1136
-        );
1137
-    }
1138
-
1139
-
1140
-    /**
1141
-     * Gets the latest API version served. Eg if there
1142
-     * are two versions served of the API, 4.8.29 and 4.8.32, and
1143
-     * we are on core version 4.8.34, it will return the string "4.8.32"
1144
-     *
1145
-     * @return string
1146
-     */
1147
-    public static function latest_rest_api_version()
1148
-    {
1149
-        $versions_served = \EED_Core_Rest_Api::versions_served();
1150
-        $versions_served_keys = array_keys($versions_served);
1151
-        return end($versions_served_keys);
1152
-    }
1153
-
1154
-
1155
-    /**
1156
-     * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of
1157
-     * EE the API can serve requests for. Eg, if we are on 4.15 of core, and
1158
-     * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ).
1159
-     * We also indicate whether or not this version should be put in the index or not
1160
-     *
1161
-     * @return array keys are API version numbers (just major and minor numbers), and values
1162
-     * are whether or not they should be hidden
1163
-     */
1164
-    public static function versions_served()
1165
-    {
1166
-        $versions_served = array();
1167
-        $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities();
1168
-        $lowest_compatible_version = end($possibly_served_versions);
1169
-        reset($possibly_served_versions);
1170
-        $versions_served_historically = array_keys($possibly_served_versions);
1171
-        $latest_version = end($versions_served_historically);
1172
-        reset($versions_served_historically);
1173
-        // for each version of core we have ever served:
1174
-        foreach ($versions_served_historically as $key_versioned_endpoint) {
1175
-            // if it's not above the current core version, and it's compatible with the current version of core
1176
-            if ($key_versioned_endpoint === $latest_version) {
1177
-                // don't hide the latest version in the index
1178
-                $versions_served[ $key_versioned_endpoint ] = false;
1179
-            } elseif ($key_versioned_endpoint >= $lowest_compatible_version
1180
-                && $key_versioned_endpoint < EED_Core_Rest_Api::core_version()
1181
-            ) {
1182
-                // include, but hide, previous versions which are still supported
1183
-                $versions_served[ $key_versioned_endpoint ] = true;
1184
-            } elseif (apply_filters(
1185
-                'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions',
1186
-                false,
1187
-                $possibly_served_versions
1188
-            )) {
1189
-                // if a version is no longer supported, don't include it in index or list of versions served
1190
-                $versions_served[ $key_versioned_endpoint ] = true;
1191
-            }
1192
-        }
1193
-        return $versions_served;
1194
-    }
1195
-
1196
-
1197
-    /**
1198
-     * Gets the major and minor version of EE core's version string
1199
-     *
1200
-     * @return string
1201
-     */
1202
-    public static function core_version()
1203
-    {
1204
-        return apply_filters(
1205
-            'FHEE__EED_Core_REST_API__core_version',
1206
-            implode(
1207
-                '.',
1208
-                array_slice(
1209
-                    explode(
1210
-                        '.',
1211
-                        espresso_version()
1212
-                    ),
1213
-                    0,
1214
-                    3
1215
-                )
1216
-            )
1217
-        );
1218
-    }
1219
-
1220
-
1221
-    /**
1222
-     * Gets the default limit that should be used when querying for resources
1223
-     *
1224
-     * @return int
1225
-     */
1226
-    public static function get_default_query_limit()
1227
-    {
1228
-        // we actually don't use a const because we want folks to always use
1229
-        // this method, not the const directly
1230
-        return apply_filters(
1231
-            'FHEE__EED_Core_Rest_Api__get_default_query_limit',
1232
-            50
1233
-        );
1234
-    }
1235
-
1236
-
1237
-    /**
1238
-     *    run - initial module setup
1239
-     *
1240
-     * @access    public
1241
-     * @param  WP $WP
1242
-     * @return    void
1243
-     */
1244
-    public function run($WP)
1245
-    {
1246
-    }
26
+	const ee_api_namespace = Domain::API_NAMESPACE;
27
+
28
+	const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/';
29
+
30
+	const saved_routes_option_names = 'ee_core_routes';
31
+
32
+	/**
33
+	 * string used in _links response bodies to make them globally unique.
34
+	 *
35
+	 * @see http://v2.wp-api.org/extending/linking/
36
+	 */
37
+	const ee_api_link_namespace = 'https://api.eventespresso.com/';
38
+
39
+	/**
40
+	 * @var CalculatedModelFields
41
+	 */
42
+	protected static $_field_calculator;
43
+
44
+
45
+	/**
46
+	 * @return EED_Core_Rest_Api|EED_Module
47
+	 */
48
+	public static function instance()
49
+	{
50
+		self::$_field_calculator = LoaderFactory::getLoader()->load('EventEspresso\core\libraries\rest_api\CalculatedModelFields');
51
+		return parent::get_instance(__CLASS__);
52
+	}
53
+
54
+
55
+	/**
56
+	 *    set_hooks - for hooking into EE Core, other modules, etc
57
+	 *
58
+	 * @access    public
59
+	 * @return    void
60
+	 */
61
+	public static function set_hooks()
62
+	{
63
+		self::set_hooks_both();
64
+	}
65
+
66
+
67
+	/**
68
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
69
+	 *
70
+	 * @access    public
71
+	 * @return    void
72
+	 */
73
+	public static function set_hooks_admin()
74
+	{
75
+		self::set_hooks_both();
76
+	}
77
+
78
+
79
+	public static function set_hooks_both()
80
+	{
81
+		add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10);
82
+		add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5);
83
+		add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2);
84
+		add_filter(
85
+			'rest_index',
86
+			array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex')
87
+		);
88
+		EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change();
89
+	}
90
+
91
+
92
+	/**
93
+	 * sets up hooks which only need to be included as part of REST API requests;
94
+	 * other requests like to the frontend or admin etc don't need them
95
+	 *
96
+	 * @throws \EE_Error
97
+	 */
98
+	public static function set_hooks_rest_api()
99
+	{
100
+		// set hooks which account for changes made to the API
101
+		EED_Core_Rest_Api::_set_hooks_for_changes();
102
+	}
103
+
104
+
105
+	/**
106
+	 * public wrapper of _set_hooks_for_changes.
107
+	 * Loads all the hooks which make requests to old versions of the API
108
+	 * appear the same as they always did
109
+	 *
110
+	 * @throws EE_Error
111
+	 */
112
+	public static function set_hooks_for_changes()
113
+	{
114
+		self::_set_hooks_for_changes();
115
+	}
116
+
117
+
118
+	/**
119
+	 * Loads all the hooks which make requests to old versions of the API
120
+	 * appear the same as they always did
121
+	 *
122
+	 * @throws EE_Error
123
+	 */
124
+	protected static function _set_hooks_for_changes()
125
+	{
126
+		$folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false);
127
+		foreach ($folder_contents as $classname_in_namespace => $filepath) {
128
+			// ignore the base parent class
129
+			// and legacy named classes
130
+			if ($classname_in_namespace === 'ChangesInBase'
131
+				|| strpos($classname_in_namespace, 'Changes_In_') === 0
132
+			) {
133
+				continue;
134
+			}
135
+			$full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
136
+			if (class_exists($full_classname)) {
137
+				$instance_of_class = new $full_classname;
138
+				if ($instance_of_class instanceof ChangesInBase) {
139
+					$instance_of_class->setHooks();
140
+				}
141
+			}
142
+		}
143
+	}
144
+
145
+
146
+	/**
147
+	 * Filters the WP routes to add our EE-related ones. This takes a bit of time
148
+	 * so we actually prefer to only do it when an EE plugin is activated or upgraded
149
+	 *
150
+	 * @throws \EE_Error
151
+	 */
152
+	public static function register_routes()
153
+	{
154
+		foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) {
155
+			foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) {
156
+				/**
157
+				 * @var array     $data_for_multiple_endpoints numerically indexed array
158
+				 *                                         but can also contain route options like {
159
+				 * @type array    $schema                      {
160
+				 * @type callable $schema_callback
161
+				 * @type array    $callback_args               arguments that will be passed to the callback, after the
162
+				 * WP_REST_Request of course
163
+				 * }
164
+				 * }
165
+				 */
166
+				// when registering routes, register all the endpoints' data at the same time
167
+				$multiple_endpoint_args = array();
168
+				foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) {
169
+					/**
170
+					 * @var array     $data_for_single_endpoint {
171
+					 * @type callable $callback
172
+					 * @type string methods
173
+					 * @type array args
174
+					 * @type array _links
175
+					 * @type array    $callback_args            arguments that will be passed to the callback, after the
176
+					 * WP_REST_Request of course
177
+					 * }
178
+					 */
179
+					// skip route options
180
+					if (! is_numeric($endpoint_key)) {
181
+						continue;
182
+					}
183
+					if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) {
184
+						throw new EE_Error(
185
+							esc_html__(
186
+							// @codingStandardsIgnoreStart
187
+								'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).',
188
+								// @codingStandardsIgnoreEnd
189
+								'event_espresso'
190
+							)
191
+						);
192
+					}
193
+					$callback = $data_for_single_endpoint['callback'];
194
+					$single_endpoint_args = array(
195
+						'methods' => $data_for_single_endpoint['methods'],
196
+						'args'    => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args']
197
+							: array(),
198
+					);
199
+					if (isset($data_for_single_endpoint['_links'])) {
200
+						$single_endpoint_args['_links'] = $data_for_single_endpoint['_links'];
201
+					}
202
+					if (isset($data_for_single_endpoint['callback_args'])) {
203
+						$callback_args = $data_for_single_endpoint['callback_args'];
204
+						$single_endpoint_args['callback'] = function (\WP_REST_Request $request) use (
205
+							$callback,
206
+							$callback_args
207
+						) {
208
+							array_unshift($callback_args, $request);
209
+							return call_user_func_array(
210
+								$callback,
211
+								$callback_args
212
+							);
213
+						};
214
+					} else {
215
+						$single_endpoint_args['callback'] = $data_for_single_endpoint['callback'];
216
+					}
217
+					$multiple_endpoint_args[] = $single_endpoint_args;
218
+				}
219
+				if (isset($data_for_multiple_endpoints['schema'])) {
220
+					$schema_route_data = $data_for_multiple_endpoints['schema'];
221
+					$schema_callback = $schema_route_data['schema_callback'];
222
+					$callback_args = $schema_route_data['callback_args'];
223
+					$multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) {
224
+						return call_user_func_array(
225
+							$schema_callback,
226
+							$callback_args
227
+						);
228
+					};
229
+				}
230
+				register_rest_route(
231
+					$namespace,
232
+					$relative_route,
233
+					$multiple_endpoint_args
234
+				);
235
+			}
236
+		}
237
+	}
238
+
239
+
240
+	/**
241
+	 * Checks if there was a version change or something that merits invalidating the cached
242
+	 * route data. If so, invalidates the cached route data so that it gets refreshed
243
+	 * next time the WP API is used
244
+	 */
245
+	public static function invalidate_cached_route_data_on_version_change()
246
+	{
247
+		if (EE_System::instance()->detect_req_type() !== EE_System::req_type_normal) {
248
+			EED_Core_Rest_Api::invalidate_cached_route_data();
249
+		}
250
+		foreach (EE_Registry::instance()->addons as $addon) {
251
+			if ($addon instanceof EE_Addon && $addon->detect_req_type() !== EE_System::req_type_normal) {
252
+				EED_Core_Rest_Api::invalidate_cached_route_data();
253
+			}
254
+		}
255
+	}
256
+
257
+
258
+	/**
259
+	 * Removes the cached route data so it will get refreshed next time the WP API is used
260
+	 */
261
+	public static function invalidate_cached_route_data()
262
+	{
263
+		// delete the saved EE REST API routes
264
+		foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
265
+			delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
266
+		}
267
+	}
268
+
269
+
270
+	/**
271
+	 * Gets the EE route data
272
+	 *
273
+	 * @return array top-level key is the namespace, next-level key is the route and its value is array{
274
+	 * @throws \EE_Error
275
+	 * @type string|array $callback
276
+	 * @type string       $methods
277
+	 * @type boolean      $hidden_endpoint
278
+	 * }
279
+	 */
280
+	public static function get_ee_route_data()
281
+	{
282
+		$ee_routes = array();
283
+		foreach (self::versions_served() as $version => $hidden_endpoints) {
284
+			$ee_routes[ self::ee_api_namespace . $version ] = self::_get_ee_route_data_for_version(
285
+				$version,
286
+				$hidden_endpoints
287
+			);
288
+		}
289
+		return $ee_routes;
290
+	}
291
+
292
+
293
+	/**
294
+	 * Gets the EE route data from the wp options if it exists already,
295
+	 * otherwise re-generates it and saves it to the option
296
+	 *
297
+	 * @param string  $version
298
+	 * @param boolean $hidden_endpoints
299
+	 * @return array
300
+	 * @throws \EE_Error
301
+	 */
302
+	protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
303
+	{
304
+		$ee_routes = get_option(self::saved_routes_option_names . $version, null);
305
+		if (! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
306
+			$ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
307
+		}
308
+		return $ee_routes;
309
+	}
310
+
311
+
312
+	/**
313
+	 * Saves the EE REST API route data to a wp option and returns it
314
+	 *
315
+	 * @param string  $version
316
+	 * @param boolean $hidden_endpoints
317
+	 * @return mixed|null
318
+	 * @throws \EE_Error
319
+	 */
320
+	protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false)
321
+	{
322
+		$instance = self::instance();
323
+		$routes = apply_filters(
324
+			'EED_Core_Rest_Api__save_ee_route_data_for_version__routes',
325
+			array_replace_recursive(
326
+				$instance->_get_config_route_data_for_version($version, $hidden_endpoints),
327
+				$instance->_get_meta_route_data_for_version($version, $hidden_endpoints),
328
+				$instance->_get_model_route_data_for_version($version, $hidden_endpoints),
329
+				$instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
330
+			)
331
+		);
332
+		$option_name = self::saved_routes_option_names . $version;
333
+		if (get_option($option_name)) {
334
+			update_option($option_name, $routes, true);
335
+		} else {
336
+			add_option($option_name, $routes, null, 'no');
337
+		}
338
+		return $routes;
339
+	}
340
+
341
+
342
+	/**
343
+	 * Calculates all the EE routes and saves it to a WordPress option so we don't
344
+	 * need to calculate it on every request
345
+	 *
346
+	 * @deprecated since version 4.9.1
347
+	 * @return void
348
+	 */
349
+	public static function save_ee_routes()
350
+	{
351
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
352
+			$instance = self::instance();
353
+			$routes = apply_filters(
354
+				'EED_Core_Rest_Api__save_ee_routes__routes',
355
+				array_replace_recursive(
356
+					$instance->_register_config_routes(),
357
+					$instance->_register_meta_routes(),
358
+					$instance->_register_model_routes(),
359
+					$instance->_register_rpc_routes()
360
+				)
361
+			);
362
+			update_option(self::saved_routes_option_names, $routes, true);
363
+		}
364
+	}
365
+
366
+
367
+	/**
368
+	 * Gets all the route information relating to EE models
369
+	 *
370
+	 * @return array @see get_ee_route_data
371
+	 * @deprecated since version 4.9.1
372
+	 */
373
+	protected function _register_model_routes()
374
+	{
375
+		$model_routes = array();
376
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
377
+			$model_routes[ EED_Core_Rest_Api::ee_api_namespace
378
+						   . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
379
+		}
380
+		return $model_routes;
381
+	}
382
+
383
+
384
+	/**
385
+	 * Decides whether or not to add write endpoints for this model.
386
+	 *
387
+	 * Currently, this defaults to exclude all global tables and models
388
+	 * which would allow inserting WP core data (we don't want to duplicate
389
+	 * what WP API does, as it's unnecessary, extra work, and potentially extra bugs)
390
+	 *
391
+	 * @param EEM_Base $model
392
+	 * @return bool
393
+	 */
394
+	public static function should_have_write_endpoints(EEM_Base $model)
395
+	{
396
+		if ($model->is_wp_core_model()) {
397
+			return false;
398
+		}
399
+		foreach ($model->get_tables() as $table) {
400
+			if ($table->is_global()) {
401
+				return false;
402
+			}
403
+		}
404
+		return true;
405
+	}
406
+
407
+
408
+	/**
409
+	 * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`)
410
+	 * in this versioned namespace of EE4
411
+	 *
412
+	 * @param $version
413
+	 * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event')
414
+	 */
415
+	public static function model_names_with_plural_routes($version)
416
+	{
417
+		$model_version_info = new ModelVersionInfo($version);
418
+		$models_to_register = $model_version_info->modelsForRequestedVersion();
419
+		// let's not bother having endpoints for extra metas
420
+		unset(
421
+			$models_to_register['Extra_Meta'],
422
+			$models_to_register['Extra_Join'],
423
+			$models_to_register['Post_Meta']
424
+		);
425
+		return apply_filters(
426
+			'FHEE__EED_Core_REST_API___register_model_routes',
427
+			$models_to_register
428
+		);
429
+	}
430
+
431
+
432
+	/**
433
+	 * Gets the route data for EE models in the specified version
434
+	 *
435
+	 * @param string  $version
436
+	 * @param boolean $hidden_endpoint
437
+	 * @return array
438
+	 * @throws EE_Error
439
+	 */
440
+	protected function _get_model_route_data_for_version($version, $hidden_endpoint = false)
441
+	{
442
+		$model_routes = array();
443
+		$model_version_info = new ModelVersionInfo($version);
444
+		foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) {
445
+			$model = \EE_Registry::instance()->load_model($model_name);
446
+			// if this isn't a valid model then let's skip iterate to the next item in the loop.
447
+			if (! $model instanceof EEM_Base) {
448
+				continue;
449
+			}
450
+			// yes we could just register one route for ALL models, but then they wouldn't show up in the index
451
+			$plural_model_route = EED_Core_Rest_Api::get_collection_route($model);
452
+			$singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)');
453
+			$model_routes[ $plural_model_route ] = array(
454
+				array(
455
+					'callback'        => array(
456
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
457
+						'handleRequestGetAll',
458
+					),
459
+					'callback_args'   => array($version, $model_name),
460
+					'methods'         => WP_REST_Server::READABLE,
461
+					'hidden_endpoint' => $hidden_endpoint,
462
+					'args'            => $this->_get_read_query_params($model, $version),
463
+					'_links'          => array(
464
+						'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
465
+					),
466
+				),
467
+				'schema' => array(
468
+					'schema_callback' => array(
469
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
470
+						'handleSchemaRequest',
471
+					),
472
+					'callback_args'   => array($version, $model_name),
473
+				),
474
+			);
475
+			$model_routes[ $singular_model_route ] = array(
476
+				array(
477
+					'callback'        => array(
478
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
479
+						'handleRequestGetOne',
480
+					),
481
+					'callback_args'   => array($version, $model_name),
482
+					'methods'         => WP_REST_Server::READABLE,
483
+					'hidden_endpoint' => $hidden_endpoint,
484
+					'args'            => $this->_get_response_selection_query_params($model, $version),
485
+				),
486
+			);
487
+			if (apply_filters(
488
+				'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints',
489
+				EED_Core_Rest_Api::should_have_write_endpoints($model),
490
+				$model
491
+			)) {
492
+				$model_routes[ $plural_model_route ][] = array(
493
+					'callback'        => array(
494
+						'EventEspresso\core\libraries\rest_api\controllers\model\Write',
495
+						'handleRequestInsert',
496
+					),
497
+					'callback_args'   => array($version, $model_name),
498
+					'methods'         => WP_REST_Server::CREATABLE,
499
+					'hidden_endpoint' => $hidden_endpoint,
500
+					'args'            => $this->_get_write_params($model_name, $model_version_info, true),
501
+				);
502
+				$model_routes[ $singular_model_route ] = array_merge(
503
+					$model_routes[ $singular_model_route ],
504
+					array(
505
+						array(
506
+							'callback'        => array(
507
+								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
508
+								'handleRequestUpdate',
509
+							),
510
+							'callback_args'   => array($version, $model_name),
511
+							'methods'         => WP_REST_Server::EDITABLE,
512
+							'hidden_endpoint' => $hidden_endpoint,
513
+							'args'            => $this->_get_write_params($model_name, $model_version_info),
514
+						),
515
+						array(
516
+							'callback'        => array(
517
+								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
518
+								'handleRequestDelete',
519
+							),
520
+							'callback_args'   => array($version, $model_name),
521
+							'methods'         => WP_REST_Server::DELETABLE,
522
+							'hidden_endpoint' => $hidden_endpoint,
523
+							'args'            => $this->_get_delete_query_params($model, $version),
524
+						),
525
+					)
526
+				);
527
+			}
528
+			foreach ($model->relation_settings() as $relation_name => $relation_obj) {
529
+				$related_route = EED_Core_Rest_Api::get_relation_route_via(
530
+					$model,
531
+					'(?P<id>[^\/]+)',
532
+					$relation_obj
533
+				);
534
+				$endpoints = array(
535
+					array(
536
+						'callback'        => array(
537
+							'EventEspresso\core\libraries\rest_api\controllers\model\Read',
538
+							'handleRequestGetRelated',
539
+						),
540
+						'callback_args'   => array($version, $model_name, $relation_name),
541
+						'methods'         => WP_REST_Server::READABLE,
542
+						'hidden_endpoint' => $hidden_endpoint,
543
+						'args'            => $this->_get_read_query_params($relation_obj->get_other_model(), $version),
544
+					),
545
+				);
546
+				$model_routes[ $related_route ] = $endpoints;
547
+			}
548
+		}
549
+		return $model_routes;
550
+	}
551
+
552
+
553
+	/**
554
+	 * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace,
555
+	 * excluding the preceding slash.
556
+	 * Eg you pass get_plural_route_to('Event') = 'events'
557
+	 *
558
+	 * @param EEM_Base $model
559
+	 * @return string
560
+	 */
561
+	public static function get_collection_route(EEM_Base $model)
562
+	{
563
+		return EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
564
+	}
565
+
566
+
567
+	/**
568
+	 * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace,
569
+	 * excluding the preceding slash.
570
+	 * Eg you pass get_plural_route_to('Event', 12) = 'events/12'
571
+	 *
572
+	 * @param EEM_Base $model eg Event or Venue
573
+	 * @param string   $id
574
+	 * @return string
575
+	 */
576
+	public static function get_entity_route($model, $id)
577
+	{
578
+		return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id;
579
+	}
580
+
581
+
582
+	/**
583
+	 * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace,
584
+	 * excluding the preceding slash.
585
+	 * Eg you pass get_plural_route_to('Event', 12) = 'events/12'
586
+	 *
587
+	 * @param EEM_Base               $model eg Event or Venue
588
+	 * @param string                 $id
589
+	 * @param EE_Model_Relation_Base $relation_obj
590
+	 * @return string
591
+	 */
592
+	public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj)
593
+	{
594
+		$related_model_name_endpoint_part = ModelRead::getRelatedEntityName(
595
+			$relation_obj->get_other_model()->get_this_model_name(),
596
+			$relation_obj
597
+		);
598
+		return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part;
599
+	}
600
+
601
+
602
+	/**
603
+	 * Adds onto the $relative_route the EE4 REST API versioned namespace.
604
+	 * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events'
605
+	 *
606
+	 * @param string $relative_route
607
+	 * @param string $version
608
+	 * @return string
609
+	 */
610
+	public static function get_versioned_route_to($relative_route, $version = '4.8.36')
611
+	{
612
+		return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route;
613
+	}
614
+
615
+
616
+	/**
617
+	 * Adds all the RPC-style routes (remote procedure call-like routes, ie
618
+	 * routes that don't conform to the traditional REST CRUD-style).
619
+	 *
620
+	 * @deprecated since 4.9.1
621
+	 */
622
+	protected function _register_rpc_routes()
623
+	{
624
+		$routes = array();
625
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
626
+			$routes[ self::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version(
627
+				$version,
628
+				$hidden_endpoint
629
+			);
630
+		}
631
+		return $routes;
632
+	}
633
+
634
+
635
+	/**
636
+	 * @param string  $version
637
+	 * @param boolean $hidden_endpoint
638
+	 * @return array
639
+	 */
640
+	protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false)
641
+	{
642
+		$this_versions_routes = array();
643
+		// checkin endpoint
644
+		$this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array(
645
+			array(
646
+				'callback'        => array(
647
+					'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin',
648
+					'handleRequestToggleCheckin',
649
+				),
650
+				'methods'         => WP_REST_Server::CREATABLE,
651
+				'hidden_endpoint' => $hidden_endpoint,
652
+				'args'            => array(
653
+					'force' => array(
654
+						'required'    => false,
655
+						'default'     => false,
656
+						'description' => __(
657
+						// @codingStandardsIgnoreStart
658
+							'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses',
659
+							// @codingStandardsIgnoreEnd
660
+							'event_espresso'
661
+						),
662
+					),
663
+				),
664
+				'callback_args'   => array($version),
665
+			),
666
+		);
667
+		return apply_filters(
668
+			'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes',
669
+			$this_versions_routes,
670
+			$version,
671
+			$hidden_endpoint
672
+		);
673
+	}
674
+
675
+
676
+	/**
677
+	 * Gets the query params that can be used when request one or many
678
+	 *
679
+	 * @param EEM_Base $model
680
+	 * @param string   $version
681
+	 * @return array
682
+	 */
683
+	protected function _get_response_selection_query_params(\EEM_Base $model, $version)
684
+	{
685
+		return apply_filters(
686
+			'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
687
+			array(
688
+				'include'   => array(
689
+					'required' => false,
690
+					'default'  => '*',
691
+					'type'     => 'string',
692
+				),
693
+				'calculate' => array(
694
+					'required'          => false,
695
+					'default'           => '',
696
+					'enum'              => self::$_field_calculator->retrieveCalculatedFieldsForModel($model),
697
+					'type'              => 'string',
698
+					// because we accept a CSV'd list of the enumerated strings, WP core validation and sanitization
699
+					// freaks out. We'll just validate this argument while handling the request
700
+					'validate_callback' => null,
701
+					'sanitize_callback' => null,
702
+				),
703
+			),
704
+			$model,
705
+			$version
706
+		);
707
+	}
708
+
709
+
710
+	/**
711
+	 * Gets the parameters acceptable for delete requests
712
+	 *
713
+	 * @param \EEM_Base $model
714
+	 * @param string    $version
715
+	 * @return array
716
+	 */
717
+	protected function _get_delete_query_params(\EEM_Base $model, $version)
718
+	{
719
+		$params_for_delete = array(
720
+			'allow_blocking' => array(
721
+				'required' => false,
722
+				'default'  => true,
723
+				'type'     => 'boolean',
724
+			),
725
+		);
726
+		$params_for_delete['force'] = array(
727
+			'required' => false,
728
+			'default'  => false,
729
+			'type'     => 'boolean',
730
+		);
731
+		return apply_filters(
732
+			'FHEE__EED_Core_Rest_Api___get_delete_query_params',
733
+			$params_for_delete,
734
+			$model,
735
+			$version
736
+		);
737
+	}
738
+
739
+
740
+	/**
741
+	 * Gets info about reading query params that are acceptable
742
+	 *
743
+	 * @param \EEM_Base $model eg 'Event' or 'Venue'
744
+	 * @param  string   $version
745
+	 * @return array    describing the args acceptable when querying this model
746
+	 * @throws EE_Error
747
+	 */
748
+	protected function _get_read_query_params(\EEM_Base $model, $version)
749
+	{
750
+		$default_orderby = array();
751
+		foreach ($model->get_combined_primary_key_fields() as $key_field) {
752
+			$default_orderby[ $key_field->get_name() ] = 'ASC';
753
+		}
754
+		return array_merge(
755
+			$this->_get_response_selection_query_params($model, $version),
756
+			array(
757
+				'where'    => array(
758
+					'required'          => false,
759
+					'default'           => array(),
760
+					'type'              => 'object',
761
+					// because we accept an almost infinite list of possible where conditions, WP
762
+					// core validation and sanitization freaks out. We'll just validate this argument
763
+					// while handling the request
764
+					'validate_callback' => null,
765
+					'sanitize_callback' => null,
766
+				),
767
+				'limit'    => array(
768
+					'required'          => false,
769
+					'default'           => EED_Core_Rest_Api::get_default_query_limit(),
770
+					'type'              => array(
771
+						'array',
772
+						'string',
773
+						'integer',
774
+					),
775
+					// because we accept a variety of types, WP core validation and sanitization
776
+					// freaks out. We'll just validate this argument while handling the request
777
+					'validate_callback' => null,
778
+					'sanitize_callback' => null,
779
+				),
780
+				'order_by' => array(
781
+					'required'          => false,
782
+					'default'           => $default_orderby,
783
+					'type'              => array(
784
+						'object',
785
+						'string',
786
+					),// because we accept a variety of types, WP core validation and sanitization
787
+					// freaks out. We'll just validate this argument while handling the request
788
+					'validate_callback' => null,
789
+					'sanitize_callback' => null,
790
+				),
791
+				'group_by' => array(
792
+					'required'          => false,
793
+					'default'           => null,
794
+					'type'              => array(
795
+						'object',
796
+						'string',
797
+					),
798
+					// because we accept  an almost infinite list of possible groupings,
799
+					// WP core validation and sanitization
800
+					// freaks out. We'll just validate this argument while handling the request
801
+					'validate_callback' => null,
802
+					'sanitize_callback' => null,
803
+				),
804
+				'having'   => array(
805
+					'required'          => false,
806
+					'default'           => null,
807
+					'type'              => 'object',
808
+					// because we accept an almost infinite list of possible where conditions, WP
809
+					// core validation and sanitization freaks out. We'll just validate this argument
810
+					// while handling the request
811
+					'validate_callback' => null,
812
+					'sanitize_callback' => null,
813
+				),
814
+				'caps'     => array(
815
+					'required' => false,
816
+					'default'  => EEM_Base::caps_read,
817
+					'type'     => 'string',
818
+					'enum'     => array(
819
+						EEM_Base::caps_read,
820
+						EEM_Base::caps_read_admin,
821
+						EEM_Base::caps_edit,
822
+						EEM_Base::caps_delete,
823
+					),
824
+				),
825
+			)
826
+		);
827
+	}
828
+
829
+
830
+	/**
831
+	 * Gets parameter information for a model regarding writing data
832
+	 *
833
+	 * @param string           $model_name
834
+	 * @param ModelVersionInfo $model_version_info
835
+	 * @param boolean          $create                                       whether this is for request to create (in
836
+	 *                                                                       which case we need all required params) or
837
+	 *                                                                       just to update (in which case we don't
838
+	 *                                                                       need those on every request)
839
+	 * @return array
840
+	 */
841
+	protected function _get_write_params(
842
+		$model_name,
843
+		ModelVersionInfo $model_version_info,
844
+		$create = false
845
+	) {
846
+		$model = EE_Registry::instance()->load_model($model_name);
847
+		$fields = $model_version_info->fieldsOnModelInThisVersion($model);
848
+		$args_info = array();
849
+		foreach ($fields as $field_name => $field_obj) {
850
+			if ($field_obj->is_auto_increment()) {
851
+				// totally ignore auto increment IDs
852
+				continue;
853
+			}
854
+			$arg_info = $field_obj->getSchema();
855
+			$required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null;
856
+			$arg_info['required'] = $required;
857
+			// remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right?
858
+			unset($arg_info['readonly']);
859
+			$schema_properties = $field_obj->getSchemaProperties();
860
+			if (isset($schema_properties['raw'])
861
+				&& $field_obj->getSchemaType() === 'object'
862
+			) {
863
+				// if there's a "raw" form of this argument, use those properties instead
864
+				$arg_info = array_replace(
865
+					$arg_info,
866
+					$schema_properties['raw']
867
+				);
868
+			}
869
+			$arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson(
870
+				$field_obj,
871
+				$field_obj->get_default_value(),
872
+				$model_version_info->requestedVersion()
873
+			);
874
+			// we do our own validation and sanitization within the controller
875
+			if (function_exists('rest_validate_value_from_schema')) {
876
+				$sanitize_callback = array(
877
+					'EED_Core_Rest_Api',
878
+					'default_sanitize_callback',
879
+				);
880
+			} else {
881
+				$sanitize_callback = null;
882
+			}
883
+			$arg_info['sanitize_callback'] = $sanitize_callback;
884
+			$args_info[ $field_name ] = $arg_info;
885
+			if ($field_obj instanceof EE_Datetime_Field) {
886
+				$gmt_arg_info = $arg_info;
887
+				$gmt_arg_info['description'] = sprintf(
888
+					esc_html__(
889
+						'%1$s - the value for this field in UTC. Ignored if %2$s is provided.',
890
+						'event_espresso'
891
+					),
892
+					$field_obj->get_nicename(),
893
+					$field_name
894
+				);
895
+				$args_info[ $field_name . '_gmt' ] = $gmt_arg_info;
896
+			}
897
+		}
898
+		return $args_info;
899
+	}
900
+
901
+
902
+	/**
903
+	 * Replacement for WP API's 'rest_parse_request_arg'.
904
+	 * If the value is blank but not required, don't bother validating it.
905
+	 * Also, it uses our email validation instead of WP API's default.
906
+	 *
907
+	 * @param                 $value
908
+	 * @param WP_REST_Request $request
909
+	 * @param                 $param
910
+	 * @return bool|true|WP_Error
911
+	 * @throws InvalidArgumentException
912
+	 * @throws InvalidInterfaceException
913
+	 * @throws InvalidDataTypeException
914
+	 */
915
+	public static function default_sanitize_callback($value, WP_REST_Request $request, $param)
916
+	{
917
+		$attributes = $request->get_attributes();
918
+		if (! isset($attributes['args'][ $param ])
919
+			|| ! is_array($attributes['args'][ $param ])) {
920
+			$validation_result = true;
921
+		} else {
922
+			$args = $attributes['args'][ $param ];
923
+			if ((
924
+					$value === ''
925
+					|| $value === null
926
+				)
927
+				&& (! isset($args['required'])
928
+					|| $args['required'] === false
929
+				)
930
+			) {
931
+				// not required and not provided? that's cool
932
+				$validation_result = true;
933
+			} elseif (isset($args['format'])
934
+					  && $args['format'] === 'email'
935
+			) {
936
+				$validation_result = true;
937
+				if (! self::_validate_email($value)) {
938
+					$validation_result = new WP_Error(
939
+						'rest_invalid_param',
940
+						esc_html__(
941
+							'The email address is not valid or does not exist.',
942
+							'event_espresso'
943
+						)
944
+					);
945
+				}
946
+			} else {
947
+				$validation_result = rest_validate_value_from_schema($value, $args, $param);
948
+			}
949
+		}
950
+		if (is_wp_error($validation_result)) {
951
+			return $validation_result;
952
+		}
953
+		return rest_sanitize_request_arg($value, $request, $param);
954
+	}
955
+
956
+
957
+	/**
958
+	 * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email()
959
+	 *
960
+	 * @param $email
961
+	 * @return bool
962
+	 * @throws InvalidArgumentException
963
+	 * @throws InvalidInterfaceException
964
+	 * @throws InvalidDataTypeException
965
+	 */
966
+	protected static function _validate_email($email)
967
+	{
968
+		try {
969
+			EmailAddressFactory::create($email);
970
+			return true;
971
+		} catch (EmailValidationException $e) {
972
+			return false;
973
+		}
974
+	}
975
+
976
+
977
+	/**
978
+	 * Gets routes for the config
979
+	 *
980
+	 * @return array @see _register_model_routes
981
+	 * @deprecated since version 4.9.1
982
+	 */
983
+	protected function _register_config_routes()
984
+	{
985
+		$config_routes = array();
986
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
987
+			$config_routes[ self::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version(
988
+				$version,
989
+				$hidden_endpoint
990
+			);
991
+		}
992
+		return $config_routes;
993
+	}
994
+
995
+
996
+	/**
997
+	 * Gets routes for the config for the specified version
998
+	 *
999
+	 * @param string  $version
1000
+	 * @param boolean $hidden_endpoint
1001
+	 * @return array
1002
+	 */
1003
+	protected function _get_config_route_data_for_version($version, $hidden_endpoint)
1004
+	{
1005
+		return array(
1006
+			'config'    => array(
1007
+				array(
1008
+					'callback'        => array(
1009
+						'EventEspresso\core\libraries\rest_api\controllers\config\Read',
1010
+						'handleRequest',
1011
+					),
1012
+					'methods'         => WP_REST_Server::READABLE,
1013
+					'hidden_endpoint' => $hidden_endpoint,
1014
+					'callback_args'   => array($version),
1015
+				),
1016
+			),
1017
+			'site_info' => array(
1018
+				array(
1019
+					'callback'        => array(
1020
+						'EventEspresso\core\libraries\rest_api\controllers\config\Read',
1021
+						'handleRequestSiteInfo',
1022
+					),
1023
+					'methods'         => WP_REST_Server::READABLE,
1024
+					'hidden_endpoint' => $hidden_endpoint,
1025
+					'callback_args'   => array($version),
1026
+				),
1027
+			),
1028
+		);
1029
+	}
1030
+
1031
+
1032
+	/**
1033
+	 * Gets the meta info routes
1034
+	 *
1035
+	 * @return array @see _register_model_routes
1036
+	 * @deprecated since version 4.9.1
1037
+	 */
1038
+	protected function _register_meta_routes()
1039
+	{
1040
+		$meta_routes = array();
1041
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
1042
+			$meta_routes[ self::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version(
1043
+				$version,
1044
+				$hidden_endpoint
1045
+			);
1046
+		}
1047
+		return $meta_routes;
1048
+	}
1049
+
1050
+
1051
+	/**
1052
+	 * @param string  $version
1053
+	 * @param boolean $hidden_endpoint
1054
+	 * @return array
1055
+	 */
1056
+	protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false)
1057
+	{
1058
+		return array(
1059
+			'resources' => array(
1060
+				array(
1061
+					'callback'        => array(
1062
+						'EventEspresso\core\libraries\rest_api\controllers\model\Meta',
1063
+						'handleRequestModelsMeta',
1064
+					),
1065
+					'methods'         => WP_REST_Server::READABLE,
1066
+					'hidden_endpoint' => $hidden_endpoint,
1067
+					'callback_args'   => array($version),
1068
+				),
1069
+			),
1070
+		);
1071
+	}
1072
+
1073
+
1074
+	/**
1075
+	 * Tries to hide old 4.6 endpoints from the
1076
+	 *
1077
+	 * @param array $route_data
1078
+	 * @return array
1079
+	 * @throws \EE_Error
1080
+	 */
1081
+	public static function hide_old_endpoints($route_data)
1082
+	{
1083
+		// allow API clients to override which endpoints get hidden, in case
1084
+		// they want to discover particular endpoints
1085
+		// also, we don't have access to the request so we have to just grab it from the superglobal
1086
+		$force_show_ee_namespace = ltrim(
1087
+			EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''),
1088
+			'/'
1089
+		);
1090
+		foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
1091
+			foreach ($relative_urls as $resource_name => $endpoints) {
1092
+				foreach ($endpoints as $key => $endpoint) {
1093
+					// skip schema and other route options
1094
+					if (! is_numeric($key)) {
1095
+						continue;
1096
+					}
1097
+					// by default, hide "hidden_endpoint"s, unless the request indicates
1098
+					// to $force_show_ee_namespace, in which case only show that one
1099
+					// namespace's endpoints (and hide all others)
1100
+					if (($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
1101
+						|| ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '')
1102
+					) {
1103
+						$full_route = '/' . ltrim($namespace, '/');
1104
+						$full_route .= '/' . ltrim($resource_name, '/');
1105
+						unset($route_data[ $full_route ]);
1106
+					}
1107
+				}
1108
+			}
1109
+		}
1110
+		return $route_data;
1111
+	}
1112
+
1113
+
1114
+	/**
1115
+	 * Returns an array describing which versions of core support serving requests for.
1116
+	 * Keys are core versions' major and minor version, and values are the
1117
+	 * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like
1118
+	 * data by just removing a few models and fields from the responses. However, 4.15 might remove
1119
+	 * the answers table entirely, in which case it would be very difficult for
1120
+	 * it to serve 4.6-style responses.
1121
+	 * Versions of core that are missing from this array are unknowns.
1122
+	 * previous ver
1123
+	 *
1124
+	 * @return array
1125
+	 */
1126
+	public static function version_compatibilities()
1127
+	{
1128
+		return apply_filters(
1129
+			'FHEE__EED_Core_REST_API__version_compatibilities',
1130
+			array(
1131
+				'4.8.29' => '4.8.29',
1132
+				'4.8.33' => '4.8.29',
1133
+				'4.8.34' => '4.8.29',
1134
+				'4.8.36' => '4.8.29',
1135
+			)
1136
+		);
1137
+	}
1138
+
1139
+
1140
+	/**
1141
+	 * Gets the latest API version served. Eg if there
1142
+	 * are two versions served of the API, 4.8.29 and 4.8.32, and
1143
+	 * we are on core version 4.8.34, it will return the string "4.8.32"
1144
+	 *
1145
+	 * @return string
1146
+	 */
1147
+	public static function latest_rest_api_version()
1148
+	{
1149
+		$versions_served = \EED_Core_Rest_Api::versions_served();
1150
+		$versions_served_keys = array_keys($versions_served);
1151
+		return end($versions_served_keys);
1152
+	}
1153
+
1154
+
1155
+	/**
1156
+	 * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of
1157
+	 * EE the API can serve requests for. Eg, if we are on 4.15 of core, and
1158
+	 * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ).
1159
+	 * We also indicate whether or not this version should be put in the index or not
1160
+	 *
1161
+	 * @return array keys are API version numbers (just major and minor numbers), and values
1162
+	 * are whether or not they should be hidden
1163
+	 */
1164
+	public static function versions_served()
1165
+	{
1166
+		$versions_served = array();
1167
+		$possibly_served_versions = EED_Core_Rest_Api::version_compatibilities();
1168
+		$lowest_compatible_version = end($possibly_served_versions);
1169
+		reset($possibly_served_versions);
1170
+		$versions_served_historically = array_keys($possibly_served_versions);
1171
+		$latest_version = end($versions_served_historically);
1172
+		reset($versions_served_historically);
1173
+		// for each version of core we have ever served:
1174
+		foreach ($versions_served_historically as $key_versioned_endpoint) {
1175
+			// if it's not above the current core version, and it's compatible with the current version of core
1176
+			if ($key_versioned_endpoint === $latest_version) {
1177
+				// don't hide the latest version in the index
1178
+				$versions_served[ $key_versioned_endpoint ] = false;
1179
+			} elseif ($key_versioned_endpoint >= $lowest_compatible_version
1180
+				&& $key_versioned_endpoint < EED_Core_Rest_Api::core_version()
1181
+			) {
1182
+				// include, but hide, previous versions which are still supported
1183
+				$versions_served[ $key_versioned_endpoint ] = true;
1184
+			} elseif (apply_filters(
1185
+				'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions',
1186
+				false,
1187
+				$possibly_served_versions
1188
+			)) {
1189
+				// if a version is no longer supported, don't include it in index or list of versions served
1190
+				$versions_served[ $key_versioned_endpoint ] = true;
1191
+			}
1192
+		}
1193
+		return $versions_served;
1194
+	}
1195
+
1196
+
1197
+	/**
1198
+	 * Gets the major and minor version of EE core's version string
1199
+	 *
1200
+	 * @return string
1201
+	 */
1202
+	public static function core_version()
1203
+	{
1204
+		return apply_filters(
1205
+			'FHEE__EED_Core_REST_API__core_version',
1206
+			implode(
1207
+				'.',
1208
+				array_slice(
1209
+					explode(
1210
+						'.',
1211
+						espresso_version()
1212
+					),
1213
+					0,
1214
+					3
1215
+				)
1216
+			)
1217
+		);
1218
+	}
1219
+
1220
+
1221
+	/**
1222
+	 * Gets the default limit that should be used when querying for resources
1223
+	 *
1224
+	 * @return int
1225
+	 */
1226
+	public static function get_default_query_limit()
1227
+	{
1228
+		// we actually don't use a const because we want folks to always use
1229
+		// this method, not the const directly
1230
+		return apply_filters(
1231
+			'FHEE__EED_Core_Rest_Api__get_default_query_limit',
1232
+			50
1233
+		);
1234
+	}
1235
+
1236
+
1237
+	/**
1238
+	 *    run - initial module setup
1239
+	 *
1240
+	 * @access    public
1241
+	 * @param  WP $WP
1242
+	 * @return    void
1243
+	 */
1244
+	public function run($WP)
1245
+	{
1246
+	}
1247 1247
 }
Please login to merge, or discard this patch.
core/services/collections/iterators/CollectionFilterCallbackIterator.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -9,51 +9,51 @@
 block discarded – undo
9 9
 class CollectionFilterCallbackIterator extends FilterIterator
10 10
 {
11 11
 
12
-    /**
13
-     * Used for determining whether the iterated object in the Collection is "valid" or not.
14
-     * @var Closure
15
-     */
16
-    private $acceptance_callback;
17
-
18
-
19
-    /**
20
-     * CollectionFilterCallbackIterator constructor.
21
-     *
22
-     * @param Collection $collection
23
-     * @param Closure    $acceptance_callback  The closure will receive an instance of whatever object is stored on the
24
-     *                                         collection when iterating over the collection and should return boolean.
25
-     */
26
-    public function __construct(Collection $collection, Closure $acceptance_callback)
27
-    {
28
-        $this->acceptance_callback = $acceptance_callback;
29
-        parent::__construct($collection);
30
-    }
31
-
32
-    /**
33
-     * Check whether the current element of the iterator is acceptable
34
-     *
35
-     * @link  http://php.net/manual/en/filteriterator.accept.php
36
-     * @return bool true if the current element is acceptable, otherwise false.
37
-     */
38
-    public function accept()
39
-    {
40
-        $acceptance_callback = $this->acceptance_callback;
41
-        return $acceptance_callback($this->getInnerIterator()->current());
42
-    }
43
-
44
-
45
-
46
-    /**
47
-     * Returns a filtered array of objects from the collection using the provided acceptance callback
48
-     * @return array
49
-     */
50
-    public function getFiltered()
51
-    {
52
-        $filtered_array = array();
53
-        $this->rewind();
54
-        foreach ($this as $filtered_object) {
55
-            $filtered_array[] = $filtered_object;
56
-        }
57
-        return $filtered_array;
58
-    }
12
+	/**
13
+	 * Used for determining whether the iterated object in the Collection is "valid" or not.
14
+	 * @var Closure
15
+	 */
16
+	private $acceptance_callback;
17
+
18
+
19
+	/**
20
+	 * CollectionFilterCallbackIterator constructor.
21
+	 *
22
+	 * @param Collection $collection
23
+	 * @param Closure    $acceptance_callback  The closure will receive an instance of whatever object is stored on the
24
+	 *                                         collection when iterating over the collection and should return boolean.
25
+	 */
26
+	public function __construct(Collection $collection, Closure $acceptance_callback)
27
+	{
28
+		$this->acceptance_callback = $acceptance_callback;
29
+		parent::__construct($collection);
30
+	}
31
+
32
+	/**
33
+	 * Check whether the current element of the iterator is acceptable
34
+	 *
35
+	 * @link  http://php.net/manual/en/filteriterator.accept.php
36
+	 * @return bool true if the current element is acceptable, otherwise false.
37
+	 */
38
+	public function accept()
39
+	{
40
+		$acceptance_callback = $this->acceptance_callback;
41
+		return $acceptance_callback($this->getInnerIterator()->current());
42
+	}
43
+
44
+
45
+
46
+	/**
47
+	 * Returns a filtered array of objects from the collection using the provided acceptance callback
48
+	 * @return array
49
+	 */
50
+	public function getFiltered()
51
+	{
52
+		$filtered_array = array();
53
+		$this->rewind();
54
+		foreach ($this as $filtered_object) {
55
+			$filtered_array[] = $filtered_object;
56
+		}
57
+		return $filtered_array;
58
+	}
59 59
 }
Please login to merge, or discard this patch.