Completed
Branch updates-from-cafe (85364e)
by
unknown
09:54 queued 02:28
created
core/services/address/formatters/NullAddressFormatter.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -12,25 +12,25 @@
 block discarded – undo
12 12
  */
13 13
 class NullAddressFormatter implements AddressFormatterInterface
14 14
 {
15
-    /**
16
-     * @param string $address
17
-     * @param string $address2
18
-     * @param string $city
19
-     * @param string $state
20
-     * @param string $zip
21
-     * @param string $country
22
-     * @param string $CNT_ISO
23
-     * @return string|null
24
-     */
25
-    public function format(
26
-        string $address,
27
-        string $address2,
28
-        string $city,
29
-        string $state,
30
-        string $zip,
31
-        string $country,
32
-        string $CNT_ISO
33
-    ): ?string {
34
-        return null;
35
-    }
15
+	/**
16
+	 * @param string $address
17
+	 * @param string $address2
18
+	 * @param string $city
19
+	 * @param string $state
20
+	 * @param string $zip
21
+	 * @param string $country
22
+	 * @param string $CNT_ISO
23
+	 * @return string|null
24
+	 */
25
+	public function format(
26
+		string $address,
27
+		string $address2,
28
+		string $city,
29
+		string $state,
30
+		string $zip,
31
+		string $country,
32
+		string $CNT_ISO
33
+	): ?string {
34
+		return null;
35
+	}
36 36
 }
Please login to merge, or discard this patch.
core/domain/entities/GenericAddress.php 1 patch
Indentation   +236 added lines, -236 removed lines patch added patch discarded remove patch
@@ -19,240 +19,240 @@
 block discarded – undo
19 19
  */
20 20
 class GenericAddress implements AddressInterface
21 21
 {
22
-    // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
23
-    /**
24
-     * @var string
25
-     */
26
-    private $_address;
27
-
28
-    /**
29
-     * @var string
30
-     */
31
-    private $_address2;
32
-
33
-    /**
34
-     * @var string
35
-     */
36
-    private $_city;
37
-
38
-    /**
39
-     * @var int
40
-     */
41
-    private $_state_ID = 0;
42
-
43
-    /**
44
-     * @var EE_State
45
-     */
46
-    private $_state_obj;
47
-
48
-    /**
49
-     * @var string
50
-     */
51
-    private $_zip;
52
-
53
-    /**
54
-     * @var string
55
-     */
56
-    private $_country_ID = '';
57
-
58
-    /**
59
-     * @var EE_Country
60
-     */
61
-    private $_country_obj;
62
-    // phpcs:enable
63
-
64
-
65
-    // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
66
-    /**
67
-     * @param string            $address
68
-     * @param string            $address2
69
-     * @param string            $city
70
-     * @param EE_State|int      $state
71
-     * @param string            $zip
72
-     * @param EE_Country|string $country
73
-     * @throws EE_Error
74
-     * @throws ReflectionException
75
-     */
76
-    public function __construct(string $address, string $address2, string $city, $state, string $zip, $country)
77
-    {
78
-        $this->_address  = $address;
79
-        $this->_address2 = $address2;
80
-        $this->_city     = $city;
81
-        if ($state instanceof EE_State) {
82
-            $this->_state_obj = $state;
83
-        } else {
84
-            $this->_state_ID  = $state;
85
-            $this->_state_obj = $this->_get_state_obj();
86
-        }
87
-        $this->_zip = $zip;
88
-        if ($country instanceof EE_Country) {
89
-            $this->_country_obj = $country;
90
-        } else {
91
-            $this->_country_ID  = $country;
92
-            $this->_country_obj = $this->_get_country_obj();
93
-        }
94
-    }
95
-
96
-
97
-    /**
98
-     * @return string
99
-     */
100
-    public function address(): string
101
-    {
102
-        return $this->_address;
103
-    }
104
-
105
-
106
-    /**
107
-     * @return string
108
-     */
109
-    public function address2(): string
110
-    {
111
-        return $this->_address2;
112
-    }
113
-
114
-
115
-    /**
116
-     * @return string
117
-     */
118
-    public function city(): string
119
-    {
120
-        return $this->_city;
121
-    }
122
-
123
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
124
-
125
-
126
-    /**
127
-     * @return EE_State
128
-     * @throws EE_Error
129
-     * @throws ReflectionException
130
-     */
131
-    private function _get_state_obj(): EE_State
132
-    {
133
-        return $this->_state_obj instanceof EE_State
134
-            ? $this->_state_obj
135
-            : EE_Registry::instance()->load_model('State')->get_one_by_ID($this->_state_ID);
136
-    }
137
-
138
-
139
-    /**
140
-     * @return int
141
-     */
142
-    public function state_ID(): int
143
-    {
144
-        return $this->_state_ID;
145
-    }
146
-
147
-
148
-    /**
149
-     * @return string
150
-     */
151
-    public function state_abbrev(): string
152
-    {
153
-        return $this->state_obj() instanceof EE_State
154
-            ? $this->state_obj()->abbrev()
155
-            : '';
156
-    }
157
-
158
-
159
-    /**
160
-     * @return string
161
-     */
162
-    public function state_name(): string
163
-    {
164
-        return $this->state_obj() instanceof EE_State
165
-            ? $this->state_obj()->name()
166
-            : '';
167
-    }
168
-
169
-
170
-    /**
171
-     * @return EE_State
172
-     */
173
-    public function state_obj(): EE_State
174
-    {
175
-        return $this->_state_obj;
176
-    }
177
-
178
-
179
-    /**
180
-     * @return string
181
-     */
182
-    public function state(): string
183
-    {
184
-        if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) {
185
-            return $this->state_obj()->abbrev();
186
-        } else {
187
-            return $this->state_name();
188
-        }
189
-    }
190
-
191
-
192
-    /**
193
-     * @return EE_Country
194
-     * @throws EE_Error
195
-     * @throws ReflectionException
196
-     */
197
-    private function _get_country_obj(): EE_Country
198
-    {
199
-        return $this->_country_obj instanceof EE_Country
200
-            ? $this->_country_obj
201
-            : EE_Registry::instance()->load_model('Country')->get_one_by_ID($this->_country_ID);
202
-    }
203
-
204
-
205
-    /**
206
-     * @return string
207
-     */
208
-    public function country_ID(): string
209
-    {
210
-        return $this->_country_ID;
211
-    }
212
-
213
-
214
-    /**
215
-     * @return string
216
-     * @throws EE_Error
217
-     * @throws ReflectionException
218
-     */
219
-    public function country_name(): string
220
-    {
221
-        return $this->country_obj() instanceof EE_Country
222
-            ? $this->country_obj()->name()
223
-            : '';
224
-    }
225
-
226
-
227
-    /**
228
-     * @return EE_Country
229
-     */
230
-    public function country_obj(): EE_Country
231
-    {
232
-        return $this->_country_obj;
233
-    }
234
-
235
-
236
-    /**
237
-     * @return string
238
-     * @throws EE_Error
239
-     * @throws ReflectionException
240
-     */
241
-    public function country(): string
242
-    {
243
-        if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) {
244
-            return $this->country_ID();
245
-        } else {
246
-            return $this->country_name();
247
-        }
248
-    }
249
-
250
-
251
-    /**
252
-     * @return string
253
-     */
254
-    public function zip(): string
255
-    {
256
-        return $this->_zip;
257
-    }
22
+	// phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
23
+	/**
24
+	 * @var string
25
+	 */
26
+	private $_address;
27
+
28
+	/**
29
+	 * @var string
30
+	 */
31
+	private $_address2;
32
+
33
+	/**
34
+	 * @var string
35
+	 */
36
+	private $_city;
37
+
38
+	/**
39
+	 * @var int
40
+	 */
41
+	private $_state_ID = 0;
42
+
43
+	/**
44
+	 * @var EE_State
45
+	 */
46
+	private $_state_obj;
47
+
48
+	/**
49
+	 * @var string
50
+	 */
51
+	private $_zip;
52
+
53
+	/**
54
+	 * @var string
55
+	 */
56
+	private $_country_ID = '';
57
+
58
+	/**
59
+	 * @var EE_Country
60
+	 */
61
+	private $_country_obj;
62
+	// phpcs:enable
63
+
64
+
65
+	// phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
66
+	/**
67
+	 * @param string            $address
68
+	 * @param string            $address2
69
+	 * @param string            $city
70
+	 * @param EE_State|int      $state
71
+	 * @param string            $zip
72
+	 * @param EE_Country|string $country
73
+	 * @throws EE_Error
74
+	 * @throws ReflectionException
75
+	 */
76
+	public function __construct(string $address, string $address2, string $city, $state, string $zip, $country)
77
+	{
78
+		$this->_address  = $address;
79
+		$this->_address2 = $address2;
80
+		$this->_city     = $city;
81
+		if ($state instanceof EE_State) {
82
+			$this->_state_obj = $state;
83
+		} else {
84
+			$this->_state_ID  = $state;
85
+			$this->_state_obj = $this->_get_state_obj();
86
+		}
87
+		$this->_zip = $zip;
88
+		if ($country instanceof EE_Country) {
89
+			$this->_country_obj = $country;
90
+		} else {
91
+			$this->_country_ID  = $country;
92
+			$this->_country_obj = $this->_get_country_obj();
93
+		}
94
+	}
95
+
96
+
97
+	/**
98
+	 * @return string
99
+	 */
100
+	public function address(): string
101
+	{
102
+		return $this->_address;
103
+	}
104
+
105
+
106
+	/**
107
+	 * @return string
108
+	 */
109
+	public function address2(): string
110
+	{
111
+		return $this->_address2;
112
+	}
113
+
114
+
115
+	/**
116
+	 * @return string
117
+	 */
118
+	public function city(): string
119
+	{
120
+		return $this->_city;
121
+	}
122
+
123
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
124
+
125
+
126
+	/**
127
+	 * @return EE_State
128
+	 * @throws EE_Error
129
+	 * @throws ReflectionException
130
+	 */
131
+	private function _get_state_obj(): EE_State
132
+	{
133
+		return $this->_state_obj instanceof EE_State
134
+			? $this->_state_obj
135
+			: EE_Registry::instance()->load_model('State')->get_one_by_ID($this->_state_ID);
136
+	}
137
+
138
+
139
+	/**
140
+	 * @return int
141
+	 */
142
+	public function state_ID(): int
143
+	{
144
+		return $this->_state_ID;
145
+	}
146
+
147
+
148
+	/**
149
+	 * @return string
150
+	 */
151
+	public function state_abbrev(): string
152
+	{
153
+		return $this->state_obj() instanceof EE_State
154
+			? $this->state_obj()->abbrev()
155
+			: '';
156
+	}
157
+
158
+
159
+	/**
160
+	 * @return string
161
+	 */
162
+	public function state_name(): string
163
+	{
164
+		return $this->state_obj() instanceof EE_State
165
+			? $this->state_obj()->name()
166
+			: '';
167
+	}
168
+
169
+
170
+	/**
171
+	 * @return EE_State
172
+	 */
173
+	public function state_obj(): EE_State
174
+	{
175
+		return $this->_state_obj;
176
+	}
177
+
178
+
179
+	/**
180
+	 * @return string
181
+	 */
182
+	public function state(): string
183
+	{
184
+		if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) {
185
+			return $this->state_obj()->abbrev();
186
+		} else {
187
+			return $this->state_name();
188
+		}
189
+	}
190
+
191
+
192
+	/**
193
+	 * @return EE_Country
194
+	 * @throws EE_Error
195
+	 * @throws ReflectionException
196
+	 */
197
+	private function _get_country_obj(): EE_Country
198
+	{
199
+		return $this->_country_obj instanceof EE_Country
200
+			? $this->_country_obj
201
+			: EE_Registry::instance()->load_model('Country')->get_one_by_ID($this->_country_ID);
202
+	}
203
+
204
+
205
+	/**
206
+	 * @return string
207
+	 */
208
+	public function country_ID(): string
209
+	{
210
+		return $this->_country_ID;
211
+	}
212
+
213
+
214
+	/**
215
+	 * @return string
216
+	 * @throws EE_Error
217
+	 * @throws ReflectionException
218
+	 */
219
+	public function country_name(): string
220
+	{
221
+		return $this->country_obj() instanceof EE_Country
222
+			? $this->country_obj()->name()
223
+			: '';
224
+	}
225
+
226
+
227
+	/**
228
+	 * @return EE_Country
229
+	 */
230
+	public function country_obj(): EE_Country
231
+	{
232
+		return $this->_country_obj;
233
+	}
234
+
235
+
236
+	/**
237
+	 * @return string
238
+	 * @throws EE_Error
239
+	 * @throws ReflectionException
240
+	 */
241
+	public function country(): string
242
+	{
243
+		if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) {
244
+			return $this->country_ID();
245
+		} else {
246
+			return $this->country_name();
247
+		}
248
+	}
249
+
250
+
251
+	/**
252
+	 * @return string
253
+	 */
254
+	public function zip(): string
255
+	{
256
+		return $this->_zip;
257
+	}
258 258
 }
Please login to merge, or discard this patch.
core/libraries/iframe_display/iframe_wrapper.template.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
                 <?php echo esc_js($eei18n); ?>
37 37
             </script>
38 38
         <?php foreach ($header_js as $key => $url) :?>
39
-            <?php $header_attributes = isset($header_js_attributes[ $key ]) ? $header_js_attributes[ $key ] : ''; ?>
39
+            <?php $header_attributes = isset($header_js_attributes[$key]) ? $header_js_attributes[$key] : ''; ?>
40 40
         <script type="text/javascript" src="<?php echo esc_url_raw($url); ?>" <?php echo AttributesSanitizer::clean($header_attributes, AllowedTags::getAllowedTags(), 'script'); ?>></script>
41 41
         <?php endforeach; ?>
42 42
     <?php endif; ?>
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     <?php echo wp_kses($content, AllowedTags::getWithFullTags()); ?>
48 48
 </div>
49 49
 <?php foreach ($footer_js as $key => $url) : ?>
50
-    <?php $footer_attributes = isset($footer_js_attributes[ $key ]) ? $footer_js_attributes[ $key ] : ''; ?>
50
+    <?php $footer_attributes = isset($footer_js_attributes[$key]) ? $footer_js_attributes[$key] : ''; ?>
51 51
     <script type="text/javascript" src="<?php echo esc_url_raw($url); ?>" <?php echo AttributesSanitizer::clean($footer_attributes, AllowedTags::getAllowedTags(), 'script'); ?>></script>
52 52
 <?php endforeach; ?>
53 53
 <?php if ($enqueue_wp_assets) : ?>
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,9 +28,12 @@
 block discarded – undo
28 28
     <title><?php echo wp_strip_all_tags($title); ?></title>
29 29
     <?php if ($enqueue_wp_assets) : ?>
30 30
         <?php wp_head(); ?>
31
-    <?php else : ?>
31
+    <?php else {
32
+	: ?>
32 33
         <?php foreach ($css as $url) :?>
33
-    <link rel="stylesheet" type="text/css" href="<?php echo esc_url_raw($url); ?>">
34
+    <link rel="stylesheet" type="text/css" href="<?php echo esc_url_raw($url);
35
+}
36
+?>">
34 37
         <?php endforeach; ?>
35 38
             <script type="text/javascript">
36 39
                 <?php echo esc_js($eei18n); ?>
Please login to merge, or discard this patch.
libraries/payment_methods/templates/payment_details_content.template.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,5 +8,5 @@
 block discarded – undo
8 8
  */
9 9
 $gateway_response = $payment->gateway_response();
10 10
 if (! empty($gateway_response)) {
11
-    echo '<span class="error payment-problem">' . esc_html($gateway_response) . '</span>';
11
+	echo '<span class="error payment-problem">' . esc_html($gateway_response) . '</span>';
12 12
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -7,6 +7,6 @@
 block discarded – undo
7 7
  * @var EE_Payment_Method $payment_method
8 8
  */
9 9
 $gateway_response = $payment->gateway_response();
10
-if (! empty($gateway_response)) {
11
-    echo '<span class="error payment-problem">' . esc_html($gateway_response) . '</span>';
10
+if ( ! empty($gateway_response)) {
11
+    echo '<span class="error payment-problem">'.esc_html($gateway_response).'</span>';
12 12
 }
Please login to merge, or discard this patch.
core/EE_Load_Textdomain.core.php 2 patches
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -12,110 +12,110 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Load_Textdomain extends EE_Base
14 14
 {
15
-    /**
16
-     * holds the current lang in WP
17
-     *
18
-     * @var string
19
-     */
20
-    private static $locale;
15
+	/**
16
+	 * holds the current lang in WP
17
+	 *
18
+	 * @var string
19
+	 */
20
+	private static $locale;
21 21
 
22 22
 
23
-    /**
24
-     * this takes care of retrieving a matching textdomain for event espresso for the current WPLANG from EE GitHub
25
-     * repo (if necessary) and then loading it for translations. should only be called in wp plugins_loaded callback
26
-     *
27
-     * @return void
28
-     * @throws EE_Error
29
-     * @throws InvalidArgumentException
30
-     * @throws ReflectionException
31
-     * @throws InvalidDataTypeException
32
-     * @throws InvalidInterfaceException
33
-     */
34
-    public static function load_textdomain()
35
-    {
36
-        EE_Load_Textdomain::loadTranslationsForLocale();
37
-        // now load the textdomain
38
-        if (!empty(EE_Load_Textdomain::$locale)) {
39
-            $github_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-' . EE_Load_Textdomain::$locale . '.mo';
40
-            if (is_readable($github_mo_path)) {
41
-                load_plugin_textdomain('event_espresso', false, EE_LANGUAGES_SAFE_LOC);
42
-                return;
43
-            }
44
-            $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR . 'event-espresso-4-' . EE_Load_Textdomain::$locale . '.mo';
45
-            if (is_readable($glotpress_mo_path)) {
46
-                load_textdomain('event_espresso', $glotpress_mo_path);
47
-                return;
48
-            }
49
-        }
50
-        load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME) . '/languages/');
51
-    }
23
+	/**
24
+	 * this takes care of retrieving a matching textdomain for event espresso for the current WPLANG from EE GitHub
25
+	 * repo (if necessary) and then loading it for translations. should only be called in wp plugins_loaded callback
26
+	 *
27
+	 * @return void
28
+	 * @throws EE_Error
29
+	 * @throws InvalidArgumentException
30
+	 * @throws ReflectionException
31
+	 * @throws InvalidDataTypeException
32
+	 * @throws InvalidInterfaceException
33
+	 */
34
+	public static function load_textdomain()
35
+	{
36
+		EE_Load_Textdomain::loadTranslationsForLocale();
37
+		// now load the textdomain
38
+		if (!empty(EE_Load_Textdomain::$locale)) {
39
+			$github_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-' . EE_Load_Textdomain::$locale . '.mo';
40
+			if (is_readable($github_mo_path)) {
41
+				load_plugin_textdomain('event_espresso', false, EE_LANGUAGES_SAFE_LOC);
42
+				return;
43
+			}
44
+			$glotpress_mo_path = EE_LANGUAGES_SAFE_DIR . 'event-espresso-4-' . EE_Load_Textdomain::$locale . '.mo';
45
+			if (is_readable($glotpress_mo_path)) {
46
+				load_textdomain('event_espresso', $glotpress_mo_path);
47
+				return;
48
+			}
49
+		}
50
+		load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME) . '/languages/');
51
+	}
52 52
 
53 53
 
54
-    /**
55
-     * The purpose of this method is to sideload all of the lang files for EE, this includes the POT file and also the PO/MO files for the given WPLANG locale (if necessary).
56
-     *
57
-     * @access private
58
-     * @static
59
-     * @return void
60
-     * @throws EE_Error
61
-     * @throws InvalidArgumentException
62
-     * @throws ReflectionException
63
-     * @throws InvalidDataTypeException
64
-     * @throws InvalidInterfaceException
65
-     */
66
-    private static function loadTranslationsForLocale()
67
-    {
68
-        EE_Load_Textdomain::$locale = get_locale();
69
-        // can't download a language file if a language isn't set <taps temple>
70
-        if (empty(EE_Load_Textdomain::$locale)) {
71
-            return;
72
-        }
73
-        $language_check_option_name = 'ee_lang_check_' . EE_Load_Textdomain::$locale . '_' . EVENT_ESPRESSO_VERSION;
74
-        // check if language files has already been sideloaded
75
-        if (get_option($language_check_option_name)) {
76
-            return;
77
-        }
54
+	/**
55
+	 * The purpose of this method is to sideload all of the lang files for EE, this includes the POT file and also the PO/MO files for the given WPLANG locale (if necessary).
56
+	 *
57
+	 * @access private
58
+	 * @static
59
+	 * @return void
60
+	 * @throws EE_Error
61
+	 * @throws InvalidArgumentException
62
+	 * @throws ReflectionException
63
+	 * @throws InvalidDataTypeException
64
+	 * @throws InvalidInterfaceException
65
+	 */
66
+	private static function loadTranslationsForLocale()
67
+	{
68
+		EE_Load_Textdomain::$locale = get_locale();
69
+		// can't download a language file if a language isn't set <taps temple>
70
+		if (empty(EE_Load_Textdomain::$locale)) {
71
+			return;
72
+		}
73
+		$language_check_option_name = 'ee_lang_check_' . EE_Load_Textdomain::$locale . '_' . EVENT_ESPRESSO_VERSION;
74
+		// check if language files has already been sideloaded
75
+		if (get_option($language_check_option_name)) {
76
+			return;
77
+		}
78 78
 
79
-        $repo_base_URL = 'https://github.com/eventespresso/languages-ee4/blob/master/event_espresso';
79
+		$repo_base_URL = 'https://github.com/eventespresso/languages-ee4/blob/master/event_espresso';
80 80
 
81
-        // Create directory if not exists
82
-        if (! is_dir(EE_PLUGIN_DIR_PATH . 'languages/')) {
83
-            wp_mkdir_p(EE_PLUGIN_DIR_PATH . 'languages/');
84
-        }
81
+		// Create directory if not exists
82
+		if (! is_dir(EE_PLUGIN_DIR_PATH . 'languages/')) {
83
+			wp_mkdir_p(EE_PLUGIN_DIR_PATH . 'languages/');
84
+		}
85 85
 
86
-        // load sideloader and sideload the .POT file as this should always be included.
87
-        $sideloader_args = array(
88
-            '_upload_to'     => EE_PLUGIN_DIR_PATH . 'languages/',
89
-            '_download_from'   => $repo_base_URL . '.pot?raw=true',
90
-            '_new_file_name' => 'event_espresso.pot',
91
-        );
92
-        /** @var EEH_Sideloader $sideloader */
93
-        $sideloader = EE_Registry::instance()->load_helper('Sideloader', $sideloader_args, false);
94
-        // sideload the .POT file only for main site of the network, or if not running Multisite.
95
-        if (is_main_site()) {
96
-            $sideloader->sideload();
97
-        }
86
+		// load sideloader and sideload the .POT file as this should always be included.
87
+		$sideloader_args = array(
88
+			'_upload_to'     => EE_PLUGIN_DIR_PATH . 'languages/',
89
+			'_download_from'   => $repo_base_URL . '.pot?raw=true',
90
+			'_new_file_name' => 'event_espresso.pot',
91
+		);
92
+		/** @var EEH_Sideloader $sideloader */
93
+		$sideloader = EE_Registry::instance()->load_helper('Sideloader', $sideloader_args, false);
94
+		// sideload the .POT file only for main site of the network, or if not running Multisite.
95
+		if (is_main_site()) {
96
+			$sideloader->sideload();
97
+		}
98 98
 
99
-        // if locale is "en_US" then lets just get out, since Event Espresso core is already "en_US"
100
-        if (EE_Load_Textdomain::$locale === 'en_US') {
101
-            // but set option first else we'll forever be downloading the pot file
102
-            update_option($language_check_option_name, 1);
103
-            return;
104
-        }
105
-        $repo_locale_URL = $repo_base_URL . '-' . EE_Load_Textdomain::$locale;
106
-        $file_name_base = 'event_espresso-' . EE_Load_Textdomain::$locale;
99
+		// if locale is "en_US" then lets just get out, since Event Espresso core is already "en_US"
100
+		if (EE_Load_Textdomain::$locale === 'en_US') {
101
+			// but set option first else we'll forever be downloading the pot file
102
+			update_option($language_check_option_name, 1);
103
+			return;
104
+		}
105
+		$repo_locale_URL = $repo_base_URL . '-' . EE_Load_Textdomain::$locale;
106
+		$file_name_base = 'event_espresso-' . EE_Load_Textdomain::$locale;
107 107
 
108
-        // made it here so let's get the language files from the github repo, first the .mo file
109
-        $sideloader->set_download_from("{$repo_locale_URL}.mo?raw=true");
110
-        $sideloader->set_new_file_name("{$file_name_base}.mo");
111
-        $sideloader->sideload();
108
+		// made it here so let's get the language files from the github repo, first the .mo file
109
+		$sideloader->set_download_from("{$repo_locale_URL}.mo?raw=true");
110
+		$sideloader->set_new_file_name("{$file_name_base}.mo");
111
+		$sideloader->sideload();
112 112
 
113
-        // now the .po file:
114
-        $sideloader->set_download_from("{$repo_locale_URL}.po?raw=true");
115
-        $sideloader->set_new_file_name("{$file_name_base}.po");
116
-        $sideloader->sideload();
113
+		// now the .po file:
114
+		$sideloader->set_download_from("{$repo_locale_URL}.po?raw=true");
115
+		$sideloader->set_new_file_name("{$file_name_base}.po");
116
+		$sideloader->sideload();
117 117
 
118
-        // set option so the above only runs when EE updates.
119
-        update_option($language_check_option_name, 1);
120
-    }
118
+		// set option so the above only runs when EE updates.
119
+		update_option($language_check_option_name, 1);
120
+	}
121 121
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -35,19 +35,19 @@  discard block
 block discarded – undo
35 35
     {
36 36
         EE_Load_Textdomain::loadTranslationsForLocale();
37 37
         // now load the textdomain
38
-        if (!empty(EE_Load_Textdomain::$locale)) {
39
-            $github_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-' . EE_Load_Textdomain::$locale . '.mo';
38
+        if ( ! empty(EE_Load_Textdomain::$locale)) {
39
+            $github_mo_path = EE_LANGUAGES_SAFE_DIR.'event_espresso-'.EE_Load_Textdomain::$locale.'.mo';
40 40
             if (is_readable($github_mo_path)) {
41 41
                 load_plugin_textdomain('event_espresso', false, EE_LANGUAGES_SAFE_LOC);
42 42
                 return;
43 43
             }
44
-            $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR . 'event-espresso-4-' . EE_Load_Textdomain::$locale . '.mo';
44
+            $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR.'event-espresso-4-'.EE_Load_Textdomain::$locale.'.mo';
45 45
             if (is_readable($glotpress_mo_path)) {
46 46
                 load_textdomain('event_espresso', $glotpress_mo_path);
47 47
                 return;
48 48
             }
49 49
         }
50
-        load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME) . '/languages/');
50
+        load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME).'/languages/');
51 51
     }
52 52
 
53 53
 
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
         if (empty(EE_Load_Textdomain::$locale)) {
71 71
             return;
72 72
         }
73
-        $language_check_option_name = 'ee_lang_check_' . EE_Load_Textdomain::$locale . '_' . EVENT_ESPRESSO_VERSION;
73
+        $language_check_option_name = 'ee_lang_check_'.EE_Load_Textdomain::$locale.'_'.EVENT_ESPRESSO_VERSION;
74 74
         // check if language files has already been sideloaded
75 75
         if (get_option($language_check_option_name)) {
76 76
             return;
@@ -79,14 +79,14 @@  discard block
 block discarded – undo
79 79
         $repo_base_URL = 'https://github.com/eventespresso/languages-ee4/blob/master/event_espresso';
80 80
 
81 81
         // Create directory if not exists
82
-        if (! is_dir(EE_PLUGIN_DIR_PATH . 'languages/')) {
83
-            wp_mkdir_p(EE_PLUGIN_DIR_PATH . 'languages/');
82
+        if ( ! is_dir(EE_PLUGIN_DIR_PATH.'languages/')) {
83
+            wp_mkdir_p(EE_PLUGIN_DIR_PATH.'languages/');
84 84
         }
85 85
 
86 86
         // load sideloader and sideload the .POT file as this should always be included.
87 87
         $sideloader_args = array(
88
-            '_upload_to'     => EE_PLUGIN_DIR_PATH . 'languages/',
89
-            '_download_from'   => $repo_base_URL . '.pot?raw=true',
88
+            '_upload_to'     => EE_PLUGIN_DIR_PATH.'languages/',
89
+            '_download_from'   => $repo_base_URL.'.pot?raw=true',
90 90
             '_new_file_name' => 'event_espresso.pot',
91 91
         );
92 92
         /** @var EEH_Sideloader $sideloader */
@@ -102,8 +102,8 @@  discard block
 block discarded – undo
102 102
             update_option($language_check_option_name, 1);
103 103
             return;
104 104
         }
105
-        $repo_locale_URL = $repo_base_URL . '-' . EE_Load_Textdomain::$locale;
106
-        $file_name_base = 'event_espresso-' . EE_Load_Textdomain::$locale;
105
+        $repo_locale_URL = $repo_base_URL.'-'.EE_Load_Textdomain::$locale;
106
+        $file_name_base = 'event_espresso-'.EE_Load_Textdomain::$locale;
107 107
 
108 108
         // made it here so let's get the language files from the github repo, first the .mo file
109 109
         $sideloader->set_download_from("{$repo_locale_URL}.mo?raw=true");
Please login to merge, or discard this patch.
core/EE_Psr4AutoloaderInit.core.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -15,42 +15,42 @@
 block discarded – undo
15 15
  */
16 16
 class EE_Psr4AutoloaderInit
17 17
 {
18
-    /**
19
-     * @type Psr4Autoloader
20
-     */
21
-    protected static $psr4_loader;
18
+	/**
19
+	 * @type Psr4Autoloader
20
+	 */
21
+	protected static $psr4_loader;
22 22
 
23 23
 
24
-    /**
25
-     * @return void
26
-     * @throws EE_Error
27
-     */
28
-    public function initializeAutoloader()
29
-    {
30
-        static $initialized = false;
31
-        if (! $initialized) {
32
-            // register the base directories for the namespace prefix
33
-            EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH);
34
-            EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch');
35
-            EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EventEspressoVendor', EE_THIRD_PARTY);
36
-            $initialized = true;
37
-        }
38
-    }
24
+	/**
25
+	 * @return void
26
+	 * @throws EE_Error
27
+	 */
28
+	public function initializeAutoloader()
29
+	{
30
+		static $initialized = false;
31
+		if (! $initialized) {
32
+			// register the base directories for the namespace prefix
33
+			EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH);
34
+			EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch');
35
+			EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EventEspressoVendor', EE_THIRD_PARTY);
36
+			$initialized = true;
37
+		}
38
+	}
39 39
 
40 40
 
41
-    /**
42
-     * @return Psr4Autoloader
43
-     * @throws EE_Error
44
-     */
45
-    public static function psr4_loader(): Psr4Autoloader
46
-    {
47
-        if (! EE_Psr4AutoloaderInit::$psr4_loader instanceof Psr4Autoloader) {
48
-            // instantiate PSR4 autoloader
49
-            espresso_load_required('Psr4Autoloader', __DIR__ . '/Psr4Autoloader.php');
50
-            EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader();
51
-            // register the autoloader
52
-            EE_Psr4AutoloaderInit::psr4_loader()->register();
53
-        }
54
-        return EE_Psr4AutoloaderInit::$psr4_loader;
55
-    }
41
+	/**
42
+	 * @return Psr4Autoloader
43
+	 * @throws EE_Error
44
+	 */
45
+	public static function psr4_loader(): Psr4Autoloader
46
+	{
47
+		if (! EE_Psr4AutoloaderInit::$psr4_loader instanceof Psr4Autoloader) {
48
+			// instantiate PSR4 autoloader
49
+			espresso_load_required('Psr4Autoloader', __DIR__ . '/Psr4Autoloader.php');
50
+			EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader();
51
+			// register the autoloader
52
+			EE_Psr4AutoloaderInit::psr4_loader()->register();
53
+		}
54
+		return EE_Psr4AutoloaderInit::$psr4_loader;
55
+	}
56 56
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -28,10 +28,10 @@  discard block
 block discarded – undo
28 28
     public function initializeAutoloader()
29 29
     {
30 30
         static $initialized = false;
31
-        if (! $initialized) {
31
+        if ( ! $initialized) {
32 32
             // register the base directories for the namespace prefix
33 33
             EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH);
34
-            EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES . 'batch');
34
+            EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES.'batch');
35 35
             EE_Psr4AutoloaderInit::psr4_loader()->addNamespace('EventEspressoVendor', EE_THIRD_PARTY);
36 36
             $initialized = true;
37 37
         }
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
      */
45 45
     public static function psr4_loader(): Psr4Autoloader
46 46
     {
47
-        if (! EE_Psr4AutoloaderInit::$psr4_loader instanceof Psr4Autoloader) {
47
+        if ( ! EE_Psr4AutoloaderInit::$psr4_loader instanceof Psr4Autoloader) {
48 48
             // instantiate PSR4 autoloader
49
-            espresso_load_required('Psr4Autoloader', __DIR__ . '/Psr4Autoloader.php');
49
+            espresso_load_required('Psr4Autoloader', __DIR__.'/Psr4Autoloader.php');
50 50
             EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader();
51 51
             // register the autoloader
52 52
             EE_Psr4AutoloaderInit::psr4_loader()->register();
Please login to merge, or discard this patch.
core/bootstrap_espresso.php 1 patch
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -14,33 +14,33 @@  discard block
 block discarded – undo
14 14
  */
15 15
 function espresso_load_error_handling()
16 16
 {
17
-    static $error_handling_loaded = false;
18
-    if ($error_handling_loaded) {
19
-        return;
20
-    }
21
-    // load debugging tools
22
-    if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
23
-        require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php';
24
-        EEH_Debug_Tools::instance();
25
-    }
26
-    // load error handling
27
-    if (is_readable(EE_CORE . 'EE_Error.core.php')) {
28
-        require_once EE_CORE . 'EE_Error.core.php';
29
-        // if you're a dev and want to receive all errors via email
30
-        // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE );
31
-        if (
32
-            defined('WP_DEBUG')
33
-            && WP_DEBUG === true
34
-            && defined('EE_ERROR_EMAILS')
35
-            && EE_ERROR_EMAILS === true
36
-        ) {
37
-            set_error_handler(['EE_Error', 'error_handler']);
38
-            register_shutdown_function(['EE_Error', 'fatal_error_handler']);
39
-        }
40
-    } else {
41
-        wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
42
-    }
43
-    $error_handling_loaded = true;
17
+	static $error_handling_loaded = false;
18
+	if ($error_handling_loaded) {
19
+		return;
20
+	}
21
+	// load debugging tools
22
+	if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
23
+		require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php';
24
+		EEH_Debug_Tools::instance();
25
+	}
26
+	// load error handling
27
+	if (is_readable(EE_CORE . 'EE_Error.core.php')) {
28
+		require_once EE_CORE . 'EE_Error.core.php';
29
+		// if you're a dev and want to receive all errors via email
30
+		// add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE );
31
+		if (
32
+			defined('WP_DEBUG')
33
+			&& WP_DEBUG === true
34
+			&& defined('EE_ERROR_EMAILS')
35
+			&& EE_ERROR_EMAILS === true
36
+		) {
37
+			set_error_handler(['EE_Error', 'error_handler']);
38
+			register_shutdown_function(['EE_Error', 'fatal_error_handler']);
39
+		}
40
+	} else {
41
+		wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
42
+	}
43
+	$error_handling_loaded = true;
44 44
 }
45 45
 
46 46
 
@@ -54,21 +54,21 @@  discard block
 block discarded – undo
54 54
  */
55 55
 function espresso_load_required(string $classname, string $full_path_to_file)
56 56
 {
57
-    if (is_readable($full_path_to_file)) {
58
-        require_once $full_path_to_file;
59
-    } else {
60
-        throw new EE_Error(
61
-            sprintf(
62
-                esc_html__(
63
-                    'The %1$s class file could not be located or is not readable due to file permissions. %3$s supplied path: %2$s',
64
-                    'event_espresso'
65
-                ),
66
-                $classname,
67
-                $full_path_to_file,
68
-                '<br>'
69
-            )
70
-        );
71
-    }
57
+	if (is_readable($full_path_to_file)) {
58
+		require_once $full_path_to_file;
59
+	} else {
60
+		throw new EE_Error(
61
+			sprintf(
62
+				esc_html__(
63
+					'The %1$s class file could not be located or is not readable due to file permissions. %3$s supplied path: %2$s',
64
+					'event_espresso'
65
+				),
66
+				$classname,
67
+				$full_path_to_file,
68
+				'<br>'
69
+			)
70
+		);
71
+	}
72 72
 }
73 73
 
74 74
 
@@ -86,52 +86,52 @@  discard block
 block discarded – undo
86 86
  */
87 87
 function bootstrap_espresso()
88 88
 {
89
-    require_once __DIR__ . '/espresso_definitions.php';
90
-    try {
91
-        espresso_load_error_handling();
92
-        // include WordPress shims for functions introduced in later versions of WordPress
93
-        espresso_load_required(
94
-            '',
95
-            EE_CORE . 'wordpress-shims.php'
96
-        );
97
-        espresso_load_required(
98
-            '',
99
-            EE_CORE . 'third-party-compatibility.php'
100
-        );
101
-        espresso_load_required(
102
-            'EEH_Base',
103
-            EE_CORE . 'helpers/EEH_Base.helper.php'
104
-        );
105
-        espresso_load_required(
106
-            'EEH_File',
107
-            EE_CORE . 'interfaces/EEHI_File.interface.php'
108
-        );
109
-        espresso_load_required(
110
-            'EEH_File',
111
-            EE_CORE . 'helpers/EEH_File.helper.php'
112
-        );
113
-        espresso_load_required(
114
-            'EEH_Array',
115
-            EE_CORE . 'helpers/EEH_Array.helper.php'
116
-        );
117
-        espresso_load_required(
118
-            'EE_Base',
119
-            EE_CORE . 'EE_Base.core.php'
120
-        );
121
-        // instantiate and configure PSR4 autoloader
122
-        espresso_load_required(
123
-            'Psr4Autoloader',
124
-            EE_CORE . 'Psr4Autoloader.php'
125
-        );
126
-        espresso_load_required(
127
-            'EE_Psr4AutoloaderInit',
128
-            EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
129
-        );
130
-        $AutoloaderInit = new EE_Psr4AutoloaderInit();
131
-        $AutoloaderInit->initializeAutoloader();
132
-        new EventEspresso\core\services\bootstrap\BootstrapCore();
133
-    } catch (Exception $e) {
134
-        require_once EE_CORE . 'exceptions/ExceptionStackTraceDisplay.php';
135
-        new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
136
-    }
89
+	require_once __DIR__ . '/espresso_definitions.php';
90
+	try {
91
+		espresso_load_error_handling();
92
+		// include WordPress shims for functions introduced in later versions of WordPress
93
+		espresso_load_required(
94
+			'',
95
+			EE_CORE . 'wordpress-shims.php'
96
+		);
97
+		espresso_load_required(
98
+			'',
99
+			EE_CORE . 'third-party-compatibility.php'
100
+		);
101
+		espresso_load_required(
102
+			'EEH_Base',
103
+			EE_CORE . 'helpers/EEH_Base.helper.php'
104
+		);
105
+		espresso_load_required(
106
+			'EEH_File',
107
+			EE_CORE . 'interfaces/EEHI_File.interface.php'
108
+		);
109
+		espresso_load_required(
110
+			'EEH_File',
111
+			EE_CORE . 'helpers/EEH_File.helper.php'
112
+		);
113
+		espresso_load_required(
114
+			'EEH_Array',
115
+			EE_CORE . 'helpers/EEH_Array.helper.php'
116
+		);
117
+		espresso_load_required(
118
+			'EE_Base',
119
+			EE_CORE . 'EE_Base.core.php'
120
+		);
121
+		// instantiate and configure PSR4 autoloader
122
+		espresso_load_required(
123
+			'Psr4Autoloader',
124
+			EE_CORE . 'Psr4Autoloader.php'
125
+		);
126
+		espresso_load_required(
127
+			'EE_Psr4AutoloaderInit',
128
+			EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
129
+		);
130
+		$AutoloaderInit = new EE_Psr4AutoloaderInit();
131
+		$AutoloaderInit->initializeAutoloader();
132
+		new EventEspresso\core\services\bootstrap\BootstrapCore();
133
+	} catch (Exception $e) {
134
+		require_once EE_CORE . 'exceptions/ExceptionStackTraceDisplay.php';
135
+		new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
136
+	}
137 137
 }
Please login to merge, or discard this patch.
core/Psr4Autoloader.php 2 patches
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -44,149 +44,149 @@
 block discarded – undo
44 44
  */
45 45
 class Psr4Autoloader
46 46
 {
47
-    /**
48
-     * namespace separator
49
-     */
50
-    public const NS = '\\';
47
+	/**
48
+	 * namespace separator
49
+	 */
50
+	public const NS = '\\';
51 51
 
52
-    /**
53
-     * An associative array where the key is a namespace prefix and the value
54
-     * is an array of base directories for classes in that namespace.
55
-     *
56
-     * @var array
57
-     */
58
-    protected $prefixes = array();
52
+	/**
53
+	 * An associative array where the key is a namespace prefix and the value
54
+	 * is an array of base directories for classes in that namespace.
55
+	 *
56
+	 * @var array
57
+	 */
58
+	protected $prefixes = array();
59 59
 
60 60
 
61
-    /**
62
-     * returns an array of registered namespace prefixes
63
-     *
64
-     * @param string $prefix
65
-     * @return array
66
-     */
67
-    public function prefixes(string $prefix = ''): array
68
-    {
69
-        if (! empty($prefix)) {
70
-            // are there any base directories for this namespace prefix?
71
-            return $this->prefixes[ $prefix ] ?? [];
72
-        }
73
-        return $this->prefixes;
74
-    }
61
+	/**
62
+	 * returns an array of registered namespace prefixes
63
+	 *
64
+	 * @param string $prefix
65
+	 * @return array
66
+	 */
67
+	public function prefixes(string $prefix = ''): array
68
+	{
69
+		if (! empty($prefix)) {
70
+			// are there any base directories for this namespace prefix?
71
+			return $this->prefixes[ $prefix ] ?? [];
72
+		}
73
+		return $this->prefixes;
74
+	}
75 75
 
76 76
 
77
-    /**
78
-     * Register loader with SPL autoloader stack.
79
-     *
80
-     * @return void
81
-     */
82
-    public function register()
83
-    {
84
-        spl_autoload_register(array($this, 'loadClass'));
85
-    }
77
+	/**
78
+	 * Register loader with SPL autoloader stack.
79
+	 *
80
+	 * @return void
81
+	 */
82
+	public function register()
83
+	{
84
+		spl_autoload_register(array($this, 'loadClass'));
85
+	}
86 86
 
87 87
 
88
-    /**
89
-     * Adds a base directory for a namespace prefix.
90
-     *
91
-     * @param string $prefix   The namespace prefix.
92
-     * @param string $base_dir A base directory for class files in the
93
-     *                         namespace.
94
-     * @param bool   $prepend  If true, prepend the base directory to the stack
95
-     *                         instead of appending it; this causes it to be searched first rather
96
-     *                         than last.
97
-     * @return void
98
-     */
99
-    public function addNamespace(string $prefix, string $base_dir, bool $prepend = false)
100
-    {
101
-        // normalize namespace prefix
102
-        $prefix = trim($prefix, Psr4Autoloader::NS) . Psr4Autoloader::NS;
103
-        // normalize the base directory with a trailing separator
104
-        $base_dir = str_replace(['\\', '/'], '/', $base_dir);
105
-        $base_dir = rtrim($base_dir, '/\\') . '/';
106
-        // initialize the namespace prefix array
107
-        if (isset($this->prefixes[ $prefix ]) === false) {
108
-            $this->prefixes[ $prefix ] = array();
109
-        }
110
-        // retain the base directory for the namespace prefix
111
-        if ($prepend) {
112
-            array_unshift($this->prefixes[ $prefix ], $base_dir);
113
-        } else {
114
-            $this->prefixes[ $prefix ][] = $base_dir;
115
-        }
116
-    }
88
+	/**
89
+	 * Adds a base directory for a namespace prefix.
90
+	 *
91
+	 * @param string $prefix   The namespace prefix.
92
+	 * @param string $base_dir A base directory for class files in the
93
+	 *                         namespace.
94
+	 * @param bool   $prepend  If true, prepend the base directory to the stack
95
+	 *                         instead of appending it; this causes it to be searched first rather
96
+	 *                         than last.
97
+	 * @return void
98
+	 */
99
+	public function addNamespace(string $prefix, string $base_dir, bool $prepend = false)
100
+	{
101
+		// normalize namespace prefix
102
+		$prefix = trim($prefix, Psr4Autoloader::NS) . Psr4Autoloader::NS;
103
+		// normalize the base directory with a trailing separator
104
+		$base_dir = str_replace(['\\', '/'], '/', $base_dir);
105
+		$base_dir = rtrim($base_dir, '/\\') . '/';
106
+		// initialize the namespace prefix array
107
+		if (isset($this->prefixes[ $prefix ]) === false) {
108
+			$this->prefixes[ $prefix ] = array();
109
+		}
110
+		// retain the base directory for the namespace prefix
111
+		if ($prepend) {
112
+			array_unshift($this->prefixes[ $prefix ], $base_dir);
113
+		} else {
114
+			$this->prefixes[ $prefix ][] = $base_dir;
115
+		}
116
+	}
117 117
 
118 118
 
119
-    /**
120
-     * Loads the class file for a given class name.
121
-     *
122
-     * @param string $class The fully-qualified class name.
123
-     * @return false|string The mapped file name on success or boolean false on failure.
124
-     */
125
-    public function loadClass(string $class)
126
-    {
127
-        // the current namespace prefix
128
-        $prefix = $class;
129
-        // work backwards through the namespace names of the fully-qualified
130
-        // class name to find a mapped file name
131
-        while (false !== $pos = strrpos($prefix, Psr4Autoloader::NS)) {
132
-            // retain the trailing namespace separator in the prefix
133
-            $prefix = substr($class, 0, $pos + 1);
134
-            // the rest is the relative class name
135
-            $relative_class = substr($class, $pos + 1);
136
-            // try to load a mapped file for the prefix and relative class
137
-            $mapped_file = $this->loadMappedFile($prefix, $relative_class);
138
-            if ($mapped_file) {
139
-                return $mapped_file;
140
-            }
141
-            // remove the trailing namespace separator for the next iteration of strrpos()
142
-            $prefix = rtrim($prefix, Psr4Autoloader::NS);
143
-        }
144
-        // never found a mapped file
145
-        return false;
146
-    }
119
+	/**
120
+	 * Loads the class file for a given class name.
121
+	 *
122
+	 * @param string $class The fully-qualified class name.
123
+	 * @return false|string The mapped file name on success or boolean false on failure.
124
+	 */
125
+	public function loadClass(string $class)
126
+	{
127
+		// the current namespace prefix
128
+		$prefix = $class;
129
+		// work backwards through the namespace names of the fully-qualified
130
+		// class name to find a mapped file name
131
+		while (false !== $pos = strrpos($prefix, Psr4Autoloader::NS)) {
132
+			// retain the trailing namespace separator in the prefix
133
+			$prefix = substr($class, 0, $pos + 1);
134
+			// the rest is the relative class name
135
+			$relative_class = substr($class, $pos + 1);
136
+			// try to load a mapped file for the prefix and relative class
137
+			$mapped_file = $this->loadMappedFile($prefix, $relative_class);
138
+			if ($mapped_file) {
139
+				return $mapped_file;
140
+			}
141
+			// remove the trailing namespace separator for the next iteration of strrpos()
142
+			$prefix = rtrim($prefix, Psr4Autoloader::NS);
143
+		}
144
+		// never found a mapped file
145
+		return false;
146
+	}
147 147
 
148 148
 
149
-    /**
150
-     * Load the mapped file for a namespace prefix and relative class.
151
-     *
152
-     * @param string $prefix         The namespace prefix.
153
-     * @param string $relative_class The relative class name.
154
-     * @return string|null           null if no mapped file can be loaded,
155
-     *                               or the name of the mapped file that was loaded.
156
-     */
157
-    protected function loadMappedFile(string $prefix, string $relative_class): ?string
158
-    {
159
-        // look through base directories for this namespace prefix
160
-        foreach ($this->prefixes($prefix) as $base_dir) {
161
-            // replace the namespace prefix with the base directory,
162
-            // replace namespace separators with directory separators
163
-            // in the relative class name, append with .php
164
-            $file = $base_dir
165
-                    . str_replace(Psr4Autoloader::NS, '/', $relative_class)
166
-                    . '.php';
167
-            // if the mapped file exists, require it
168
-            if ($this->requireFile($file)) {
169
-                // yes, we're done
170
-                return $file;
171
-            }
172
-        }
173
-        // never found it
174
-        return null;
175
-    }
149
+	/**
150
+	 * Load the mapped file for a namespace prefix and relative class.
151
+	 *
152
+	 * @param string $prefix         The namespace prefix.
153
+	 * @param string $relative_class The relative class name.
154
+	 * @return string|null           null if no mapped file can be loaded,
155
+	 *                               or the name of the mapped file that was loaded.
156
+	 */
157
+	protected function loadMappedFile(string $prefix, string $relative_class): ?string
158
+	{
159
+		// look through base directories for this namespace prefix
160
+		foreach ($this->prefixes($prefix) as $base_dir) {
161
+			// replace the namespace prefix with the base directory,
162
+			// replace namespace separators with directory separators
163
+			// in the relative class name, append with .php
164
+			$file = $base_dir
165
+					. str_replace(Psr4Autoloader::NS, '/', $relative_class)
166
+					. '.php';
167
+			// if the mapped file exists, require it
168
+			if ($this->requireFile($file)) {
169
+				// yes, we're done
170
+				return $file;
171
+			}
172
+		}
173
+		// never found it
174
+		return null;
175
+	}
176 176
 
177 177
 
178
-    /**
179
-     * If a file exists, require it from the file system.
180
-     *
181
-     * @param string $file The file to require.
182
-     * @return bool True if the file exists, false if not.
183
-     */
184
-    protected function requireFile(string $file): bool
185
-    {
186
-        if (file_exists($file)) {
187
-            require $file;
188
-            return true;
189
-        }
190
-        return false;
191
-    }
178
+	/**
179
+	 * If a file exists, require it from the file system.
180
+	 *
181
+	 * @param string $file The file to require.
182
+	 * @return bool True if the file exists, false if not.
183
+	 */
184
+	protected function requireFile(string $file): bool
185
+	{
186
+		if (file_exists($file)) {
187
+			require $file;
188
+			return true;
189
+		}
190
+		return false;
191
+	}
192 192
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
      */
67 67
     public function prefixes(string $prefix = ''): array
68 68
     {
69
-        if (! empty($prefix)) {
69
+        if ( ! empty($prefix)) {
70 70
             // are there any base directories for this namespace prefix?
71
-            return $this->prefixes[ $prefix ] ?? [];
71
+            return $this->prefixes[$prefix] ?? [];
72 72
         }
73 73
         return $this->prefixes;
74 74
     }
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
     public function addNamespace(string $prefix, string $base_dir, bool $prepend = false)
100 100
     {
101 101
         // normalize namespace prefix
102
-        $prefix = trim($prefix, Psr4Autoloader::NS) . Psr4Autoloader::NS;
102
+        $prefix = trim($prefix, Psr4Autoloader::NS).Psr4Autoloader::NS;
103 103
         // normalize the base directory with a trailing separator
104 104
         $base_dir = str_replace(['\\', '/'], '/', $base_dir);
105
-        $base_dir = rtrim($base_dir, '/\\') . '/';
105
+        $base_dir = rtrim($base_dir, '/\\').'/';
106 106
         // initialize the namespace prefix array
107
-        if (isset($this->prefixes[ $prefix ]) === false) {
108
-            $this->prefixes[ $prefix ] = array();
107
+        if (isset($this->prefixes[$prefix]) === false) {
108
+            $this->prefixes[$prefix] = array();
109 109
         }
110 110
         // retain the base directory for the namespace prefix
111 111
         if ($prepend) {
112
-            array_unshift($this->prefixes[ $prefix ], $base_dir);
112
+            array_unshift($this->prefixes[$prefix], $base_dir);
113 113
         } else {
114
-            $this->prefixes[ $prefix ][] = $base_dir;
114
+            $this->prefixes[$prefix][] = $base_dir;
115 115
         }
116 116
     }
117 117
 
Please login to merge, or discard this patch.
core/helpers/EEH_Autoloader.helper.php 2 patches
Indentation   +280 added lines, -280 removed lines patch added patch discarded remove patch
@@ -11,284 +11,284 @@
 block discarded – undo
11 11
  */
12 12
 class EEH_Autoloader extends EEH_Base
13 13
 {
14
-    /**
15
-     * instance of the EE_System object
16
-     *
17
-     * @var $_instance
18
-     */
19
-    private static $_instance = null;
20
-
21
-    /**
22
-     * @var array $_autoloaders
23
-     */
24
-    private static $_autoloaders;
25
-
26
-    /**
27
-     * set to "paths" to display autoloader class => path mappings
28
-     * set to "times" to display autoloader loading times
29
-     * set to "all" to display both
30
-     *
31
-     * @var string $debug
32
-     */
33
-    public static $debug = false;
34
-
35
-
36
-    /**
37
-     * @return void
38
-     * @throws Exception
39
-     */
40
-    private function __construct()
41
-    {
42
-        if (self::$_autoloaders === null) {
43
-            self::$_autoloaders = [];
44
-            $this->_register_custom_autoloaders();
45
-            spl_autoload_register([$this, 'espresso_autoloader']);
46
-        }
47
-    }
48
-
49
-
50
-    /**
51
-     * @return EEH_Autoloader
52
-     */
53
-    public static function instance(): ?EEH_Autoloader
54
-    {
55
-        // check if class object is instantiated
56
-        if (! self::$_instance instanceof EEH_Autoloader) {
57
-            self::$_instance = new self();
58
-        }
59
-        return self::$_instance;
60
-    }
61
-
62
-
63
-    /**
64
-     *    espresso_autoloader
65
-     *
66
-     * @param   $class_name
67
-     * @return  void
68
-     * @internal  param string $class_name - simple class name ie: session
69
-     * @internal  param $className
70
-     */
71
-    public static function espresso_autoloader($class_name)
72
-    {
73
-        if (isset(self::$_autoloaders[ $class_name ])) {
74
-            require_once(self::$_autoloaders[ $class_name ]);
75
-        }
76
-    }
77
-
78
-
79
-    /**
80
-     *    register_autoloader
81
-     *
82
-     * @param array | string $class_paths - array of key => value pairings between class names and paths
83
-     * @param bool           $read_check  true if we need to check whether the file is readable or not.
84
-     * @param bool           $debug       **deprecated**
85
-     * @throws EE_Error
86
-     */
87
-    public static function register_autoloader($class_paths, bool $read_check = true, bool $debug = false)
88
-    {
89
-        $class_paths = is_array($class_paths) ? $class_paths : [$class_paths];
90
-        foreach ($class_paths as $class => $path) {
91
-            // skip all files that are not PHP
92
-            if (substr($path, strlen($path) - 3) !== 'php') {
93
-                continue;
94
-            }
95
-            // don't give up! you gotta...
96
-            // get some class
97
-            if (empty($class)) {
98
-                throw new EE_Error(
99
-                    sprintf(
100
-                        esc_html__(
101
-                            'No Class name was specified while registering an autoloader for the following path: %s.',
102
-                            'event_espresso'
103
-                        ),
104
-                        $path
105
-                    )
106
-                );
107
-            }
108
-            // one day you will find the path young grasshopper
109
-            if (empty($path)) {
110
-                throw new EE_Error(
111
-                    sprintf(
112
-                        esc_html__(
113
-                            'No path was specified while registering an autoloader for the %s class.',
114
-                            'event_espresso'
115
-                        ),
116
-                        $class
117
-                    )
118
-                );
119
-            }
120
-            // is file readable ?
121
-            if ($read_check && ! is_readable($path)) {
122
-                throw new EE_Error(
123
-                    sprintf(
124
-                        esc_html__(
125
-                            'The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
126
-                            'event_espresso'
127
-                        ),
128
-                        $class,
129
-                        $path
130
-                    )
131
-                );
132
-            }
133
-            if (! isset(self::$_autoloaders[ $class ])) {
134
-                self::$_autoloaders[ $class ] = str_replace(['/', '\\'], '/', $path);
135
-                if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) {
136
-                    EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__);
137
-                }
138
-            }
139
-        }
140
-    }
141
-
142
-
143
-    /**
144
-     *  get_autoloaders
145
-     *
146
-     * @return array
147
-     */
148
-    public static function get_autoloaders(): array
149
-    {
150
-        return self::$_autoloaders;
151
-    }
152
-
153
-
154
-    /**
155
-     *  register core, model and class 'autoloaders'
156
-     *
157
-     * @return void
158
-     * @throws EE_Error
159
-     */
160
-    private function _register_custom_autoloaders()
161
-    {
162
-        EEH_Autoloader::$debug = '';
163
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true);
164
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
165
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE);
166
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
167
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
168
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
169
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages');
170
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
171
-            EEH_Debug_Tools::instance()->show_times();
172
-        }
173
-    }
174
-
175
-
176
-    public static function register_helpers_autoloaders()
177
-    {
178
-        // EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
179
-    }
180
-
181
-    public static function register_form_sections_autoloaders()
182
-    {
183
-        // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true );
184
-    }
185
-
186
-
187
-    /**
188
-     *  register core, model and class 'autoloaders'
189
-     *
190
-     * @return void
191
-     * @throws EE_Error
192
-     */
193
-    public static function register_line_item_display_autoloaders()
194
-    {
195
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true);
196
-    }
197
-
198
-
199
-    /**
200
-     *  register core, model and class 'autoloaders'
201
-     *
202
-     * @return void
203
-     * @throws EE_Error
204
-     */
205
-    public static function register_line_item_filter_autoloaders()
206
-    {
207
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true);
208
-    }
209
-
210
-
211
-    /**
212
-     *  register template part 'autoloaders'
213
-     *
214
-     * @return void
215
-     * @throws EE_Error
216
-     */
217
-    public static function register_template_part_autoloaders()
218
-    {
219
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true);
220
-    }
221
-
222
-
223
-    /**
224
-     * @return void
225
-     * @throws EE_Error
226
-     */
227
-    public static function register_business_classes()
228
-    {
229
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business');
230
-    }
231
-
232
-
233
-    /**
234
-     * Assumes all the files in this folder have the normal naming scheme (namely that their classname
235
-     * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list.
236
-     * If that's not the case, you'll need to improve this function or just use
237
-     * EEH_File::get_classname_from_filepath_with_standard_filename() directly. Yes this has to scan the directory for
238
-     * files, but it only does it once -- not on EACH time the autoloader is used
239
-     *
240
-     * @param string $folder name, with or without trailing /, doesn't matter
241
-     * @param bool   $recursive
242
-     * @param bool   $debug  **deprecated**
243
-     * @throws EE_Error
244
-     */
245
-    public static function register_autoloaders_for_each_file_in_folder(
246
-        string $folder,
247
-        bool $recursive = false,
248
-        bool $debug = false
249
-    ) {
250
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) {
251
-            EEH_Debug_Tools::instance()->start_timer(basename($folder));
252
-        }
253
-        // make sure last char is a /
254
-        $folder .= $folder[ strlen($folder) - 1 ] !== '/' ? '/' : '';
255
-        $class_to_filepath_map = [];
256
-        $exclude = ['index'];
257
-        // get all the files in that folder that end in php
258
-        $filepaths = glob($folder . '*');
259
-
260
-        if (empty($filepaths)) {
261
-            return;
262
-        }
263
-
264
-        foreach ($filepaths as $filepath) {
265
-            if (substr($filepath, -4, 4) === '.php') {
266
-                $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
267
-                if (! in_array($class_name, $exclude)) {
268
-                    $class_to_filepath_map [ $class_name ] = $filepath;
269
-                }
270
-            } elseif ($recursive) {
271
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug);
272
-            }
273
-        }
274
-        // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories.
275
-        self::register_autoloader($class_to_filepath_map, false, $debug);
276
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
277
-            EEH_Debug_Tools::instance()->stop_timer(basename($folder));
278
-        }
279
-    }
280
-
281
-
282
-    /**
283
-     * register additional autoloader based on variation of the classname for an existing autoloader
284
-     *
285
-     * @param string $class_name - simple class name ie: EE_Session
286
-     * @param string $alias      - variation on class name ie: EE_session, session, etc
287
-     */
288
-    public static function add_alias(string $class_name, string $alias)
289
-    {
290
-        if (isset(self::$_autoloaders[ $class_name ])) {
291
-            self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ];
292
-        }
293
-    }
14
+	/**
15
+	 * instance of the EE_System object
16
+	 *
17
+	 * @var $_instance
18
+	 */
19
+	private static $_instance = null;
20
+
21
+	/**
22
+	 * @var array $_autoloaders
23
+	 */
24
+	private static $_autoloaders;
25
+
26
+	/**
27
+	 * set to "paths" to display autoloader class => path mappings
28
+	 * set to "times" to display autoloader loading times
29
+	 * set to "all" to display both
30
+	 *
31
+	 * @var string $debug
32
+	 */
33
+	public static $debug = false;
34
+
35
+
36
+	/**
37
+	 * @return void
38
+	 * @throws Exception
39
+	 */
40
+	private function __construct()
41
+	{
42
+		if (self::$_autoloaders === null) {
43
+			self::$_autoloaders = [];
44
+			$this->_register_custom_autoloaders();
45
+			spl_autoload_register([$this, 'espresso_autoloader']);
46
+		}
47
+	}
48
+
49
+
50
+	/**
51
+	 * @return EEH_Autoloader
52
+	 */
53
+	public static function instance(): ?EEH_Autoloader
54
+	{
55
+		// check if class object is instantiated
56
+		if (! self::$_instance instanceof EEH_Autoloader) {
57
+			self::$_instance = new self();
58
+		}
59
+		return self::$_instance;
60
+	}
61
+
62
+
63
+	/**
64
+	 *    espresso_autoloader
65
+	 *
66
+	 * @param   $class_name
67
+	 * @return  void
68
+	 * @internal  param string $class_name - simple class name ie: session
69
+	 * @internal  param $className
70
+	 */
71
+	public static function espresso_autoloader($class_name)
72
+	{
73
+		if (isset(self::$_autoloaders[ $class_name ])) {
74
+			require_once(self::$_autoloaders[ $class_name ]);
75
+		}
76
+	}
77
+
78
+
79
+	/**
80
+	 *    register_autoloader
81
+	 *
82
+	 * @param array | string $class_paths - array of key => value pairings between class names and paths
83
+	 * @param bool           $read_check  true if we need to check whether the file is readable or not.
84
+	 * @param bool           $debug       **deprecated**
85
+	 * @throws EE_Error
86
+	 */
87
+	public static function register_autoloader($class_paths, bool $read_check = true, bool $debug = false)
88
+	{
89
+		$class_paths = is_array($class_paths) ? $class_paths : [$class_paths];
90
+		foreach ($class_paths as $class => $path) {
91
+			// skip all files that are not PHP
92
+			if (substr($path, strlen($path) - 3) !== 'php') {
93
+				continue;
94
+			}
95
+			// don't give up! you gotta...
96
+			// get some class
97
+			if (empty($class)) {
98
+				throw new EE_Error(
99
+					sprintf(
100
+						esc_html__(
101
+							'No Class name was specified while registering an autoloader for the following path: %s.',
102
+							'event_espresso'
103
+						),
104
+						$path
105
+					)
106
+				);
107
+			}
108
+			// one day you will find the path young grasshopper
109
+			if (empty($path)) {
110
+				throw new EE_Error(
111
+					sprintf(
112
+						esc_html__(
113
+							'No path was specified while registering an autoloader for the %s class.',
114
+							'event_espresso'
115
+						),
116
+						$class
117
+					)
118
+				);
119
+			}
120
+			// is file readable ?
121
+			if ($read_check && ! is_readable($path)) {
122
+				throw new EE_Error(
123
+					sprintf(
124
+						esc_html__(
125
+							'The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
126
+							'event_espresso'
127
+						),
128
+						$class,
129
+						$path
130
+					)
131
+				);
132
+			}
133
+			if (! isset(self::$_autoloaders[ $class ])) {
134
+				self::$_autoloaders[ $class ] = str_replace(['/', '\\'], '/', $path);
135
+				if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) {
136
+					EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__);
137
+				}
138
+			}
139
+		}
140
+	}
141
+
142
+
143
+	/**
144
+	 *  get_autoloaders
145
+	 *
146
+	 * @return array
147
+	 */
148
+	public static function get_autoloaders(): array
149
+	{
150
+		return self::$_autoloaders;
151
+	}
152
+
153
+
154
+	/**
155
+	 *  register core, model and class 'autoloaders'
156
+	 *
157
+	 * @return void
158
+	 * @throws EE_Error
159
+	 */
160
+	private function _register_custom_autoloaders()
161
+	{
162
+		EEH_Autoloader::$debug = '';
163
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true);
164
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
165
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE);
166
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
167
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
168
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
169
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages');
170
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
171
+			EEH_Debug_Tools::instance()->show_times();
172
+		}
173
+	}
174
+
175
+
176
+	public static function register_helpers_autoloaders()
177
+	{
178
+		// EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
179
+	}
180
+
181
+	public static function register_form_sections_autoloaders()
182
+	{
183
+		// EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true );
184
+	}
185
+
186
+
187
+	/**
188
+	 *  register core, model and class 'autoloaders'
189
+	 *
190
+	 * @return void
191
+	 * @throws EE_Error
192
+	 */
193
+	public static function register_line_item_display_autoloaders()
194
+	{
195
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true);
196
+	}
197
+
198
+
199
+	/**
200
+	 *  register core, model and class 'autoloaders'
201
+	 *
202
+	 * @return void
203
+	 * @throws EE_Error
204
+	 */
205
+	public static function register_line_item_filter_autoloaders()
206
+	{
207
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true);
208
+	}
209
+
210
+
211
+	/**
212
+	 *  register template part 'autoloaders'
213
+	 *
214
+	 * @return void
215
+	 * @throws EE_Error
216
+	 */
217
+	public static function register_template_part_autoloaders()
218
+	{
219
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true);
220
+	}
221
+
222
+
223
+	/**
224
+	 * @return void
225
+	 * @throws EE_Error
226
+	 */
227
+	public static function register_business_classes()
228
+	{
229
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business');
230
+	}
231
+
232
+
233
+	/**
234
+	 * Assumes all the files in this folder have the normal naming scheme (namely that their classname
235
+	 * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list.
236
+	 * If that's not the case, you'll need to improve this function or just use
237
+	 * EEH_File::get_classname_from_filepath_with_standard_filename() directly. Yes this has to scan the directory for
238
+	 * files, but it only does it once -- not on EACH time the autoloader is used
239
+	 *
240
+	 * @param string $folder name, with or without trailing /, doesn't matter
241
+	 * @param bool   $recursive
242
+	 * @param bool   $debug  **deprecated**
243
+	 * @throws EE_Error
244
+	 */
245
+	public static function register_autoloaders_for_each_file_in_folder(
246
+		string $folder,
247
+		bool $recursive = false,
248
+		bool $debug = false
249
+	) {
250
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) {
251
+			EEH_Debug_Tools::instance()->start_timer(basename($folder));
252
+		}
253
+		// make sure last char is a /
254
+		$folder .= $folder[ strlen($folder) - 1 ] !== '/' ? '/' : '';
255
+		$class_to_filepath_map = [];
256
+		$exclude = ['index'];
257
+		// get all the files in that folder that end in php
258
+		$filepaths = glob($folder . '*');
259
+
260
+		if (empty($filepaths)) {
261
+			return;
262
+		}
263
+
264
+		foreach ($filepaths as $filepath) {
265
+			if (substr($filepath, -4, 4) === '.php') {
266
+				$class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
267
+				if (! in_array($class_name, $exclude)) {
268
+					$class_to_filepath_map [ $class_name ] = $filepath;
269
+				}
270
+			} elseif ($recursive) {
271
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug);
272
+			}
273
+		}
274
+		// we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories.
275
+		self::register_autoloader($class_to_filepath_map, false, $debug);
276
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
277
+			EEH_Debug_Tools::instance()->stop_timer(basename($folder));
278
+		}
279
+	}
280
+
281
+
282
+	/**
283
+	 * register additional autoloader based on variation of the classname for an existing autoloader
284
+	 *
285
+	 * @param string $class_name - simple class name ie: EE_Session
286
+	 * @param string $alias      - variation on class name ie: EE_session, session, etc
287
+	 */
288
+	public static function add_alias(string $class_name, string $alias)
289
+	{
290
+		if (isset(self::$_autoloaders[ $class_name ])) {
291
+			self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ];
292
+		}
293
+	}
294 294
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     public static function instance(): ?EEH_Autoloader
54 54
     {
55 55
         // check if class object is instantiated
56
-        if (! self::$_instance instanceof EEH_Autoloader) {
56
+        if ( ! self::$_instance instanceof EEH_Autoloader) {
57 57
             self::$_instance = new self();
58 58
         }
59 59
         return self::$_instance;
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
      */
71 71
     public static function espresso_autoloader($class_name)
72 72
     {
73
-        if (isset(self::$_autoloaders[ $class_name ])) {
74
-            require_once(self::$_autoloaders[ $class_name ]);
73
+        if (isset(self::$_autoloaders[$class_name])) {
74
+            require_once(self::$_autoloaders[$class_name]);
75 75
         }
76 76
     }
77 77
 
@@ -130,10 +130,10 @@  discard block
 block discarded – undo
130 130
                     )
131 131
                 );
132 132
             }
133
-            if (! isset(self::$_autoloaders[ $class ])) {
134
-                self::$_autoloaders[ $class ] = str_replace(['/', '\\'], '/', $path);
133
+            if ( ! isset(self::$_autoloaders[$class])) {
134
+                self::$_autoloaders[$class] = str_replace(['/', '\\'], '/', $path);
135 135
                 if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) {
136
-                    EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__);
136
+                    EEH_Debug_Tools::printr(self::$_autoloaders[$class], $class, __FILE__, __LINE__);
137 137
                 }
138 138
             }
139 139
         }
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
167 167
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
168 168
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
169
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages');
169
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'messages');
170 170
         if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
171 171
             EEH_Debug_Tools::instance()->show_times();
172 172
         }
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
      */
193 193
     public static function register_line_item_display_autoloaders()
194 194
     {
195
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true);
195
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_display', true);
196 196
     }
197 197
 
198 198
 
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
      */
205 205
     public static function register_line_item_filter_autoloaders()
206 206
     {
207
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true);
207
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_filters', true);
208 208
     }
209 209
 
210 210
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
      */
217 217
     public static function register_template_part_autoloaders()
218 218
     {
219
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true);
219
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'template_parts', true);
220 220
     }
221 221
 
222 222
 
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
      */
227 227
     public static function register_business_classes()
228 228
     {
229
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business');
229
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'business');
230 230
     }
231 231
 
232 232
 
@@ -251,11 +251,11 @@  discard block
 block discarded – undo
251 251
             EEH_Debug_Tools::instance()->start_timer(basename($folder));
252 252
         }
253 253
         // make sure last char is a /
254
-        $folder .= $folder[ strlen($folder) - 1 ] !== '/' ? '/' : '';
254
+        $folder .= $folder[strlen($folder) - 1] !== '/' ? '/' : '';
255 255
         $class_to_filepath_map = [];
256 256
         $exclude = ['index'];
257 257
         // get all the files in that folder that end in php
258
-        $filepaths = glob($folder . '*');
258
+        $filepaths = glob($folder.'*');
259 259
 
260 260
         if (empty($filepaths)) {
261 261
             return;
@@ -264,8 +264,8 @@  discard block
 block discarded – undo
264 264
         foreach ($filepaths as $filepath) {
265 265
             if (substr($filepath, -4, 4) === '.php') {
266 266
                 $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
267
-                if (! in_array($class_name, $exclude)) {
268
-                    $class_to_filepath_map [ $class_name ] = $filepath;
267
+                if ( ! in_array($class_name, $exclude)) {
268
+                    $class_to_filepath_map [$class_name] = $filepath;
269 269
                 }
270 270
             } elseif ($recursive) {
271 271
                 EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug);
@@ -287,8 +287,8 @@  discard block
 block discarded – undo
287 287
      */
288 288
     public static function add_alias(string $class_name, string $alias)
289 289
     {
290
-        if (isset(self::$_autoloaders[ $class_name ])) {
291
-            self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ];
290
+        if (isset(self::$_autoloaders[$class_name])) {
291
+            self::$_autoloaders[$alias] = self::$_autoloaders[$class_name];
292 292
         }
293 293
     }
294 294
 }
Please login to merge, or discard this patch.