Completed
Push — master ( 39c49c...e3f5df )
by James
06:01 queued 03:51
created
src/Contract/Core/HasActions.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -2,13 +2,13 @@
 block discarded – undo
2 2
 namespace Intraxia\Jaxion\Contract\Core;
3 3
 
4 4
 interface HasActions {
5
-	/**
6
-	 * Provides the array of actions the class wants to register with WordPress.
7
-	 *
8
-	 * These actions are retrieved by the Loader class and used to register the
9
-	 * correct service methods with WordPress.
10
-	 *
11
-	 * @return array[]
12
-	 */
13
-	public function action_hooks();
5
+    /**
6
+     * Provides the array of actions the class wants to register with WordPress.
7
+     *
8
+     * These actions are retrieved by the Loader class and used to register the
9
+     * correct service methods with WordPress.
10
+     *
11
+     * @return array[]
12
+     */
13
+    public function action_hooks();
14 14
 }
15 15
\ No newline at end of file
Please login to merge, or discard this patch.
src/Contract/Assets/Register.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -4,48 +4,48 @@
 block discarded – undo
4 4
 use Intraxia\Jaxion\Contract\Core\HasActions;
5 5
 
6 6
 interface Register extends HasActions {
7
-	/**
8
-	 * Enable debug mode for the enqueued assets.
9
-	 *
10
-	 * Debug mode will enqueue unminified versions of the registered assets.
11
-	 * Primarily, this is intended to be used along with WordPress's `SCRIPT_DEBUG`
12
-	 * constant, which enables unminified core assets to be enqueued.
13
-	 *
14
-	 * @param bool $debug
15
-	 */
16
-	public function set_debug( $debug );
17
-
18
-	/**
19
-	 * Provides a method to register new scripts outside of the constructor.
20
-	 *
21
-	 * @param $script
22
-	 */
23
-	public function register_script( $script );
24
-
25
-	/**
26
-	 * Provides a method to register new styles outside of the constructor.
27
-	 *
28
-	 * @param $style
29
-	 */
30
-	public function register_style( $style );
31
-
32
-	/**
33
-	 * Enqueues the web & shared scripts on the Register.
34
-	 */
35
-	public function enqueue_web_scripts();
36
-
37
-	/**
38
-	 * Enqueues the web & shared styles on the Register.
39
-	 */
40
-	public function enqueue_web_styles();
41
-
42
-	/**
43
-	 * Enqueues the admin & shared scripts on the Register.
44
-	 */
45
-	public function enqueue_admin_scripts();
46
-
47
-	/**
48
-	 * Enqueues the admin & shared styles on the Register.
49
-	 */
50
-	public function enqueue_admin_styles();
7
+    /**
8
+     * Enable debug mode for the enqueued assets.
9
+     *
10
+     * Debug mode will enqueue unminified versions of the registered assets.
11
+     * Primarily, this is intended to be used along with WordPress's `SCRIPT_DEBUG`
12
+     * constant, which enables unminified core assets to be enqueued.
13
+     *
14
+     * @param bool $debug
15
+     */
16
+    public function set_debug( $debug );
17
+
18
+    /**
19
+     * Provides a method to register new scripts outside of the constructor.
20
+     *
21
+     * @param $script
22
+     */
23
+    public function register_script( $script );
24
+
25
+    /**
26
+     * Provides a method to register new styles outside of the constructor.
27
+     *
28
+     * @param $style
29
+     */
30
+    public function register_style( $style );
31
+
32
+    /**
33
+     * Enqueues the web & shared scripts on the Register.
34
+     */
35
+    public function enqueue_web_scripts();
36
+
37
+    /**
38
+     * Enqueues the web & shared styles on the Register.
39
+     */
40
+    public function enqueue_web_styles();
41
+
42
+    /**
43
+     * Enqueues the admin & shared scripts on the Register.
44
+     */
45
+    public function enqueue_admin_scripts();
46
+
47
+    /**
48
+     * Enqueues the admin & shared styles on the Register.
49
+     */
50
+    public function enqueue_admin_styles();
51 51
 }
Please login to merge, or discard this patch.
src/Contract/Http/Filter.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -10,13 +10,13 @@
 block discarded – undo
10 10
  * @subpackage Contract\Http
11 11
  */
12 12
 interface Filter {
13
-	/**
14
-	 * Generates argument rules.
15
-	 *
16
-	 * Returns an array matching the WP-API format for argument rules,
17
-	 * including sanitization, validation, required, or defaults.
18
-	 *
19
-	 * @return array
20
-	 */
21
-	public function rules();
13
+    /**
14
+     * Generates argument rules.
15
+     *
16
+     * Returns an array matching the WP-API format for argument rules,
17
+     * including sanitization, validation, required, or defaults.
18
+     *
19
+     * @return array
20
+     */
21
+    public function rules();
22 22
 }
Please login to merge, or discard this patch.
src/Contract/Http/Guard.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -10,13 +10,13 @@
 block discarded – undo
10 10
  * @subpackage Contract\Http
11 11
  */
12 12
 interface Guard {
13
-	/**
14
-	 * Validates when the user is authorized for the route.
15
-	 *
16
-	 * Returns a boolean based on whether the current user is authorized
17
-	 * to interact with the given route.
18
-	 *
19
-	 * @return bool
20
-	 */
21
-	public function authorized();
13
+    /**
14
+     * Validates when the user is authorized for the route.
15
+     *
16
+     * Returns a boolean based on whether the current user is authorized
17
+     * to interact with the given route.
18
+     *
19
+     * @return bool
20
+     */
21
+    public function authorized();
22 22
 }
Please login to merge, or discard this patch.
src/Assets/Register.php 1 patch
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -12,198 +12,198 @@
 block discarded – undo
12 12
  * @subpackage Register
13 13
  */
14 14
 class Register implements RegisterContract {
15
-	/**
16
-	 * Minification string for enqueued assets.
17
-	 *
18
-	 * @var string
19
-	 */
20
-	private $min = '';
21
-
22
-	/**
23
-	 * Url to the plugin directory.
24
-	 *
25
-	 * @var string
26
-	 */
27
-	protected $url;
28
-
29
-	/**
30
-	 * Script/plugin version.
31
-	 *
32
-	 * @var string
33
-	 */
34
-	protected $version;
35
-
36
-	/**
37
-	 * Array of script definition arrays.
38
-	 *
39
-	 * @var array
40
-	 */
41
-	private $scripts = array();
42
-
43
-	/**
44
-	 * Array of style definition arrays.
45
-	 *
46
-	 * @var array
47
-	 */
48
-	private $styles = array();
49
-
50
-	/**
51
-	 * Instantiates a new instance of the Register class.
52
-	 *
53
-	 * The URL param should be relative to the plugin directory. The URL
54
-	 * form should always end with a '/'. All asset location definitions
55
-	 * should not begin with a slash and should be relative to the plugin's
56
-	 * root directory. The URL provided by default from the Application
57
-	 * class is compatible.
58
-	 *
59
-	 * @param string $url
60
-	 * @param string $version
61
-	 */
62
-	public function __construct( $url, $version = null ) {
63
-		$this->url = $url;
64
-		$this->version = $version;
65
-	}
66
-
67
-	/**
68
-	 * {@inheritdoc}
69
-	 *
70
-	 * @param bool $debug
71
-	 */
72
-	public function set_debug( $debug ) {
73
-		if ( $debug ) {
74
-			$this->min = '.min';
75
-		} else {
76
-			$this->min = '';
77
-		}
78
-	}
79
-
80
-	/**
81
-	 * {@inheritdoc}
82
-	 *
83
-	 * @param array $script
84
-	 */
85
-	public function register_script( $script ) {
86
-		$this->scripts[] = $script;
87
-	}
88
-
89
-	/**
90
-	 * {@inheritdoc}
91
-	 *
92
-	 * @param array $style
93
-	 */
94
-	public function register_style( $style ) {
95
-		$this->styles[] = $style;
96
-	}
97
-
98
-	/**
99
-	 * {@inheritDoc}
100
-	 */
101
-	public function enqueue_web_scripts() {
102
-		foreach ( $this->scripts as $script ) {
103
-			if ( in_array( $script['type'], array( 'web', 'shared' ) ) ) {
104
-				$this->enqueue_script( $script );
105
-			}
106
-		}
107
-	}
108
-
109
-	/**
110
-	 * {@inheritDoc}
111
-	 */
112
-	public function enqueue_web_styles() {
113
-		foreach ( $this->styles as $style ) {
114
-			if ( in_array( $style['type'], array( 'web', 'shared' ) ) ) {
115
-				$this->enqueue_style( $style );
116
-			}
117
-		}
118
-	}
119
-
120
-	/**
121
-	 * {@inheritDoc}
122
-	 */
123
-	public function enqueue_admin_scripts() {
124
-		foreach ( $this->scripts as $script ) {
125
-			if ( in_array( $script['type'], array( 'admin', 'shared' ) ) ) {
126
-				$this->enqueue_script( $script );
127
-			}
128
-		}
129
-	}
130
-
131
-	/**
132
-	 * {@inheritDoc}
133
-	 */
134
-	public function enqueue_admin_styles() {
135
-		foreach ( $this->styles as $style ) {
136
-			if ( in_array( $style['type'], array( 'admin', 'shared' ) ) ) {
137
-				$this->enqueue_style( $style );
138
-			}
139
-		}
140
-	}
141
-
142
-	/**
143
-	 * {@inheritDoc}
144
-	 *
145
-	 * @return array[]
146
-	 */
147
-	public function action_hooks() {
148
-		return array(
149
-			array(
150
-				'hook'   => 'wp_enqueue_scripts',
151
-				'method' => 'enqueue_web_scripts',
152
-			),
153
-			array(
154
-				'hook'   => 'wp_enqueue_scripts',
155
-				'method' => 'enqueue_web_styles',
156
-			),
157
-			array(
158
-				'hook'   => 'admin_enqueue_scripts',
159
-				'method' => 'enqueue_admin_scripts',
160
-			),
161
-			array(
162
-				'hook'   => 'admin_enqueue_scripts',
163
-				'method' => 'enqueue_admin_styles',
164
-			),
165
-		);
166
-	}
167
-
168
-	/**
169
-	 * Enqueues an individual script if the style's condition is met.
170
-	 *
171
-	 * @param array $script
172
-	 */
173
-	protected function enqueue_script( $script ) {
174
-		if ( $script['condition']() ) {
175
-			wp_enqueue_script(
176
-				$script['handle'],
177
-				$this->url . $script['src'] . '.js',
178
-				isset( $script['deps'] ) ? $script['deps'] : array(),
179
-				$this->version,
180
-				isset( $script['footer'] ) ? $script['footer'] : false
181
-			);
182
-
183
-			if ( isset( $script['localize'] ) ) {
184
-				wp_localize_script(
185
-					$script['handle'],
186
-					$script['localize']['name'],
187
-					$script['localize']['data']
188
-				);
189
-			}
190
-		}
191
-	}
192
-
193
-	/**
194
-	 * Enqueues an individual stylesheet if the style's condition is met.
195
-	 *
196
-	 * @param array $style
197
-	 */
198
-	protected function enqueue_style( $style ) {
199
-		if ( $style['condition']() ) {
200
-			wp_enqueue_style(
201
-				$style['handle'],
202
-				$this->url . $style['src'] . '.css',
203
-				isset( $style['deps'] ) ? $style['deps'] : array(),
204
-				$this->version,
205
-				isset( $style['media'] ) ? $style['media'] : 'all'
206
-			);
207
-		}
208
-	}
15
+    /**
16
+     * Minification string for enqueued assets.
17
+     *
18
+     * @var string
19
+     */
20
+    private $min = '';
21
+
22
+    /**
23
+     * Url to the plugin directory.
24
+     *
25
+     * @var string
26
+     */
27
+    protected $url;
28
+
29
+    /**
30
+     * Script/plugin version.
31
+     *
32
+     * @var string
33
+     */
34
+    protected $version;
35
+
36
+    /**
37
+     * Array of script definition arrays.
38
+     *
39
+     * @var array
40
+     */
41
+    private $scripts = array();
42
+
43
+    /**
44
+     * Array of style definition arrays.
45
+     *
46
+     * @var array
47
+     */
48
+    private $styles = array();
49
+
50
+    /**
51
+     * Instantiates a new instance of the Register class.
52
+     *
53
+     * The URL param should be relative to the plugin directory. The URL
54
+     * form should always end with a '/'. All asset location definitions
55
+     * should not begin with a slash and should be relative to the plugin's
56
+     * root directory. The URL provided by default from the Application
57
+     * class is compatible.
58
+     *
59
+     * @param string $url
60
+     * @param string $version
61
+     */
62
+    public function __construct( $url, $version = null ) {
63
+        $this->url = $url;
64
+        $this->version = $version;
65
+    }
66
+
67
+    /**
68
+     * {@inheritdoc}
69
+     *
70
+     * @param bool $debug
71
+     */
72
+    public function set_debug( $debug ) {
73
+        if ( $debug ) {
74
+            $this->min = '.min';
75
+        } else {
76
+            $this->min = '';
77
+        }
78
+    }
79
+
80
+    /**
81
+     * {@inheritdoc}
82
+     *
83
+     * @param array $script
84
+     */
85
+    public function register_script( $script ) {
86
+        $this->scripts[] = $script;
87
+    }
88
+
89
+    /**
90
+     * {@inheritdoc}
91
+     *
92
+     * @param array $style
93
+     */
94
+    public function register_style( $style ) {
95
+        $this->styles[] = $style;
96
+    }
97
+
98
+    /**
99
+     * {@inheritDoc}
100
+     */
101
+    public function enqueue_web_scripts() {
102
+        foreach ( $this->scripts as $script ) {
103
+            if ( in_array( $script['type'], array( 'web', 'shared' ) ) ) {
104
+                $this->enqueue_script( $script );
105
+            }
106
+        }
107
+    }
108
+
109
+    /**
110
+     * {@inheritDoc}
111
+     */
112
+    public function enqueue_web_styles() {
113
+        foreach ( $this->styles as $style ) {
114
+            if ( in_array( $style['type'], array( 'web', 'shared' ) ) ) {
115
+                $this->enqueue_style( $style );
116
+            }
117
+        }
118
+    }
119
+
120
+    /**
121
+     * {@inheritDoc}
122
+     */
123
+    public function enqueue_admin_scripts() {
124
+        foreach ( $this->scripts as $script ) {
125
+            if ( in_array( $script['type'], array( 'admin', 'shared' ) ) ) {
126
+                $this->enqueue_script( $script );
127
+            }
128
+        }
129
+    }
130
+
131
+    /**
132
+     * {@inheritDoc}
133
+     */
134
+    public function enqueue_admin_styles() {
135
+        foreach ( $this->styles as $style ) {
136
+            if ( in_array( $style['type'], array( 'admin', 'shared' ) ) ) {
137
+                $this->enqueue_style( $style );
138
+            }
139
+        }
140
+    }
141
+
142
+    /**
143
+     * {@inheritDoc}
144
+     *
145
+     * @return array[]
146
+     */
147
+    public function action_hooks() {
148
+        return array(
149
+            array(
150
+                'hook'   => 'wp_enqueue_scripts',
151
+                'method' => 'enqueue_web_scripts',
152
+            ),
153
+            array(
154
+                'hook'   => 'wp_enqueue_scripts',
155
+                'method' => 'enqueue_web_styles',
156
+            ),
157
+            array(
158
+                'hook'   => 'admin_enqueue_scripts',
159
+                'method' => 'enqueue_admin_scripts',
160
+            ),
161
+            array(
162
+                'hook'   => 'admin_enqueue_scripts',
163
+                'method' => 'enqueue_admin_styles',
164
+            ),
165
+        );
166
+    }
167
+
168
+    /**
169
+     * Enqueues an individual script if the style's condition is met.
170
+     *
171
+     * @param array $script
172
+     */
173
+    protected function enqueue_script( $script ) {
174
+        if ( $script['condition']() ) {
175
+            wp_enqueue_script(
176
+                $script['handle'],
177
+                $this->url . $script['src'] . '.js',
178
+                isset( $script['deps'] ) ? $script['deps'] : array(),
179
+                $this->version,
180
+                isset( $script['footer'] ) ? $script['footer'] : false
181
+            );
182
+
183
+            if ( isset( $script['localize'] ) ) {
184
+                wp_localize_script(
185
+                    $script['handle'],
186
+                    $script['localize']['name'],
187
+                    $script['localize']['data']
188
+                );
189
+            }
190
+        }
191
+    }
192
+
193
+    /**
194
+     * Enqueues an individual stylesheet if the style's condition is met.
195
+     *
196
+     * @param array $style
197
+     */
198
+    protected function enqueue_style( $style ) {
199
+        if ( $style['condition']() ) {
200
+            wp_enqueue_style(
201
+                $style['handle'],
202
+                $this->url . $style['src'] . '.css',
203
+                isset( $style['deps'] ) ? $style['deps'] : array(),
204
+                $this->version,
205
+                isset( $style['media'] ) ? $style['media'] : 'all'
206
+            );
207
+        }
208
+    }
209 209
 }
Please login to merge, or discard this patch.
src/Assets/RegisterServiceProvider.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -5,29 +5,29 @@
 block discarded – undo
5 5
 use Intraxia\Jaxion\Contract\Core\ServiceProvider;
6 6
 
7 7
 class RegisterServiceProvider implements ServiceProvider {
8
-	/**
9
-	 * {@inheritDoc}
10
-	 */
11
-	public function register( Container $container ) {
12
-		$container->define(
13
-			array( 'register' => 'Intraxia\Jaxion\Contract\Assets\Register' ),
14
-			$register = new Register( $container->fetch( 'url' ), $container->fetch( 'version' ) )
15
-		);
8
+    /**
9
+     * {@inheritDoc}
10
+     */
11
+    public function register( Container $container ) {
12
+        $container->define(
13
+            array( 'register' => 'Intraxia\Jaxion\Contract\Assets\Register' ),
14
+            $register = new Register( $container->fetch( 'url' ), $container->fetch( 'version' ) )
15
+        );
16 16
 
17
-		$this->add_assets( $register );
18
-	}
17
+        $this->add_assets( $register );
18
+    }
19 19
 
20
-	/**
21
-	 * Registers the assets on the generated Register.
22
-	 *
23
-	 * This is a no-op by default by can be overwritten by the implementing developer
24
-	 * to provide a single, clean location to register their assets.
25
-	 *
26
-	 * @param Register $register
27
-	 *
28
-	 * @codeCoverageIgnore
29
-	 */
30
-	protected function add_assets( Register $register ) {
31
-		// no-op
32
-	}
20
+    /**
21
+     * Registers the assets on the generated Register.
22
+     *
23
+     * This is a no-op by default by can be overwritten by the implementing developer
24
+     * to provide a single, clean location to register their assets.
25
+     *
26
+     * @param Register $register
27
+     *
28
+     * @codeCoverageIgnore
29
+     */
30
+    protected function add_assets( Register $register ) {
31
+        // no-op
32
+    }
33 33
 }
34 34
\ No newline at end of file
Please login to merge, or discard this patch.
src/Utility/Str.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -11,39 +11,39 @@
 block discarded – undo
11 11
  * @subpackage Utility
12 12
  */
13 13
 class Str {
14
-	/**
15
-	 * Determine if a given string starts with a given substring.
16
-	 *
17
-	 * @param  string       $haystack
18
-	 * @param  string|array $needles
19
-	 *
20
-	 * @return bool
21
-	 */
22
-	public static function starts_with( $haystack, $needles ) {
23
-		foreach ( (array) $needles as $needle ) {
24
-			if ( $needle != '' && strpos( $haystack, $needle ) === 0 ) {
25
-				return true;
26
-			}
27
-		}
14
+    /**
15
+     * Determine if a given string starts with a given substring.
16
+     *
17
+     * @param  string       $haystack
18
+     * @param  string|array $needles
19
+     *
20
+     * @return bool
21
+     */
22
+    public static function starts_with( $haystack, $needles ) {
23
+        foreach ( (array) $needles as $needle ) {
24
+            if ( $needle != '' && strpos( $haystack, $needle ) === 0 ) {
25
+                return true;
26
+            }
27
+        }
28 28
 
29
-		return false;
30
-	}
29
+        return false;
30
+    }
31 31
 
32
-	/**
33
-	 * Determine if a given string ends with a given substring.
34
-	 *
35
-	 * @param  string       $haystack
36
-	 * @param  string|array $needles
37
-	 *
38
-	 * @return bool
39
-	 */
40
-	public static function ends_with( $haystack, $needles ) {
41
-		foreach ( (array) $needles as $needle ) {
42
-			if ( (string) $needle === substr( $haystack, - strlen( $needle ) ) ) {
43
-				return true;
44
-			}
45
-		}
32
+    /**
33
+     * Determine if a given string ends with a given substring.
34
+     *
35
+     * @param  string       $haystack
36
+     * @param  string|array $needles
37
+     *
38
+     * @return bool
39
+     */
40
+    public static function ends_with( $haystack, $needles ) {
41
+        foreach ( (array) $needles as $needle ) {
42
+            if ( (string) $needle === substr( $haystack, - strlen( $needle ) ) ) {
43
+                return true;
44
+            }
45
+        }
46 46
 
47
-		return false;
48
-	}
47
+        return false;
48
+    }
49 49
 }
Please login to merge, or discard this patch.
src/Http/Router.php 1 patch
Indentation   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -21,202 +21,202 @@
 block discarded – undo
21 21
  * @method Endpoint all(string $route, callable $callback, array $options = array())
22 22
  */
23 23
 class Router implements HasActions {
24
-	/**
25
-	 * Resource's vendor prefix.
26
-	 *
27
-	 * @var string
28
-	 */
29
-	protected $vendor;
30
-
31
-	/**
32
-	 * Resource's version.
33
-	 *
34
-	 * @var int
35
-	 */
36
-	protected $version;
37
-
38
-	/**
39
-	 * Valid methods and their HTTP verb(s).
40
-	 *
41
-	 * @var array
42
-	 */
43
-	private $methods = array(
44
-		'get'      => 'GET',
45
-		'post'     => 'POST',
46
-		'put'      => 'PUT',
47
-		'patch'    => 'PATCH',
48
-		'delete'   => 'DELETE',
49
-		'editable' => 'POST, PUT, PATCH',
50
-		'all'      => 'GET, POST, PUT, PATCH, DELETE',
51
-	);
52
-
53
-	/**
54
-	 * Endpoints registered for the resource.
55
-	 *
56
-	 * @var Endpoint[]
57
-	 */
58
-	protected $endpoints = array();
59
-
60
-	/**
61
-	 * Returns all the resource endpoints.
62
-	 *
63
-	 * @return Endpoint[]
64
-	 */
65
-	public function get_endpoints() {
66
-		return $this->endpoints;
67
-	}
68
-
69
-	/**
70
-	 * Sets the resource's vendor prefix.
71
-	 *
72
-	 * @param string $vendor
73
-	 */
74
-	public function set_vendor( $vendor ) {
75
-		$this->vendor = $vendor;
76
-	}
77
-
78
-	/**
79
-	 * Sets the resource's version.
80
-	 *
81
-	 * @param int $version
82
-	 */
83
-	public function set_version( $version ) {
84
-		$this->version = $version;
85
-	}
86
-
87
-	/**
88
-	 * Registers all of the routes with the WP-API.
89
-	 *
90
-	 * Runs on the `rest_api_init` hook. Registers all of the routes loaded
91
-	 * on the router into the WordPress REST API.
92
-	 *
93
-	 * @throws VendorNotSetException
94
-	 * @throws VersionNotSetException
95
-	 */
96
-	public function register() {
97
-		if ( ! $this->vendor ) {
98
-			throw new VendorNotSetException;
99
-		}
100
-
101
-		if ( ! $this->version ) {
102
-			throw new VersionNotSetException;
103
-		}
104
-
105
-		foreach ( $this->endpoints as $endpoint ) {
106
-			register_rest_route(
107
-				$this->get_namespace(),
108
-				$endpoint->get_route(),
109
-				$endpoint->get_options()
110
-			);
111
-		}
112
-	}
113
-
114
-	/**
115
-	 * Registers a set of routes with a shared set of options.
116
-	 *
117
-	 * Allows you to group routes together with shared set of options, including
118
-	 * a route prefix, shared guards, and common parameter validation or sanitization.
119
-	 *
120
-	 * @param array    $options
121
-	 * @param callable $callback
122
-	 */
123
-	public function group( array $options, $callback ) {
124
-		$router = new static;
125
-
126
-		call_user_func( $callback, $router );
127
-
128
-		foreach ( $router->get_endpoints() as $endpoint ) {
129
-			$this->endpoints[] = $this->set_options( $endpoint, $options );
130
-		}
131
-	}
132
-
133
-	/**
134
-	 * Magic __call method.
135
-	 *
136
-	 * All of the endpoints registration method calls pass through here. This validates whether the method
137
-	 * is a valid endpoint type to register, and creates a new endpoint with the passed options.
138
-	 *
139
-	 * @param string $name
140
-	 * @param array  $arguments
141
-	 *
142
-	 * @return Endpoint
143
-	 *
144
-	 * @throws UnknownMethodException
145
-	 * @throws MissingArgumentException
146
-	 * @throws InvalidArgumentException
147
-	 */
148
-	public function __call( $name, $arguments ) {
149
-		if ( ! in_array( $name, array_keys( $this->methods ) ) ) {
150
-			throw new UnknownMethodException;
151
-		}
152
-
153
-		// array_merge ensures we have 3 elements
154
-		list( $route, $callback, $options ) = array_merge( $arguments, array( null, null, null ) );
155
-
156
-		if ( ! $route || ! $callback ) {
157
-			throw new MissingArgumentException;
158
-		}
159
-
160
-		if ( ! is_callable( $callback ) ) {
161
-			throw new InvalidArgumentException;
162
-		}
163
-
164
-		$endpoint = new Endpoint( $route, $this->methods[ $name ], $callback );
165
-
166
-		if ( $options && is_array( $options ) ) {
167
-			$endpoint = $this->set_options( $endpoint, $options );
168
-		}
169
-
170
-		return $this->endpoints[] = $endpoint;
171
-	}
172
-
173
-	/**
174
-	 * Sets the passed options on the endpoint.
175
-	 *
176
-	 * Only sets endpoints matching setters in the Endpoint class.
177
-	 *
178
-	 * @param Endpoint $endpoint
179
-	 * @param array    $options
180
-	 *
181
-	 * @return Endpoint
182
-	 * @throws MalformedRouteException
183
-	 */
184
-	protected function set_options( Endpoint $endpoint, array $options ) {
185
-		if ( isset( $options['guard'] ) ) {
186
-			$endpoint->set_guard( $options['guard'] );
187
-		}
188
-
189
-		if ( isset( $options['filter'] ) ) {
190
-			$endpoint->set_filter( $options['filter'] );
191
-		}
192
-
193
-		if ( isset( $options['prefix'] ) ) {
194
-			$endpoint->set_prefix( $options['prefix'] );
195
-		}
196
-
197
-		return $endpoint;
198
-	}
199
-
200
-	/**
201
-	 * Generates the resource's namespace.
202
-	 *
203
-	 * @return string
204
-	 */
205
-	protected function get_namespace() {
206
-		return $this->vendor . '/v' . $this->version;
207
-	}
208
-
209
-	/**
210
-	 * {@inheritDoc}
211
-	 *
212
-	 * @return array[]
213
-	 */
214
-	public function action_hooks() {
215
-		return array(
216
-			array(
217
-				'method' => 'register',
218
-				'hook'   => 'rest_api_init',
219
-			),
220
-		);
221
-	}
24
+    /**
25
+     * Resource's vendor prefix.
26
+     *
27
+     * @var string
28
+     */
29
+    protected $vendor;
30
+
31
+    /**
32
+     * Resource's version.
33
+     *
34
+     * @var int
35
+     */
36
+    protected $version;
37
+
38
+    /**
39
+     * Valid methods and their HTTP verb(s).
40
+     *
41
+     * @var array
42
+     */
43
+    private $methods = array(
44
+        'get'      => 'GET',
45
+        'post'     => 'POST',
46
+        'put'      => 'PUT',
47
+        'patch'    => 'PATCH',
48
+        'delete'   => 'DELETE',
49
+        'editable' => 'POST, PUT, PATCH',
50
+        'all'      => 'GET, POST, PUT, PATCH, DELETE',
51
+    );
52
+
53
+    /**
54
+     * Endpoints registered for the resource.
55
+     *
56
+     * @var Endpoint[]
57
+     */
58
+    protected $endpoints = array();
59
+
60
+    /**
61
+     * Returns all the resource endpoints.
62
+     *
63
+     * @return Endpoint[]
64
+     */
65
+    public function get_endpoints() {
66
+        return $this->endpoints;
67
+    }
68
+
69
+    /**
70
+     * Sets the resource's vendor prefix.
71
+     *
72
+     * @param string $vendor
73
+     */
74
+    public function set_vendor( $vendor ) {
75
+        $this->vendor = $vendor;
76
+    }
77
+
78
+    /**
79
+     * Sets the resource's version.
80
+     *
81
+     * @param int $version
82
+     */
83
+    public function set_version( $version ) {
84
+        $this->version = $version;
85
+    }
86
+
87
+    /**
88
+     * Registers all of the routes with the WP-API.
89
+     *
90
+     * Runs on the `rest_api_init` hook. Registers all of the routes loaded
91
+     * on the router into the WordPress REST API.
92
+     *
93
+     * @throws VendorNotSetException
94
+     * @throws VersionNotSetException
95
+     */
96
+    public function register() {
97
+        if ( ! $this->vendor ) {
98
+            throw new VendorNotSetException;
99
+        }
100
+
101
+        if ( ! $this->version ) {
102
+            throw new VersionNotSetException;
103
+        }
104
+
105
+        foreach ( $this->endpoints as $endpoint ) {
106
+            register_rest_route(
107
+                $this->get_namespace(),
108
+                $endpoint->get_route(),
109
+                $endpoint->get_options()
110
+            );
111
+        }
112
+    }
113
+
114
+    /**
115
+     * Registers a set of routes with a shared set of options.
116
+     *
117
+     * Allows you to group routes together with shared set of options, including
118
+     * a route prefix, shared guards, and common parameter validation or sanitization.
119
+     *
120
+     * @param array    $options
121
+     * @param callable $callback
122
+     */
123
+    public function group( array $options, $callback ) {
124
+        $router = new static;
125
+
126
+        call_user_func( $callback, $router );
127
+
128
+        foreach ( $router->get_endpoints() as $endpoint ) {
129
+            $this->endpoints[] = $this->set_options( $endpoint, $options );
130
+        }
131
+    }
132
+
133
+    /**
134
+     * Magic __call method.
135
+     *
136
+     * All of the endpoints registration method calls pass through here. This validates whether the method
137
+     * is a valid endpoint type to register, and creates a new endpoint with the passed options.
138
+     *
139
+     * @param string $name
140
+     * @param array  $arguments
141
+     *
142
+     * @return Endpoint
143
+     *
144
+     * @throws UnknownMethodException
145
+     * @throws MissingArgumentException
146
+     * @throws InvalidArgumentException
147
+     */
148
+    public function __call( $name, $arguments ) {
149
+        if ( ! in_array( $name, array_keys( $this->methods ) ) ) {
150
+            throw new UnknownMethodException;
151
+        }
152
+
153
+        // array_merge ensures we have 3 elements
154
+        list( $route, $callback, $options ) = array_merge( $arguments, array( null, null, null ) );
155
+
156
+        if ( ! $route || ! $callback ) {
157
+            throw new MissingArgumentException;
158
+        }
159
+
160
+        if ( ! is_callable( $callback ) ) {
161
+            throw new InvalidArgumentException;
162
+        }
163
+
164
+        $endpoint = new Endpoint( $route, $this->methods[ $name ], $callback );
165
+
166
+        if ( $options && is_array( $options ) ) {
167
+            $endpoint = $this->set_options( $endpoint, $options );
168
+        }
169
+
170
+        return $this->endpoints[] = $endpoint;
171
+    }
172
+
173
+    /**
174
+     * Sets the passed options on the endpoint.
175
+     *
176
+     * Only sets endpoints matching setters in the Endpoint class.
177
+     *
178
+     * @param Endpoint $endpoint
179
+     * @param array    $options
180
+     *
181
+     * @return Endpoint
182
+     * @throws MalformedRouteException
183
+     */
184
+    protected function set_options( Endpoint $endpoint, array $options ) {
185
+        if ( isset( $options['guard'] ) ) {
186
+            $endpoint->set_guard( $options['guard'] );
187
+        }
188
+
189
+        if ( isset( $options['filter'] ) ) {
190
+            $endpoint->set_filter( $options['filter'] );
191
+        }
192
+
193
+        if ( isset( $options['prefix'] ) ) {
194
+            $endpoint->set_prefix( $options['prefix'] );
195
+        }
196
+
197
+        return $endpoint;
198
+    }
199
+
200
+    /**
201
+     * Generates the resource's namespace.
202
+     *
203
+     * @return string
204
+     */
205
+    protected function get_namespace() {
206
+        return $this->vendor . '/v' . $this->version;
207
+    }
208
+
209
+    /**
210
+     * {@inheritDoc}
211
+     *
212
+     * @return array[]
213
+     */
214
+    public function action_hooks() {
215
+        return array(
216
+            array(
217
+                'method' => 'register',
218
+                'hook'   => 'rest_api_init',
219
+            ),
220
+        );
221
+    }
222 222
 }
Please login to merge, or discard this patch.
src/Http/Filter.php 1 patch
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -12,96 +12,96 @@
 block discarded – undo
12 12
  * @subpackage Http
13 13
  */
14 14
 class Filter implements FilterContract {
15
-	/**
16
-	 * Filter rules.
17
-	 *
18
-	 * @var array
19
-	 */
20
-	protected $rules;
15
+    /**
16
+     * Filter rules.
17
+     *
18
+     * @var array
19
+     */
20
+    protected $rules;
21 21
 
22
-	/**
23
-	 * Instantiates a new filter with the provided rules array.
24
-	 *
25
-	 * @param array $rules
26
-	 */
27
-	public function __construct( $rules = array() ) {
28
-		$this->rules = $rules;
29
-	}
22
+    /**
23
+     * Instantiates a new filter with the provided rules array.
24
+     *
25
+     * @param array $rules
26
+     */
27
+    public function __construct( $rules = array() ) {
28
+        $this->rules = $rules;
29
+    }
30 30
 
31
-	/**
32
-	 * Generates argument rules.
33
-	 *
34
-	 * Returns an array matching the WP-API format for argument rules,
35
-	 * including sanitization, validation, required, or defaults.
36
-	 *
37
-	 * @return array
38
-	 */
39
-	public function rules() {
40
-		$args = array();
31
+    /**
32
+     * Generates argument rules.
33
+     *
34
+     * Returns an array matching the WP-API format for argument rules,
35
+     * including sanitization, validation, required, or defaults.
36
+     *
37
+     * @return array
38
+     */
39
+    public function rules() {
40
+        $args = array();
41 41
 
42
-		foreach ( $this->rules as $arg => $validation ) {
43
-			if ( ! $validation || ! is_string( $validation ) ) {
44
-				continue;
45
-			}
42
+        foreach ( $this->rules as $arg => $validation ) {
43
+            if ( ! $validation || ! is_string( $validation ) ) {
44
+                continue;
45
+            }
46 46
 
47
-			$args[ $arg ] = $this->parse_validation( $validation );
48
-		}
47
+            $args[ $arg ] = $this->parse_validation( $validation );
48
+        }
49 49
 
50
-		return $args;
51
-	}
50
+        return $args;
51
+    }
52 52
 
53
-	/**
54
-	 * Parses a validation string into a WP-API compatible rule.
55
-	 *
56
-	 * @param string $validation
57
-	 *
58
-	 * @return array
59
-	 */
60
-	protected function parse_validation( $validation ) {
61
-		$validation = explode( '|', $validation );
53
+    /**
54
+     * Parses a validation string into a WP-API compatible rule.
55
+     *
56
+     * @param string $validation
57
+     *
58
+     * @return array
59
+     */
60
+    protected function parse_validation( $validation ) {
61
+        $validation = explode( '|', $validation );
62 62
 
63
-		$rules = array();
63
+        $rules = array();
64 64
 
65
-		foreach ( $validation as $rule ) {
66
-			if ( 0 === strpos( $rule, 'default' ) ) {
67
-				$ruleArr = explode( ':', $rule );
65
+        foreach ( $validation as $rule ) {
66
+            if ( 0 === strpos( $rule, 'default' ) ) {
67
+                $ruleArr = explode( ':', $rule );
68 68
 
69
-				$rules['default'] = count( $ruleArr ) === 2 ? array_pop( $ruleArr ) : '';
70
-			}
69
+                $rules['default'] = count( $ruleArr ) === 2 ? array_pop( $ruleArr ) : '';
70
+            }
71 71
 
72
-			switch ( $rule ) {
73
-				case 'required':
74
-					$rules['required'] = true;
75
-					break;
76
-				case 'integer':
77
-					$rules['validate_callback'] = array( $this, 'validate_integer' );
78
-					$rules['sanitize_callback'] = array( $this, 'make_integer' );
79
-					break;
80
-			}
81
-		}
72
+            switch ( $rule ) {
73
+                case 'required':
74
+                    $rules['required'] = true;
75
+                    break;
76
+                case 'integer':
77
+                    $rules['validate_callback'] = array( $this, 'validate_integer' );
78
+                    $rules['sanitize_callback'] = array( $this, 'make_integer' );
79
+                    break;
80
+            }
81
+        }
82 82
 
83
-		return $rules;
84
-	}
83
+        return $rules;
84
+    }
85 85
 
86
-	/**
87
-	 * Validate that provided value is an integer.
88
-	 *
89
-	 * @param mixed $value
90
-	 *
91
-	 * @return bool
92
-	 */
93
-	public function validate_integer( $value ) {
94
-		return filter_var( $value, FILTER_VALIDATE_INT ) !== false;
95
-	}
86
+    /**
87
+     * Validate that provided value is an integer.
88
+     *
89
+     * @param mixed $value
90
+     *
91
+     * @return bool
92
+     */
93
+    public function validate_integer( $value ) {
94
+        return filter_var( $value, FILTER_VALIDATE_INT ) !== false;
95
+    }
96 96
 
97
-	/**
98
-	 * Casts a provided value to an integer.
99
-	 *
100
-	 * @param mixed $value
101
-	 *
102
-	 * @return int
103
-	 */
104
-	public function make_integer( $value ) {
105
-		return (int) $value;
106
-	}
97
+    /**
98
+     * Casts a provided value to an integer.
99
+     *
100
+     * @param mixed $value
101
+     *
102
+     * @return int
103
+     */
104
+    public function make_integer( $value ) {
105
+        return (int) $value;
106
+    }
107 107
 }
Please login to merge, or discard this patch.