Completed
Push — master ( a8d3e3...cc8041 )
by James
8s
created
src/Assets/Register.php 2 patches
Indentation   +204 added lines, -204 removed lines patch added patch discarded remove patch
@@ -12,208 +12,208 @@
 block discarded – undo
12 12
  * @subpackage Register
13 13
  */
14 14
 class Register implements RegisterContract {
15
-	/**
16
-	 * Minification string for enqueued assets.
17
-	 *
18
-	 * @var string
19
-	 */
20
-	private $min = '';
21
-
22
-	/**
23
-	 * Url to the plugin directory.
24
-	 *
25
-	 * @var string
26
-	 */
27
-	protected $url;
28
-
29
-	/**
30
-	 * Script/plugin version.
31
-	 *
32
-	 * @var string
33
-	 */
34
-	protected $version;
35
-
36
-	/**
37
-	 * Array of script definition arrays.
38
-	 *
39
-	 * @var array
40
-	 */
41
-	private $scripts = array();
42
-
43
-	/**
44
-	 * Array of style definition arrays.
45
-	 *
46
-	 * @var array
47
-	 */
48
-	private $styles = array();
49
-
50
-	/**
51
-	 * Instantiates a new instance of the Register class.
52
-	 *
53
-	 * The URL param should be relative to the plugin directory. The URL
54
-	 * form should always end with a '/'. All asset location definitions
55
-	 * should not begin with a slash and should be relative to the plugin's
56
-	 * root directory. The URL provided by default from the Application
57
-	 * class is compatible.
58
-	 *
59
-	 * @param string $url
60
-	 * @param string $version
61
-	 */
62
-	public function __construct( $url, $version = null ) {
63
-		$this->url     = $url;
64
-		$this->version = $version ?: null; // Empty string should remain null.
65
-	}
66
-
67
-	/**
68
-	 * {@inheritdoc}
69
-	 *
70
-	 * @param bool $debug
71
-	 */
72
-	public function set_debug( $debug ) {
73
-		if ( $debug ) {
74
-			$this->min = '.min';
75
-		} else {
76
-			$this->min = '';
77
-		}
78
-	}
79
-
80
-	/**
81
-	 * {@inheritdoc}
82
-	 *
83
-	 * @param array $script
84
-	 */
85
-	public function register_script( $script ) {
86
-		$this->scripts[] = $script;
87
-	}
88
-
89
-	/**
90
-	 * {@inheritdoc}
91
-	 *
92
-	 * @param array $style
93
-	 */
94
-	public function register_style( $style ) {
95
-		$this->styles[] = $style;
96
-	}
97
-
98
-	/**
99
-	 * {@inheritDoc}
100
-	 */
101
-	public function enqueue_web_scripts() {
102
-		foreach ( $this->scripts as $script ) {
103
-			if ( in_array( $script['type'], array( 'web', 'shared' ) ) ) {
104
-				$this->enqueue_script( $script );
105
-			}
106
-		}
107
-	}
108
-
109
-	/**
110
-	 * {@inheritDoc}
111
-	 */
112
-	public function enqueue_web_styles() {
113
-		foreach ( $this->styles as $style ) {
114
-			if ( in_array( $style['type'], array( 'web', 'shared' ) ) ) {
115
-				$this->enqueue_style( $style );
116
-			}
117
-		}
118
-	}
119
-
120
-	/**
121
-	 * {@inheritDoc}
122
-	 *
123
-	 * @param string $hook Passes a string representing the current page.
124
-	 */
125
-	public function enqueue_admin_scripts( $hook ) {
126
-		foreach ( $this->scripts as $script ) {
127
-			if ( in_array( $script['type'], array( 'admin', 'shared' ) ) ) {
128
-				$this->enqueue_script( $script, $hook );
129
-			}
130
-		}
131
-	}
132
-
133
-	/**
134
-	 * {@inheritDoc}
135
-	 *
136
-	 * @param string $hook Passes a string representing the current page.
137
-	 */
138
-	public function enqueue_admin_styles( $hook ) {
139
-		foreach ( $this->styles as $style ) {
140
-			if ( in_array( $style['type'], array( 'admin', 'shared' ) ) ) {
141
-				$this->enqueue_style( $style, $hook );
142
-			}
143
-		}
144
-	}
145
-
146
-	/**
147
-	 * {@inheritDoc}
148
-	 *
149
-	 * @return array[]
150
-	 */
151
-	public function action_hooks() {
152
-		return array(
153
-			array(
154
-				'hook'   => 'wp_enqueue_scripts',
155
-				'method' => 'enqueue_web_scripts',
156
-			),
157
-			array(
158
-				'hook'   => 'wp_enqueue_scripts',
159
-				'method' => 'enqueue_web_styles',
160
-			),
161
-			array(
162
-				'hook'   => 'admin_enqueue_scripts',
163
-				'method' => 'enqueue_admin_scripts',
164
-			),
165
-			array(
166
-				'hook'   => 'admin_enqueue_scripts',
167
-				'method' => 'enqueue_admin_styles',
168
-			),
169
-		);
170
-	}
171
-
172
-	/**
173
-	 * Enqueues an individual script if the style's condition is met.
174
-	 *
175
-	 * @param array  $script The script attachment callback.
176
-	 * @param string $hook   The location hook. Only passed on admin side.
177
-	 */
178
-	protected function enqueue_script( $script, $hook = null ) {
179
-		if ( $script['condition']( $hook ) ) {
180
-			wp_enqueue_script(
181
-				$script['handle'],
182
-				$this->url . $script['src'] . '.js',
183
-				isset( $script['deps'] ) ? $script['deps'] : array(),
184
-				$this->version,
185
-				isset( $script['footer'] ) ? $script['footer'] : false
186
-			);
187
-
188
-			if ( isset( $script['localize'] ) ) {
189
-				if ( is_callable( $script['localize'] ) ) { // @todo make all properties callables
190
-					$script['localize'] = call_user_func( $script['localize'] );
191
-				}
192
-
193
-				wp_localize_script(
194
-					$script['handle'],
195
-					$script['localize']['name'],
196
-					$script['localize']['data']
197
-				);
198
-			}
199
-		}
200
-	}
201
-
202
-	/**
203
-	 * Enqueues an individual stylesheet if the style's condition is met.
204
-	 *
205
-	 * @param array  $style The style attachment callback.
206
-	 * @param string $hook  The location hook.
207
-	 */
208
-	protected function enqueue_style( $style, $hook = null ) {
209
-		if ( $style['condition']( $hook ) ) {
210
-			wp_enqueue_style(
211
-				$style['handle'],
212
-				$this->url . $style['src'] . '.css',
213
-				isset( $style['deps'] ) ? $style['deps'] : array(),
214
-				$this->version,
215
-				isset( $style['media'] ) ? $style['media'] : 'all'
216
-			);
217
-		}
218
-	}
15
+    /**
16
+     * Minification string for enqueued assets.
17
+     *
18
+     * @var string
19
+     */
20
+    private $min = '';
21
+
22
+    /**
23
+     * Url to the plugin directory.
24
+     *
25
+     * @var string
26
+     */
27
+    protected $url;
28
+
29
+    /**
30
+     * Script/plugin version.
31
+     *
32
+     * @var string
33
+     */
34
+    protected $version;
35
+
36
+    /**
37
+     * Array of script definition arrays.
38
+     *
39
+     * @var array
40
+     */
41
+    private $scripts = array();
42
+
43
+    /**
44
+     * Array of style definition arrays.
45
+     *
46
+     * @var array
47
+     */
48
+    private $styles = array();
49
+
50
+    /**
51
+     * Instantiates a new instance of the Register class.
52
+     *
53
+     * The URL param should be relative to the plugin directory. The URL
54
+     * form should always end with a '/'. All asset location definitions
55
+     * should not begin with a slash and should be relative to the plugin's
56
+     * root directory. The URL provided by default from the Application
57
+     * class is compatible.
58
+     *
59
+     * @param string $url
60
+     * @param string $version
61
+     */
62
+    public function __construct( $url, $version = null ) {
63
+        $this->url     = $url;
64
+        $this->version = $version ?: null; // Empty string should remain null.
65
+    }
66
+
67
+    /**
68
+     * {@inheritdoc}
69
+     *
70
+     * @param bool $debug
71
+     */
72
+    public function set_debug( $debug ) {
73
+        if ( $debug ) {
74
+            $this->min = '.min';
75
+        } else {
76
+            $this->min = '';
77
+        }
78
+    }
79
+
80
+    /**
81
+     * {@inheritdoc}
82
+     *
83
+     * @param array $script
84
+     */
85
+    public function register_script( $script ) {
86
+        $this->scripts[] = $script;
87
+    }
88
+
89
+    /**
90
+     * {@inheritdoc}
91
+     *
92
+     * @param array $style
93
+     */
94
+    public function register_style( $style ) {
95
+        $this->styles[] = $style;
96
+    }
97
+
98
+    /**
99
+     * {@inheritDoc}
100
+     */
101
+    public function enqueue_web_scripts() {
102
+        foreach ( $this->scripts as $script ) {
103
+            if ( in_array( $script['type'], array( 'web', 'shared' ) ) ) {
104
+                $this->enqueue_script( $script );
105
+            }
106
+        }
107
+    }
108
+
109
+    /**
110
+     * {@inheritDoc}
111
+     */
112
+    public function enqueue_web_styles() {
113
+        foreach ( $this->styles as $style ) {
114
+            if ( in_array( $style['type'], array( 'web', 'shared' ) ) ) {
115
+                $this->enqueue_style( $style );
116
+            }
117
+        }
118
+    }
119
+
120
+    /**
121
+     * {@inheritDoc}
122
+     *
123
+     * @param string $hook Passes a string representing the current page.
124
+     */
125
+    public function enqueue_admin_scripts( $hook ) {
126
+        foreach ( $this->scripts as $script ) {
127
+            if ( in_array( $script['type'], array( 'admin', 'shared' ) ) ) {
128
+                $this->enqueue_script( $script, $hook );
129
+            }
130
+        }
131
+    }
132
+
133
+    /**
134
+     * {@inheritDoc}
135
+     *
136
+     * @param string $hook Passes a string representing the current page.
137
+     */
138
+    public function enqueue_admin_styles( $hook ) {
139
+        foreach ( $this->styles as $style ) {
140
+            if ( in_array( $style['type'], array( 'admin', 'shared' ) ) ) {
141
+                $this->enqueue_style( $style, $hook );
142
+            }
143
+        }
144
+    }
145
+
146
+    /**
147
+     * {@inheritDoc}
148
+     *
149
+     * @return array[]
150
+     */
151
+    public function action_hooks() {
152
+        return array(
153
+            array(
154
+                'hook'   => 'wp_enqueue_scripts',
155
+                'method' => 'enqueue_web_scripts',
156
+            ),
157
+            array(
158
+                'hook'   => 'wp_enqueue_scripts',
159
+                'method' => 'enqueue_web_styles',
160
+            ),
161
+            array(
162
+                'hook'   => 'admin_enqueue_scripts',
163
+                'method' => 'enqueue_admin_scripts',
164
+            ),
165
+            array(
166
+                'hook'   => 'admin_enqueue_scripts',
167
+                'method' => 'enqueue_admin_styles',
168
+            ),
169
+        );
170
+    }
171
+
172
+    /**
173
+     * Enqueues an individual script if the style's condition is met.
174
+     *
175
+     * @param array  $script The script attachment callback.
176
+     * @param string $hook   The location hook. Only passed on admin side.
177
+     */
178
+    protected function enqueue_script( $script, $hook = null ) {
179
+        if ( $script['condition']( $hook ) ) {
180
+            wp_enqueue_script(
181
+                $script['handle'],
182
+                $this->url . $script['src'] . '.js',
183
+                isset( $script['deps'] ) ? $script['deps'] : array(),
184
+                $this->version,
185
+                isset( $script['footer'] ) ? $script['footer'] : false
186
+            );
187
+
188
+            if ( isset( $script['localize'] ) ) {
189
+                if ( is_callable( $script['localize'] ) ) { // @todo make all properties callables
190
+                    $script['localize'] = call_user_func( $script['localize'] );
191
+                }
192
+
193
+                wp_localize_script(
194
+                    $script['handle'],
195
+                    $script['localize']['name'],
196
+                    $script['localize']['data']
197
+                );
198
+            }
199
+        }
200
+    }
201
+
202
+    /**
203
+     * Enqueues an individual stylesheet if the style's condition is met.
204
+     *
205
+     * @param array  $style The style attachment callback.
206
+     * @param string $hook  The location hook.
207
+     */
208
+    protected function enqueue_style( $style, $hook = null ) {
209
+        if ( $style['condition']( $hook ) ) {
210
+            wp_enqueue_style(
211
+                $style['handle'],
212
+                $this->url . $style['src'] . '.css',
213
+                isset( $style['deps'] ) ? $style['deps'] : array(),
214
+                $this->version,
215
+                isset( $style['media'] ) ? $style['media'] : 'all'
216
+            );
217
+        }
218
+    }
219 219
 }
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 * @param string $url
60 60
 	 * @param string $version
61 61
 	 */
62
-	public function __construct( $url, $version = null ) {
62
+	public function __construct($url, $version = null) {
63 63
 		$this->url     = $url;
64 64
 		$this->version = $version ?: null; // Empty string should remain null.
65 65
 	}
@@ -69,8 +69,8 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @param bool $debug
71 71
 	 */
72
-	public function set_debug( $debug ) {
73
-		if ( $debug ) {
72
+	public function set_debug($debug) {
73
+		if ($debug) {
74 74
 			$this->min = '.min';
75 75
 		} else {
76 76
 			$this->min = '';
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	 *
83 83
 	 * @param array $script
84 84
 	 */
85
-	public function register_script( $script ) {
85
+	public function register_script($script) {
86 86
 		$this->scripts[] = $script;
87 87
 	}
88 88
 
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	 *
92 92
 	 * @param array $style
93 93
 	 */
94
-	public function register_style( $style ) {
94
+	public function register_style($style) {
95 95
 		$this->styles[] = $style;
96 96
 	}
97 97
 
@@ -99,9 +99,9 @@  discard block
 block discarded – undo
99 99
 	 * {@inheritDoc}
100 100
 	 */
101 101
 	public function enqueue_web_scripts() {
102
-		foreach ( $this->scripts as $script ) {
103
-			if ( in_array( $script['type'], array( 'web', 'shared' ) ) ) {
104
-				$this->enqueue_script( $script );
102
+		foreach ($this->scripts as $script) {
103
+			if (in_array($script['type'], array('web', 'shared'))) {
104
+				$this->enqueue_script($script);
105 105
 			}
106 106
 		}
107 107
 	}
@@ -110,9 +110,9 @@  discard block
 block discarded – undo
110 110
 	 * {@inheritDoc}
111 111
 	 */
112 112
 	public function enqueue_web_styles() {
113
-		foreach ( $this->styles as $style ) {
114
-			if ( in_array( $style['type'], array( 'web', 'shared' ) ) ) {
115
-				$this->enqueue_style( $style );
113
+		foreach ($this->styles as $style) {
114
+			if (in_array($style['type'], array('web', 'shared'))) {
115
+				$this->enqueue_style($style);
116 116
 			}
117 117
 		}
118 118
 	}
@@ -122,10 +122,10 @@  discard block
 block discarded – undo
122 122
 	 *
123 123
 	 * @param string $hook Passes a string representing the current page.
124 124
 	 */
125
-	public function enqueue_admin_scripts( $hook ) {
126
-		foreach ( $this->scripts as $script ) {
127
-			if ( in_array( $script['type'], array( 'admin', 'shared' ) ) ) {
128
-				$this->enqueue_script( $script, $hook );
125
+	public function enqueue_admin_scripts($hook) {
126
+		foreach ($this->scripts as $script) {
127
+			if (in_array($script['type'], array('admin', 'shared'))) {
128
+				$this->enqueue_script($script, $hook);
129 129
 			}
130 130
 		}
131 131
 	}
@@ -135,10 +135,10 @@  discard block
 block discarded – undo
135 135
 	 *
136 136
 	 * @param string $hook Passes a string representing the current page.
137 137
 	 */
138
-	public function enqueue_admin_styles( $hook ) {
139
-		foreach ( $this->styles as $style ) {
140
-			if ( in_array( $style['type'], array( 'admin', 'shared' ) ) ) {
141
-				$this->enqueue_style( $style, $hook );
138
+	public function enqueue_admin_styles($hook) {
139
+		foreach ($this->styles as $style) {
140
+			if (in_array($style['type'], array('admin', 'shared'))) {
141
+				$this->enqueue_style($style, $hook);
142 142
 			}
143 143
 		}
144 144
 	}
@@ -175,19 +175,19 @@  discard block
 block discarded – undo
175 175
 	 * @param array  $script The script attachment callback.
176 176
 	 * @param string $hook   The location hook. Only passed on admin side.
177 177
 	 */
178
-	protected function enqueue_script( $script, $hook = null ) {
179
-		if ( $script['condition']( $hook ) ) {
178
+	protected function enqueue_script($script, $hook = null) {
179
+		if ($script['condition']($hook)) {
180 180
 			wp_enqueue_script(
181 181
 				$script['handle'],
182
-				$this->url . $script['src'] . '.js',
183
-				isset( $script['deps'] ) ? $script['deps'] : array(),
182
+				$this->url.$script['src'].'.js',
183
+				isset($script['deps']) ? $script['deps'] : array(),
184 184
 				$this->version,
185
-				isset( $script['footer'] ) ? $script['footer'] : false
185
+				isset($script['footer']) ? $script['footer'] : false
186 186
 			);
187 187
 
188
-			if ( isset( $script['localize'] ) ) {
189
-				if ( is_callable( $script['localize'] ) ) { // @todo make all properties callables
190
-					$script['localize'] = call_user_func( $script['localize'] );
188
+			if (isset($script['localize'])) {
189
+				if (is_callable($script['localize'])) { // @todo make all properties callables
190
+					$script['localize'] = call_user_func($script['localize']);
191 191
 				}
192 192
 
193 193
 				wp_localize_script(
@@ -205,14 +205,14 @@  discard block
 block discarded – undo
205 205
 	 * @param array  $style The style attachment callback.
206 206
 	 * @param string $hook  The location hook.
207 207
 	 */
208
-	protected function enqueue_style( $style, $hook = null ) {
209
-		if ( $style['condition']( $hook ) ) {
208
+	protected function enqueue_style($style, $hook = null) {
209
+		if ($style['condition']($hook)) {
210 210
 			wp_enqueue_style(
211 211
 				$style['handle'],
212
-				$this->url . $style['src'] . '.css',
213
-				isset( $style['deps'] ) ? $style['deps'] : array(),
212
+				$this->url.$style['src'].'.css',
213
+				isset($style['deps']) ? $style['deps'] : array(),
214 214
 				$this->version,
215
-				isset( $style['media'] ) ? $style['media'] : 'all'
215
+				isset($style['media']) ? $style['media'] : 'all'
216 216
 			);
217 217
 		}
218 218
 	}
Please login to merge, or discard this patch.
src/Contract/Assets/Register.php 2 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -4,52 +4,52 @@
 block discarded – undo
4 4
 use Intraxia\Jaxion\Contract\Core\HasActions;
5 5
 
6 6
 interface Register extends HasActions {
7
-	/**
8
-	 * Enable debug mode for the enqueued assets.
9
-	 *
10
-	 * Debug mode will enqueue unminified versions of the registered assets.
11
-	 * Primarily, this is intended to be used along with WordPress's `SCRIPT_DEBUG`
12
-	 * constant, which enables unminified core assets to be enqueued.
13
-	 *
14
-	 * @param bool $debug
15
-	 */
16
-	public function set_debug( $debug );
17
-
18
-	/**
19
-	 * Provides a method to register new scripts outside of the constructor.
20
-	 *
21
-	 * @param array $script
22
-	 */
23
-	public function register_script( $script );
24
-
25
-	/**
26
-	 * Provides a method to register new styles outside of the constructor.
27
-	 *
28
-	 * @param array $style
29
-	 */
30
-	public function register_style( $style );
31
-
32
-	/**
33
-	 * Enqueues the web & shared scripts on the Register.
34
-	 */
35
-	public function enqueue_web_scripts();
36
-
37
-	/**
38
-	 * Enqueues the web & shared styles on the Register.
39
-	 */
40
-	public function enqueue_web_styles();
41
-
42
-	/**
43
-	 * Enqueues the admin & shared scripts on the Register.
44
-	 *
45
-	 * @param string $hook Passes a string representing the current page.
46
-	 */
47
-	public function enqueue_admin_scripts( $hook );
48
-
49
-	/**
50
-	 * Enqueues the admin & shared styles on the Register.
51
-	 *
52
-	 * @param string $hook Passes a string representing the current page.
53
-	 */
54
-	public function enqueue_admin_styles( $hook );
7
+    /**
8
+     * Enable debug mode for the enqueued assets.
9
+     *
10
+     * Debug mode will enqueue unminified versions of the registered assets.
11
+     * Primarily, this is intended to be used along with WordPress's `SCRIPT_DEBUG`
12
+     * constant, which enables unminified core assets to be enqueued.
13
+     *
14
+     * @param bool $debug
15
+     */
16
+    public function set_debug( $debug );
17
+
18
+    /**
19
+     * Provides a method to register new scripts outside of the constructor.
20
+     *
21
+     * @param array $script
22
+     */
23
+    public function register_script( $script );
24
+
25
+    /**
26
+     * Provides a method to register new styles outside of the constructor.
27
+     *
28
+     * @param array $style
29
+     */
30
+    public function register_style( $style );
31
+
32
+    /**
33
+     * Enqueues the web & shared scripts on the Register.
34
+     */
35
+    public function enqueue_web_scripts();
36
+
37
+    /**
38
+     * Enqueues the web & shared styles on the Register.
39
+     */
40
+    public function enqueue_web_styles();
41
+
42
+    /**
43
+     * Enqueues the admin & shared scripts on the Register.
44
+     *
45
+     * @param string $hook Passes a string representing the current page.
46
+     */
47
+    public function enqueue_admin_scripts( $hook );
48
+
49
+    /**
50
+     * Enqueues the admin & shared styles on the Register.
51
+     *
52
+     * @param string $hook Passes a string representing the current page.
53
+     */
54
+    public function enqueue_admin_styles( $hook );
55 55
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -13,21 +13,21 @@  discard block
 block discarded – undo
13 13
 	 *
14 14
 	 * @param bool $debug
15 15
 	 */
16
-	public function set_debug( $debug );
16
+	public function set_debug($debug);
17 17
 
18 18
 	/**
19 19
 	 * Provides a method to register new scripts outside of the constructor.
20 20
 	 *
21 21
 	 * @param array $script
22 22
 	 */
23
-	public function register_script( $script );
23
+	public function register_script($script);
24 24
 
25 25
 	/**
26 26
 	 * Provides a method to register new styles outside of the constructor.
27 27
 	 *
28 28
 	 * @param array $style
29 29
 	 */
30
-	public function register_style( $style );
30
+	public function register_style($style);
31 31
 
32 32
 	/**
33 33
 	 * Enqueues the web & shared scripts on the Register.
@@ -44,12 +44,12 @@  discard block
 block discarded – undo
44 44
 	 *
45 45
 	 * @param string $hook Passes a string representing the current page.
46 46
 	 */
47
-	public function enqueue_admin_scripts( $hook );
47
+	public function enqueue_admin_scripts($hook);
48 48
 
49 49
 	/**
50 50
 	 * Enqueues the admin & shared styles on the Register.
51 51
 	 *
52 52
 	 * @param string $hook Passes a string representing the current page.
53 53
 	 */
54
-	public function enqueue_admin_styles( $hook );
54
+	public function enqueue_admin_styles($hook);
55 55
 }
Please login to merge, or discard this patch.