Completed
Push — master ( ea9096...6a09cf )
by James
04:38
created
src/Contract/Core/Loader.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -2,41 +2,41 @@
 block discarded – undo
2 2
 namespace Intraxia\Jaxion\Contract\Core;
3 3
 
4 4
 interface Loader {
5
-	/**
6
-	 * Register all the actions and filters with WordPress.
7
-	 *
8
-	 * Loops through all the registered actions/filters and fires add_* for each of
9
-	 * them respectively.
10
-	 */
11
-	public function run();
5
+    /**
6
+     * Register all the actions and filters with WordPress.
7
+     *
8
+     * Loops through all the registered actions/filters and fires add_* for each of
9
+     * them respectively.
10
+     */
11
+    public function run();
12 12
 
13
-	/**
14
-	 * Registers the service's actions with the loader.
15
-	 *
16
-	 * Actions retrieved from the service are registered with the Loader.
17
-	 * When the loader runs, this actions are registered with WordPress.
18
-	 *
19
-	 * @param HasActions $service
20
-	 */
21
-	public function register_actions( HasActions $service );
13
+    /**
14
+     * Registers the service's actions with the loader.
15
+     *
16
+     * Actions retrieved from the service are registered with the Loader.
17
+     * When the loader runs, this actions are registered with WordPress.
18
+     *
19
+     * @param HasActions $service
20
+     */
21
+    public function register_actions( HasActions $service );
22 22
 
23
-	/**
24
-	 * Registers the service's filters with the loader.
25
-	 *
26
-	 * Filters retrieved from the service are registered with the Loader.
27
-	 * When the loader runs, these filters are registered with WordPress.
28
-	 *
29
-	 * @param HasFilters $service
30
-	 */
31
-	public function register_filters( HasFilters $service );
23
+    /**
24
+     * Registers the service's filters with the loader.
25
+     *
26
+     * Filters retrieved from the service are registered with the Loader.
27
+     * When the loader runs, these filters are registered with WordPress.
28
+     *
29
+     * @param HasFilters $service
30
+     */
31
+    public function register_filters( HasFilters $service );
32 32
 
33
-	/**
34
-	 * Registers the service's shortcode with the loader.
35
-	 *
36
-	 * Service's method definitions are passed into the add_shortcode hook
37
-	 * in WordPress to register the shortcode.
38
-	 *
39
-	 * @param HasShortcode $service
40
-	 */
41
-	public function register_shortcode( HasShortcode $service );
33
+    /**
34
+     * Registers the service's shortcode with the loader.
35
+     *
36
+     * Service's method definitions are passed into the add_shortcode hook
37
+     * in WordPress to register the shortcode.
38
+     *
39
+     * @param HasShortcode $service
40
+     */
41
+    public function register_shortcode( HasShortcode $service );
42 42
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 	 *
19 19
 	 * @param HasActions $service
20 20
 	 */
21
-	public function register_actions( HasActions $service );
21
+	public function register_actions(HasActions $service);
22 22
 
23 23
 	/**
24 24
 	 * Registers the service's filters with the loader.
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 	 *
29 29
 	 * @param HasFilters $service
30 30
 	 */
31
-	public function register_filters( HasFilters $service );
31
+	public function register_filters(HasFilters $service);
32 32
 
33 33
 	/**
34 34
 	 * Registers the service's shortcode with the loader.
@@ -38,5 +38,5 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @param HasShortcode $service
40 40
 	 */
41
-	public function register_shortcode( HasShortcode $service );
41
+	public function register_shortcode(HasShortcode $service);
42 42
 }
Please login to merge, or discard this patch.
src/Contract/Core/HasFilters.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 HasFilters {
5
-	/**
6
-	 * Provides the array of filters the class wants to register with WordPress.
7
-	 *
8
-	 * These filters 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 filter_hooks();
5
+    /**
6
+     * Provides the array of filters the class wants to register with WordPress.
7
+     *
8
+     * These filters 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 filter_hooks();
14 14
 }
Please login to merge, or discard this patch.
src/Contract/Core/ServiceProvider.php 2 patches
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 ServiceProvider {
5
-	/**
6
-	 * Register the provider's services on the container.
7
-	 *
8
-	 * This method is passed the container to register on, giving the service provider
9
-	 * an opportunity to register its services on the container in an encapsulated way.
10
-	 *
11
-	 * @param Container $container
12
-	 */
13
-	public function register( Container $container );
5
+    /**
6
+     * Register the provider's services on the container.
7
+     *
8
+     * This method is passed the container to register on, giving the service provider
9
+     * an opportunity to register its services on the container in an encapsulated way.
10
+     *
11
+     * @param Container $container
12
+     */
13
+    public function register( Container $container );
14 14
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,5 +10,5 @@
 block discarded – undo
10 10
 	 *
11 11
 	 * @param Container $container
12 12
 	 */
13
-	public function register( Container $container );
13
+	public function register(Container $container);
14 14
 }
Please login to merge, or discard this patch.
src/Contract/Core/Application.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -4,52 +4,52 @@
 block discarded – undo
4 4
 use Intraxia\Jaxion\Core\ApplicationNotBootedException;
5 5
 
6 6
 interface Application {
7
-	/**
8
-	 * Starts up the Application.
9
-	 *
10
-	 * Retrieves the Application's loader instance, and registers all of the Application's
11
-	 * services with the loader. It loops through its own services, and any services that
12
-	 * implement the required interface are passed into the loader. It then attaches the
13
-	 * loader to the required WordPress hook.
14
-	 */
15
-	public function boot();
7
+    /**
8
+     * Starts up the Application.
9
+     *
10
+     * Retrieves the Application's loader instance, and registers all of the Application's
11
+     * services with the loader. It loops through its own services, and any services that
12
+     * implement the required interface are passed into the loader. It then attaches the
13
+     * loader to the required WordPress hook.
14
+     */
15
+    public function boot();
16 16
 
17
-	/**
18
-	 * Fired on plugin activation.
19
-	 *
20
-	 * This function is attached to `register_activation_hook` and is fired when the plugin is
21
-	 * activated by WordPress. This gives the developer a place to set up any options,
22
-	 * add any custom tables, or flush rewrite rules, as required.
23
-	 */
24
-	public function activate();
17
+    /**
18
+     * Fired on plugin activation.
19
+     *
20
+     * This function is attached to `register_activation_hook` and is fired when the plugin is
21
+     * activated by WordPress. This gives the developer a place to set up any options,
22
+     * add any custom tables, or flush rewrite rules, as required.
23
+     */
24
+    public function activate();
25 25
 
26
-	/**
27
-	 * Fired on plugin deactivation.
28
-	 *
29
-	 * This function is attached to `register_deactivation_hook` and is fired when the plugin
30
-	 * is deactivated by WordPress. This gives the developer a place to clean up anything left
31
-	 * behind by the plugin.
32
-	 */
33
-	public function deactivate();
26
+    /**
27
+     * Fired on plugin deactivation.
28
+     *
29
+     * This function is attached to `register_deactivation_hook` and is fired when the plugin
30
+     * is deactivated by WordPress. This gives the developer a place to clean up anything left
31
+     * behind by the plugin.
32
+     */
33
+    public function deactivate();
34 34
 
35
-	/**
36
-	 * Retrieves the booted Application instance.
37
-	 *
38
-	 * If the Application has not yet been booted, an Exception will be thrown.
39
-	 *
40
-	 * @return Application
41
-	 * @throws ApplicationNotBootedException
42
-	 */
43
-	public static function instance();
35
+    /**
36
+     * Retrieves the booted Application instance.
37
+     *
38
+     * If the Application has not yet been booted, an Exception will be thrown.
39
+     *
40
+     * @return Application
41
+     * @throws ApplicationNotBootedException
42
+     */
43
+    public static function instance();
44 44
 
45
-	/**
46
-	 * Shuts down the booted Application.
47
-	 *
48
-	 * If the Application has already been booted, the Application instance
49
-	 * will be destroyed by assigning it a null value, freeing it from memory.
50
-	 * However, the service objects will likely remain in memory if they've been
51
-	 * attached to hooks when this method is called. This function is primarily
52
-	 * for uniting testing to make sure you can boot a new instance for each test.
53
-	 */
54
-	public static function shutdown();
45
+    /**
46
+     * Shuts down the booted Application.
47
+     *
48
+     * If the Application has already been booted, the Application instance
49
+     * will be destroyed by assigning it a null value, freeing it from memory.
50
+     * However, the service objects will likely remain in memory if they've been
51
+     * attached to hooks when this method is called. This function is primarily
52
+     * for uniting testing to make sure you can boot a new instance for each test.
53
+     */
54
+    public static function shutdown();
55 55
 }
Please login to merge, or discard this patch.
src/Contract/Axolotl/UsesWordPressTerm.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -8,10 +8,10 @@
 block discarded – undo
8 8
  * @subpackage Contract\Axolotl
9 9
  */
10 10
 interface UsesWordPressTerm {
11
-	/**
12
-	 * Returns the taxonomy used by the Model.
13
-	 *
14
-	 * @return string
15
-	 */
16
-	public static function get_taxonomy();
11
+    /**
12
+     * Returns the taxonomy used by the Model.
13
+     *
14
+     * @return string
15
+     */
16
+    public static function get_taxonomy();
17 17
 }
Please login to merge, or discard this patch.
src/Contract/Axolotl/Serializes.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -2,10 +2,10 @@
 block discarded – undo
2 2
 namespace Intraxia\Jaxion\Contract\Axolotl;
3 3
 
4 4
 interface Serializes {
5
-	/**
6
-	 * Serializes the model's public data into an array.
7
-	 *
8
-	 * @return array
9
-	 */
10
-	public function serialize();
5
+    /**
6
+     * Serializes the model's public data into an array.
7
+     *
8
+     * @return array
9
+     */
10
+    public function serialize();
11 11
 }
Please login to merge, or discard this patch.
src/Contract/Axolotl/UsesWordPressPost.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -8,10 +8,10 @@
 block discarded – undo
8 8
  * @subpackage Contract\Axolotl
9 9
  */
10 10
 interface UsesWordPressPost {
11
-	/**
12
-	 * Returns the custom post type used by the Model.
13
-	 *
14
-	 * @return string
15
-	 */
16
-	public static function get_post_type();
11
+    /**
12
+     * Returns the custom post type used by the Model.
13
+     *
14
+     * @return string
15
+     */
16
+    public static function get_post_type();
17 17
 }
Please login to merge, or discard this patch.
src/Assets/ServiceProvider.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -11,40 +11,40 @@
 block discarded – undo
11 11
  * @subpackage Assets
12 12
  */
13 13
 class ServiceProvider implements ServiceProviderContract {
14
-	/**
15
-	 * Container to register with.
16
-	 *
17
-	 * @var Container
18
-	 */
19
-	protected $container;
14
+    /**
15
+     * Container to register with.
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
-		$container->define(
30
-			array( 'assets' => 'Intraxia\Jaxion\Contract\Assets\Register' ),
31
-			$register = new Register( $container->fetch( 'url' ), $container->fetch( 'version' ) )
32
-		);
29
+        $container->define(
30
+            array( 'assets' => 'Intraxia\Jaxion\Contract\Assets\Register' ),
31
+            $register = new Register( $container->fetch( 'url' ), $container->fetch( 'version' ) )
32
+        );
33 33
 
34
-		$this->add_assets( $register );
35
-	}
34
+        $this->add_assets( $register );
35
+    }
36 36
 
37
-	/**
38
-	 * Registers the assets on the generated Register.
39
-	 *
40
-	 * This is a no-op by default by can be overwritten by the implementing developer
41
-	 * to provide a single, clean location to register their assets.
42
-	 *
43
-	 * @param Register $register
44
-	 *
45
-	 * @codeCoverageIgnore
46
-	 */
47
-	protected function add_assets( Register $register ) {
48
-		// no-op
49
-	}
37
+    /**
38
+     * Registers the assets on the generated Register.
39
+     *
40
+     * This is a no-op by default by can be overwritten by the implementing developer
41
+     * to provide a single, clean location to register their assets.
42
+     *
43
+     * @param Register $register
44
+     *
45
+     * @codeCoverageIgnore
46
+     */
47
+    protected function add_assets( Register $register ) {
48
+        // no-op
49
+    }
50 50
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -23,15 +23,15 @@  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 29
 		$container->define(
30
-			array( 'assets' => 'Intraxia\Jaxion\Contract\Assets\Register' ),
31
-			$register = new Register( $container->fetch( 'url' ), $container->fetch( 'version' ) )
30
+			array('assets' => 'Intraxia\Jaxion\Contract\Assets\Register'),
31
+			$register = new Register($container->fetch('url'), $container->fetch('version'))
32 32
 		);
33 33
 
34
-		$this->add_assets( $register );
34
+		$this->add_assets($register);
35 35
 	}
36 36
 
37 37
 	/**
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	 *
45 45
 	 * @codeCoverageIgnore
46 46
 	 */
47
-	protected function add_assets( Register $register ) {
47
+	protected function add_assets(Register $register) {
48 48
 		// no-op
49 49
 	}
50 50
 }
Please login to merge, or discard this patch.
src/Core/Container.php 2 patches
Indentation   +318 added lines, -318 removed lines patch added patch discarded remove patch
@@ -13,322 +13,322 @@
 block discarded – undo
13 13
  * @subpackage Core
14 14
  */
15 15
 class Container implements ContainerContract {
16
-	/**
17
-	 * ServiceProvider names to register with the container.
18
-	 *
19
-	 * Can be overwritten to include predefined providers.
20
-	 *
21
-	 * @var string[]
22
-	 */
23
-	protected $providers = array();
24
-
25
-	/**
26
-	 * Registered definitions.
27
-	 *
28
-	 * @var mixed[]
29
-	 */
30
-	private $definitions = array();
31
-
32
-	/**
33
-	 * Aliases to share between fetches.
34
-	 *
35
-	 * @var <string, true>[]
36
-	 */
37
-	private $shared = array();
38
-
39
-	/**
40
-	 * Aliases of all the registered services.
41
-	 *
42
-	 * @var <string, true>[]
43
-	 */
44
-	private $aliases = array();
45
-
46
-	/**
47
-	 * Array of classes registered on the container.
48
-	 *
49
-	 * @var <string, true>[]
50
-	 */
51
-	private $classes = array();
52
-
53
-	/**
54
-	 * Current position in the loop.
55
-	 *
56
-	 * @var int
57
-	 */
58
-	private $position;
59
-
60
-	/**
61
-	 * 0-indexed array of aliases for looping.
62
-	 *
63
-	 * @var string[]
64
-	 */
65
-	private $keys = array();
66
-
67
-	/**
68
-	 * Create a new container with the given providers.
69
-	 *
70
-	 * Providers can be instances or the class of the provider as a string.
71
-	 *
72
-	 * @param ServiceProvider[]|string[] $providers
73
-	 */
74
-	public function __construct( array $providers = array() ) {
75
-		// array_unique ensures we only register each provider once.
76
-		$providers = array_unique( array_merge( $this->providers, $providers ) );
77
-
78
-		foreach ( $providers as $provider ) {
79
-			if ( is_string( $provider ) && class_exists( $provider ) ) {
80
-				$provider = new $provider;
81
-			}
82
-
83
-			if ( $provider instanceof ServiceProvider ) {
84
-				$this->register( $provider );
85
-			}
86
-		}
87
-	}
88
-
89
-
90
-	/**
91
-	 * {@inheritdoc}
92
-	 *
93
-	 * @param string|array $alias
94
-	 * @param mixed        $definition
95
-	 *
96
-	 * @throws DefinedAliasException
97
-	 *
98
-	 * @return $this
99
-	 */
100
-	public function define( $alias, $definition ) {
101
-		if ( is_array( $alias ) ) {
102
-			$class = current( $alias );
103
-			$alias = key( $alias );
104
-		}
105
-
106
-		if ( isset( $this->aliases[ $alias ] ) ) {
107
-			throw new DefinedAliasException( $alias );
108
-		}
109
-
110
-		$this->aliases[ $alias ]     = true;
111
-		$this->definitions[ $alias ] = $definition;
112
-
113
-		// Closures are treated as factories unless
114
-		// defined via Container::share.
115
-		if ( ! $definition instanceof \Closure ) {
116
-			$this->shared[ $alias ] = true;
117
-		}
118
-
119
-		if ( isset( $class ) ) {
120
-			$this->classes[ $class ] = $alias;
121
-		}
122
-
123
-		return $this;
124
-	}
125
-
126
-	/**
127
-	 * {@inheritdoc}
128
-	 *
129
-	 * @param string|array $alias
130
-	 * @param mixed        $definition
131
-	 *
132
-	 * @throws DefinedAliasException
133
-	 *
134
-	 * @return $this
135
-	 */
136
-	public function share( $alias, $definition ) {
137
-		$this->define( $alias, $definition );
138
-
139
-		if ( is_array( $alias ) ) {
140
-			$alias = key( $alias );
141
-		}
142
-
143
-		$this->shared[ $alias ] = true;
144
-
145
-		return $this;
146
-	}
147
-
148
-	/**
149
-	 * {@inheritdoc}
150
-	 *
151
-	 * @param string $alias
152
-	 *
153
-	 * @throws UndefinedAliasException
154
-	 *
155
-	 * @return mixed
156
-	 */
157
-	public function fetch( $alias ) {
158
-		if ( isset( $this->classes[ $alias ] ) ) {
159
-			// If the alias is a class name,
160
-			// then retrieve its linked alias.
161
-			// This is only registered when
162
-			// registering using an array.
163
-			$alias = $this->classes[ $alias ];
164
-		}
165
-
166
-		if ( ! isset( $this->aliases[ $alias ] ) ) {
167
-			throw new UndefinedAliasException( $alias );
168
-		}
169
-
170
-		$value = $this->definitions[ $alias ];
171
-
172
-		// If the shared value is a closure,
173
-		// execute it and assign the result
174
-		// in place of the closure.
175
-		if ( $value instanceof \Closure ) {
176
-			$factory = $value;
177
-			$value   = $factory( $this );
178
-		}
179
-
180
-		// If the value is shared, save the shared value.
181
-		if ( isset( $this->shared[ $alias ] ) ) {
182
-			$this->definitions[ $alias ] = $value;
183
-		}
184
-
185
-		// Return the fetched value.
186
-		return $value;
187
-	}
188
-
189
-	/**
190
-	 * {@inheritdoc}
191
-	 *
192
-	 * @param  string $alias
193
-	 *
194
-	 * @return bool
195
-	 */
196
-	public function has( $alias ) {
197
-		return isset( $this->aliases[ $alias ] );
198
-	}
199
-
200
-	/**
201
-	 * {@inheritDoc}
202
-	 *
203
-	 * @param string $alias
204
-	 *
205
-	 * @return $this
206
-	 */
207
-	public function remove( $alias ) {
208
-		if ( isset( $this->aliases[ $alias ] ) ) {
209
-			/**
210
-			 * If there's no reference in the aliases array,
211
-			 * the service won't be found on fetching and
212
-			 * can be overwritten on setting.
213
-			 *
214
-			 * Pros: Quick setting/unsetting, faster
215
-			 * performance on those operations when doing
216
-			 * a lot of these.
217
-			 *
218
-			 * Cons: Objects and values set in the container
219
-			 * can't get garbage collected.
220
-			 *
221
-			 * If this is a problem, this may need to be revisited.
222
-			 */
223
-			unset( $this->aliases[ $alias ] );
224
-		}
225
-
226
-		return $this;
227
-	}
228
-
229
-	/**
230
-	 * {@inheritDoc}
231
-	 *
232
-	 * @param ServiceProvider $provider
233
-	 *
234
-	 * @return $this
235
-	 */
236
-	public function register( ServiceProvider $provider ) {
237
-		// @todo make sure provider is only registered once
238
-		$provider->register( $this );
239
-
240
-		return $this;
241
-	}
242
-
243
-	/**
244
-	 * Set a value into the container.
245
-	 *
246
-	 * @param  string $id
247
-	 * @param  mixed  $value
248
-	 *
249
-	 * @see    define
250
-	 */
251
-	public function offsetSet( $id, $value ) {
252
-		$this->define( $id, $value );
253
-	}
254
-
255
-	/**
256
-	 * Get an value from the container.
257
-	 *
258
-	 * @param  string $id
259
-	 *
260
-	 * @return object
261
-	 * @throws UndefinedAliasException
262
-	 *
263
-	 * @see    fetch
264
-	 */
265
-	public function offsetGet( $id ) {
266
-		return $this->fetch( $id );
267
-	}
268
-
269
-	/**
270
-	 * Checks if a key is set on the container.
271
-	 *
272
-	 * @param  string $id
273
-	 *
274
-	 * @return bool
275
-	 *
276
-	 * @see    has
277
-	 */
278
-	public function offsetExists( $id ) {
279
-		return $this->has( $id );
280
-	}
281
-
282
-	/**
283
-	 * Remove a key from the container.
284
-	 *
285
-	 * @param string $id
286
-	 *
287
-	 * @see   remove
288
-	 */
289
-	public function offsetUnset( $id ) {
290
-		$this->remove( $id );
291
-	}
292
-
293
-	/**
294
-	 * Sets the object properties to prepare for the loop.
295
-	 */
296
-	public function rewind() {
297
-		$this->position = 0;
298
-		$this->keys     = array_keys( $this->aliases );
299
-	}
300
-
301
-	/**
302
-	 * Retrieves the service object for the current step in the loop.
303
-	 *
304
-	 * @return object
305
-	 */
306
-	public function current() {
307
-		return $this->fetch( $this->keys[ $this->position ] );
308
-	}
309
-
310
-	/**
311
-	 * Retrieves the key for the current step in the loop.
312
-	 *
313
-	 * @return string
314
-	 */
315
-	public function key() {
316
-		return $this->keys[ $this->position ];
317
-	}
318
-
319
-	/**
320
-	 * Increments to the next step in the loop.
321
-	 */
322
-	public function next() {
323
-		$this->position ++;
324
-	}
325
-
326
-	/**
327
-	 * Checks if the next step in the loop in valid.
328
-	 *
329
-	 * @return bool
330
-	 */
331
-	public function valid() {
332
-		return isset( $this->keys[ $this->position ] );
333
-	}
16
+    /**
17
+     * ServiceProvider names to register with the container.
18
+     *
19
+     * Can be overwritten to include predefined providers.
20
+     *
21
+     * @var string[]
22
+     */
23
+    protected $providers = array();
24
+
25
+    /**
26
+     * Registered definitions.
27
+     *
28
+     * @var mixed[]
29
+     */
30
+    private $definitions = array();
31
+
32
+    /**
33
+     * Aliases to share between fetches.
34
+     *
35
+     * @var <string, true>[]
36
+     */
37
+    private $shared = array();
38
+
39
+    /**
40
+     * Aliases of all the registered services.
41
+     *
42
+     * @var <string, true>[]
43
+     */
44
+    private $aliases = array();
45
+
46
+    /**
47
+     * Array of classes registered on the container.
48
+     *
49
+     * @var <string, true>[]
50
+     */
51
+    private $classes = array();
52
+
53
+    /**
54
+     * Current position in the loop.
55
+     *
56
+     * @var int
57
+     */
58
+    private $position;
59
+
60
+    /**
61
+     * 0-indexed array of aliases for looping.
62
+     *
63
+     * @var string[]
64
+     */
65
+    private $keys = array();
66
+
67
+    /**
68
+     * Create a new container with the given providers.
69
+     *
70
+     * Providers can be instances or the class of the provider as a string.
71
+     *
72
+     * @param ServiceProvider[]|string[] $providers
73
+     */
74
+    public function __construct( array $providers = array() ) {
75
+        // array_unique ensures we only register each provider once.
76
+        $providers = array_unique( array_merge( $this->providers, $providers ) );
77
+
78
+        foreach ( $providers as $provider ) {
79
+            if ( is_string( $provider ) && class_exists( $provider ) ) {
80
+                $provider = new $provider;
81
+            }
82
+
83
+            if ( $provider instanceof ServiceProvider ) {
84
+                $this->register( $provider );
85
+            }
86
+        }
87
+    }
88
+
89
+
90
+    /**
91
+     * {@inheritdoc}
92
+     *
93
+     * @param string|array $alias
94
+     * @param mixed        $definition
95
+     *
96
+     * @throws DefinedAliasException
97
+     *
98
+     * @return $this
99
+     */
100
+    public function define( $alias, $definition ) {
101
+        if ( is_array( $alias ) ) {
102
+            $class = current( $alias );
103
+            $alias = key( $alias );
104
+        }
105
+
106
+        if ( isset( $this->aliases[ $alias ] ) ) {
107
+            throw new DefinedAliasException( $alias );
108
+        }
109
+
110
+        $this->aliases[ $alias ]     = true;
111
+        $this->definitions[ $alias ] = $definition;
112
+
113
+        // Closures are treated as factories unless
114
+        // defined via Container::share.
115
+        if ( ! $definition instanceof \Closure ) {
116
+            $this->shared[ $alias ] = true;
117
+        }
118
+
119
+        if ( isset( $class ) ) {
120
+            $this->classes[ $class ] = $alias;
121
+        }
122
+
123
+        return $this;
124
+    }
125
+
126
+    /**
127
+     * {@inheritdoc}
128
+     *
129
+     * @param string|array $alias
130
+     * @param mixed        $definition
131
+     *
132
+     * @throws DefinedAliasException
133
+     *
134
+     * @return $this
135
+     */
136
+    public function share( $alias, $definition ) {
137
+        $this->define( $alias, $definition );
138
+
139
+        if ( is_array( $alias ) ) {
140
+            $alias = key( $alias );
141
+        }
142
+
143
+        $this->shared[ $alias ] = true;
144
+
145
+        return $this;
146
+    }
147
+
148
+    /**
149
+     * {@inheritdoc}
150
+     *
151
+     * @param string $alias
152
+     *
153
+     * @throws UndefinedAliasException
154
+     *
155
+     * @return mixed
156
+     */
157
+    public function fetch( $alias ) {
158
+        if ( isset( $this->classes[ $alias ] ) ) {
159
+            // If the alias is a class name,
160
+            // then retrieve its linked alias.
161
+            // This is only registered when
162
+            // registering using an array.
163
+            $alias = $this->classes[ $alias ];
164
+        }
165
+
166
+        if ( ! isset( $this->aliases[ $alias ] ) ) {
167
+            throw new UndefinedAliasException( $alias );
168
+        }
169
+
170
+        $value = $this->definitions[ $alias ];
171
+
172
+        // If the shared value is a closure,
173
+        // execute it and assign the result
174
+        // in place of the closure.
175
+        if ( $value instanceof \Closure ) {
176
+            $factory = $value;
177
+            $value   = $factory( $this );
178
+        }
179
+
180
+        // If the value is shared, save the shared value.
181
+        if ( isset( $this->shared[ $alias ] ) ) {
182
+            $this->definitions[ $alias ] = $value;
183
+        }
184
+
185
+        // Return the fetched value.
186
+        return $value;
187
+    }
188
+
189
+    /**
190
+     * {@inheritdoc}
191
+     *
192
+     * @param  string $alias
193
+     *
194
+     * @return bool
195
+     */
196
+    public function has( $alias ) {
197
+        return isset( $this->aliases[ $alias ] );
198
+    }
199
+
200
+    /**
201
+     * {@inheritDoc}
202
+     *
203
+     * @param string $alias
204
+     *
205
+     * @return $this
206
+     */
207
+    public function remove( $alias ) {
208
+        if ( isset( $this->aliases[ $alias ] ) ) {
209
+            /**
210
+             * If there's no reference in the aliases array,
211
+             * the service won't be found on fetching and
212
+             * can be overwritten on setting.
213
+             *
214
+             * Pros: Quick setting/unsetting, faster
215
+             * performance on those operations when doing
216
+             * a lot of these.
217
+             *
218
+             * Cons: Objects and values set in the container
219
+             * can't get garbage collected.
220
+             *
221
+             * If this is a problem, this may need to be revisited.
222
+             */
223
+            unset( $this->aliases[ $alias ] );
224
+        }
225
+
226
+        return $this;
227
+    }
228
+
229
+    /**
230
+     * {@inheritDoc}
231
+     *
232
+     * @param ServiceProvider $provider
233
+     *
234
+     * @return $this
235
+     */
236
+    public function register( ServiceProvider $provider ) {
237
+        // @todo make sure provider is only registered once
238
+        $provider->register( $this );
239
+
240
+        return $this;
241
+    }
242
+
243
+    /**
244
+     * Set a value into the container.
245
+     *
246
+     * @param  string $id
247
+     * @param  mixed  $value
248
+     *
249
+     * @see    define
250
+     */
251
+    public function offsetSet( $id, $value ) {
252
+        $this->define( $id, $value );
253
+    }
254
+
255
+    /**
256
+     * Get an value from the container.
257
+     *
258
+     * @param  string $id
259
+     *
260
+     * @return object
261
+     * @throws UndefinedAliasException
262
+     *
263
+     * @see    fetch
264
+     */
265
+    public function offsetGet( $id ) {
266
+        return $this->fetch( $id );
267
+    }
268
+
269
+    /**
270
+     * Checks if a key is set on the container.
271
+     *
272
+     * @param  string $id
273
+     *
274
+     * @return bool
275
+     *
276
+     * @see    has
277
+     */
278
+    public function offsetExists( $id ) {
279
+        return $this->has( $id );
280
+    }
281
+
282
+    /**
283
+     * Remove a key from the container.
284
+     *
285
+     * @param string $id
286
+     *
287
+     * @see   remove
288
+     */
289
+    public function offsetUnset( $id ) {
290
+        $this->remove( $id );
291
+    }
292
+
293
+    /**
294
+     * Sets the object properties to prepare for the loop.
295
+     */
296
+    public function rewind() {
297
+        $this->position = 0;
298
+        $this->keys     = array_keys( $this->aliases );
299
+    }
300
+
301
+    /**
302
+     * Retrieves the service object for the current step in the loop.
303
+     *
304
+     * @return object
305
+     */
306
+    public function current() {
307
+        return $this->fetch( $this->keys[ $this->position ] );
308
+    }
309
+
310
+    /**
311
+     * Retrieves the key for the current step in the loop.
312
+     *
313
+     * @return string
314
+     */
315
+    public function key() {
316
+        return $this->keys[ $this->position ];
317
+    }
318
+
319
+    /**
320
+     * Increments to the next step in the loop.
321
+     */
322
+    public function next() {
323
+        $this->position ++;
324
+    }
325
+
326
+    /**
327
+     * Checks if the next step in the loop in valid.
328
+     *
329
+     * @return bool
330
+     */
331
+    public function valid() {
332
+        return isset( $this->keys[ $this->position ] );
333
+    }
334 334
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -71,17 +71,17 @@  discard block
 block discarded – undo
71 71
 	 *
72 72
 	 * @param ServiceProvider[]|string[] $providers
73 73
 	 */
74
-	public function __construct( array $providers = array() ) {
74
+	public function __construct(array $providers = array()) {
75 75
 		// array_unique ensures we only register each provider once.
76
-		$providers = array_unique( array_merge( $this->providers, $providers ) );
76
+		$providers = array_unique(array_merge($this->providers, $providers));
77 77
 
78
-		foreach ( $providers as $provider ) {
79
-			if ( is_string( $provider ) && class_exists( $provider ) ) {
78
+		foreach ($providers as $provider) {
79
+			if (is_string($provider) && class_exists($provider)) {
80 80
 				$provider = new $provider;
81 81
 			}
82 82
 
83
-			if ( $provider instanceof ServiceProvider ) {
84
-				$this->register( $provider );
83
+			if ($provider instanceof ServiceProvider) {
84
+				$this->register($provider);
85 85
 			}
86 86
 		}
87 87
 	}
@@ -97,27 +97,27 @@  discard block
 block discarded – undo
97 97
 	 *
98 98
 	 * @return $this
99 99
 	 */
100
-	public function define( $alias, $definition ) {
101
-		if ( is_array( $alias ) ) {
102
-			$class = current( $alias );
103
-			$alias = key( $alias );
100
+	public function define($alias, $definition) {
101
+		if (is_array($alias)) {
102
+			$class = current($alias);
103
+			$alias = key($alias);
104 104
 		}
105 105
 
106
-		if ( isset( $this->aliases[ $alias ] ) ) {
107
-			throw new DefinedAliasException( $alias );
106
+		if (isset($this->aliases[$alias])) {
107
+			throw new DefinedAliasException($alias);
108 108
 		}
109 109
 
110
-		$this->aliases[ $alias ]     = true;
111
-		$this->definitions[ $alias ] = $definition;
110
+		$this->aliases[$alias]     = true;
111
+		$this->definitions[$alias] = $definition;
112 112
 
113 113
 		// Closures are treated as factories unless
114 114
 		// defined via Container::share.
115
-		if ( ! $definition instanceof \Closure ) {
116
-			$this->shared[ $alias ] = true;
115
+		if (!$definition instanceof \Closure) {
116
+			$this->shared[$alias] = true;
117 117
 		}
118 118
 
119
-		if ( isset( $class ) ) {
120
-			$this->classes[ $class ] = $alias;
119
+		if (isset($class)) {
120
+			$this->classes[$class] = $alias;
121 121
 		}
122 122
 
123 123
 		return $this;
@@ -133,14 +133,14 @@  discard block
 block discarded – undo
133 133
 	 *
134 134
 	 * @return $this
135 135
 	 */
136
-	public function share( $alias, $definition ) {
137
-		$this->define( $alias, $definition );
136
+	public function share($alias, $definition) {
137
+		$this->define($alias, $definition);
138 138
 
139
-		if ( is_array( $alias ) ) {
140
-			$alias = key( $alias );
139
+		if (is_array($alias)) {
140
+			$alias = key($alias);
141 141
 		}
142 142
 
143
-		$this->shared[ $alias ] = true;
143
+		$this->shared[$alias] = true;
144 144
 
145 145
 		return $this;
146 146
 	}
@@ -154,32 +154,32 @@  discard block
 block discarded – undo
154 154
 	 *
155 155
 	 * @return mixed
156 156
 	 */
157
-	public function fetch( $alias ) {
158
-		if ( isset( $this->classes[ $alias ] ) ) {
157
+	public function fetch($alias) {
158
+		if (isset($this->classes[$alias])) {
159 159
 			// If the alias is a class name,
160 160
 			// then retrieve its linked alias.
161 161
 			// This is only registered when
162 162
 			// registering using an array.
163
-			$alias = $this->classes[ $alias ];
163
+			$alias = $this->classes[$alias];
164 164
 		}
165 165
 
166
-		if ( ! isset( $this->aliases[ $alias ] ) ) {
167
-			throw new UndefinedAliasException( $alias );
166
+		if (!isset($this->aliases[$alias])) {
167
+			throw new UndefinedAliasException($alias);
168 168
 		}
169 169
 
170
-		$value = $this->definitions[ $alias ];
170
+		$value = $this->definitions[$alias];
171 171
 
172 172
 		// If the shared value is a closure,
173 173
 		// execute it and assign the result
174 174
 		// in place of the closure.
175
-		if ( $value instanceof \Closure ) {
175
+		if ($value instanceof \Closure) {
176 176
 			$factory = $value;
177
-			$value   = $factory( $this );
177
+			$value   = $factory($this);
178 178
 		}
179 179
 
180 180
 		// If the value is shared, save the shared value.
181
-		if ( isset( $this->shared[ $alias ] ) ) {
182
-			$this->definitions[ $alias ] = $value;
181
+		if (isset($this->shared[$alias])) {
182
+			$this->definitions[$alias] = $value;
183 183
 		}
184 184
 
185 185
 		// Return the fetched value.
@@ -193,8 +193,8 @@  discard block
 block discarded – undo
193 193
 	 *
194 194
 	 * @return bool
195 195
 	 */
196
-	public function has( $alias ) {
197
-		return isset( $this->aliases[ $alias ] );
196
+	public function has($alias) {
197
+		return isset($this->aliases[$alias]);
198 198
 	}
199 199
 
200 200
 	/**
@@ -204,8 +204,8 @@  discard block
 block discarded – undo
204 204
 	 *
205 205
 	 * @return $this
206 206
 	 */
207
-	public function remove( $alias ) {
208
-		if ( isset( $this->aliases[ $alias ] ) ) {
207
+	public function remove($alias) {
208
+		if (isset($this->aliases[$alias])) {
209 209
 			/**
210 210
 			 * If there's no reference in the aliases array,
211 211
 			 * the service won't be found on fetching and
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 			 *
221 221
 			 * If this is a problem, this may need to be revisited.
222 222
 			 */
223
-			unset( $this->aliases[ $alias ] );
223
+			unset($this->aliases[$alias]);
224 224
 		}
225 225
 
226 226
 		return $this;
@@ -233,9 +233,9 @@  discard block
 block discarded – undo
233 233
 	 *
234 234
 	 * @return $this
235 235
 	 */
236
-	public function register( ServiceProvider $provider ) {
236
+	public function register(ServiceProvider $provider) {
237 237
 		// @todo make sure provider is only registered once
238
-		$provider->register( $this );
238
+		$provider->register($this);
239 239
 
240 240
 		return $this;
241 241
 	}
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
 	 *
249 249
 	 * @see    define
250 250
 	 */
251
-	public function offsetSet( $id, $value ) {
252
-		$this->define( $id, $value );
251
+	public function offsetSet($id, $value) {
252
+		$this->define($id, $value);
253 253
 	}
254 254
 
255 255
 	/**
@@ -262,8 +262,8 @@  discard block
 block discarded – undo
262 262
 	 *
263 263
 	 * @see    fetch
264 264
 	 */
265
-	public function offsetGet( $id ) {
266
-		return $this->fetch( $id );
265
+	public function offsetGet($id) {
266
+		return $this->fetch($id);
267 267
 	}
268 268
 
269 269
 	/**
@@ -275,8 +275,8 @@  discard block
 block discarded – undo
275 275
 	 *
276 276
 	 * @see    has
277 277
 	 */
278
-	public function offsetExists( $id ) {
279
-		return $this->has( $id );
278
+	public function offsetExists($id) {
279
+		return $this->has($id);
280 280
 	}
281 281
 
282 282
 	/**
@@ -286,8 +286,8 @@  discard block
 block discarded – undo
286 286
 	 *
287 287
 	 * @see   remove
288 288
 	 */
289
-	public function offsetUnset( $id ) {
290
-		$this->remove( $id );
289
+	public function offsetUnset($id) {
290
+		$this->remove($id);
291 291
 	}
292 292
 
293 293
 	/**
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 	 */
296 296
 	public function rewind() {
297 297
 		$this->position = 0;
298
-		$this->keys     = array_keys( $this->aliases );
298
+		$this->keys     = array_keys($this->aliases);
299 299
 	}
300 300
 
301 301
 	/**
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 	 * @return object
305 305
 	 */
306 306
 	public function current() {
307
-		return $this->fetch( $this->keys[ $this->position ] );
307
+		return $this->fetch($this->keys[$this->position]);
308 308
 	}
309 309
 
310 310
 	/**
@@ -313,14 +313,14 @@  discard block
 block discarded – undo
313 313
 	 * @return string
314 314
 	 */
315 315
 	public function key() {
316
-		return $this->keys[ $this->position ];
316
+		return $this->keys[$this->position];
317 317
 	}
318 318
 
319 319
 	/**
320 320
 	 * Increments to the next step in the loop.
321 321
 	 */
322 322
 	public function next() {
323
-		$this->position ++;
323
+		$this->position++;
324 324
 	}
325 325
 
326 326
 	/**
@@ -329,6 +329,6 @@  discard block
 block discarded – undo
329 329
 	 * @return bool
330 330
 	 */
331 331
 	public function valid() {
332
-		return isset( $this->keys[ $this->position ] );
332
+		return isset($this->keys[$this->position]);
333 333
 	}
334 334
 }
Please login to merge, or discard this patch.