Completed
Push — master ( 479d34...76ed5d )
by James
16s queued 14s
created
src/Http/Guard.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,6 @@
 block discarded – undo
2 2
 namespace Intraxia\Jaxion\Http;
3 3
 
4 4
 use Intraxia\Jaxion\Contract\Http\Guard as GuardContract;
5
-use Intraxia\Jaxion\Utility\Str;
6 5
 use WP_Error;
7 6
 
8 7
 /**
Please login to merge, or discard this patch.
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -15,86 +15,86 @@
 block discarded – undo
15 15
  * @subpackage Http
16 16
  */
17 17
 class Guard implements GuardContract {
18
-	/**
19
-	 * Default options.
20
-	 *
21
-	 * @var array
22
-	 */
23
-	protected $defaults = array(
24
-		'rule'     => 'public',
25
-		'callback' => false,
26
-	);
18
+    /**
19
+     * Default options.
20
+     *
21
+     * @var array
22
+     */
23
+    protected $defaults = array(
24
+        'rule'     => 'public',
25
+        'callback' => false,
26
+    );
27 27
 
28
-	/**
29
-	 * Guard options.
30
-	 *
31
-	 * @var array
32
-	 */
33
-	protected $options;
28
+    /**
29
+     * Guard options.
30
+     *
31
+     * @var array
32
+     */
33
+    protected $options;
34 34
 
35
-	/**
36
-	 * Instantiate a new Guard with provided options.
37
-	 *
38
-	 * @param array $options
39
-	 */
40
-	public function __construct( array $options = array() ) {
41
-		$this->options = $this->set_defaults( $options );
42
-	}
35
+    /**
36
+     * Instantiate a new Guard with provided options.
37
+     *
38
+     * @param array $options
39
+     */
40
+    public function __construct( array $options = array() ) {
41
+        $this->options = $this->set_defaults( $options );
42
+    }
43 43
 
44
-	/**
45
-	 * Validates whether the current user is authorized.
46
-	 *
47
-	 * @return true|WP_Error
48
-	 */
49
-	public function authorized() {
50
-		// if the rule is public, always authorized
51
-		if ( 'public' === $this->options['rule'] ) {
52
-			return true;
53
-		}
44
+    /**
45
+     * Validates whether the current user is authorized.
46
+     *
47
+     * @return true|WP_Error
48
+     */
49
+    public function authorized() {
50
+        // if the rule is public, always authorized
51
+        if ( 'public' === $this->options['rule'] ) {
52
+            return true;
53
+        }
54 54
 
55
-		// enable passing in callback
56
-		if ( 'callback' === $this->options['rule'] && is_callable( $this->options['callback'] ) ) {
57
-			return call_user_func( $this->options['callback'] );
58
-		}
55
+        // enable passing in callback
56
+        if ( 'callback' === $this->options['rule'] && is_callable( $this->options['callback'] ) ) {
57
+            return call_user_func( $this->options['callback'] );
58
+        }
59 59
 
60
-		// map rule to method
61
-		if ( method_exists( $this, $method = $this->options['rule'] ) ) {
62
-			return $this->{$method}();
63
-		}
60
+        // map rule to method
61
+        if ( method_exists( $this, $method = $this->options['rule'] ) ) {
62
+            return $this->{$method}();
63
+        }
64 64
 
65
-		// disable in rule is misconfigused
66
-		// @todo set up internal translations
67
-		// @todo also, this error message kinda sucks
68
-		return new WP_Error( '500', __( 'Guard failure', 'jaxion' ) );
69
-	}
65
+        // disable in rule is misconfigused
66
+        // @todo set up internal translations
67
+        // @todo also, this error message kinda sucks
68
+        return new WP_Error( '500', __( 'Guard failure', 'jaxion' ) );
69
+    }
70 70
 
71
-	/**
72
-	 * Checks whether the current user can edit other's posts.
73
-	 *
74
-	 * @return bool|WP_Error
75
-	 */
76
-	protected function can_edit_others_posts() {
77
-		return current_user_can( 'edit_others_posts' ) ?: new WP_Error( 'unauthorized', __( 'Unauthorized user', 'jaxion' ), array( 'status' => 401 ) );
78
-	}
71
+    /**
72
+     * Checks whether the current user can edit other's posts.
73
+     *
74
+     * @return bool|WP_Error
75
+     */
76
+    protected function can_edit_others_posts() {
77
+        return current_user_can( 'edit_others_posts' ) ?: new WP_Error( 'unauthorized', __( 'Unauthorized user', 'jaxion' ), array( 'status' => 401 ) );
78
+    }
79 79
 
80
-	/**
81
-	 * Checks whether the user is currently logged in.
82
-	 *
83
-	 * @return bool|WP_Error
84
-	 */
85
-	protected function user_logged_in() {
86
-		return is_user_logged_in() ?: new WP_Error( 'unauthorized', __( 'Unauthorized user', 'jaxion' ), array( 'status' => 401 ) );
87
-	}
80
+    /**
81
+     * Checks whether the user is currently logged in.
82
+     *
83
+     * @return bool|WP_Error
84
+     */
85
+    protected function user_logged_in() {
86
+        return is_user_logged_in() ?: new WP_Error( 'unauthorized', __( 'Unauthorized user', 'jaxion' ), array( 'status' => 401 ) );
87
+    }
88 88
 
89
-	/**
90
-	 * Sets the default params for the Guard options.
91
-	 *
92
-	 * @param array $options
93
-	 *
94
-	 * @return array
95
-	 */
96
-	protected function set_defaults( $options ) {
97
-		// these are the valid options
98
-		return wp_parse_args( $options, $this->defaults );
99
-	}
89
+    /**
90
+     * Sets the default params for the Guard options.
91
+     *
92
+     * @param array $options
93
+     *
94
+     * @return array
95
+     */
96
+    protected function set_defaults( $options ) {
97
+        // these are the valid options
98
+        return wp_parse_args( $options, $this->defaults );
99
+    }
100 100
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 	 *
38 38
 	 * @param array $options
39 39
 	 */
40
-	public function __construct( array $options = array() ) {
41
-		$this->options = $this->set_defaults( $options );
40
+	public function __construct(array $options = array()) {
41
+		$this->options = $this->set_defaults($options);
42 42
 	}
43 43
 
44 44
 	/**
@@ -48,24 +48,24 @@  discard block
 block discarded – undo
48 48
 	 */
49 49
 	public function authorized() {
50 50
 		// if the rule is public, always authorized
51
-		if ( 'public' === $this->options['rule'] ) {
51
+		if ('public' === $this->options['rule']) {
52 52
 			return true;
53 53
 		}
54 54
 
55 55
 		// enable passing in callback
56
-		if ( 'callback' === $this->options['rule'] && is_callable( $this->options['callback'] ) ) {
57
-			return call_user_func( $this->options['callback'] );
56
+		if ('callback' === $this->options['rule'] && is_callable($this->options['callback'])) {
57
+			return call_user_func($this->options['callback']);
58 58
 		}
59 59
 
60 60
 		// map rule to method
61
-		if ( method_exists( $this, $method = $this->options['rule'] ) ) {
61
+		if (method_exists($this, $method = $this->options['rule'])) {
62 62
 			return $this->{$method}();
63 63
 		}
64 64
 
65 65
 		// disable in rule is misconfigused
66 66
 		// @todo set up internal translations
67 67
 		// @todo also, this error message kinda sucks
68
-		return new WP_Error( '500', __( 'Guard failure', 'jaxion' ) );
68
+		return new WP_Error('500', __('Guard failure', 'jaxion'));
69 69
 	}
70 70
 
71 71
 	/**
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	 * @return bool|WP_Error
75 75
 	 */
76 76
 	protected function can_edit_others_posts() {
77
-		return current_user_can( 'edit_others_posts' ) ?: new WP_Error( 'unauthorized', __( 'Unauthorized user', 'jaxion' ), array( 'status' => 401 ) );
77
+		return current_user_can('edit_others_posts') ?: new WP_Error('unauthorized', __('Unauthorized user', 'jaxion'), array('status' => 401));
78 78
 	}
79 79
 
80 80
 	/**
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 * @return bool|WP_Error
84 84
 	 */
85 85
 	protected function user_logged_in() {
86
-		return is_user_logged_in() ?: new WP_Error( 'unauthorized', __( 'Unauthorized user', 'jaxion' ), array( 'status' => 401 ) );
86
+		return is_user_logged_in() ?: new WP_Error('unauthorized', __('Unauthorized user', 'jaxion'), array('status' => 401));
87 87
 	}
88 88
 
89 89
 	/**
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
 	 *
94 94
 	 * @return array
95 95
 	 */
96
-	protected function set_defaults( $options ) {
96
+	protected function set_defaults($options) {
97 97
 		// these are the valid options
98
-		return wp_parse_args( $options, $this->defaults );
98
+		return wp_parse_args($options, $this->defaults);
99 99
 	}
100 100
 }
Please login to merge, or discard this patch.
src/Contract/Core/Container.php 2 patches
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -2,75 +2,75 @@
 block discarded – undo
2 2
 namespace Intraxia\Jaxion\Contract\Core;
3 3
 
4 4
 interface Container extends \ArrayAccess, \Iterator {
5
-	/**
6
-	 * Define a new service or value on the Container.
7
-	 *
8
-	 * The alias is the name that the value will be referenced by. This can be used by both
9
-	 * the `get` method to retrieve the value or through ArrayAccess (`$container['alias']`).
10
-	 * It should be a short name used to reference the defined value. The definition can be
11
-	 * any scalar value to assign to the alias, or it can define a service object to return.
12
-	 * This can be accomplished by passing in a closure, which takes the container and returns
13
-	 * a fully constructed object. This closure will be executed every time the class is fetched.
14
-	 * If an already-instantiated object is passed in, it will be returned when fetched. A
15
-	 * Definition object will be returned for additional manipulation. Scalar values will be
16
-	 * locked automatically and can't be overridden.
17
-	 *
18
-	 * @param string|array $alias
19
-	 * @param mixed        $definition
20
-	 *
21
-	 * @return $this
22
-	 */
23
-	public function define( $alias, $definition );
5
+    /**
6
+     * Define a new service or value on the Container.
7
+     *
8
+     * The alias is the name that the value will be referenced by. This can be used by both
9
+     * the `get` method to retrieve the value or through ArrayAccess (`$container['alias']`).
10
+     * It should be a short name used to reference the defined value. The definition can be
11
+     * any scalar value to assign to the alias, or it can define a service object to return.
12
+     * This can be accomplished by passing in a closure, which takes the container and returns
13
+     * a fully constructed object. This closure will be executed every time the class is fetched.
14
+     * If an already-instantiated object is passed in, it will be returned when fetched. A
15
+     * Definition object will be returned for additional manipulation. Scalar values will be
16
+     * locked automatically and can't be overridden.
17
+     *
18
+     * @param string|array $alias
19
+     * @param mixed        $definition
20
+     *
21
+     * @return $this
22
+     */
23
+    public function define( $alias, $definition );
24 24
 
25
-	/**
26
-	 * Defines a new singleton on the Container.
27
-	 *
28
-	 * Functions identically to Container::define, except closures passed in are only executed
29
-	 * once, and the return value is reused across multiple fetches.
30
-	 *
31
-	 * @param string|array $alias
32
-	 * @param mixed        $definition
33
-	 *
34
-	 * @return $this
35
-	 */
36
-	public function share( $alias, $definition );
25
+    /**
26
+     * Defines a new singleton on the Container.
27
+     *
28
+     * Functions identically to Container::define, except closures passed in are only executed
29
+     * once, and the return value is reused across multiple fetches.
30
+     *
31
+     * @param string|array $alias
32
+     * @param mixed        $definition
33
+     *
34
+     * @return $this
35
+     */
36
+    public function share( $alias, $definition );
37 37
 
38
-	/**
39
-	 * Fetches the value for the provided alias.
40
-	 *
41
-	 * @param string $alias
42
-	 *
43
-	 * @return mixed
44
-	 */
45
-	public function fetch( $alias );
38
+    /**
39
+     * Fetches the value for the provided alias.
40
+     *
41
+     * @param string $alias
42
+     *
43
+     * @return mixed
44
+     */
45
+    public function fetch( $alias );
46 46
 
47
-	/**
48
-	 * Checks whether the provided alias exists on the container.
49
-	 *
50
-	 * @param string $alias
51
-	 *
52
-	 * @return bool
53
-	 */
54
-	public function has( $alias );
47
+    /**
48
+     * Checks whether the provided alias exists on the container.
49
+     *
50
+     * @param string $alias
51
+     *
52
+     * @return bool
53
+     */
54
+    public function has( $alias );
55 55
 
56
-	/**
57
-	 * Removes the provided alias from the container.
58
-	 *
59
-	 * @param string $alias
60
-	 *
61
-	 * @return bool
62
-	 */
63
-	public function remove( $alias );
56
+    /**
57
+     * Removes the provided alias from the container.
58
+     *
59
+     * @param string $alias
60
+     *
61
+     * @return bool
62
+     */
63
+    public function remove( $alias );
64 64
 
65
-	/**
66
-	 * Registers a service provider with the container.
67
-	 *
68
-	 * A service provider is responsible for defining and generating services that will be bound
69
-	 * into the container. This keeps the container and Application responsible solely for maintaining
70
-	 * the generated services and the API for registering them and allows for a clean interface for
71
-	 * adding new services to the container.
72
-	 *
73
-	 * @param ServiceProvider $provider
74
-	 */
75
-	public function register( ServiceProvider $provider );
65
+    /**
66
+     * Registers a service provider with the container.
67
+     *
68
+     * A service provider is responsible for defining and generating services that will be bound
69
+     * into the container. This keeps the container and Application responsible solely for maintaining
70
+     * the generated services and the API for registering them and allows for a clean interface for
71
+     * adding new services to the container.
72
+     *
73
+     * @param ServiceProvider $provider
74
+     */
75
+    public function register( ServiceProvider $provider );
76 76
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 *
21 21
 	 * @return $this
22 22
 	 */
23
-	public function define( $alias, $definition );
23
+	public function define($alias, $definition);
24 24
 
25 25
 	/**
26 26
 	 * Defines a new singleton on the Container.
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	 *
34 34
 	 * @return $this
35 35
 	 */
36
-	public function share( $alias, $definition );
36
+	public function share($alias, $definition);
37 37
 
38 38
 	/**
39 39
 	 * Fetches the value for the provided alias.
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
 	 * @return mixed
44 44
 	 */
45
-	public function fetch( $alias );
45
+	public function fetch($alias);
46 46
 
47 47
 	/**
48 48
 	 * Checks whether the provided alias exists on the container.
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 *
52 52
 	 * @return bool
53 53
 	 */
54
-	public function has( $alias );
54
+	public function has($alias);
55 55
 
56 56
 	/**
57 57
 	 * Removes the provided alias from the container.
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 *
61 61
 	 * @return bool
62 62
 	 */
63
-	public function remove( $alias );
63
+	public function remove($alias);
64 64
 
65 65
 	/**
66 66
 	 * Registers a service provider with the container.
@@ -72,5 +72,5 @@  discard block
 block discarded – undo
72 72
 	 *
73 73
 	 * @param ServiceProvider $provider
74 74
 	 */
75
-	public function register( ServiceProvider $provider );
75
+	public function register(ServiceProvider $provider);
76 76
 }
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/Http/Endpoint.php 2 patches
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -14,141 +14,141 @@
 block discarded – undo
14 14
  * @subpackage Http
15 15
  */
16 16
 class Endpoint {
17
-	/**
18
-	 * Endpoint's route.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	protected $route;
23
-
24
-	/**
25
-	 * Endpoint's HTTP verb(s).
26
-	 *
27
-	 * @var string
28
-	 */
29
-	protected $method;
30
-
31
-	/**
32
-	 * Endpoint's callback.
33
-	 *
34
-	 * @var callable
35
-	 */
36
-	protected $callback;
37
-
38
-	/**
39
-	 * Endpoint's permission guard.
40
-	 *
41
-	 * @var GuardContract
42
-	 */
43
-	protected $guard;
44
-
45
-	/**
46
-	 * Endpoint's arguments filter.
47
-	 *
48
-	 * @var FilterContract
49
-	 */
50
-	protected $filter;
51
-
52
-	/**
53
-	 * Endpoint's route prefix.
54
-	 *
55
-	 * @var string
56
-	 */
57
-	protected $prefix;
58
-
59
-	/**
60
-	 * Instantiate a new endpoint with a provided route, method, and callback.
61
-	 *
62
-	 * @param string   $route
63
-	 * @param string   $method
64
-	 * @param callable $callback
65
-	 *
66
-	 * @throws MalformedRouteException
67
-	 */
68
-	public function __construct( $route, $method, $callback ) {
69
-		if ( ! Str::starts_with( $route, '/' ) || Str::ends_with( $route, '/' ) ) {
70
-			throw new MalformedRouteException;
71
-		}
72
-
73
-		$this->route    = $route;
74
-		$this->method   = $method;
75
-		$this->callback = $callback;
76
-	}
77
-
78
-	/**
79
-	 * Generates the endpoint's route.
80
-	 *
81
-	 * Combines the prefix with the route to generate the full route string.
82
-	 *
83
-	 * @return string
84
-	 */
85
-	public function get_route() {
86
-		return ( $this->prefix ?: '' ) . $this->route;
87
-	}
88
-
89
-	/**
90
-	 * Generates the endpoint's WP-API options array.
91
-	 *
92
-	 * @return array
93
-	 */
94
-	public function get_options() {
95
-		$options = array(
96
-			'methods'  => $this->method,
97
-			'callback' => $this->callback,
98
-		);
99
-
100
-		if ( $this->guard ) {
101
-			$options['permission_callback'] = array( $this->guard, 'authorized' );
102
-		}
103
-
104
-		if ( $this->filter ) {
105
-			$options['args'] = $this->filter->rules();
106
-		}
107
-
108
-		return $options;
109
-	}
110
-
111
-	/**
112
-	 * Sets the endpoint's permission guard.
113
-	 *
114
-	 * @param GuardContract $guard
115
-	 *
116
-	 * @return $this
117
-	 */
118
-	public function set_guard( GuardContract $guard ) {
119
-		$this->guard = $guard;
120
-
121
-		return $this;
122
-	}
123
-
124
-	/**
125
-	 * Sets the endpoint's arguments filter.
126
-	 *
127
-	 * @param FilterContract $filter
128
-	 *
129
-	 * @return $this
130
-	 */
131
-	public function set_filter( FilterContract $filter ) {
132
-		$this->filter = $filter;
133
-
134
-		return $this;
135
-	}
136
-
137
-	/**
138
-	 * Sets the endpoint's prefix.
139
-	 *
140
-	 * @param string $prefix
141
-	 *
142
-	 * @return $this
143
-	 * @throws MalformedRouteException
144
-	 */
145
-	public function set_prefix( $prefix ) {
146
-		if ( ! Str::starts_with( $prefix, '/' ) || Str::ends_with( $prefix, '/' ) ) {
147
-			throw new MalformedRouteException;
148
-		}
149
-
150
-		$this->prefix = $prefix;
151
-
152
-		return $this;
153
-	}
17
+    /**
18
+     * Endpoint's route.
19
+     *
20
+     * @var string
21
+     */
22
+    protected $route;
23
+
24
+    /**
25
+     * Endpoint's HTTP verb(s).
26
+     *
27
+     * @var string
28
+     */
29
+    protected $method;
30
+
31
+    /**
32
+     * Endpoint's callback.
33
+     *
34
+     * @var callable
35
+     */
36
+    protected $callback;
37
+
38
+    /**
39
+     * Endpoint's permission guard.
40
+     *
41
+     * @var GuardContract
42
+     */
43
+    protected $guard;
44
+
45
+    /**
46
+     * Endpoint's arguments filter.
47
+     *
48
+     * @var FilterContract
49
+     */
50
+    protected $filter;
51
+
52
+    /**
53
+     * Endpoint's route prefix.
54
+     *
55
+     * @var string
56
+     */
57
+    protected $prefix;
58
+
59
+    /**
60
+     * Instantiate a new endpoint with a provided route, method, and callback.
61
+     *
62
+     * @param string   $route
63
+     * @param string   $method
64
+     * @param callable $callback
65
+     *
66
+     * @throws MalformedRouteException
67
+     */
68
+    public function __construct( $route, $method, $callback ) {
69
+        if ( ! Str::starts_with( $route, '/' ) || Str::ends_with( $route, '/' ) ) {
70
+            throw new MalformedRouteException;
71
+        }
72
+
73
+        $this->route    = $route;
74
+        $this->method   = $method;
75
+        $this->callback = $callback;
76
+    }
77
+
78
+    /**
79
+     * Generates the endpoint's route.
80
+     *
81
+     * Combines the prefix with the route to generate the full route string.
82
+     *
83
+     * @return string
84
+     */
85
+    public function get_route() {
86
+        return ( $this->prefix ?: '' ) . $this->route;
87
+    }
88
+
89
+    /**
90
+     * Generates the endpoint's WP-API options array.
91
+     *
92
+     * @return array
93
+     */
94
+    public function get_options() {
95
+        $options = array(
96
+            'methods'  => $this->method,
97
+            'callback' => $this->callback,
98
+        );
99
+
100
+        if ( $this->guard ) {
101
+            $options['permission_callback'] = array( $this->guard, 'authorized' );
102
+        }
103
+
104
+        if ( $this->filter ) {
105
+            $options['args'] = $this->filter->rules();
106
+        }
107
+
108
+        return $options;
109
+    }
110
+
111
+    /**
112
+     * Sets the endpoint's permission guard.
113
+     *
114
+     * @param GuardContract $guard
115
+     *
116
+     * @return $this
117
+     */
118
+    public function set_guard( GuardContract $guard ) {
119
+        $this->guard = $guard;
120
+
121
+        return $this;
122
+    }
123
+
124
+    /**
125
+     * Sets the endpoint's arguments filter.
126
+     *
127
+     * @param FilterContract $filter
128
+     *
129
+     * @return $this
130
+     */
131
+    public function set_filter( FilterContract $filter ) {
132
+        $this->filter = $filter;
133
+
134
+        return $this;
135
+    }
136
+
137
+    /**
138
+     * Sets the endpoint's prefix.
139
+     *
140
+     * @param string $prefix
141
+     *
142
+     * @return $this
143
+     * @throws MalformedRouteException
144
+     */
145
+    public function set_prefix( $prefix ) {
146
+        if ( ! Str::starts_with( $prefix, '/' ) || Str::ends_with( $prefix, '/' ) ) {
147
+            throw new MalformedRouteException;
148
+        }
149
+
150
+        $this->prefix = $prefix;
151
+
152
+        return $this;
153
+    }
154 154
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
 	 *
66 66
 	 * @throws MalformedRouteException
67 67
 	 */
68
-	public function __construct( $route, $method, $callback ) {
69
-		if ( ! Str::starts_with( $route, '/' ) || Str::ends_with( $route, '/' ) ) {
68
+	public function __construct($route, $method, $callback) {
69
+		if (!Str::starts_with($route, '/') || Str::ends_with($route, '/')) {
70 70
 			throw new MalformedRouteException;
71 71
 		}
72 72
 
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 * @return string
84 84
 	 */
85 85
 	public function get_route() {
86
-		return ( $this->prefix ?: '' ) . $this->route;
86
+		return ($this->prefix ?: '').$this->route;
87 87
 	}
88 88
 
89 89
 	/**
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 			'callback' => $this->callback,
98 98
 		);
99 99
 
100
-		if ( $this->guard ) {
101
-			$options['permission_callback'] = array( $this->guard, 'authorized' );
100
+		if ($this->guard) {
101
+			$options['permission_callback'] = array($this->guard, 'authorized');
102 102
 		}
103 103
 
104
-		if ( $this->filter ) {
104
+		if ($this->filter) {
105 105
 			$options['args'] = $this->filter->rules();
106 106
 		}
107 107
 
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 *
116 116
 	 * @return $this
117 117
 	 */
118
-	public function set_guard( GuardContract $guard ) {
118
+	public function set_guard(GuardContract $guard) {
119 119
 		$this->guard = $guard;
120 120
 
121 121
 		return $this;
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 *
129 129
 	 * @return $this
130 130
 	 */
131
-	public function set_filter( FilterContract $filter ) {
131
+	public function set_filter(FilterContract $filter) {
132 132
 		$this->filter = $filter;
133 133
 
134 134
 		return $this;
@@ -142,8 +142,8 @@  discard block
 block discarded – undo
142 142
 	 * @return $this
143 143
 	 * @throws MalformedRouteException
144 144
 	 */
145
-	public function set_prefix( $prefix ) {
146
-		if ( ! Str::starts_with( $prefix, '/' ) || Str::ends_with( $prefix, '/' ) ) {
145
+	public function set_prefix($prefix) {
146
+		if (!Str::starts_with($prefix, '/') || Str::ends_with($prefix, '/')) {
147 147
 			throw new MalformedRouteException;
148 148
 		}
149 149
 
Please login to merge, or discard this patch.
src/Http/Filter.php 2 patches
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -12,134 +12,134 @@
 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;
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
-	}
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();
41
-
42
-		foreach ( $this->rules as $arg => $validation ) {
43
-			if ( ! $validation || ! is_string( $validation ) ) {
44
-				continue;
45
-			}
46
-
47
-			$args[ $arg ] = $this->parse_validation( $validation );
48
-		}
49
-
50
-		return $args;
51
-	}
52
-
53
-	/**
54
-	 * Parses a validation string into a WP-API compatible rule.
55
-	 *
56
-	 * @param string $validation
57
-	 *
58
-	 * @return array
59
-	 *
60
-	 * @todo The next rule added needs to refactor this process.
61
-	 */
62
-	protected function parse_validation( $validation ) {
63
-		$validation = explode( '|', $validation );
64
-
65
-		$rules = array();
66
-
67
-		foreach ( $validation as $rule ) {
68
-			if ( 0 === strpos( $rule, 'default' ) ) {
69
-				$rule_arr = explode( ':', $rule );
70
-
71
-				$rules['default'] = count( $rule_arr ) === 2 ? array_pop( $rule_arr ) : '';
72
-			}
73
-
74
-			if ( 0 === strpos( $rule, 'oneof' ) ) {
75
-				list( $rule, $values ) = explode( ':', $rule );
76
-
77
-				$values   = explode( ',', $values );
78
-				$callback = function ( $value ) use ( $values ) {
79
-					if ( in_array( $value, $values, true ) ) {
80
-						return true;
81
-					}
82
-
83
-					return false;
84
-				};
85
-
86
-				$rules['validate_callback'] = isset( $rules['validate_callback'] ) ? $this->add_callback( $rules['validate_callback'], $callback ) : $callback;
87
-			}
88
-
89
-			switch ( $rule ) {
90
-				case 'required':
91
-					$rules['required'] = true;
92
-					break;
93
-				case 'integer':
94
-					$callback                   = array( $this, 'validate_integer' );
95
-					$rules['validate_callback'] = isset( $rules['validate_callback'] ) ? $this->add_callback( $rules['validate_callback'], $callback ) : $callback;
96
-
97
-					$callback                   = array( $this, 'make_integer' );
98
-					$rules['sanitize_callback'] = isset( $rules['sanitize_callback'] ) ? $this->add_callback( $rules['sanitize_callback'], $callback ) : $callback;
99
-					break;
100
-			}
101
-		}
102
-
103
-		return $rules;
104
-	}
105
-
106
-	/**
107
-	 * Validate that provided value is an integer.
108
-	 *
109
-	 * @param mixed $value
110
-	 *
111
-	 * @return bool
112
-	 */
113
-	public function validate_integer( $value ) {
114
-		return filter_var( $value, FILTER_VALIDATE_INT ) !== false;
115
-	}
116
-
117
-	/**
118
-	 * Casts a provided value to an integer.
119
-	 *
120
-	 * @param mixed $value
121
-	 *
122
-	 * @return int
123
-	 */
124
-	public function make_integer( $value ) {
125
-		return (int) $value;
126
-	}
127
-
128
-	/**
129
-	 * Creates a new callback that connects the previous and next callback.
130
-	 *
131
-	 * @param callable $previous
132
-	 * @param callable $next
133
-	 *
134
-	 * @return \Closure;
135
-	 */
136
-	private function add_callback( $previous, $next ) {
137
-		return function ( $value ) use ( $previous, $next ) {
138
-			if ( call_user_func( $previous, $value ) ) {
139
-				return call_user_func( $next, $value );
140
-			}
141
-
142
-			return false;
143
-		};
144
-	}
15
+    /**
16
+     * Filter rules.
17
+     *
18
+     * @var array
19
+     */
20
+    protected $rules;
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
+    }
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();
41
+
42
+        foreach ( $this->rules as $arg => $validation ) {
43
+            if ( ! $validation || ! is_string( $validation ) ) {
44
+                continue;
45
+            }
46
+
47
+            $args[ $arg ] = $this->parse_validation( $validation );
48
+        }
49
+
50
+        return $args;
51
+    }
52
+
53
+    /**
54
+     * Parses a validation string into a WP-API compatible rule.
55
+     *
56
+     * @param string $validation
57
+     *
58
+     * @return array
59
+     *
60
+     * @todo The next rule added needs to refactor this process.
61
+     */
62
+    protected function parse_validation( $validation ) {
63
+        $validation = explode( '|', $validation );
64
+
65
+        $rules = array();
66
+
67
+        foreach ( $validation as $rule ) {
68
+            if ( 0 === strpos( $rule, 'default' ) ) {
69
+                $rule_arr = explode( ':', $rule );
70
+
71
+                $rules['default'] = count( $rule_arr ) === 2 ? array_pop( $rule_arr ) : '';
72
+            }
73
+
74
+            if ( 0 === strpos( $rule, 'oneof' ) ) {
75
+                list( $rule, $values ) = explode( ':', $rule );
76
+
77
+                $values   = explode( ',', $values );
78
+                $callback = function ( $value ) use ( $values ) {
79
+                    if ( in_array( $value, $values, true ) ) {
80
+                        return true;
81
+                    }
82
+
83
+                    return false;
84
+                };
85
+
86
+                $rules['validate_callback'] = isset( $rules['validate_callback'] ) ? $this->add_callback( $rules['validate_callback'], $callback ) : $callback;
87
+            }
88
+
89
+            switch ( $rule ) {
90
+                case 'required':
91
+                    $rules['required'] = true;
92
+                    break;
93
+                case 'integer':
94
+                    $callback                   = array( $this, 'validate_integer' );
95
+                    $rules['validate_callback'] = isset( $rules['validate_callback'] ) ? $this->add_callback( $rules['validate_callback'], $callback ) : $callback;
96
+
97
+                    $callback                   = array( $this, 'make_integer' );
98
+                    $rules['sanitize_callback'] = isset( $rules['sanitize_callback'] ) ? $this->add_callback( $rules['sanitize_callback'], $callback ) : $callback;
99
+                    break;
100
+            }
101
+        }
102
+
103
+        return $rules;
104
+    }
105
+
106
+    /**
107
+     * Validate that provided value is an integer.
108
+     *
109
+     * @param mixed $value
110
+     *
111
+     * @return bool
112
+     */
113
+    public function validate_integer( $value ) {
114
+        return filter_var( $value, FILTER_VALIDATE_INT ) !== false;
115
+    }
116
+
117
+    /**
118
+     * Casts a provided value to an integer.
119
+     *
120
+     * @param mixed $value
121
+     *
122
+     * @return int
123
+     */
124
+    public function make_integer( $value ) {
125
+        return (int) $value;
126
+    }
127
+
128
+    /**
129
+     * Creates a new callback that connects the previous and next callback.
130
+     *
131
+     * @param callable $previous
132
+     * @param callable $next
133
+     *
134
+     * @return \Closure;
135
+     */
136
+    private function add_callback( $previous, $next ) {
137
+        return function ( $value ) use ( $previous, $next ) {
138
+            if ( call_user_func( $previous, $value ) ) {
139
+                return call_user_func( $next, $value );
140
+            }
141
+
142
+            return false;
143
+        };
144
+    }
145 145
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @param array $rules
26 26
 	 */
27
-	public function __construct( $rules = array() ) {
27
+	public function __construct($rules = array()) {
28 28
 		$this->rules = $rules;
29 29
 	}
30 30
 
@@ -39,12 +39,12 @@  discard block
 block discarded – undo
39 39
 	public function rules() {
40 40
 		$args = array();
41 41
 
42
-		foreach ( $this->rules as $arg => $validation ) {
43
-			if ( ! $validation || ! is_string( $validation ) ) {
42
+		foreach ($this->rules as $arg => $validation) {
43
+			if (!$validation || !is_string($validation)) {
44 44
 				continue;
45 45
 			}
46 46
 
47
-			$args[ $arg ] = $this->parse_validation( $validation );
47
+			$args[$arg] = $this->parse_validation($validation);
48 48
 		}
49 49
 
50 50
 		return $args;
@@ -59,43 +59,43 @@  discard block
 block discarded – undo
59 59
 	 *
60 60
 	 * @todo The next rule added needs to refactor this process.
61 61
 	 */
62
-	protected function parse_validation( $validation ) {
63
-		$validation = explode( '|', $validation );
62
+	protected function parse_validation($validation) {
63
+		$validation = explode('|', $validation);
64 64
 
65 65
 		$rules = array();
66 66
 
67
-		foreach ( $validation as $rule ) {
68
-			if ( 0 === strpos( $rule, 'default' ) ) {
69
-				$rule_arr = explode( ':', $rule );
67
+		foreach ($validation as $rule) {
68
+			if (0 === strpos($rule, 'default')) {
69
+				$rule_arr = explode(':', $rule);
70 70
 
71
-				$rules['default'] = count( $rule_arr ) === 2 ? array_pop( $rule_arr ) : '';
71
+				$rules['default'] = count($rule_arr) === 2 ? array_pop($rule_arr) : '';
72 72
 			}
73 73
 
74
-			if ( 0 === strpos( $rule, 'oneof' ) ) {
75
-				list( $rule, $values ) = explode( ':', $rule );
74
+			if (0 === strpos($rule, 'oneof')) {
75
+				list($rule, $values) = explode(':', $rule);
76 76
 
77
-				$values   = explode( ',', $values );
78
-				$callback = function ( $value ) use ( $values ) {
79
-					if ( in_array( $value, $values, true ) ) {
77
+				$values   = explode(',', $values);
78
+				$callback = function($value) use ($values) {
79
+					if (in_array($value, $values, true)) {
80 80
 						return true;
81 81
 					}
82 82
 
83 83
 					return false;
84 84
 				};
85 85
 
86
-				$rules['validate_callback'] = isset( $rules['validate_callback'] ) ? $this->add_callback( $rules['validate_callback'], $callback ) : $callback;
86
+				$rules['validate_callback'] = isset($rules['validate_callback']) ? $this->add_callback($rules['validate_callback'], $callback) : $callback;
87 87
 			}
88 88
 
89
-			switch ( $rule ) {
89
+			switch ($rule) {
90 90
 				case 'required':
91 91
 					$rules['required'] = true;
92 92
 					break;
93 93
 				case 'integer':
94
-					$callback                   = array( $this, 'validate_integer' );
95
-					$rules['validate_callback'] = isset( $rules['validate_callback'] ) ? $this->add_callback( $rules['validate_callback'], $callback ) : $callback;
94
+					$callback                   = array($this, 'validate_integer');
95
+					$rules['validate_callback'] = isset($rules['validate_callback']) ? $this->add_callback($rules['validate_callback'], $callback) : $callback;
96 96
 
97
-					$callback                   = array( $this, 'make_integer' );
98
-					$rules['sanitize_callback'] = isset( $rules['sanitize_callback'] ) ? $this->add_callback( $rules['sanitize_callback'], $callback ) : $callback;
97
+					$callback                   = array($this, 'make_integer');
98
+					$rules['sanitize_callback'] = isset($rules['sanitize_callback']) ? $this->add_callback($rules['sanitize_callback'], $callback) : $callback;
99 99
 					break;
100 100
 			}
101 101
 		}
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
 	 *
111 111
 	 * @return bool
112 112
 	 */
113
-	public function validate_integer( $value ) {
114
-		return filter_var( $value, FILTER_VALIDATE_INT ) !== false;
113
+	public function validate_integer($value) {
114
+		return filter_var($value, FILTER_VALIDATE_INT) !== false;
115 115
 	}
116 116
 
117 117
 	/**
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 *
122 122
 	 * @return int
123 123
 	 */
124
-	public function make_integer( $value ) {
124
+	public function make_integer($value) {
125 125
 		return (int) $value;
126 126
 	}
127 127
 
@@ -133,10 +133,10 @@  discard block
 block discarded – undo
133 133
 	 *
134 134
 	 * @return \Closure;
135 135
 	 */
136
-	private function add_callback( $previous, $next ) {
137
-		return function ( $value ) use ( $previous, $next ) {
138
-			if ( call_user_func( $previous, $value ) ) {
139
-				return call_user_func( $next, $value );
136
+	private function add_callback($previous, $next) {
137
+		return function($value) use ($previous, $next) {
138
+			if (call_user_func($previous, $value)) {
139
+				return call_user_func($next, $value);
140 140
 			}
141 141
 
142 142
 			return false;
Please login to merge, or discard this patch.
src/Http/Router.php 2 patches
Indentation   +206 added lines, -206 removed lines patch added patch discarded remove patch
@@ -21,210 +21,210 @@
 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
-	 * @return $this
75
-	 */
76
-	public function set_vendor( $vendor ) {
77
-		$this->vendor = $vendor;
78
-
79
-		return $this;
80
-	}
81
-
82
-	/**
83
-	 * Sets the resource's version.
84
-	 *
85
-	 * @param int $version
86
-	 *
87
-	 * @return $this
88
-	 */
89
-	public function set_version( $version ) {
90
-		$this->version = $version;
91
-
92
-		return $this;
93
-	}
94
-
95
-	/**
96
-	 * Registers all of the routes with the WP-API.
97
-	 *
98
-	 * Runs on the `rest_api_init` hook. Registers all of the routes loaded
99
-	 * on the router into the WordPress REST API.
100
-	 *
101
-	 * @throws VendorNotSetException
102
-	 * @throws VersionNotSetException
103
-	 */
104
-	public function register() {
105
-		if ( ! $this->vendor ) {
106
-			throw new VendorNotSetException;
107
-		}
108
-
109
-		if ( ! $this->version ) {
110
-			throw new VersionNotSetException;
111
-		}
112
-
113
-		foreach ( $this->endpoints as $endpoint ) {
114
-			register_rest_route(
115
-				$this->get_namespace(),
116
-				$endpoint->get_route(),
117
-				$endpoint->get_options()
118
-			);
119
-		}
120
-	}
121
-
122
-	/**
123
-	 * Registers a set of routes with a shared set of options.
124
-	 *
125
-	 * Allows you to group routes together with shared set of options, including
126
-	 * a route prefix, shared guards, and common parameter validation or sanitization.
127
-	 *
128
-	 * @param array    $options
129
-	 * @param callable $callback
130
-	 */
131
-	public function group( array $options, $callback ) {
132
-		$router = new static;
133
-
134
-		call_user_func( $callback, $router );
135
-
136
-		foreach ( $router->get_endpoints() as $endpoint ) {
137
-			$this->endpoints[] = $this->set_options( $endpoint, $options );
138
-		}
139
-	}
140
-
141
-	/**
142
-	 * Magic __call method.
143
-	 *
144
-	 * All of the endpoints registration method calls pass through here. This validates whether the method
145
-	 * is a valid endpoint type to register, and creates a new endpoint with the passed options.
146
-	 *
147
-	 * @param string $name
148
-	 * @param array  $arguments
149
-	 *
150
-	 * @return Endpoint
151
-	 *
152
-	 * @throws UnknownMethodException
153
-	 * @throws MissingArgumentException
154
-	 * @throws InvalidArgumentException
155
-	 */
156
-	public function __call( $name, $arguments ) {
157
-		if ( ! in_array( $name, array_keys( $this->methods ) ) ) {
158
-			throw new UnknownMethodException;
159
-		}
160
-
161
-		// array_merge ensures we have 3 elements
162
-		list( $route, $callback, $options ) = array_merge( $arguments, array( null, null, null ) );
163
-
164
-		if ( ! $route || ! $callback ) {
165
-			throw new MissingArgumentException;
166
-		}
167
-
168
-		if ( ! is_callable( $callback ) ) {
169
-			throw new InvalidArgumentException;
170
-		}
171
-
172
-		$endpoint = new Endpoint( $route, $this->methods[ $name ], $callback );
173
-
174
-		if ( $options && is_array( $options ) ) {
175
-			$endpoint = $this->set_options( $endpoint, $options );
176
-		}
177
-
178
-		return $this->endpoints[] = $endpoint;
179
-	}
180
-
181
-	/**
182
-	 * Sets the passed options on the endpoint.
183
-	 *
184
-	 * Only sets endpoints matching setters in the Endpoint class.
185
-	 *
186
-	 * @param Endpoint $endpoint
187
-	 * @param array    $options
188
-	 *
189
-	 * @return Endpoint
190
-	 * @throws MalformedRouteException
191
-	 */
192
-	protected function set_options( Endpoint $endpoint, array $options ) {
193
-		if ( isset( $options['guard'] ) ) {
194
-			$endpoint->set_guard( $options['guard'] );
195
-		}
196
-
197
-		if ( isset( $options['filter'] ) ) {
198
-			$endpoint->set_filter( $options['filter'] );
199
-		}
200
-
201
-		if ( isset( $options['prefix'] ) ) {
202
-			$endpoint->set_prefix( $options['prefix'] );
203
-		}
204
-
205
-		return $endpoint;
206
-	}
207
-
208
-	/**
209
-	 * Generates the resource's namespace.
210
-	 *
211
-	 * @return string
212
-	 */
213
-	protected function get_namespace() {
214
-		return $this->vendor . '/v' . $this->version;
215
-	}
216
-
217
-	/**
218
-	 * {@inheritDoc}
219
-	 *
220
-	 * @return array[]
221
-	 */
222
-	public function action_hooks() {
223
-		return array(
224
-			array(
225
-				'method' => 'register',
226
-				'hook'   => 'rest_api_init',
227
-			),
228
-		);
229
-	}
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
+     * @return $this
75
+     */
76
+    public function set_vendor( $vendor ) {
77
+        $this->vendor = $vendor;
78
+
79
+        return $this;
80
+    }
81
+
82
+    /**
83
+     * Sets the resource's version.
84
+     *
85
+     * @param int $version
86
+     *
87
+     * @return $this
88
+     */
89
+    public function set_version( $version ) {
90
+        $this->version = $version;
91
+
92
+        return $this;
93
+    }
94
+
95
+    /**
96
+     * Registers all of the routes with the WP-API.
97
+     *
98
+     * Runs on the `rest_api_init` hook. Registers all of the routes loaded
99
+     * on the router into the WordPress REST API.
100
+     *
101
+     * @throws VendorNotSetException
102
+     * @throws VersionNotSetException
103
+     */
104
+    public function register() {
105
+        if ( ! $this->vendor ) {
106
+            throw new VendorNotSetException;
107
+        }
108
+
109
+        if ( ! $this->version ) {
110
+            throw new VersionNotSetException;
111
+        }
112
+
113
+        foreach ( $this->endpoints as $endpoint ) {
114
+            register_rest_route(
115
+                $this->get_namespace(),
116
+                $endpoint->get_route(),
117
+                $endpoint->get_options()
118
+            );
119
+        }
120
+    }
121
+
122
+    /**
123
+     * Registers a set of routes with a shared set of options.
124
+     *
125
+     * Allows you to group routes together with shared set of options, including
126
+     * a route prefix, shared guards, and common parameter validation or sanitization.
127
+     *
128
+     * @param array    $options
129
+     * @param callable $callback
130
+     */
131
+    public function group( array $options, $callback ) {
132
+        $router = new static;
133
+
134
+        call_user_func( $callback, $router );
135
+
136
+        foreach ( $router->get_endpoints() as $endpoint ) {
137
+            $this->endpoints[] = $this->set_options( $endpoint, $options );
138
+        }
139
+    }
140
+
141
+    /**
142
+     * Magic __call method.
143
+     *
144
+     * All of the endpoints registration method calls pass through here. This validates whether the method
145
+     * is a valid endpoint type to register, and creates a new endpoint with the passed options.
146
+     *
147
+     * @param string $name
148
+     * @param array  $arguments
149
+     *
150
+     * @return Endpoint
151
+     *
152
+     * @throws UnknownMethodException
153
+     * @throws MissingArgumentException
154
+     * @throws InvalidArgumentException
155
+     */
156
+    public function __call( $name, $arguments ) {
157
+        if ( ! in_array( $name, array_keys( $this->methods ) ) ) {
158
+            throw new UnknownMethodException;
159
+        }
160
+
161
+        // array_merge ensures we have 3 elements
162
+        list( $route, $callback, $options ) = array_merge( $arguments, array( null, null, null ) );
163
+
164
+        if ( ! $route || ! $callback ) {
165
+            throw new MissingArgumentException;
166
+        }
167
+
168
+        if ( ! is_callable( $callback ) ) {
169
+            throw new InvalidArgumentException;
170
+        }
171
+
172
+        $endpoint = new Endpoint( $route, $this->methods[ $name ], $callback );
173
+
174
+        if ( $options && is_array( $options ) ) {
175
+            $endpoint = $this->set_options( $endpoint, $options );
176
+        }
177
+
178
+        return $this->endpoints[] = $endpoint;
179
+    }
180
+
181
+    /**
182
+     * Sets the passed options on the endpoint.
183
+     *
184
+     * Only sets endpoints matching setters in the Endpoint class.
185
+     *
186
+     * @param Endpoint $endpoint
187
+     * @param array    $options
188
+     *
189
+     * @return Endpoint
190
+     * @throws MalformedRouteException
191
+     */
192
+    protected function set_options( Endpoint $endpoint, array $options ) {
193
+        if ( isset( $options['guard'] ) ) {
194
+            $endpoint->set_guard( $options['guard'] );
195
+        }
196
+
197
+        if ( isset( $options['filter'] ) ) {
198
+            $endpoint->set_filter( $options['filter'] );
199
+        }
200
+
201
+        if ( isset( $options['prefix'] ) ) {
202
+            $endpoint->set_prefix( $options['prefix'] );
203
+        }
204
+
205
+        return $endpoint;
206
+    }
207
+
208
+    /**
209
+     * Generates the resource's namespace.
210
+     *
211
+     * @return string
212
+     */
213
+    protected function get_namespace() {
214
+        return $this->vendor . '/v' . $this->version;
215
+    }
216
+
217
+    /**
218
+     * {@inheritDoc}
219
+     *
220
+     * @return array[]
221
+     */
222
+    public function action_hooks() {
223
+        return array(
224
+            array(
225
+                'method' => 'register',
226
+                'hook'   => 'rest_api_init',
227
+            ),
228
+        );
229
+    }
230 230
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	 *
74 74
 	 * @return $this
75 75
 	 */
76
-	public function set_vendor( $vendor ) {
76
+	public function set_vendor($vendor) {
77 77
 		$this->vendor = $vendor;
78 78
 
79 79
 		return $this;
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 	 *
87 87
 	 * @return $this
88 88
 	 */
89
-	public function set_version( $version ) {
89
+	public function set_version($version) {
90 90
 		$this->version = $version;
91 91
 
92 92
 		return $this;
@@ -102,15 +102,15 @@  discard block
 block discarded – undo
102 102
 	 * @throws VersionNotSetException
103 103
 	 */
104 104
 	public function register() {
105
-		if ( ! $this->vendor ) {
105
+		if (!$this->vendor) {
106 106
 			throw new VendorNotSetException;
107 107
 		}
108 108
 
109
-		if ( ! $this->version ) {
109
+		if (!$this->version) {
110 110
 			throw new VersionNotSetException;
111 111
 		}
112 112
 
113
-		foreach ( $this->endpoints as $endpoint ) {
113
+		foreach ($this->endpoints as $endpoint) {
114 114
 			register_rest_route(
115 115
 				$this->get_namespace(),
116 116
 				$endpoint->get_route(),
@@ -128,13 +128,13 @@  discard block
 block discarded – undo
128 128
 	 * @param array    $options
129 129
 	 * @param callable $callback
130 130
 	 */
131
-	public function group( array $options, $callback ) {
131
+	public function group(array $options, $callback) {
132 132
 		$router = new static;
133 133
 
134
-		call_user_func( $callback, $router );
134
+		call_user_func($callback, $router);
135 135
 
136
-		foreach ( $router->get_endpoints() as $endpoint ) {
137
-			$this->endpoints[] = $this->set_options( $endpoint, $options );
136
+		foreach ($router->get_endpoints() as $endpoint) {
137
+			$this->endpoints[] = $this->set_options($endpoint, $options);
138 138
 		}
139 139
 	}
140 140
 
@@ -153,26 +153,26 @@  discard block
 block discarded – undo
153 153
 	 * @throws MissingArgumentException
154 154
 	 * @throws InvalidArgumentException
155 155
 	 */
156
-	public function __call( $name, $arguments ) {
157
-		if ( ! in_array( $name, array_keys( $this->methods ) ) ) {
156
+	public function __call($name, $arguments) {
157
+		if (!in_array($name, array_keys($this->methods))) {
158 158
 			throw new UnknownMethodException;
159 159
 		}
160 160
 
161 161
 		// array_merge ensures we have 3 elements
162
-		list( $route, $callback, $options ) = array_merge( $arguments, array( null, null, null ) );
162
+		list($route, $callback, $options) = array_merge($arguments, array(null, null, null));
163 163
 
164
-		if ( ! $route || ! $callback ) {
164
+		if (!$route || !$callback) {
165 165
 			throw new MissingArgumentException;
166 166
 		}
167 167
 
168
-		if ( ! is_callable( $callback ) ) {
168
+		if (!is_callable($callback)) {
169 169
 			throw new InvalidArgumentException;
170 170
 		}
171 171
 
172
-		$endpoint = new Endpoint( $route, $this->methods[ $name ], $callback );
172
+		$endpoint = new Endpoint($route, $this->methods[$name], $callback);
173 173
 
174
-		if ( $options && is_array( $options ) ) {
175
-			$endpoint = $this->set_options( $endpoint, $options );
174
+		if ($options && is_array($options)) {
175
+			$endpoint = $this->set_options($endpoint, $options);
176 176
 		}
177 177
 
178 178
 		return $this->endpoints[] = $endpoint;
@@ -189,17 +189,17 @@  discard block
 block discarded – undo
189 189
 	 * @return Endpoint
190 190
 	 * @throws MalformedRouteException
191 191
 	 */
192
-	protected function set_options( Endpoint $endpoint, array $options ) {
193
-		if ( isset( $options['guard'] ) ) {
194
-			$endpoint->set_guard( $options['guard'] );
192
+	protected function set_options(Endpoint $endpoint, array $options) {
193
+		if (isset($options['guard'])) {
194
+			$endpoint->set_guard($options['guard']);
195 195
 		}
196 196
 
197
-		if ( isset( $options['filter'] ) ) {
198
-			$endpoint->set_filter( $options['filter'] );
197
+		if (isset($options['filter'])) {
198
+			$endpoint->set_filter($options['filter']);
199 199
 		}
200 200
 
201
-		if ( isset( $options['prefix'] ) ) {
202
-			$endpoint->set_prefix( $options['prefix'] );
201
+		if (isset($options['prefix'])) {
202
+			$endpoint->set_prefix($options['prefix']);
203 203
 		}
204 204
 
205 205
 		return $endpoint;
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 	 * @return string
212 212
 	 */
213 213
 	protected function get_namespace() {
214
-		return $this->vendor . '/v' . $this->version;
214
+		return $this->vendor.'/v'.$this->version;
215 215
 	}
216 216
 
217 217
 	/**
Please login to merge, or discard this patch.
src/Http/ServiceProvider.php 2 patches
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -11,37 +11,37 @@
 block discarded – undo
11 11
  * @subpackage Http
12 12
  */
13 13
 class ServiceProvider implements ServiceProviderContract {
14
-	/**
15
-	 * Container to register on.
16
-	 *
17
-	 * @var Container
18
-	 */
19
-	protected $container;
14
+    /**
15
+     * Container to register on.
16
+     *
17
+     * @var Container
18
+     */
19
+    protected $container;
20 20
 
21
-	/**
22
-	 * {@inheritDoc}
23
-	 *
24
-	 * @param Container $container
25
-	 */
26
-	public function register( Container $container ) {
27
-		$this->container = $container;
21
+    /**
22
+     * {@inheritDoc}
23
+     *
24
+     * @param Container $container
25
+     */
26
+    public function register( Container $container ) {
27
+        $this->container = $container;
28 28
 
29
-		$this->container->define( array( 'router' => 'Intraxia\Jaxion\Http\Router' ), $router = new Router );
29
+        $this->container->define( array( 'router' => 'Intraxia\Jaxion\Http\Router' ), $router = new Router );
30 30
 
31
-		$this->add_routes( $router );
32
-	}
31
+        $this->add_routes( $router );
32
+    }
33 33
 
34
-	/**
35
-	 * Registers the routes on the generated Router.
36
-	 *
37
-	 * This is a no-op by default by can be overwritten by the implementing developer
38
-	 * to provide a single, clean location to register their routes.
39
-	 *
40
-	 * @param Router $router
41
-	 *
42
-	 * @codeCoverageIgnore
43
-	 */
44
-	protected function add_routes( Router $router ) {
45
-		// no-op
46
-	}
34
+    /**
35
+     * Registers the routes on the generated Router.
36
+     *
37
+     * This is a no-op by default by can be overwritten by the implementing developer
38
+     * to provide a single, clean location to register their routes.
39
+     *
40
+     * @param Router $router
41
+     *
42
+     * @codeCoverageIgnore
43
+     */
44
+    protected function add_routes( Router $router ) {
45
+        // no-op
46
+    }
47 47
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -23,12 +23,12 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param Container $container
25 25
 	 */
26
-	public function register( Container $container ) {
26
+	public function register(Container $container) {
27 27
 		$this->container = $container;
28 28
 
29
-		$this->container->define( array( 'router' => 'Intraxia\Jaxion\Http\Router' ), $router = new Router );
29
+		$this->container->define(array('router' => 'Intraxia\Jaxion\Http\Router'), $router = new Router);
30 30
 
31
-		$this->add_routes( $router );
31
+		$this->add_routes($router);
32 32
 	}
33 33
 
34 34
 	/**
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 *
42 42
 	 * @codeCoverageIgnore
43 43
 	 */
44
-	protected function add_routes( Router $router ) {
44
+	protected function add_routes(Router $router) {
45 45
 		// no-op
46 46
 	}
47 47
 }
Please login to merge, or discard this patch.
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
 }
Please login to merge, or discard this patch.