Completed
Branch master (d65695)
by
unknown
04:25
created
core/domain/entities/routing/handlers/shared/WordPressHeartbeat.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -15,49 +15,49 @@
 block discarded – undo
15 15
  */
16 16
 class WordPressHeartbeat extends Route
17 17
 {
18
-    /**
19
-     * returns true if the current request matches this route
20
-     *
21
-     * @return bool
22
-     * @since   5.0.0.p
23
-     */
24
-    public function matchesCurrentRequest(): bool
25
-    {
26
-        return $this->request->isWordPressHeartbeat();
27
-    }
18
+	/**
19
+	 * returns true if the current request matches this route
20
+	 *
21
+	 * @return bool
22
+	 * @since   5.0.0.p
23
+	 */
24
+	public function matchesCurrentRequest(): bool
25
+	{
26
+		return $this->request->isWordPressHeartbeat();
27
+	}
28 28
 
29 29
 
30
-    /**
31
-     * @since 5.0.0.p
32
-     */
33
-    protected function registerDependencies()
34
-    {
35
-        $this->dependency_map->registerDependencies(
36
-            'EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat',
37
-            [
38
-                'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
39
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
40
-            ]
41
-        );
42
-        $this->dependency_map->registerDependencies(
43
-            'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat',
44
-            [
45
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
46
-                'EE_Environment_Config'            => EE_Dependency_Map::load_from_cache,
47
-            ]
48
-        );
49
-    }
30
+	/**
31
+	 * @since 5.0.0.p
32
+	 */
33
+	protected function registerDependencies()
34
+	{
35
+		$this->dependency_map->registerDependencies(
36
+			'EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat',
37
+			[
38
+				'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
39
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
40
+			]
41
+		);
42
+		$this->dependency_map->registerDependencies(
43
+			'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat',
44
+			[
45
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
46
+				'EE_Environment_Config'            => EE_Dependency_Map::load_from_cache,
47
+			]
48
+		);
49
+	}
50 50
 
51 51
 
52
-    /**
53
-     * implements logic required to run during request
54
-     *
55
-     * @return bool
56
-     * @since   5.0.0.p
57
-     */
58
-    protected function requestHandler(): bool
59
-    {
60
-        $this->loader->getShared('EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat');
61
-        return true;
62
-    }
52
+	/**
53
+	 * implements logic required to run during request
54
+	 *
55
+	 * @return bool
56
+	 * @since   5.0.0.p
57
+	 */
58
+	protected function requestHandler(): bool
59
+	{
60
+		$this->loader->getShared('EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat');
61
+		return true;
62
+	}
63 63
 }
Please login to merge, or discard this patch.
core/domain/entities/routing/handlers/shared/RestApiRequests.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -16,65 +16,65 @@
 block discarded – undo
16 16
  */
17 17
 class RestApiRequests extends Route
18 18
 {
19
-    /**
20
-     * returns true if the current request matches this route
21
-     *
22
-     * @return bool
23
-     * @since   5.0.0.p
24
-     */
25
-    public function matchesCurrentRequest(): bool
26
-    {
27
-        return $this->request->isAdmin() || $this->request->isApi() || $this->request->isWordPressApi();
28
-    }
19
+	/**
20
+	 * returns true if the current request matches this route
21
+	 *
22
+	 * @return bool
23
+	 * @since   5.0.0.p
24
+	 */
25
+	public function matchesCurrentRequest(): bool
26
+	{
27
+		return $this->request->isAdmin() || $this->request->isApi() || $this->request->isWordPressApi();
28
+	}
29 29
 
30 30
 
31
-    /**
32
-     * @since 5.0.0.p
33
-     */
34
-    protected function registerDependencies()
35
-    {
36
-        $this->dependency_map->registerDependencies(
37
-            'EventEspresso\core\libraries\rest_api\CalculatedModelFields',
38
-            ['EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache]
39
-        );
40
-        $this->dependency_map->registerDependencies(
41
-            'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory',
42
-            ['EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache]
43
-        );
44
-        $this->dependency_map->registerDependencies(
45
-            'EventEspresso\core\libraries\rest_api\controllers\model\Read',
46
-            ['EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache]
47
-        );
48
-        $this->dependency_map->registerDependencies(
49
-            'EventEspresso\core\libraries\rest_api\calculations\Datetime',
50
-            [
51
-                'EEM_Datetime'     => EE_Dependency_Map::load_from_cache,
52
-                'EEM_Registration' => EE_Dependency_Map::load_from_cache
53
-            ]
54
-        );
55
-        $this->dependency_map->registerDependencies(
56
-            'EventEspresso\core\libraries\rest_api\calculations\Event',
57
-            [
58
-                'EEM_Event'        => EE_Dependency_Map::load_from_cache,
59
-                'EEM_Registration' => EE_Dependency_Map::load_from_cache
60
-            ]
61
-        );
62
-        $this->dependency_map->registerDependencies(
63
-            'EventEspresso\core\libraries\rest_api\calculations\Registration',
64
-            ['EEM_Registration' => EE_Dependency_Map::load_from_cache]
65
-        );
66
-    }
31
+	/**
32
+	 * @since 5.0.0.p
33
+	 */
34
+	protected function registerDependencies()
35
+	{
36
+		$this->dependency_map->registerDependencies(
37
+			'EventEspresso\core\libraries\rest_api\CalculatedModelFields',
38
+			['EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache]
39
+		);
40
+		$this->dependency_map->registerDependencies(
41
+			'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory',
42
+			['EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache]
43
+		);
44
+		$this->dependency_map->registerDependencies(
45
+			'EventEspresso\core\libraries\rest_api\controllers\model\Read',
46
+			['EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache]
47
+		);
48
+		$this->dependency_map->registerDependencies(
49
+			'EventEspresso\core\libraries\rest_api\calculations\Datetime',
50
+			[
51
+				'EEM_Datetime'     => EE_Dependency_Map::load_from_cache,
52
+				'EEM_Registration' => EE_Dependency_Map::load_from_cache
53
+			]
54
+		);
55
+		$this->dependency_map->registerDependencies(
56
+			'EventEspresso\core\libraries\rest_api\calculations\Event',
57
+			[
58
+				'EEM_Event'        => EE_Dependency_Map::load_from_cache,
59
+				'EEM_Registration' => EE_Dependency_Map::load_from_cache
60
+			]
61
+		);
62
+		$this->dependency_map->registerDependencies(
63
+			'EventEspresso\core\libraries\rest_api\calculations\Registration',
64
+			['EEM_Registration' => EE_Dependency_Map::load_from_cache]
65
+		);
66
+	}
67 67
 
68 68
 
69
-    /**
70
-     * implements logic required to run during request
71
-     *
72
-     * @return bool
73
-     * @since   5.0.0.p
74
-     */
75
-    protected function requestHandler(): bool
76
-    {
77
-        EED_Core_Rest_Api::set_hooks_both();
78
-        return true;
79
-    }
69
+	/**
70
+	 * implements logic required to run during request
71
+	 *
72
+	 * @return bool
73
+	 * @since   5.0.0.p
74
+	 */
75
+	protected function requestHandler(): bool
76
+	{
77
+		EED_Core_Rest_Api::set_hooks_both();
78
+		return true;
79
+	}
80 80
 }
Please login to merge, or discard this patch.
core/domain/entities/shortcodes/EspressoTicketSelector.php 1 patch
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -22,104 +22,104 @@
 block discarded – undo
22 22
  */
23 23
 class EspressoTicketSelector extends EspressoShortcode
24 24
 {
25
-    /**
26
-     * the actual shortcode tag that gets registered with WordPress
27
-     *
28
-     * @return string
29
-     */
30
-    public function getTag()
31
-    {
32
-        return 'ESPRESSO_TICKET_SELECTOR';
33
-    }
25
+	/**
26
+	 * the actual shortcode tag that gets registered with WordPress
27
+	 *
28
+	 * @return string
29
+	 */
30
+	public function getTag()
31
+	{
32
+		return 'ESPRESSO_TICKET_SELECTOR';
33
+	}
34 34
 
35 35
 
36
-    /**
37
-     * the time in seconds to cache the results of the processShortcode() method
38
-     * 0 means the processShortcode() results will NOT be cached at all
39
-     *
40
-     * @return int
41
-     */
42
-    public function cacheExpiration()
43
-    {
44
-        return 0;
45
-    }
36
+	/**
37
+	 * the time in seconds to cache the results of the processShortcode() method
38
+	 * 0 means the processShortcode() results will NOT be cached at all
39
+	 *
40
+	 * @return int
41
+	 */
42
+	public function cacheExpiration()
43
+	{
44
+		return 0;
45
+	}
46 46
 
47 47
 
48
-    /**
49
-     * a place for adding any initialization code that needs to run prior to wp_header().
50
-     * this may be required for shortcodes that utilize a corresponding module,
51
-     * and need to enqueue assets for that module
52
-     *
53
-     * @return void
54
-     */
55
-    public function initializeShortcode()
56
-    {
57
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
58
-        $this->shortcodeHasBeenInitialized();
59
-    }
48
+	/**
49
+	 * a place for adding any initialization code that needs to run prior to wp_header().
50
+	 * this may be required for shortcodes that utilize a corresponding module,
51
+	 * and need to enqueue assets for that module
52
+	 *
53
+	 * @return void
54
+	 */
55
+	public function initializeShortcode()
56
+	{
57
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
58
+		$this->shortcodeHasBeenInitialized();
59
+	}
60 60
 
61 61
 
62
-    /**
63
-     * callback that runs when the shortcode is encountered in post content.
64
-     * IMPORTANT !!!
65
-     * remember that shortcode content should be RETURNED and NOT echoed out
66
-     *
67
-     * @param array|string $attributes
68
-     * @return string
69
-     * @throws InvalidArgumentException
70
-     * @throws EE_Error
71
-     * @throws InvalidDataTypeException
72
-     * @throws InvalidInterfaceException
73
-     * @throws ReflectionException
74
-     * @throws Exception
75
-     */
76
-    public function processShortcode($attributes = array())
77
-    {
78
-        extract((array) $attributes);
79
-        $event_id = $event_id ?? 0;
80
-        $event = EEM_Event::instance()->get_one_by_ID($event_id);
81
-        if (! $event instanceof EE_Event) {
82
-            return $this->processInvalidEvent($event_id);
83
-        }
84
-        ob_start();
85
-        do_action('AHEE_event_details_before_post', $event_id);
86
-        espresso_ticket_selector($event);
87
-        do_action('AHEE_event_details_after_post');
88
-        return ob_get_clean();
89
-    }
62
+	/**
63
+	 * callback that runs when the shortcode is encountered in post content.
64
+	 * IMPORTANT !!!
65
+	 * remember that shortcode content should be RETURNED and NOT echoed out
66
+	 *
67
+	 * @param array|string $attributes
68
+	 * @return string
69
+	 * @throws InvalidArgumentException
70
+	 * @throws EE_Error
71
+	 * @throws InvalidDataTypeException
72
+	 * @throws InvalidInterfaceException
73
+	 * @throws ReflectionException
74
+	 * @throws Exception
75
+	 */
76
+	public function processShortcode($attributes = array())
77
+	{
78
+		extract((array) $attributes);
79
+		$event_id = $event_id ?? 0;
80
+		$event = EEM_Event::instance()->get_one_by_ID($event_id);
81
+		if (! $event instanceof EE_Event) {
82
+			return $this->processInvalidEvent($event_id);
83
+		}
84
+		ob_start();
85
+		do_action('AHEE_event_details_before_post', $event_id);
86
+		espresso_ticket_selector($event);
87
+		do_action('AHEE_event_details_after_post');
88
+		return ob_get_clean();
89
+	}
90 90
 
91 91
 
92
-    /**
93
-     * @param string $event_id
94
-     * @return string
95
-     * @throws Exception
96
-     * @since 5.0.0.p
97
-     */
98
-    private function processInvalidEvent(string $event_id): string
99
-    {
100
-        if (WP_DEBUG === true && current_user_can('edit_pages')) {
101
-            new ExceptionStackTraceDisplay(
102
-                new InvalidArgumentException(
103
-                    sprintf(
104
-                        esc_html__(
105
-                            'A valid Event ID is required to use the "%1$s" shortcode.%4$sAn Event with an ID of "%2$s" could not be found.%4$sPlease verify that the shortcode added to this post\'s content includes an "%3$s" argument and that its value corresponds to a valid Event ID.',
106
-                            'event_espresso'
107
-                        ),
108
-                        $this->getTag(),
109
-                        $event_id,
110
-                        'event_id',
111
-                        '<br />'
112
-                    )
113
-                )
114
-            );
115
-            return '';
116
-        }
117
-        return sprintf(
118
-            esc_html__(
119
-                'An Event with an ID of "%s" could not be found. Please contact the event administrator for assistance.',
120
-                'event_espresso'
121
-            ),
122
-            $event_id
123
-        );
124
-    }
92
+	/**
93
+	 * @param string $event_id
94
+	 * @return string
95
+	 * @throws Exception
96
+	 * @since 5.0.0.p
97
+	 */
98
+	private function processInvalidEvent(string $event_id): string
99
+	{
100
+		if (WP_DEBUG === true && current_user_can('edit_pages')) {
101
+			new ExceptionStackTraceDisplay(
102
+				new InvalidArgumentException(
103
+					sprintf(
104
+						esc_html__(
105
+							'A valid Event ID is required to use the "%1$s" shortcode.%4$sAn Event with an ID of "%2$s" could not be found.%4$sPlease verify that the shortcode added to this post\'s content includes an "%3$s" argument and that its value corresponds to a valid Event ID.',
106
+							'event_espresso'
107
+						),
108
+						$this->getTag(),
109
+						$event_id,
110
+						'event_id',
111
+						'<br />'
112
+					)
113
+				)
114
+			);
115
+			return '';
116
+		}
117
+		return sprintf(
118
+			esc_html__(
119
+				'An Event with an ID of "%s" could not be found. Please contact the event administrator for assistance.',
120
+				'event_espresso'
121
+			),
122
+			$event_id
123
+		);
124
+	}
125 125
 }
Please login to merge, or discard this patch.
core/services/request/Response.php 1 patch
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -14,139 +14,139 @@
 block discarded – undo
14 14
  */
15 15
 class Response implements ResponseInterface, ReservedInstanceInterface
16 16
 {
17
-    protected bool  $deactivate_plugin = false;
18
-
19
-    protected array $notice            = [];
20
-
21
-    /**
22
-     * rendered output to be returned to WP
23
-     */
24
-    protected array $output             = [];
25
-
26
-    protected array $request_headers    = [];
27
-
28
-    protected bool  $request_terminated = false;
29
-
30
-
31
-    /**
32
-     * EE_Response constructor.
33
-     */
34
-    public function __construct()
35
-    {
36
-        $this->terminateRequest(false);
37
-    }
38
-
39
-
40
-    /**
41
-     * @param $key
42
-     * @param $value
43
-     * @return    void
44
-     */
45
-    public function setNotice($key, $value)
46
-    {
47
-        $this->notice[ $key ] = $value;
48
-    }
49
-
50
-
51
-    /**
52
-     * @param $key
53
-     * @return    mixed
54
-     */
55
-    public function getNotice($key)
56
-    {
57
-        return $this->notice[ $key ] ?? null;
58
-    }
59
-
60
-
61
-    /**
62
-     * @return array
63
-     */
64
-    public function getNotices(): array
65
-    {
66
-        return $this->notice;
67
-    }
68
-
69
-
70
-    /**
71
-     * @param string $string
72
-     * @param bool   $append
73
-     */
74
-    public function addOutput(string $string, bool $append = true)
75
-    {
76
-        if ($append) {
77
-            $this->output[] = $string;
78
-            return;
79
-        }
80
-        array_unshift($this->output, $string);
81
-    }
82
-
83
-
84
-    /**
85
-     * @param bool   $as_string
86
-     * @param string $separator
87
-     * @return array|string
88
-     */
89
-    public function getOutput(bool $as_string = true, string $separator = PHP_EOL)
90
-    {
91
-        return $as_string
92
-            ? implode($separator, $this->output)
93
-            : $this->output;
94
-    }
95
-
96
-
97
-    /**
98
-     * @return boolean
99
-     */
100
-    public function requestTerminated(): bool
101
-    {
102
-        return $this->request_terminated;
103
-    }
104
-
105
-
106
-    /**
107
-     * @param bool|int|string|null $request_terminated
108
-     */
109
-    public function terminateRequest($request_terminated = true)
110
-    {
111
-        $this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN);
112
-    }
113
-
114
-
115
-    /**
116
-     * @return boolean
117
-     */
118
-    public function pluginDeactivated(): bool
119
-    {
120
-        return $this->deactivate_plugin;
121
-    }
122
-
123
-
124
-    /**
125
-     * sets $deactivate_plugin to true
126
-     */
127
-    public function deactivatePlugin()
128
-    {
129
-        $this->deactivate_plugin = true;
130
-    }
131
-
132
-
133
-    /**
134
-     * @return array
135
-     * @since 5.0.0.p
136
-     */
137
-    public function requestHeaders(): array
138
-    {
139
-        return $this->request_headers;
140
-    }
141
-
142
-
143
-    /**
144
-     * @param string $request_header
145
-     * @return void
146
-     * @since 5.0.0.p
147
-     */
148
-    public function setRequestHeader(string $request_header): void
149
-    {
150
-        $this->request_headers[] = $request_header;
151
-    }
17
+	protected bool  $deactivate_plugin = false;
18
+
19
+	protected array $notice            = [];
20
+
21
+	/**
22
+	 * rendered output to be returned to WP
23
+	 */
24
+	protected array $output             = [];
25
+
26
+	protected array $request_headers    = [];
27
+
28
+	protected bool  $request_terminated = false;
29
+
30
+
31
+	/**
32
+	 * EE_Response constructor.
33
+	 */
34
+	public function __construct()
35
+	{
36
+		$this->terminateRequest(false);
37
+	}
38
+
39
+
40
+	/**
41
+	 * @param $key
42
+	 * @param $value
43
+	 * @return    void
44
+	 */
45
+	public function setNotice($key, $value)
46
+	{
47
+		$this->notice[ $key ] = $value;
48
+	}
49
+
50
+
51
+	/**
52
+	 * @param $key
53
+	 * @return    mixed
54
+	 */
55
+	public function getNotice($key)
56
+	{
57
+		return $this->notice[ $key ] ?? null;
58
+	}
59
+
60
+
61
+	/**
62
+	 * @return array
63
+	 */
64
+	public function getNotices(): array
65
+	{
66
+		return $this->notice;
67
+	}
68
+
69
+
70
+	/**
71
+	 * @param string $string
72
+	 * @param bool   $append
73
+	 */
74
+	public function addOutput(string $string, bool $append = true)
75
+	{
76
+		if ($append) {
77
+			$this->output[] = $string;
78
+			return;
79
+		}
80
+		array_unshift($this->output, $string);
81
+	}
82
+
83
+
84
+	/**
85
+	 * @param bool   $as_string
86
+	 * @param string $separator
87
+	 * @return array|string
88
+	 */
89
+	public function getOutput(bool $as_string = true, string $separator = PHP_EOL)
90
+	{
91
+		return $as_string
92
+			? implode($separator, $this->output)
93
+			: $this->output;
94
+	}
95
+
96
+
97
+	/**
98
+	 * @return boolean
99
+	 */
100
+	public function requestTerminated(): bool
101
+	{
102
+		return $this->request_terminated;
103
+	}
104
+
105
+
106
+	/**
107
+	 * @param bool|int|string|null $request_terminated
108
+	 */
109
+	public function terminateRequest($request_terminated = true)
110
+	{
111
+		$this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN);
112
+	}
113
+
114
+
115
+	/**
116
+	 * @return boolean
117
+	 */
118
+	public function pluginDeactivated(): bool
119
+	{
120
+		return $this->deactivate_plugin;
121
+	}
122
+
123
+
124
+	/**
125
+	 * sets $deactivate_plugin to true
126
+	 */
127
+	public function deactivatePlugin()
128
+	{
129
+		$this->deactivate_plugin = true;
130
+	}
131
+
132
+
133
+	/**
134
+	 * @return array
135
+	 * @since 5.0.0.p
136
+	 */
137
+	public function requestHeaders(): array
138
+	{
139
+		return $this->request_headers;
140
+	}
141
+
142
+
143
+	/**
144
+	 * @param string $request_header
145
+	 * @return void
146
+	 * @since 5.0.0.p
147
+	 */
148
+	public function setRequestHeader(string $request_header): void
149
+	{
150
+		$this->request_headers[] = $request_header;
151
+	}
152 152
 }
Please login to merge, or discard this patch.
core/services/request/RequestInterface.php 1 patch
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -15,224 +15,224 @@
 block discarded – undo
15 15
  */
16 16
 interface RequestInterface extends RequestTypeContextCheckerInterface
17 17
 {
18
-    /**
19
-     * @param RequestTypeContextCheckerInterface $type
20
-     */
21
-    public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type);
18
+	/**
19
+	 * @param RequestTypeContextCheckerInterface $type
20
+	 */
21
+	public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type);
22 22
 
23 23
 
24
-    /**
25
-     * @return array
26
-     */
27
-    public function getParams();
28
-
29
-
30
-    /**
31
-     * @return array
32
-     */
33
-    public function postParams();
34
-
35
-
36
-    /**
37
-     * @return array
38
-     */
39
-    public function cookieParams();
40
-
41
-
42
-    /**
43
-     * @return array
44
-     */
45
-    public function serverParams();
46
-
47
-
48
-    /**
49
-     * @param string $key
50
-     * @param mixed|null $default
51
-     * @return array|int|float|string
52
-     */
53
-    public function getServerParam($key, $default = null);
54
-
55
-
56
-    /**
57
-     * @param string                 $key
58
-     * @param array|int|float|string $value
59
-     * @param bool                   $set_global_too
60
-     * @return void
61
-     */
62
-    public function setServerParam(string $key, $value, bool $set_global_too = false);
63
-
64
-
65
-    /**
66
-     * @param string $key
67
-     * @return bool
68
-     */
69
-    public function serverParamIsSet($key);
70
-
71
-
72
-    /**
73
-     * @return array
74
-     */
75
-    public function filesParams();
76
-
77
-
78
-    /**
79
-     * returns sanitized contents of $_REQUEST
80
-     *
81
-     * @return array
82
-     */
83
-    public function requestParams();
84
-
85
-
86
-    /**
87
-     * @param string $key
88
-     * @param string $value
89
-     * @param bool   $override_ee
90
-     * @return void
91
-     */
92
-    public function setRequestParam($key, $value, $override_ee = false);
93
-
94
-
95
-    /**
96
-     * returns   the value for a request param if the given key exists
97
-     *
98
-     * @param string     $key
99
-     * @param mixed|null $default
100
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
101
-     * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
102
-     * @param string     $delimiter for CSV type strings that should be returned as an array
103
-     * @return array|bool|float|int|string
104
-     */
105
-    public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '');
106
-
107
-
108
-    /**
109
-     * check if param exists
110
-     *
111
-     * @param string $key
112
-     * @return bool
113
-     */
114
-    public function requestParamIsSet($key);
115
-
116
-
117
-    /**
118
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
119
-     * and return the value for the first match found
120
-     * wildcards can be either of the following:
121
-     *      ? to represent a single character of any type
122
-     *      * to represent one or more characters of any type
123
-     *
124
-     * @param string     $pattern
125
-     * @param mixed|null $default
126
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
127
-     * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
128
-     * @param string     $delimiter for CSV type strings that should be returned as an array
129
-     * @return array|bool|float|int|string
130
-     */
131
-    public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '');
132
-
133
-
134
-    /**
135
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
136
-     * wildcards can be either of the following:
137
-     *      ? to represent a single character of any type
138
-     *      * to represent one or more characters of any type
139
-     * returns true if a match is found or false if not
140
-     *
141
-     * @param string $pattern
142
-     * @return false|int
143
-     */
144
-    public function matches($pattern);
145
-
146
-
147
-    /**
148
-     * remove param
149
-     *
150
-     * @param string $key
151
-     * @param bool   $unset_from_global_too
152
-     */
153
-    public function unSetRequestParam($key, $unset_from_global_too = false);
154
-
155
-
156
-    /**
157
-     * remove params
158
-     *
159
-     * @param array $keys
160
-     * @param bool  $unset_from_global_too
161
-     */
162
-    public function unSetRequestParams(array $keys, $unset_from_global_too = false);
163
-
164
-
165
-    /**
166
-     * @param string $key
167
-     * @param bool   $unset_from_global_too
168
-     * @return void
169
-     */
170
-    public function unSetServerParam(string $key, bool $unset_from_global_too = false);
171
-
172
-
173
-    /**
174
-     * @return string
175
-     */
176
-    public function ipAddress();
177
-
178
-
179
-    /**
180
-     * @param boolean $relativeToWpRoot    whether or not to return the uri relative to WordPress' home URL.
181
-     * @param boolean $remove_query_params whether or not to return the uri with all query params removed.
182
-     * @return string
183
-     */
184
-    public function requestUri($relativeToWpRoot = false, $remove_query_params = false);
185
-
186
-
187
-    /**
188
-     * @return string
189
-     */
190
-    public function userAgent();
191
-
192
-
193
-    /**
194
-     * @param string $user_agent
195
-     */
196
-    public function setUserAgent($user_agent = '');
197
-
198
-
199
-    /**
200
-     * @return bool
201
-     */
202
-    public function isBot();
203
-
204
-
205
-    /**
206
-     * @param bool $is_bot
207
-     */
208
-    public function setIsBot($is_bot);
209
-
210
-
211
-    /**
212
-     * returns the path portion of the current request URI with both the WP Root (home_url()) and query params removed
213
-     *
214
-     * @return string
215
-     * @since   5.0.0.p
216
-     */
217
-    public function requestPath();
218
-
219
-
220
-    /**
221
-     * returns true if the last segment of the current request path (without params) matches the provided string
222
-     *
223
-     * @param string $uri_segment
224
-     * @return bool
225
-     * @since   5.0.0.p
226
-     */
227
-    public function currentPageIs($uri_segment);
228
-
229
-
230
-    /**
231
-     * merges the incoming array of parameters into the existing request parameters
232
-     *
233
-     * @param array $request_params
234
-     * @return mixed
235
-     * @since   4.10.24.p
236
-     */
237
-    public function mergeRequestParams(array $request_params);
24
+	/**
25
+	 * @return array
26
+	 */
27
+	public function getParams();
28
+
29
+
30
+	/**
31
+	 * @return array
32
+	 */
33
+	public function postParams();
34
+
35
+
36
+	/**
37
+	 * @return array
38
+	 */
39
+	public function cookieParams();
40
+
41
+
42
+	/**
43
+	 * @return array
44
+	 */
45
+	public function serverParams();
46
+
47
+
48
+	/**
49
+	 * @param string $key
50
+	 * @param mixed|null $default
51
+	 * @return array|int|float|string
52
+	 */
53
+	public function getServerParam($key, $default = null);
54
+
55
+
56
+	/**
57
+	 * @param string                 $key
58
+	 * @param array|int|float|string $value
59
+	 * @param bool                   $set_global_too
60
+	 * @return void
61
+	 */
62
+	public function setServerParam(string $key, $value, bool $set_global_too = false);
63
+
64
+
65
+	/**
66
+	 * @param string $key
67
+	 * @return bool
68
+	 */
69
+	public function serverParamIsSet($key);
70
+
71
+
72
+	/**
73
+	 * @return array
74
+	 */
75
+	public function filesParams();
76
+
77
+
78
+	/**
79
+	 * returns sanitized contents of $_REQUEST
80
+	 *
81
+	 * @return array
82
+	 */
83
+	public function requestParams();
84
+
85
+
86
+	/**
87
+	 * @param string $key
88
+	 * @param string $value
89
+	 * @param bool   $override_ee
90
+	 * @return void
91
+	 */
92
+	public function setRequestParam($key, $value, $override_ee = false);
93
+
94
+
95
+	/**
96
+	 * returns   the value for a request param if the given key exists
97
+	 *
98
+	 * @param string     $key
99
+	 * @param mixed|null $default
100
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
101
+	 * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
102
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
103
+	 * @return array|bool|float|int|string
104
+	 */
105
+	public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '');
106
+
107
+
108
+	/**
109
+	 * check if param exists
110
+	 *
111
+	 * @param string $key
112
+	 * @return bool
113
+	 */
114
+	public function requestParamIsSet($key);
115
+
116
+
117
+	/**
118
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
119
+	 * and return the value for the first match found
120
+	 * wildcards can be either of the following:
121
+	 *      ? to represent a single character of any type
122
+	 *      * to represent one or more characters of any type
123
+	 *
124
+	 * @param string     $pattern
125
+	 * @param mixed|null $default
126
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
127
+	 * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
128
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
129
+	 * @return array|bool|float|int|string
130
+	 */
131
+	public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '');
132
+
133
+
134
+	/**
135
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
136
+	 * wildcards can be either of the following:
137
+	 *      ? to represent a single character of any type
138
+	 *      * to represent one or more characters of any type
139
+	 * returns true if a match is found or false if not
140
+	 *
141
+	 * @param string $pattern
142
+	 * @return false|int
143
+	 */
144
+	public function matches($pattern);
145
+
146
+
147
+	/**
148
+	 * remove param
149
+	 *
150
+	 * @param string $key
151
+	 * @param bool   $unset_from_global_too
152
+	 */
153
+	public function unSetRequestParam($key, $unset_from_global_too = false);
154
+
155
+
156
+	/**
157
+	 * remove params
158
+	 *
159
+	 * @param array $keys
160
+	 * @param bool  $unset_from_global_too
161
+	 */
162
+	public function unSetRequestParams(array $keys, $unset_from_global_too = false);
163
+
164
+
165
+	/**
166
+	 * @param string $key
167
+	 * @param bool   $unset_from_global_too
168
+	 * @return void
169
+	 */
170
+	public function unSetServerParam(string $key, bool $unset_from_global_too = false);
171
+
172
+
173
+	/**
174
+	 * @return string
175
+	 */
176
+	public function ipAddress();
177
+
178
+
179
+	/**
180
+	 * @param boolean $relativeToWpRoot    whether or not to return the uri relative to WordPress' home URL.
181
+	 * @param boolean $remove_query_params whether or not to return the uri with all query params removed.
182
+	 * @return string
183
+	 */
184
+	public function requestUri($relativeToWpRoot = false, $remove_query_params = false);
185
+
186
+
187
+	/**
188
+	 * @return string
189
+	 */
190
+	public function userAgent();
191
+
192
+
193
+	/**
194
+	 * @param string $user_agent
195
+	 */
196
+	public function setUserAgent($user_agent = '');
197
+
198
+
199
+	/**
200
+	 * @return bool
201
+	 */
202
+	public function isBot();
203
+
204
+
205
+	/**
206
+	 * @param bool $is_bot
207
+	 */
208
+	public function setIsBot($is_bot);
209
+
210
+
211
+	/**
212
+	 * returns the path portion of the current request URI with both the WP Root (home_url()) and query params removed
213
+	 *
214
+	 * @return string
215
+	 * @since   5.0.0.p
216
+	 */
217
+	public function requestPath();
218
+
219
+
220
+	/**
221
+	 * returns true if the last segment of the current request path (without params) matches the provided string
222
+	 *
223
+	 * @param string $uri_segment
224
+	 * @return bool
225
+	 * @since   5.0.0.p
226
+	 */
227
+	public function currentPageIs($uri_segment);
228
+
229
+
230
+	/**
231
+	 * merges the incoming array of parameters into the existing request parameters
232
+	 *
233
+	 * @param array $request_params
234
+	 * @return mixed
235
+	 * @since   4.10.24.p
236
+	 */
237
+	public function mergeRequestParams(array $request_params);
238 238
 }
Please login to merge, or discard this patch.
core/services/request/ResponseInterface.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -11,77 +11,77 @@
 block discarded – undo
11 11
  */
12 12
 interface ResponseInterface
13 13
 {
14
-    /**
15
-     * @param $key
16
-     * @param $value
17
-     * @return    void
18
-     */
19
-    public function setNotice($key, $value);
14
+	/**
15
+	 * @param $key
16
+	 * @param $value
17
+	 * @return    void
18
+	 */
19
+	public function setNotice($key, $value);
20 20
 
21 21
 
22
-    /**
23
-     * @param $key
24
-     * @return    mixed
25
-     */
26
-    public function getNotice($key);
22
+	/**
23
+	 * @param $key
24
+	 * @return    mixed
25
+	 */
26
+	public function getNotice($key);
27 27
 
28 28
 
29
-    /**
30
-     * @return    array
31
-     */
32
-    public function getNotices(): array;
29
+	/**
30
+	 * @return    array
31
+	 */
32
+	public function getNotices(): array;
33 33
 
34 34
 
35
-    /**
36
-     * @param string $string
37
-     * @param bool   $append
38
-     */
39
-    public function addOutput(string $string, bool $append = true);
35
+	/**
36
+	 * @param string $string
37
+	 * @param bool   $append
38
+	 */
39
+	public function addOutput(string $string, bool $append = true);
40 40
 
41 41
 
42
-    /**
43
-     * @param bool   $as_string
44
-     * @param string $separator
45
-     * @return array|string
46
-     */
47
-    public function getOutput(bool $as_string = true, string $separator = PHP_EOL);
42
+	/**
43
+	 * @param bool   $as_string
44
+	 * @param string $separator
45
+	 * @return array|string
46
+	 */
47
+	public function getOutput(bool $as_string = true, string $separator = PHP_EOL);
48 48
 
49 49
 
50
-    /**
51
-     * @return boolean
52
-     */
53
-    public function requestTerminated(): bool;
50
+	/**
51
+	 * @return boolean
52
+	 */
53
+	public function requestTerminated(): bool;
54 54
 
55 55
 
56
-    /**
57
-     * @param bool|int|string|null $request_terminated
58
-     */
59
-    public function terminateRequest($request_terminated = true);
56
+	/**
57
+	 * @param bool|int|string|null $request_terminated
58
+	 */
59
+	public function terminateRequest($request_terminated = true);
60 60
 
61 61
 
62
-    /**
63
-     * @return boolean
64
-     */
65
-    public function pluginDeactivated(): bool;
62
+	/**
63
+	 * @return boolean
64
+	 */
65
+	public function pluginDeactivated(): bool;
66 66
 
67 67
 
68
-    /**
69
-     * sets $deactivate_plugin to true
70
-     */
71
-    public function deactivatePlugin();
68
+	/**
69
+	 * sets $deactivate_plugin to true
70
+	 */
71
+	public function deactivatePlugin();
72 72
 
73 73
 
74
-    /**
75
-     * @return array
76
-     * @since 5.0.0.p
77
-     */
78
-    public function requestHeaders(): array;
74
+	/**
75
+	 * @return array
76
+	 * @since 5.0.0.p
77
+	 */
78
+	public function requestHeaders(): array;
79 79
 
80 80
 
81
-    /**
82
-     * @param string $request_header
83
-     * @return void
84
-     * @since 5.0.0.p
85
-     */
86
-    public function setRequestHeader(string $request_header): void;
81
+	/**
82
+	 * @param string $request_header
83
+	 * @return void
84
+	 * @since 5.0.0.p
85
+	 */
86
+	public function setRequestHeader(string $request_header): void;
87 87
 }
Please login to merge, or discard this patch.
core/services/request/Request.php 1 patch
Indentation   +549 added lines, -549 removed lines patch added patch discarded remove patch
@@ -16,553 +16,553 @@
 block discarded – undo
16 16
  */
17 17
 class Request implements InterminableInterface, RequestInterface, ReservedInstanceInterface
18 18
 {
19
-    /**
20
-     * $_COOKIE parameters
21
-     *
22
-     * @var array
23
-     */
24
-    protected $cookies;
25
-
26
-    /**
27
-     * $_FILES parameters
28
-     *
29
-     * @var array
30
-     */
31
-    protected $files;
32
-
33
-    /**
34
-     * true if current user appears to be some kind of bot
35
-     *
36
-     * @var bool
37
-     */
38
-    protected $is_bot;
39
-
40
-    /**
41
-     * @var RequestParams
42
-     */
43
-    protected $request_params;
44
-
45
-    /**
46
-     * @var RequestTypeContextCheckerInterface
47
-     */
48
-    protected $request_type;
49
-
50
-    /**
51
-     * @var ServerParams
52
-     */
53
-    protected $server_params;
54
-
55
-
56
-    public function __construct(
57
-        RequestParams $request_params,
58
-        ServerParams $server_params,
59
-        array $cookies = [],
60
-        array $files = []
61
-    ) {
62
-        $this->cookies        = ! empty($cookies)
63
-            ? $cookies
64
-            : filter_input_array(INPUT_COOKIE, FILTER_UNSAFE_RAW);
65
-        $this->files          = ! empty($files) ? $files : $_FILES;
66
-        $this->request_params = $request_params;
67
-        $this->server_params  = $server_params;
68
-    }
69
-
70
-
71
-    /**
72
-     * @param RequestTypeContextCheckerInterface $type
73
-     */
74
-    public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
75
-    {
76
-        $this->request_type = $type;
77
-    }
78
-
79
-
80
-    /**
81
-     * @return array
82
-     */
83
-    public function getParams()
84
-    {
85
-        return $this->request_params->getParams();
86
-    }
87
-
88
-
89
-    /**
90
-     * @return array
91
-     */
92
-    public function postParams()
93
-    {
94
-        return $this->request_params->postParams();
95
-    }
96
-
97
-
98
-    /**
99
-     * @return array
100
-     */
101
-    public function cookieParams()
102
-    {
103
-        return $this->cookies;
104
-    }
105
-
106
-
107
-    /**
108
-     * @return array
109
-     */
110
-    public function serverParams()
111
-    {
112
-        return $this->server_params->getAllServerParams();
113
-    }
114
-
115
-
116
-    /**
117
-     * @param string     $key
118
-     * @param mixed|null $default
119
-     * @return array|int|float|string
120
-     */
121
-    public function getServerParam($key, $default = null)
122
-    {
123
-        return $this->server_params->getServerParam($key, $default);
124
-    }
125
-
126
-
127
-    /**
128
-     * @param string                 $key
129
-     * @param array|int|float|string $value
130
-     * @param bool                   $set_global_too
131
-     * @return void
132
-     */
133
-    public function setServerParam(string $key, $value, bool $set_global_too = false)
134
-    {
135
-        $this->server_params->setServerParam($key, $value, $set_global_too);
136
-    }
137
-
138
-
139
-    /**
140
-     * @param string $key
141
-     * @return bool
142
-     */
143
-    public function serverParamIsSet($key)
144
-    {
145
-        return $this->server_params->serverParamIsSet($key);
146
-    }
147
-
148
-
149
-    /**
150
-     * @return array
151
-     */
152
-    public function filesParams()
153
-    {
154
-        return $this->files;
155
-    }
156
-
157
-
158
-    /**
159
-     * returns sanitized contents of $_REQUEST
160
-     *
161
-     * @return array
162
-     */
163
-    public function requestParams()
164
-    {
165
-        return $this->request_params->requestParams();
166
-    }
167
-
168
-
169
-    /**
170
-     * @param string     $key
171
-     * @param mixed|null $value
172
-     * @param bool       $override_ee
173
-     * @return void
174
-     */
175
-    public function setRequestParam($key, $value, $override_ee = false)
176
-    {
177
-        $this->request_params->setRequestParam($key, $value, $override_ee);
178
-    }
179
-
180
-
181
-    /**
182
-     * merges the incoming array of parameters into the existing request parameters
183
-     *
184
-     * @param array $request_params
185
-     * @return void
186
-     * @since   4.10.24.p
187
-     */
188
-    public function mergeRequestParams(array $request_params)
189
-    {
190
-        $this->request_params->mergeRequestParams($request_params);
191
-    }
192
-
193
-
194
-    /**
195
-     * returns sanitized value for a request param if the given key exists
196
-     *
197
-     * @param string     $key
198
-     * @param mixed|null $default
199
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
200
-     * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
201
-     * @param string     $delimiter for CSV type strings that should be returned as an array
202
-     * @return array|bool|float|int|string
203
-     */
204
-    public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '')
205
-    {
206
-        return $this->request_params->getRequestParam($key, $default, $type, $is_array, $delimiter);
207
-    }
208
-
209
-
210
-    /**
211
-     * check if param exists
212
-     *
213
-     * @param string $key
214
-     * @return bool
215
-     */
216
-    public function requestParamIsSet($key)
217
-    {
218
-        return $this->request_params->requestParamIsSet($key);
219
-    }
220
-
221
-
222
-    /**
223
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
224
-     * and return the sanitized value for the first match found
225
-     * wildcards can be either of the following:
226
-     *      ? to represent a single character of any type
227
-     *      * to represent one or more characters of any type
228
-     *
229
-     * @param string     $pattern
230
-     * @param mixed|null $default
231
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
232
-     * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
233
-     * @param string     $delimiter for CSV type strings that should be returned as an array
234
-     * @return array|bool|float|int|string
235
-     */
236
-    public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '')
237
-    {
238
-        return $this->request_params->getMatch($pattern, $default, $type, $is_array, $delimiter);
239
-    }
240
-
241
-
242
-    /**
243
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
244
-     * wildcards can be either of the following:
245
-     *      ? to represent a single character of any type
246
-     *      * to represent one or more characters of any type
247
-     * returns true if a match is found or false if not
248
-     *
249
-     * @param string $pattern
250
-     * @return bool
251
-     */
252
-    public function matches($pattern)
253
-    {
254
-        return $this->request_params->matches($pattern);
255
-    }
256
-
257
-
258
-    /**
259
-     * remove param
260
-     *
261
-     * @param      $key
262
-     * @param bool $unset_from_global_too
263
-     */
264
-    public function unSetRequestParam($key, $unset_from_global_too = false)
265
-    {
266
-        $this->request_params->unSetRequestParam($key, $unset_from_global_too);
267
-    }
268
-
269
-
270
-    /**
271
-     * remove params
272
-     *
273
-     * @param array $keys
274
-     * @param bool  $unset_from_global_too
275
-     */
276
-    public function unSetRequestParams(array $keys, $unset_from_global_too = false)
277
-    {
278
-        $this->request_params->unSetRequestParams($keys, $unset_from_global_too);
279
-    }
280
-
281
-
282
-    /**
283
-     * @param string $key
284
-     * @param bool   $unset_from_global_too
285
-     * @return void
286
-     */
287
-    public function unSetServerParam(string $key, bool $unset_from_global_too = false)
288
-    {
289
-        $this->server_params->unSetServerParam($key, $unset_from_global_too);
290
-    }
291
-
292
-
293
-    /**
294
-     * @return string
295
-     */
296
-    public function ipAddress()
297
-    {
298
-        return $this->server_params->ipAddress();
299
-    }
300
-
301
-
302
-    /**
303
-     * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison.
304
-     *
305
-     * @param boolean $relativeToWpRoot    If home_url() is "http://mysite.com/wp/", and a request comes to
306
-     *                                     "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return
307
-     *                                     "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/".
308
-     * @param boolean $remove_query_params whether or not to return the uri with all query params removed.
309
-     * @return string
310
-     */
311
-    public function requestUri($relativeToWpRoot = false, $remove_query_params = false)
312
-    {
313
-        return $this->server_params->requestUri($relativeToWpRoot);
314
-    }
315
-
316
-
317
-    /**
318
-     * @return string
319
-     */
320
-    public function userAgent()
321
-    {
322
-        return $this->server_params->userAgent();
323
-    }
324
-
325
-
326
-    /**
327
-     * @param string $user_agent
328
-     */
329
-    public function setUserAgent($user_agent = '')
330
-    {
331
-        $this->server_params->setUserAgent($user_agent);
332
-    }
333
-
334
-
335
-    /**
336
-     * @return bool
337
-     */
338
-    public function isBot()
339
-    {
340
-        return $this->is_bot;
341
-    }
342
-
343
-
344
-    /**
345
-     * @param bool $is_bot
346
-     */
347
-    public function setIsBot($is_bot)
348
-    {
349
-        $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN);
350
-    }
351
-
352
-
353
-    /**
354
-     * @return bool
355
-     */
356
-    public function isActivation()
357
-    {
358
-        return $this->request_type->isActivation();
359
-    }
360
-
361
-
362
-    /**
363
-     * @param $is_activation
364
-     * @return bool
365
-     */
366
-    public function setIsActivation($is_activation)
367
-    {
368
-        return $this->request_type->setIsActivation($is_activation);
369
-    }
370
-
371
-
372
-    /**
373
-     * @return bool
374
-     */
375
-    public function isAdmin()
376
-    {
377
-        return $this->request_type->isAdmin();
378
-    }
379
-
380
-
381
-    /**
382
-     * @return bool
383
-     */
384
-    public function isAdminAjax()
385
-    {
386
-        return $this->request_type->isAdminAjax();
387
-    }
388
-
389
-
390
-    /**
391
-     * @return bool
392
-     */
393
-    public function isAjax()
394
-    {
395
-        return $this->request_type->isAjax();
396
-    }
397
-
398
-
399
-    /**
400
-     * @return bool
401
-     */
402
-    public function isEeAjax()
403
-    {
404
-        return $this->request_type->isEeAjax();
405
-    }
406
-
407
-
408
-    /**
409
-     * @return bool
410
-     */
411
-    public function isOtherAjax()
412
-    {
413
-        return $this->request_type->isOtherAjax();
414
-    }
415
-
416
-
417
-    /**
418
-     * @return bool
419
-     */
420
-    public function isApi()
421
-    {
422
-        return $this->request_type->isApi();
423
-    }
424
-
425
-
426
-    /**
427
-     * @return bool
428
-     */
429
-    public function isCli()
430
-    {
431
-        return $this->request_type->isCli();
432
-    }
433
-
434
-
435
-    /**
436
-     * @return bool
437
-     */
438
-    public function isCron()
439
-    {
440
-        return $this->request_type->isCron();
441
-    }
442
-
443
-
444
-    /**
445
-     * @return bool
446
-     */
447
-    public function isFeed()
448
-    {
449
-        return $this->request_type->isFeed();
450
-    }
451
-
452
-
453
-    /**
454
-     * @return bool
455
-     */
456
-    public function isFrontend()
457
-    {
458
-        return $this->request_type->isFrontend();
459
-    }
460
-
461
-
462
-    /**
463
-     * @return bool
464
-     */
465
-    public function isFrontAjax()
466
-    {
467
-        return $this->request_type->isFrontAjax();
468
-    }
469
-
470
-
471
-    /**
472
-     * @return bool
473
-     */
474
-    public function isGQL()
475
-    {
476
-        return $this->request_type->isGQL();
477
-    }
478
-
479
-
480
-    /**
481
-     * @return bool
482
-     */
483
-    public function isIframe()
484
-    {
485
-        return $this->request_type->isIframe();
486
-    }
487
-
488
-
489
-    /**
490
-     * @return bool
491
-     */
492
-    public function isUnitTesting()
493
-    {
494
-        return $this->request_type->isUnitTesting();
495
-    }
496
-
497
-
498
-    /**
499
-     * @return bool
500
-     */
501
-    public function isWordPressApi()
502
-    {
503
-        return $this->request_type->isWordPressApi();
504
-    }
505
-
506
-
507
-    /**
508
-     * @return bool
509
-     */
510
-    public function isWordPressHeartbeat()
511
-    {
512
-        return $this->request_type->isWordPressHeartbeat();
513
-    }
514
-
515
-
516
-    /**
517
-     * @return bool
518
-     */
519
-    public function isWordPressScrape()
520
-    {
521
-        return $this->request_type->isWordPressScrape();
522
-    }
523
-
524
-
525
-    /**
526
-     * @return string
527
-     */
528
-    public function slug()
529
-    {
530
-        return $this->request_type->slug();
531
-    }
532
-
533
-
534
-    /**
535
-     * returns the path portion of the current request URI with both the WP Root (home_url()) and query params removed
536
-     *
537
-     * @return string
538
-     * @since   5.0.0.p
539
-     */
540
-    public function requestPath()
541
-    {
542
-        return $this->requestUri(true, true);
543
-    }
544
-
545
-
546
-    /**
547
-     * returns true if the last segment of the current request path (without params) matches the provided string
548
-     *
549
-     * @param string $uri_segment
550
-     * @return bool
551
-     * @since   5.0.0.p
552
-     */
553
-    public function currentPageIs($uri_segment)
554
-    {
555
-        $request_path = $this->requestPath();
556
-        $current_page = explode('/', $request_path);
557
-        return end($current_page) === $uri_segment;
558
-    }
559
-
560
-
561
-    /**
562
-     * @return RequestTypeContextCheckerInterface
563
-     */
564
-    public function getRequestType(): RequestTypeContextCheckerInterface
565
-    {
566
-        return $this->request_type;
567
-    }
19
+	/**
20
+	 * $_COOKIE parameters
21
+	 *
22
+	 * @var array
23
+	 */
24
+	protected $cookies;
25
+
26
+	/**
27
+	 * $_FILES parameters
28
+	 *
29
+	 * @var array
30
+	 */
31
+	protected $files;
32
+
33
+	/**
34
+	 * true if current user appears to be some kind of bot
35
+	 *
36
+	 * @var bool
37
+	 */
38
+	protected $is_bot;
39
+
40
+	/**
41
+	 * @var RequestParams
42
+	 */
43
+	protected $request_params;
44
+
45
+	/**
46
+	 * @var RequestTypeContextCheckerInterface
47
+	 */
48
+	protected $request_type;
49
+
50
+	/**
51
+	 * @var ServerParams
52
+	 */
53
+	protected $server_params;
54
+
55
+
56
+	public function __construct(
57
+		RequestParams $request_params,
58
+		ServerParams $server_params,
59
+		array $cookies = [],
60
+		array $files = []
61
+	) {
62
+		$this->cookies        = ! empty($cookies)
63
+			? $cookies
64
+			: filter_input_array(INPUT_COOKIE, FILTER_UNSAFE_RAW);
65
+		$this->files          = ! empty($files) ? $files : $_FILES;
66
+		$this->request_params = $request_params;
67
+		$this->server_params  = $server_params;
68
+	}
69
+
70
+
71
+	/**
72
+	 * @param RequestTypeContextCheckerInterface $type
73
+	 */
74
+	public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
75
+	{
76
+		$this->request_type = $type;
77
+	}
78
+
79
+
80
+	/**
81
+	 * @return array
82
+	 */
83
+	public function getParams()
84
+	{
85
+		return $this->request_params->getParams();
86
+	}
87
+
88
+
89
+	/**
90
+	 * @return array
91
+	 */
92
+	public function postParams()
93
+	{
94
+		return $this->request_params->postParams();
95
+	}
96
+
97
+
98
+	/**
99
+	 * @return array
100
+	 */
101
+	public function cookieParams()
102
+	{
103
+		return $this->cookies;
104
+	}
105
+
106
+
107
+	/**
108
+	 * @return array
109
+	 */
110
+	public function serverParams()
111
+	{
112
+		return $this->server_params->getAllServerParams();
113
+	}
114
+
115
+
116
+	/**
117
+	 * @param string     $key
118
+	 * @param mixed|null $default
119
+	 * @return array|int|float|string
120
+	 */
121
+	public function getServerParam($key, $default = null)
122
+	{
123
+		return $this->server_params->getServerParam($key, $default);
124
+	}
125
+
126
+
127
+	/**
128
+	 * @param string                 $key
129
+	 * @param array|int|float|string $value
130
+	 * @param bool                   $set_global_too
131
+	 * @return void
132
+	 */
133
+	public function setServerParam(string $key, $value, bool $set_global_too = false)
134
+	{
135
+		$this->server_params->setServerParam($key, $value, $set_global_too);
136
+	}
137
+
138
+
139
+	/**
140
+	 * @param string $key
141
+	 * @return bool
142
+	 */
143
+	public function serverParamIsSet($key)
144
+	{
145
+		return $this->server_params->serverParamIsSet($key);
146
+	}
147
+
148
+
149
+	/**
150
+	 * @return array
151
+	 */
152
+	public function filesParams()
153
+	{
154
+		return $this->files;
155
+	}
156
+
157
+
158
+	/**
159
+	 * returns sanitized contents of $_REQUEST
160
+	 *
161
+	 * @return array
162
+	 */
163
+	public function requestParams()
164
+	{
165
+		return $this->request_params->requestParams();
166
+	}
167
+
168
+
169
+	/**
170
+	 * @param string     $key
171
+	 * @param mixed|null $value
172
+	 * @param bool       $override_ee
173
+	 * @return void
174
+	 */
175
+	public function setRequestParam($key, $value, $override_ee = false)
176
+	{
177
+		$this->request_params->setRequestParam($key, $value, $override_ee);
178
+	}
179
+
180
+
181
+	/**
182
+	 * merges the incoming array of parameters into the existing request parameters
183
+	 *
184
+	 * @param array $request_params
185
+	 * @return void
186
+	 * @since   4.10.24.p
187
+	 */
188
+	public function mergeRequestParams(array $request_params)
189
+	{
190
+		$this->request_params->mergeRequestParams($request_params);
191
+	}
192
+
193
+
194
+	/**
195
+	 * returns sanitized value for a request param if the given key exists
196
+	 *
197
+	 * @param string     $key
198
+	 * @param mixed|null $default
199
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
200
+	 * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
201
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
202
+	 * @return array|bool|float|int|string
203
+	 */
204
+	public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '')
205
+	{
206
+		return $this->request_params->getRequestParam($key, $default, $type, $is_array, $delimiter);
207
+	}
208
+
209
+
210
+	/**
211
+	 * check if param exists
212
+	 *
213
+	 * @param string $key
214
+	 * @return bool
215
+	 */
216
+	public function requestParamIsSet($key)
217
+	{
218
+		return $this->request_params->requestParamIsSet($key);
219
+	}
220
+
221
+
222
+	/**
223
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
224
+	 * and return the sanitized value for the first match found
225
+	 * wildcards can be either of the following:
226
+	 *      ? to represent a single character of any type
227
+	 *      * to represent one or more characters of any type
228
+	 *
229
+	 * @param string     $pattern
230
+	 * @param mixed|null $default
231
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
232
+	 * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
233
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
234
+	 * @return array|bool|float|int|string
235
+	 */
236
+	public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '')
237
+	{
238
+		return $this->request_params->getMatch($pattern, $default, $type, $is_array, $delimiter);
239
+	}
240
+
241
+
242
+	/**
243
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
244
+	 * wildcards can be either of the following:
245
+	 *      ? to represent a single character of any type
246
+	 *      * to represent one or more characters of any type
247
+	 * returns true if a match is found or false if not
248
+	 *
249
+	 * @param string $pattern
250
+	 * @return bool
251
+	 */
252
+	public function matches($pattern)
253
+	{
254
+		return $this->request_params->matches($pattern);
255
+	}
256
+
257
+
258
+	/**
259
+	 * remove param
260
+	 *
261
+	 * @param      $key
262
+	 * @param bool $unset_from_global_too
263
+	 */
264
+	public function unSetRequestParam($key, $unset_from_global_too = false)
265
+	{
266
+		$this->request_params->unSetRequestParam($key, $unset_from_global_too);
267
+	}
268
+
269
+
270
+	/**
271
+	 * remove params
272
+	 *
273
+	 * @param array $keys
274
+	 * @param bool  $unset_from_global_too
275
+	 */
276
+	public function unSetRequestParams(array $keys, $unset_from_global_too = false)
277
+	{
278
+		$this->request_params->unSetRequestParams($keys, $unset_from_global_too);
279
+	}
280
+
281
+
282
+	/**
283
+	 * @param string $key
284
+	 * @param bool   $unset_from_global_too
285
+	 * @return void
286
+	 */
287
+	public function unSetServerParam(string $key, bool $unset_from_global_too = false)
288
+	{
289
+		$this->server_params->unSetServerParam($key, $unset_from_global_too);
290
+	}
291
+
292
+
293
+	/**
294
+	 * @return string
295
+	 */
296
+	public function ipAddress()
297
+	{
298
+		return $this->server_params->ipAddress();
299
+	}
300
+
301
+
302
+	/**
303
+	 * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison.
304
+	 *
305
+	 * @param boolean $relativeToWpRoot    If home_url() is "http://mysite.com/wp/", and a request comes to
306
+	 *                                     "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return
307
+	 *                                     "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/".
308
+	 * @param boolean $remove_query_params whether or not to return the uri with all query params removed.
309
+	 * @return string
310
+	 */
311
+	public function requestUri($relativeToWpRoot = false, $remove_query_params = false)
312
+	{
313
+		return $this->server_params->requestUri($relativeToWpRoot);
314
+	}
315
+
316
+
317
+	/**
318
+	 * @return string
319
+	 */
320
+	public function userAgent()
321
+	{
322
+		return $this->server_params->userAgent();
323
+	}
324
+
325
+
326
+	/**
327
+	 * @param string $user_agent
328
+	 */
329
+	public function setUserAgent($user_agent = '')
330
+	{
331
+		$this->server_params->setUserAgent($user_agent);
332
+	}
333
+
334
+
335
+	/**
336
+	 * @return bool
337
+	 */
338
+	public function isBot()
339
+	{
340
+		return $this->is_bot;
341
+	}
342
+
343
+
344
+	/**
345
+	 * @param bool $is_bot
346
+	 */
347
+	public function setIsBot($is_bot)
348
+	{
349
+		$this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN);
350
+	}
351
+
352
+
353
+	/**
354
+	 * @return bool
355
+	 */
356
+	public function isActivation()
357
+	{
358
+		return $this->request_type->isActivation();
359
+	}
360
+
361
+
362
+	/**
363
+	 * @param $is_activation
364
+	 * @return bool
365
+	 */
366
+	public function setIsActivation($is_activation)
367
+	{
368
+		return $this->request_type->setIsActivation($is_activation);
369
+	}
370
+
371
+
372
+	/**
373
+	 * @return bool
374
+	 */
375
+	public function isAdmin()
376
+	{
377
+		return $this->request_type->isAdmin();
378
+	}
379
+
380
+
381
+	/**
382
+	 * @return bool
383
+	 */
384
+	public function isAdminAjax()
385
+	{
386
+		return $this->request_type->isAdminAjax();
387
+	}
388
+
389
+
390
+	/**
391
+	 * @return bool
392
+	 */
393
+	public function isAjax()
394
+	{
395
+		return $this->request_type->isAjax();
396
+	}
397
+
398
+
399
+	/**
400
+	 * @return bool
401
+	 */
402
+	public function isEeAjax()
403
+	{
404
+		return $this->request_type->isEeAjax();
405
+	}
406
+
407
+
408
+	/**
409
+	 * @return bool
410
+	 */
411
+	public function isOtherAjax()
412
+	{
413
+		return $this->request_type->isOtherAjax();
414
+	}
415
+
416
+
417
+	/**
418
+	 * @return bool
419
+	 */
420
+	public function isApi()
421
+	{
422
+		return $this->request_type->isApi();
423
+	}
424
+
425
+
426
+	/**
427
+	 * @return bool
428
+	 */
429
+	public function isCli()
430
+	{
431
+		return $this->request_type->isCli();
432
+	}
433
+
434
+
435
+	/**
436
+	 * @return bool
437
+	 */
438
+	public function isCron()
439
+	{
440
+		return $this->request_type->isCron();
441
+	}
442
+
443
+
444
+	/**
445
+	 * @return bool
446
+	 */
447
+	public function isFeed()
448
+	{
449
+		return $this->request_type->isFeed();
450
+	}
451
+
452
+
453
+	/**
454
+	 * @return bool
455
+	 */
456
+	public function isFrontend()
457
+	{
458
+		return $this->request_type->isFrontend();
459
+	}
460
+
461
+
462
+	/**
463
+	 * @return bool
464
+	 */
465
+	public function isFrontAjax()
466
+	{
467
+		return $this->request_type->isFrontAjax();
468
+	}
469
+
470
+
471
+	/**
472
+	 * @return bool
473
+	 */
474
+	public function isGQL()
475
+	{
476
+		return $this->request_type->isGQL();
477
+	}
478
+
479
+
480
+	/**
481
+	 * @return bool
482
+	 */
483
+	public function isIframe()
484
+	{
485
+		return $this->request_type->isIframe();
486
+	}
487
+
488
+
489
+	/**
490
+	 * @return bool
491
+	 */
492
+	public function isUnitTesting()
493
+	{
494
+		return $this->request_type->isUnitTesting();
495
+	}
496
+
497
+
498
+	/**
499
+	 * @return bool
500
+	 */
501
+	public function isWordPressApi()
502
+	{
503
+		return $this->request_type->isWordPressApi();
504
+	}
505
+
506
+
507
+	/**
508
+	 * @return bool
509
+	 */
510
+	public function isWordPressHeartbeat()
511
+	{
512
+		return $this->request_type->isWordPressHeartbeat();
513
+	}
514
+
515
+
516
+	/**
517
+	 * @return bool
518
+	 */
519
+	public function isWordPressScrape()
520
+	{
521
+		return $this->request_type->isWordPressScrape();
522
+	}
523
+
524
+
525
+	/**
526
+	 * @return string
527
+	 */
528
+	public function slug()
529
+	{
530
+		return $this->request_type->slug();
531
+	}
532
+
533
+
534
+	/**
535
+	 * returns the path portion of the current request URI with both the WP Root (home_url()) and query params removed
536
+	 *
537
+	 * @return string
538
+	 * @since   5.0.0.p
539
+	 */
540
+	public function requestPath()
541
+	{
542
+		return $this->requestUri(true, true);
543
+	}
544
+
545
+
546
+	/**
547
+	 * returns true if the last segment of the current request path (without params) matches the provided string
548
+	 *
549
+	 * @param string $uri_segment
550
+	 * @return bool
551
+	 * @since   5.0.0.p
552
+	 */
553
+	public function currentPageIs($uri_segment)
554
+	{
555
+		$request_path = $this->requestPath();
556
+		$current_page = explode('/', $request_path);
557
+		return end($current_page) === $uri_segment;
558
+	}
559
+
560
+
561
+	/**
562
+	 * @return RequestTypeContextCheckerInterface
563
+	 */
564
+	public function getRequestType(): RequestTypeContextCheckerInterface
565
+	{
566
+		return $this->request_type;
567
+	}
568 568
 }
Please login to merge, or discard this patch.
core/services/json/JsonConfig.php 1 patch
Indentation   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -16,191 +16,191 @@
 block discarded – undo
16 16
  */
17 17
 abstract class JsonConfig
18 18
 {
19
-    /**
20
-     * @var boolean $has_changes
21
-     */
22
-    private $has_changes = false;
23
-
24
-    /**
25
-     * @var string $option_name
26
-     */
27
-    private $option_name;
28
-
29
-
30
-    /**
31
-     * SettingsConfig constructor.
32
-     *
33
-     * @param array $defaults
34
-     */
35
-    public function __construct(array $defaults)
36
-    {
37
-        $this->setOptionName();
38
-        $this->load($defaults);
39
-        $this->clearChanges();
40
-    }
41
-
42
-
43
-    /**
44
-     * @return array
45
-     */
46
-    abstract protected function getProperties();
47
-
48
-
49
-    /**
50
-     * converts property name to:
51
-     *      camelCase for getters ex: show_expired => showExpired
52
-     *      PascalCase for setters ex: show_expired => ShowExpired
53
-     *
54
-     * @param string $string
55
-     * @param false  $camelCase
56
-     * @return string|string[]
57
-     * @since   5.0.0.p
58
-     */
59
-    private function convertCase($string, $camelCase = false)
60
-    {
61
-        $string = str_replace(' ', '', ucwords(str_replace('_', ' ', $string)));
62
-        if ($camelCase) {
63
-            $string = lcfirst($string);
64
-        }
65
-        return $string;
66
-    }
67
-
68
-
69
-    /**
70
-     * @param string $property
71
-     * @param bool   $getter
72
-     * @return string
73
-     */
74
-    private function createGetterSetter($property, $getter = true)
75
-    {
76
-        $setterOrGetter = $this->convertCase($property, $getter);
77
-        // if not a getter, prepend with "set". ex: Show_expired => setShowExpired
78
-        $setterOrGetter = ! $getter ? 'set' . $setterOrGetter : $setterOrGetter;
79
-        return $this->isValidMethod($setterOrGetter) ? $setterOrGetter : '';
80
-    }
81
-
82
-
83
-    /**
84
-     * @param string $method
85
-     * @return bool
86
-     * @throws DomainException
87
-     */
88
-    private function isValidMethod($method)
89
-    {
90
-        if (method_exists($this, $method)) {
91
-            return true;
92
-        }
93
-        throw new DomainException(
94
-            sprintf(
95
-                esc_html__('Missing %1$s method on JsonConfig class %2$s.', 'event_espresso'),
96
-                $method,
97
-                get_class($this)
98
-            )
99
-        );
100
-    }
101
-
102
-
103
-    /**
104
-     * converts class name to option name by changing backslashes to dashes
105
-     */
106
-    private function setOptionName()
107
-    {
108
-        $this->option_name = str_replace(['EventEspresso', '\\'], ['ee', '-'], get_class($this));
109
-    }
110
-
111
-
112
-    /**
113
-     * retrieves WP option for class, decodes the data, and resigns values to properties
114
-     *
115
-     * @param array $defaults
116
-     */
117
-    protected function load(array $defaults)
118
-    {
119
-        $config = get_option($this->option_name, '{}');
120
-        $config = (array) json_decode($config) + $defaults;
121
-        foreach ($this->getProperties() as $property => $value) {
122
-            if ($property === 'option_name') {
123
-                continue;
124
-            }
125
-            // convert to PascalCase and prepend with "set". ex: show_expired => setShowExpired
126
-            $setter = $this->createGetterSetter($property, false);
127
-            $value  = array_key_exists($property, $config) ? $config[ $property ] : null;
128
-            $this->{$setter}($value);
129
-        }
130
-    }
131
-
132
-
133
-    /**
134
-     * updates property value and marks changes if property value has changed
135
-     *
136
-     * @param string $property
137
-     * @param mixed  $value
138
-     */
139
-    protected function setProperty($property, $value)
140
-    {
141
-        $this->markChanges($this->{$property} === $value);
142
-        $this->{$property} = $value;
143
-    }
144
-
145
-
146
-    /**
147
-     * will only toggle has_changes to true otherwise keeps existing value (ie: will never toggle to false)
148
-     * why? this allows this method to be fed with the result of a conditional
149
-     * that compares an incoming value in a setter with it's previously set value.
150
-     * ie: if $x = 1 and you call setX(1) then the value has not really changed.
151
-     *
152
-     * @param bool $changes
153
-     * @since   5.0.0.p
154
-     */
155
-    protected function markChanges($changes = true)
156
-    {
157
-        $this->has_changes = filter_var($changes, FILTER_VALIDATE_BOOLEAN) ? true : $this->has_changes;
158
-    }
159
-
160
-
161
-    /**
162
-     * resets $has_changes flag to false but does NOT actually reset any data
163
-     */
164
-    public function clearChanges()
165
-    {
166
-        $this->has_changes = false;
167
-    }
168
-
169
-
170
-    /**
171
-     * flag for marking that changes have been made to property data
172
-     *
173
-     * @return bool
174
-     */
175
-    public function hasChanges()
176
-    {
177
-        return $this->has_changes;
178
-    }
179
-
180
-
181
-    /**
182
-     * encodes all property data to JSON and saves it to a WP option
183
-     */
184
-    public function update()
185
-    {
186
-        $config_exists = get_option($this->option_name);
187
-        if ($config_exists && ! $this->has_changes) {
188
-            return;
189
-        }
190
-        $config = [];
191
-        foreach ($this->getProperties() as $property => $value) {
192
-            if ($property === 'option_name') {
193
-                continue;
194
-            }
195
-            $getter = $this->createGetterSetter($property);
196
-            $config[ $property ] = $this->{$getter}();
197
-        }
198
-        $config = wp_json_encode($config);
199
-        if ($config_exists) {
200
-            update_option($this->option_name, $config);
201
-        } else {
202
-            add_option($this->option_name, $config, '', 'no');
203
-        }
204
-        $this->clearChanges();
205
-    }
19
+	/**
20
+	 * @var boolean $has_changes
21
+	 */
22
+	private $has_changes = false;
23
+
24
+	/**
25
+	 * @var string $option_name
26
+	 */
27
+	private $option_name;
28
+
29
+
30
+	/**
31
+	 * SettingsConfig constructor.
32
+	 *
33
+	 * @param array $defaults
34
+	 */
35
+	public function __construct(array $defaults)
36
+	{
37
+		$this->setOptionName();
38
+		$this->load($defaults);
39
+		$this->clearChanges();
40
+	}
41
+
42
+
43
+	/**
44
+	 * @return array
45
+	 */
46
+	abstract protected function getProperties();
47
+
48
+
49
+	/**
50
+	 * converts property name to:
51
+	 *      camelCase for getters ex: show_expired => showExpired
52
+	 *      PascalCase for setters ex: show_expired => ShowExpired
53
+	 *
54
+	 * @param string $string
55
+	 * @param false  $camelCase
56
+	 * @return string|string[]
57
+	 * @since   5.0.0.p
58
+	 */
59
+	private function convertCase($string, $camelCase = false)
60
+	{
61
+		$string = str_replace(' ', '', ucwords(str_replace('_', ' ', $string)));
62
+		if ($camelCase) {
63
+			$string = lcfirst($string);
64
+		}
65
+		return $string;
66
+	}
67
+
68
+
69
+	/**
70
+	 * @param string $property
71
+	 * @param bool   $getter
72
+	 * @return string
73
+	 */
74
+	private function createGetterSetter($property, $getter = true)
75
+	{
76
+		$setterOrGetter = $this->convertCase($property, $getter);
77
+		// if not a getter, prepend with "set". ex: Show_expired => setShowExpired
78
+		$setterOrGetter = ! $getter ? 'set' . $setterOrGetter : $setterOrGetter;
79
+		return $this->isValidMethod($setterOrGetter) ? $setterOrGetter : '';
80
+	}
81
+
82
+
83
+	/**
84
+	 * @param string $method
85
+	 * @return bool
86
+	 * @throws DomainException
87
+	 */
88
+	private function isValidMethod($method)
89
+	{
90
+		if (method_exists($this, $method)) {
91
+			return true;
92
+		}
93
+		throw new DomainException(
94
+			sprintf(
95
+				esc_html__('Missing %1$s method on JsonConfig class %2$s.', 'event_espresso'),
96
+				$method,
97
+				get_class($this)
98
+			)
99
+		);
100
+	}
101
+
102
+
103
+	/**
104
+	 * converts class name to option name by changing backslashes to dashes
105
+	 */
106
+	private function setOptionName()
107
+	{
108
+		$this->option_name = str_replace(['EventEspresso', '\\'], ['ee', '-'], get_class($this));
109
+	}
110
+
111
+
112
+	/**
113
+	 * retrieves WP option for class, decodes the data, and resigns values to properties
114
+	 *
115
+	 * @param array $defaults
116
+	 */
117
+	protected function load(array $defaults)
118
+	{
119
+		$config = get_option($this->option_name, '{}');
120
+		$config = (array) json_decode($config) + $defaults;
121
+		foreach ($this->getProperties() as $property => $value) {
122
+			if ($property === 'option_name') {
123
+				continue;
124
+			}
125
+			// convert to PascalCase and prepend with "set". ex: show_expired => setShowExpired
126
+			$setter = $this->createGetterSetter($property, false);
127
+			$value  = array_key_exists($property, $config) ? $config[ $property ] : null;
128
+			$this->{$setter}($value);
129
+		}
130
+	}
131
+
132
+
133
+	/**
134
+	 * updates property value and marks changes if property value has changed
135
+	 *
136
+	 * @param string $property
137
+	 * @param mixed  $value
138
+	 */
139
+	protected function setProperty($property, $value)
140
+	{
141
+		$this->markChanges($this->{$property} === $value);
142
+		$this->{$property} = $value;
143
+	}
144
+
145
+
146
+	/**
147
+	 * will only toggle has_changes to true otherwise keeps existing value (ie: will never toggle to false)
148
+	 * why? this allows this method to be fed with the result of a conditional
149
+	 * that compares an incoming value in a setter with it's previously set value.
150
+	 * ie: if $x = 1 and you call setX(1) then the value has not really changed.
151
+	 *
152
+	 * @param bool $changes
153
+	 * @since   5.0.0.p
154
+	 */
155
+	protected function markChanges($changes = true)
156
+	{
157
+		$this->has_changes = filter_var($changes, FILTER_VALIDATE_BOOLEAN) ? true : $this->has_changes;
158
+	}
159
+
160
+
161
+	/**
162
+	 * resets $has_changes flag to false but does NOT actually reset any data
163
+	 */
164
+	public function clearChanges()
165
+	{
166
+		$this->has_changes = false;
167
+	}
168
+
169
+
170
+	/**
171
+	 * flag for marking that changes have been made to property data
172
+	 *
173
+	 * @return bool
174
+	 */
175
+	public function hasChanges()
176
+	{
177
+		return $this->has_changes;
178
+	}
179
+
180
+
181
+	/**
182
+	 * encodes all property data to JSON and saves it to a WP option
183
+	 */
184
+	public function update()
185
+	{
186
+		$config_exists = get_option($this->option_name);
187
+		if ($config_exists && ! $this->has_changes) {
188
+			return;
189
+		}
190
+		$config = [];
191
+		foreach ($this->getProperties() as $property => $value) {
192
+			if ($property === 'option_name') {
193
+				continue;
194
+			}
195
+			$getter = $this->createGetterSetter($property);
196
+			$config[ $property ] = $this->{$getter}();
197
+		}
198
+		$config = wp_json_encode($config);
199
+		if ($config_exists) {
200
+			update_option($this->option_name, $config);
201
+		} else {
202
+			add_option($this->option_name, $config, '', 'no');
203
+		}
204
+		$this->clearChanges();
205
+	}
206 206
 }
Please login to merge, or discard this patch.
core/services/json/JsonDataNodeInterface.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -18,61 +18,61 @@
 block discarded – undo
18 18
  */
19 19
 interface JsonDataNodeInterface extends JsonSerializable
20 20
 {
21
-    /**
22
-     * @param JsonDataNode $data_node
23
-     * @throws DomainException
24
-     */
25
-    public function addDataNode(JsonDataNode $data_node);
21
+	/**
22
+	 * @param JsonDataNode $data_node
23
+	 * @throws DomainException
24
+	 */
25
+	public function addDataNode(JsonDataNode $data_node);
26 26
 
27 27
 
28
-    /**
29
-     * the actual data in key value array format
30
-     *
31
-     * @return array
32
-     */
33
-    public function data();
28
+	/**
29
+	 * the actual data in key value array format
30
+	 *
31
+	 * @return array
32
+	 */
33
+	public function data();
34 34
 
35 35
 
36
-    /**
37
-     * specifies the domain (use case) that this route defines
38
-     * ! IMPORTANT !
39
-     * only one domain can be set pre request
40
-     *
41
-     * @return string
42
-     */
43
-    public function domain();
36
+	/**
37
+	 * specifies the domain (use case) that this route defines
38
+	 * ! IMPORTANT !
39
+	 * only one domain can be set pre request
40
+	 *
41
+	 * @return string
42
+	 */
43
+	public function domain();
44 44
 
45 45
 
46
-    /**
47
-     * !!! IMPORTANT !!!
48
-     * JsonDataNode::setInitialized(true) needs to be called once initialization is complete
49
-     * else you're a bad person and bad things will happen to you !!!
50
-     *
51
-     * @since 5.0.0.p
52
-     */
53
-    public function initialize();
46
+	/**
47
+	 * !!! IMPORTANT !!!
48
+	 * JsonDataNode::setInitialized(true) needs to be called once initialization is complete
49
+	 * else you're a bad person and bad things will happen to you !!!
50
+	 *
51
+	 * @since 5.0.0.p
52
+	 */
53
+	public function initialize();
54 54
 
55 55
 
56
-    /**
57
-     * true if the data node has been initialized,
58
-     * which entails retrieving the required data and adding it to the data node data array
59
-     *
60
-     * @return bool
61
-     */
62
-    public function isInitialized();
56
+	/**
57
+	 * true if the data node has been initialized,
58
+	 * which entails retrieving the required data and adding it to the data node data array
59
+	 *
60
+	 * @return bool
61
+	 */
62
+	public function isInitialized();
63 63
 
64 64
 
65
-    /**
66
-     * true if the data node has NOT been initialized
67
-     *
68
-     * @return bool
69
-     */
70
-    public function isNotInitialized();
65
+	/**
66
+	 * true if the data node has NOT been initialized
67
+	 *
68
+	 * @return bool
69
+	 */
70
+	public function isNotInitialized();
71 71
 
72 72
 
73
-    /**
74
-     * @return string
75
-     * @since 5.0.0.p
76
-     */
77
-    public function nodeName();
73
+	/**
74
+	 * @return string
75
+	 * @since 5.0.0.p
76
+	 */
77
+	public function nodeName();
78 78
 }
Please login to merge, or discard this patch.