Completed
Pull Request — development (#3620)
by Emanuele
07:38 queued 07:38
created
sources/ext/ClassLoader.php 1 patch
Indentation   +391 added lines, -391 removed lines patch added patch discarded remove patch
@@ -42,396 +42,396 @@  discard block
 block discarded – undo
42 42
  */
43 43
 class ClassLoader
44 44
 {
45
-    // PSR-4
46
-    private $prefixLengthsPsr4 = array();
47
-    private $prefixDirsPsr4 = array();
48
-    private $fallbackDirsPsr4 = array();
49
-
50
-    // PSR-0
51
-    private $prefixesPsr0 = array();
52
-    private $fallbackDirsPsr0 = array();
53
-
54
-    private $useIncludePath = false;
55
-    private $classMap = array();
56
-    private $classMapAuthoritative = false;
57
-    private $missingClasses = array();
58
-    private $apcuPrefix;
59
-
60
-    public function getPrefixes()
61
-    {
62
-        if (!empty($this->prefixesPsr0)) {
63
-            return call_user_func_array('array_merge', $this->prefixesPsr0);
64
-        }
65
-
66
-        return array();
67
-    }
68
-
69
-    public function getPrefixesPsr4()
70
-    {
71
-        return $this->prefixDirsPsr4;
72
-    }
73
-
74
-    public function getFallbackDirs()
75
-    {
76
-        return $this->fallbackDirsPsr0;
77
-    }
78
-
79
-    public function getFallbackDirsPsr4()
80
-    {
81
-        return $this->fallbackDirsPsr4;
82
-    }
83
-
84
-    public function getClassMap()
85
-    {
86
-        return $this->classMap;
87
-    }
88
-
89
-    /**
90
-     * @param array $classMap Class to filename map
91
-     */
92
-    public function addClassMap(array $classMap)
93
-    {
94
-        if ($this->classMap) {
95
-            $this->classMap = array_merge($this->classMap, $classMap);
96
-        } else {
97
-            $this->classMap = $classMap;
98
-        }
99
-    }
100
-
101
-    /**
102
-     * Registers a set of PSR-0 directories for a given prefix, either
103
-     * appending or prepending to the ones previously set for this prefix.
104
-     *
105
-     * @param string       $prefix  The prefix
106
-     * @param array|string $paths   The PSR-0 root directories
107
-     * @param bool         $prepend Whether to prepend the directories
108
-     */
109
-    public function add($prefix, $paths, $prepend = false)
110
-    {
111
-        if (!$prefix) {
112
-            if ($prepend) {
113
-                $this->fallbackDirsPsr0 = array_merge(
114
-                    (array) $paths,
115
-                    $this->fallbackDirsPsr0
116
-                );
117
-            } else {
118
-                $this->fallbackDirsPsr0 = array_merge(
119
-                    $this->fallbackDirsPsr0,
120
-                    (array) $paths
121
-                );
122
-            }
123
-
124
-            return;
125
-        }
126
-
127
-        $first = $prefix[0];
128
-        if (!isset($this->prefixesPsr0[$first][$prefix])) {
129
-            $this->prefixesPsr0[$first][$prefix] = (array) $paths;
130
-
131
-            return;
132
-        }
133
-        if ($prepend) {
134
-            $this->prefixesPsr0[$first][$prefix] = array_merge(
135
-                (array) $paths,
136
-                $this->prefixesPsr0[$first][$prefix]
137
-            );
138
-        } else {
139
-            $this->prefixesPsr0[$first][$prefix] = array_merge(
140
-                $this->prefixesPsr0[$first][$prefix],
141
-                (array) $paths
142
-            );
143
-        }
144
-    }
145
-
146
-    /**
147
-     * Registers a set of PSR-4 directories for a given namespace, either
148
-     * appending or prepending to the ones previously set for this namespace.
149
-     *
150
-     * @param string       $prefix  The prefix/namespace, with trailing '\\'
151
-     * @param array|string $paths   The PSR-4 base directories
152
-     * @param bool         $prepend Whether to prepend the directories
153
-     *
154
-     * @throws \InvalidArgumentException
155
-     */
156
-    public function addPsr4($prefix, $paths, $prepend = false)
157
-    {
158
-        if (!$prefix) {
159
-            // Register directories for the root namespace.
160
-            if ($prepend) {
161
-                $this->fallbackDirsPsr4 = array_merge(
162
-                    (array) $paths,
163
-                    $this->fallbackDirsPsr4
164
-                );
165
-            } else {
166
-                $this->fallbackDirsPsr4 = array_merge(
167
-                    $this->fallbackDirsPsr4,
168
-                    (array) $paths
169
-                );
170
-            }
171
-        } elseif (!isset($this->prefixDirsPsr4[$prefix])) {
172
-            // Register directories for a new namespace.
173
-            $length = strlen($prefix);
174
-            if ('\\' !== $prefix[$length - 1]) {
175
-                throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
176
-            }
177
-            $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
178
-            $this->prefixDirsPsr4[$prefix] = (array) $paths;
179
-        } elseif ($prepend) {
180
-            // Prepend directories for an already registered namespace.
181
-            $this->prefixDirsPsr4[$prefix] = array_merge(
182
-                (array) $paths,
183
-                $this->prefixDirsPsr4[$prefix]
184
-            );
185
-        } else {
186
-            // Append directories for an already registered namespace.
187
-            $this->prefixDirsPsr4[$prefix] = array_merge(
188
-                $this->prefixDirsPsr4[$prefix],
189
-                (array) $paths
190
-            );
191
-        }
192
-    }
193
-
194
-    /**
195
-     * Registers a set of PSR-0 directories for a given prefix,
196
-     * replacing any others previously set for this prefix.
197
-     *
198
-     * @param string       $prefix The prefix
199
-     * @param array|string $paths  The PSR-0 base directories
200
-     */
201
-    public function set($prefix, $paths)
202
-    {
203
-        if (!$prefix) {
204
-            $this->fallbackDirsPsr0 = (array) $paths;
205
-        } else {
206
-            $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
207
-        }
208
-    }
209
-
210
-    /**
211
-     * Registers a set of PSR-4 directories for a given namespace,
212
-     * replacing any others previously set for this namespace.
213
-     *
214
-     * @param string       $prefix The prefix/namespace, with trailing '\\'
215
-     * @param array|string $paths  The PSR-4 base directories
216
-     *
217
-     * @throws \InvalidArgumentException
218
-     */
219
-    public function setPsr4($prefix, $paths)
220
-    {
221
-        if (!$prefix) {
222
-            $this->fallbackDirsPsr4 = (array) $paths;
223
-        } else {
224
-            $length = strlen($prefix);
225
-            if ('\\' !== $prefix[$length - 1]) {
226
-                throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
227
-            }
228
-            $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
229
-            $this->prefixDirsPsr4[$prefix] = (array) $paths;
230
-        }
231
-    }
232
-
233
-    /**
234
-     * Turns on searching the include path for class files.
235
-     *
236
-     * @param bool $useIncludePath
237
-     */
238
-    public function setUseIncludePath($useIncludePath)
239
-    {
240
-        $this->useIncludePath = $useIncludePath;
241
-    }
242
-
243
-    /**
244
-     * Can be used to check if the autoloader uses the include path to check
245
-     * for classes.
246
-     *
247
-     * @return bool
248
-     */
249
-    public function getUseIncludePath()
250
-    {
251
-        return $this->useIncludePath;
252
-    }
253
-
254
-    /**
255
-     * Turns off searching the prefix and fallback directories for classes
256
-     * that have not been registered with the class map.
257
-     *
258
-     * @param bool $classMapAuthoritative
259
-     */
260
-    public function setClassMapAuthoritative($classMapAuthoritative)
261
-    {
262
-        $this->classMapAuthoritative = $classMapAuthoritative;
263
-    }
264
-
265
-    /**
266
-     * Should class lookup fail if not found in the current class map?
267
-     *
268
-     * @return bool
269
-     */
270
-    public function isClassMapAuthoritative()
271
-    {
272
-        return $this->classMapAuthoritative;
273
-    }
274
-
275
-    /**
276
-     * APCu prefix to use to cache found/not-found classes, if the extension is enabled.
277
-     *
278
-     * @param string|null $apcuPrefix
279
-     */
280
-    public function setApcuPrefix($apcuPrefix)
281
-    {
282
-        $this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null;
283
-    }
284
-
285
-    /**
286
-     * The APCu prefix in use, or null if APCu caching is not enabled.
287
-     *
288
-     * @return string|null
289
-     */
290
-    public function getApcuPrefix()
291
-    {
292
-        return $this->apcuPrefix;
293
-    }
294
-
295
-    /**
296
-     * Registers this instance as an autoloader.
297
-     *
298
-     * @param bool $prepend Whether to prepend the autoloader or not
299
-     */
300
-    public function register($prepend = false)
301
-    {
302
-        spl_autoload_register(array($this, 'loadClass'), true, $prepend);
303
-    }
304
-
305
-    /**
306
-     * Unregisters this instance as an autoloader.
307
-     */
308
-    public function unregister()
309
-    {
310
-        spl_autoload_unregister(array($this, 'loadClass'));
311
-    }
312
-
313
-    /**
314
-     * Loads the given class or interface.
315
-     *
316
-     * @param  string    $class The name of the class
317
-     * @return bool|null True if loaded, null otherwise
318
-     */
319
-    public function loadClass($class)
320
-    {
321
-        if ($file = $this->findFile($class)) {
322
-            includeFile($file);
323
-
324
-            return true;
325
-        }
326
-    }
327
-
328
-    /**
329
-     * Finds the path to the file where the class is defined.
330
-     *
331
-     * @param string $class The name of the class
332
-     *
333
-     * @return string|false The path if found, false otherwise
334
-     */
335
-    public function findFile($class)
336
-    {
337
-        // class map lookup
338
-        if (isset($this->classMap[$class])) {
339
-            return $this->classMap[$class];
340
-        }
341
-        if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
342
-            return false;
343
-        }
344
-        if (null !== $this->apcuPrefix) {
345
-            $file = apcu_fetch($this->apcuPrefix.$class, $hit);
346
-            if ($hit) {
347
-                return $file;
348
-            }
349
-        }
350
-
351
-        $file = $this->findFileWithExtension($class, '.php');
352
-
353
-        // Search for Hack files if we are running on HHVM
354
-        if (false === $file && defined('HHVM_VERSION')) {
355
-            $file = $this->findFileWithExtension($class, '.hh');
356
-        }
357
-
358
-        if (null !== $this->apcuPrefix) {
359
-            apcu_add($this->apcuPrefix.$class, $file);
360
-        }
361
-
362
-        if (false === $file) {
363
-            // Remember that this class does not exist.
364
-            $this->missingClasses[$class] = true;
365
-        }
366
-
367
-        return $file;
368
-    }
369
-
370
-    private function findFileWithExtension($class, $ext)
371
-    {
372
-        // PSR-4 lookup
373
-        $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
374
-
375
-        $first = $class[0];
376
-        if (isset($this->prefixLengthsPsr4[$first])) {
377
-            $subPath = $class;
378
-            while (false !== $lastPos = strrpos($subPath, '\\')) {
379
-                $subPath = substr($subPath, 0, $lastPos);
380
-                $search = $subPath . '\\';
381
-                if (isset($this->prefixDirsPsr4[$search])) {
382
-                    $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
383
-                    foreach ($this->prefixDirsPsr4[$search] as $dir) {
384
-                        if (file_exists($file = $dir . $pathEnd)) {
385
-                            return $file;
386
-                        }
387
-                    }
388
-                }
389
-            }
390
-        }
391
-
392
-        // PSR-4 fallback dirs
393
-        foreach ($this->fallbackDirsPsr4 as $dir) {
394
-            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
395
-                return $file;
396
-            }
397
-        }
398
-
399
-        // PSR-0 lookup
400
-        if (false !== $pos = strrpos($class, '\\')) {
401
-            // namespaced class name
402
-            $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
403
-                . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
404
-        } else {
405
-            // PEAR-like class name
406
-            $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
407
-        }
408
-
409
-        if (isset($this->prefixesPsr0[$first])) {
410
-            foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
411
-                if (0 === strpos($class, $prefix)) {
412
-                    foreach ($dirs as $dir) {
413
-                        if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
414
-                            return $file;
415
-                        }
416
-                    }
417
-                }
418
-            }
419
-        }
420
-
421
-        // PSR-0 fallback dirs
422
-        foreach ($this->fallbackDirsPsr0 as $dir) {
423
-            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
424
-                return $file;
425
-            }
426
-        }
427
-
428
-        // PSR-0 include paths.
429
-        if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
430
-            return $file;
431
-        }
432
-
433
-        return false;
434
-    }
45
+	// PSR-4
46
+	private $prefixLengthsPsr4 = array();
47
+	private $prefixDirsPsr4 = array();
48
+	private $fallbackDirsPsr4 = array();
49
+
50
+	// PSR-0
51
+	private $prefixesPsr0 = array();
52
+	private $fallbackDirsPsr0 = array();
53
+
54
+	private $useIncludePath = false;
55
+	private $classMap = array();
56
+	private $classMapAuthoritative = false;
57
+	private $missingClasses = array();
58
+	private $apcuPrefix;
59
+
60
+	public function getPrefixes()
61
+	{
62
+		if (!empty($this->prefixesPsr0)) {
63
+			return call_user_func_array('array_merge', $this->prefixesPsr0);
64
+		}
65
+
66
+		return array();
67
+	}
68
+
69
+	public function getPrefixesPsr4()
70
+	{
71
+		return $this->prefixDirsPsr4;
72
+	}
73
+
74
+	public function getFallbackDirs()
75
+	{
76
+		return $this->fallbackDirsPsr0;
77
+	}
78
+
79
+	public function getFallbackDirsPsr4()
80
+	{
81
+		return $this->fallbackDirsPsr4;
82
+	}
83
+
84
+	public function getClassMap()
85
+	{
86
+		return $this->classMap;
87
+	}
88
+
89
+	/**
90
+	 * @param array $classMap Class to filename map
91
+	 */
92
+	public function addClassMap(array $classMap)
93
+	{
94
+		if ($this->classMap) {
95
+			$this->classMap = array_merge($this->classMap, $classMap);
96
+		} else {
97
+			$this->classMap = $classMap;
98
+		}
99
+	}
100
+
101
+	/**
102
+	 * Registers a set of PSR-0 directories for a given prefix, either
103
+	 * appending or prepending to the ones previously set for this prefix.
104
+	 *
105
+	 * @param string       $prefix  The prefix
106
+	 * @param array|string $paths   The PSR-0 root directories
107
+	 * @param bool         $prepend Whether to prepend the directories
108
+	 */
109
+	public function add($prefix, $paths, $prepend = false)
110
+	{
111
+		if (!$prefix) {
112
+			if ($prepend) {
113
+				$this->fallbackDirsPsr0 = array_merge(
114
+					(array) $paths,
115
+					$this->fallbackDirsPsr0
116
+				);
117
+			} else {
118
+				$this->fallbackDirsPsr0 = array_merge(
119
+					$this->fallbackDirsPsr0,
120
+					(array) $paths
121
+				);
122
+			}
123
+
124
+			return;
125
+		}
126
+
127
+		$first = $prefix[0];
128
+		if (!isset($this->prefixesPsr0[$first][$prefix])) {
129
+			$this->prefixesPsr0[$first][$prefix] = (array) $paths;
130
+
131
+			return;
132
+		}
133
+		if ($prepend) {
134
+			$this->prefixesPsr0[$first][$prefix] = array_merge(
135
+				(array) $paths,
136
+				$this->prefixesPsr0[$first][$prefix]
137
+			);
138
+		} else {
139
+			$this->prefixesPsr0[$first][$prefix] = array_merge(
140
+				$this->prefixesPsr0[$first][$prefix],
141
+				(array) $paths
142
+			);
143
+		}
144
+	}
145
+
146
+	/**
147
+	 * Registers a set of PSR-4 directories for a given namespace, either
148
+	 * appending or prepending to the ones previously set for this namespace.
149
+	 *
150
+	 * @param string       $prefix  The prefix/namespace, with trailing '\\'
151
+	 * @param array|string $paths   The PSR-4 base directories
152
+	 * @param bool         $prepend Whether to prepend the directories
153
+	 *
154
+	 * @throws \InvalidArgumentException
155
+	 */
156
+	public function addPsr4($prefix, $paths, $prepend = false)
157
+	{
158
+		if (!$prefix) {
159
+			// Register directories for the root namespace.
160
+			if ($prepend) {
161
+				$this->fallbackDirsPsr4 = array_merge(
162
+					(array) $paths,
163
+					$this->fallbackDirsPsr4
164
+				);
165
+			} else {
166
+				$this->fallbackDirsPsr4 = array_merge(
167
+					$this->fallbackDirsPsr4,
168
+					(array) $paths
169
+				);
170
+			}
171
+		} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
172
+			// Register directories for a new namespace.
173
+			$length = strlen($prefix);
174
+			if ('\\' !== $prefix[$length - 1]) {
175
+				throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
176
+			}
177
+			$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
178
+			$this->prefixDirsPsr4[$prefix] = (array) $paths;
179
+		} elseif ($prepend) {
180
+			// Prepend directories for an already registered namespace.
181
+			$this->prefixDirsPsr4[$prefix] = array_merge(
182
+				(array) $paths,
183
+				$this->prefixDirsPsr4[$prefix]
184
+			);
185
+		} else {
186
+			// Append directories for an already registered namespace.
187
+			$this->prefixDirsPsr4[$prefix] = array_merge(
188
+				$this->prefixDirsPsr4[$prefix],
189
+				(array) $paths
190
+			);
191
+		}
192
+	}
193
+
194
+	/**
195
+	 * Registers a set of PSR-0 directories for a given prefix,
196
+	 * replacing any others previously set for this prefix.
197
+	 *
198
+	 * @param string       $prefix The prefix
199
+	 * @param array|string $paths  The PSR-0 base directories
200
+	 */
201
+	public function set($prefix, $paths)
202
+	{
203
+		if (!$prefix) {
204
+			$this->fallbackDirsPsr0 = (array) $paths;
205
+		} else {
206
+			$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
207
+		}
208
+	}
209
+
210
+	/**
211
+	 * Registers a set of PSR-4 directories for a given namespace,
212
+	 * replacing any others previously set for this namespace.
213
+	 *
214
+	 * @param string       $prefix The prefix/namespace, with trailing '\\'
215
+	 * @param array|string $paths  The PSR-4 base directories
216
+	 *
217
+	 * @throws \InvalidArgumentException
218
+	 */
219
+	public function setPsr4($prefix, $paths)
220
+	{
221
+		if (!$prefix) {
222
+			$this->fallbackDirsPsr4 = (array) $paths;
223
+		} else {
224
+			$length = strlen($prefix);
225
+			if ('\\' !== $prefix[$length - 1]) {
226
+				throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
227
+			}
228
+			$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
229
+			$this->prefixDirsPsr4[$prefix] = (array) $paths;
230
+		}
231
+	}
232
+
233
+	/**
234
+	 * Turns on searching the include path for class files.
235
+	 *
236
+	 * @param bool $useIncludePath
237
+	 */
238
+	public function setUseIncludePath($useIncludePath)
239
+	{
240
+		$this->useIncludePath = $useIncludePath;
241
+	}
242
+
243
+	/**
244
+	 * Can be used to check if the autoloader uses the include path to check
245
+	 * for classes.
246
+	 *
247
+	 * @return bool
248
+	 */
249
+	public function getUseIncludePath()
250
+	{
251
+		return $this->useIncludePath;
252
+	}
253
+
254
+	/**
255
+	 * Turns off searching the prefix and fallback directories for classes
256
+	 * that have not been registered with the class map.
257
+	 *
258
+	 * @param bool $classMapAuthoritative
259
+	 */
260
+	public function setClassMapAuthoritative($classMapAuthoritative)
261
+	{
262
+		$this->classMapAuthoritative = $classMapAuthoritative;
263
+	}
264
+
265
+	/**
266
+	 * Should class lookup fail if not found in the current class map?
267
+	 *
268
+	 * @return bool
269
+	 */
270
+	public function isClassMapAuthoritative()
271
+	{
272
+		return $this->classMapAuthoritative;
273
+	}
274
+
275
+	/**
276
+	 * APCu prefix to use to cache found/not-found classes, if the extension is enabled.
277
+	 *
278
+	 * @param string|null $apcuPrefix
279
+	 */
280
+	public function setApcuPrefix($apcuPrefix)
281
+	{
282
+		$this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null;
283
+	}
284
+
285
+	/**
286
+	 * The APCu prefix in use, or null if APCu caching is not enabled.
287
+	 *
288
+	 * @return string|null
289
+	 */
290
+	public function getApcuPrefix()
291
+	{
292
+		return $this->apcuPrefix;
293
+	}
294
+
295
+	/**
296
+	 * Registers this instance as an autoloader.
297
+	 *
298
+	 * @param bool $prepend Whether to prepend the autoloader or not
299
+	 */
300
+	public function register($prepend = false)
301
+	{
302
+		spl_autoload_register(array($this, 'loadClass'), true, $prepend);
303
+	}
304
+
305
+	/**
306
+	 * Unregisters this instance as an autoloader.
307
+	 */
308
+	public function unregister()
309
+	{
310
+		spl_autoload_unregister(array($this, 'loadClass'));
311
+	}
312
+
313
+	/**
314
+	 * Loads the given class or interface.
315
+	 *
316
+	 * @param  string    $class The name of the class
317
+	 * @return bool|null True if loaded, null otherwise
318
+	 */
319
+	public function loadClass($class)
320
+	{
321
+		if ($file = $this->findFile($class)) {
322
+			includeFile($file);
323
+
324
+			return true;
325
+		}
326
+	}
327
+
328
+	/**
329
+	 * Finds the path to the file where the class is defined.
330
+	 *
331
+	 * @param string $class The name of the class
332
+	 *
333
+	 * @return string|false The path if found, false otherwise
334
+	 */
335
+	public function findFile($class)
336
+	{
337
+		// class map lookup
338
+		if (isset($this->classMap[$class])) {
339
+			return $this->classMap[$class];
340
+		}
341
+		if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
342
+			return false;
343
+		}
344
+		if (null !== $this->apcuPrefix) {
345
+			$file = apcu_fetch($this->apcuPrefix.$class, $hit);
346
+			if ($hit) {
347
+				return $file;
348
+			}
349
+		}
350
+
351
+		$file = $this->findFileWithExtension($class, '.php');
352
+
353
+		// Search for Hack files if we are running on HHVM
354
+		if (false === $file && defined('HHVM_VERSION')) {
355
+			$file = $this->findFileWithExtension($class, '.hh');
356
+		}
357
+
358
+		if (null !== $this->apcuPrefix) {
359
+			apcu_add($this->apcuPrefix.$class, $file);
360
+		}
361
+
362
+		if (false === $file) {
363
+			// Remember that this class does not exist.
364
+			$this->missingClasses[$class] = true;
365
+		}
366
+
367
+		return $file;
368
+	}
369
+
370
+	private function findFileWithExtension($class, $ext)
371
+	{
372
+		// PSR-4 lookup
373
+		$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
374
+
375
+		$first = $class[0];
376
+		if (isset($this->prefixLengthsPsr4[$first])) {
377
+			$subPath = $class;
378
+			while (false !== $lastPos = strrpos($subPath, '\\')) {
379
+				$subPath = substr($subPath, 0, $lastPos);
380
+				$search = $subPath . '\\';
381
+				if (isset($this->prefixDirsPsr4[$search])) {
382
+					$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
383
+					foreach ($this->prefixDirsPsr4[$search] as $dir) {
384
+						if (file_exists($file = $dir . $pathEnd)) {
385
+							return $file;
386
+						}
387
+					}
388
+				}
389
+			}
390
+		}
391
+
392
+		// PSR-4 fallback dirs
393
+		foreach ($this->fallbackDirsPsr4 as $dir) {
394
+			if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
395
+				return $file;
396
+			}
397
+		}
398
+
399
+		// PSR-0 lookup
400
+		if (false !== $pos = strrpos($class, '\\')) {
401
+			// namespaced class name
402
+			$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
403
+				. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
404
+		} else {
405
+			// PEAR-like class name
406
+			$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
407
+		}
408
+
409
+		if (isset($this->prefixesPsr0[$first])) {
410
+			foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
411
+				if (0 === strpos($class, $prefix)) {
412
+					foreach ($dirs as $dir) {
413
+						if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
414
+							return $file;
415
+						}
416
+					}
417
+				}
418
+			}
419
+		}
420
+
421
+		// PSR-0 fallback dirs
422
+		foreach ($this->fallbackDirsPsr0 as $dir) {
423
+			if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
424
+				return $file;
425
+			}
426
+		}
427
+
428
+		// PSR-0 include paths.
429
+		if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
430
+			return $file;
431
+		}
432
+
433
+		return false;
434
+	}
435 435
 }
436 436
 
437 437
 /**
@@ -441,5 +441,5 @@  discard block
 block discarded – undo
441 441
  */
442 442
 function includeFile($file)
443 443
 {
444
-    include $file;
444
+	include $file;
445 445
 }
Please login to merge, or discard this patch.
sources/subs/Maintenance.subs.php 1 patch
Switch Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -348,8 +348,8 @@  discard block
 block discarded – undo
348 348
 
349 349
 	switch ($type)
350 350
 	{
351
-		case 'posts':
352
-			$db->fetchQuery('
351
+	case 'posts':
352
+		$db->fetchQuery('
353 353
 				SELECT 
354 354
 					/*!40001 SQL_NO_CACHE */ m.id_board, COUNT(*) AS real_num_posts
355 355
 				FROM {db_prefix}messages AS m
@@ -357,29 +357,29 @@  discard block
 block discarded – undo
357 357
 					AND m.id_topic <= {int:id_topic_max}
358 358
 					AND m.approved = {int:is_approved}
359 359
 				GROUP BY m.id_board',
360
-				array(
361
-					'id_topic_min' => $start,
362
-					'id_topic_max' => $start + $increment,
363
-					'is_approved' => 1,
364
-				)
365
-			)->fetch_callback(
366
-				function ($row) use ($db) {
367
-					$db->query('', '
360
+			array(
361
+				'id_topic_min' => $start,
362
+				'id_topic_max' => $start + $increment,
363
+				'is_approved' => 1,
364
+			)
365
+		)->fetch_callback(
366
+			function ($row) use ($db) {
367
+				$db->query('', '
368 368
 					UPDATE {db_prefix}boards
369 369
 					SET 
370 370
 						num_posts = num_posts + {int:real_num_posts}
371 371
 					WHERE id_board = {int:id_board}',
372
-						array(
373
-							'id_board' => $row['id_board'],
374
-							'real_num_posts' => $row['real_num_posts'],
375
-						)
376
-					);
377
-				}
378
-			);
379
-			break;
372
+					array(
373
+						'id_board' => $row['id_board'],
374
+						'real_num_posts' => $row['real_num_posts'],
375
+					)
376
+				);
377
+			}
378
+		);
379
+		break;
380 380
 
381
-		case 'topics':
382
-			$db->fetchQuery('
381
+	case 'topics':
382
+		$db->fetchQuery('
383 383
 				SELECT 
384 384
 					/*!40001 SQL_NO_CACHE */ t.id_board, COUNT(*) AS real_num_topics
385 385
 				FROM {db_prefix}topics AS t
@@ -387,29 +387,29 @@  discard block
 block discarded – undo
387 387
 					AND t.id_topic > {int:id_topic_min}
388 388
 					AND t.id_topic <= {int:id_topic_max}
389 389
 				GROUP BY t.id_board',
390
-				array(
391
-					'is_approved' => 1,
392
-					'id_topic_min' => $start,
393
-					'id_topic_max' => $start + $increment,
394
-				)
395
-			)->fetch_callback(
396
-				function ($row) use ($db) {
397
-					$db->query('', '
390
+			array(
391
+				'is_approved' => 1,
392
+				'id_topic_min' => $start,
393
+				'id_topic_max' => $start + $increment,
394
+			)
395
+		)->fetch_callback(
396
+			function ($row) use ($db) {
397
+				$db->query('', '
398 398
 					UPDATE {db_prefix}boards
399 399
 					SET 
400 400
 						num_topics = num_topics + {int:real_num_topics}
401 401
 					WHERE id_board = {int:id_board}',
402
-						array(
403
-							'id_board' => $row['id_board'],
404
-							'real_num_topics' => $row['real_num_topics'],
405
-						)
406
-					);
407
-				}
408
-			);
409
-			break;
402
+					array(
403
+						'id_board' => $row['id_board'],
404
+						'real_num_topics' => $row['real_num_topics'],
405
+					)
406
+				);
407
+			}
408
+		);
409
+		break;
410 410
 
411
-		case 'unapproved_posts':
412
-			$db->fetchQuery('
411
+	case 'unapproved_posts':
412
+		$db->fetchQuery('
413 413
 				SELECT 
414 414
 					/*!40001 SQL_NO_CACHE */ m.id_board, COUNT(*) AS real_unapproved_posts
415 415
 				FROM {db_prefix}messages AS m
@@ -417,28 +417,28 @@  discard block
 block discarded – undo
417 417
 					AND m.id_topic <= {int:id_topic_max}
418 418
 					AND m.approved = {int:is_approved}
419 419
 				GROUP BY m.id_board',
420
-				array(
421
-					'id_topic_min' => $start,
422
-					'id_topic_max' => $start + $increment,
423
-					'is_approved' => 0,
424
-				)
425
-			)->fetch_callback(
426
-				function ($row) use ($db) {
427
-					$db->query('', '
420
+			array(
421
+				'id_topic_min' => $start,
422
+				'id_topic_max' => $start + $increment,
423
+				'is_approved' => 0,
424
+			)
425
+		)->fetch_callback(
426
+			function ($row) use ($db) {
427
+				$db->query('', '
428 428
 					UPDATE {db_prefix}boards
429 429
 					SET unapproved_posts = unapproved_posts + {int:unapproved_posts}
430 430
 					WHERE id_board = {int:id_board}',
431
-						array(
432
-							'id_board' => $row['id_board'],
433
-							'unapproved_posts' => $row['real_unapproved_posts'],
434
-						)
435
-					);
436
-				}
437
-			);
438
-			break;
431
+					array(
432
+						'id_board' => $row['id_board'],
433
+						'unapproved_posts' => $row['real_unapproved_posts'],
434
+					)
435
+				);
436
+			}
437
+		);
438
+		break;
439 439
 
440
-		case 'unapproved_topics':
441
-			$db->fetchQuery('
440
+	case 'unapproved_topics':
441
+		$db->fetchQuery('
442 442
 				SELECT 
443 443
 					/*!40001 SQL_NO_CACHE */ t.id_board, COUNT(*) AS real_unapproved_topics
444 444
 				FROM {db_prefix}topics AS t
@@ -446,28 +446,28 @@  discard block
 block discarded – undo
446 446
 					AND t.id_topic > {int:id_topic_min}
447 447
 					AND t.id_topic <= {int:id_topic_max}
448 448
 				GROUP BY t.id_board',
449
-				array(
450
-					'is_approved' => 0,
451
-					'id_topic_min' => $start,
452
-					'id_topic_max' => $start + $increment,
453
-				)
454
-			)->fetch_callback(
455
-				function ($row) use ($db) {
456
-					$db->query('', '
449
+			array(
450
+				'is_approved' => 0,
451
+				'id_topic_min' => $start,
452
+				'id_topic_max' => $start + $increment,
453
+			)
454
+		)->fetch_callback(
455
+			function ($row) use ($db) {
456
+				$db->query('', '
457 457
 					UPDATE {db_prefix}boards
458 458
 					SET unapproved_topics = unapproved_topics + {int:real_unapproved_topics}
459 459
 					WHERE id_board = {int:id_board}',
460
-						array(
461
-							'id_board' => $row['id_board'],
462
-							'real_unapproved_topics' => $row['real_unapproved_topics'],
463
-						)
464
-					);
465
-				}
466
-			);
467
-			break;
460
+					array(
461
+						'id_board' => $row['id_board'],
462
+						'real_unapproved_topics' => $row['real_unapproved_topics'],
463
+					)
464
+				);
465
+			}
466
+		);
467
+		break;
468 468
 
469
-		default:
470
-			trigger_error('updateBoardsCounter(): Invalid counter type \'' . $type . '\'', E_USER_NOTICE);
469
+	default:
470
+		trigger_error('updateBoardsCounter(): Invalid counter type \'' . $type . '\'', E_USER_NOTICE);
471 471
 	}
472 472
 }
473 473
 
Please login to merge, or discard this patch.
sources/subs/Profile.subs.php 1 patch
Switch Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1843,13 +1843,13 @@
 block discarded – undo
1843 1843
 			{
1844 1844
 				switch ($is_valid)
1845 1845
 				{
1846
-					case 'custom_field_too_long':
1847
-						$value = Util::substr($value, 0, $row['field_length']);
1848
-						break;
1849
-					case 'custom_field_invalid_email':
1850
-					case 'custom_field_inproper_format':
1851
-						$value = $row['default_value'];
1852
-						break;
1846
+				case 'custom_field_too_long':
1847
+					$value = Util::substr($value, 0, $row['field_length']);
1848
+					break;
1849
+				case 'custom_field_invalid_email':
1850
+				case 'custom_field_inproper_format':
1851
+					$value = $row['default_value'];
1852
+					break;
1853 1853
 				}
1854 1854
 			}
1855 1855
 
Please login to merge, or discard this patch.
sources/subs/Membergroups.subs.php 1 patch
Switch Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1525,11 +1525,11 @@
 block discarded – undo
1525 1525
 			$updates[] = $name . '={' . $known_properties[$name]['type'] . ':subs_' . $name . '}';
1526 1526
 			switch ($known_properties[$name]['type'])
1527 1527
 			{
1528
-				case 'string':
1529
-					$values['subs_' . $name] = Util::htmlspecialchars((string) $value);
1530
-					break;
1531
-				default:
1532
-					$values['subs_' . $name] = (int) $value;
1528
+			case 'string':
1529
+				$values['subs_' . $name] = Util::htmlspecialchars((string) $value);
1530
+				break;
1531
+			default:
1532
+				$values['subs_' . $name] = (int) $value;
1533 1533
 			}
1534 1534
 		}
1535 1535
 	}
Please login to merge, or discard this patch.
sources/subs/PaidSubscriptions.subs.php 1 patch
Switch Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -220,20 +220,20 @@  discard block
 block discarded – undo
220 220
 	{
221 221
 		switch ($renewal)
222 222
 		{
223
-			case 'D':
224
-				$duration = 86400;
225
-				break;
226
-			case 'W':
227
-				$duration = 604800;
228
-				break;
229
-			case 'M':
230
-				$duration = 2629743;
231
-				break;
232
-			case 'Y':
233
-				$duration = 31556926;
234
-				break;
235
-			default:
236
-				break;
223
+		case 'D':
224
+			$duration = 86400;
225
+			break;
226
+		case 'W':
227
+			$duration = 604800;
228
+			break;
229
+		case 'M':
230
+			$duration = 2629743;
231
+			break;
232
+		case 'Y':
233
+			$duration = 31556926;
234
+			break;
235
+		default:
236
+			break;
237 237
 		}
238 238
 	}
239 239
 
@@ -505,24 +505,24 @@  discard block
 block discarded – undo
505 505
 				$length = $match[1] . ' ';
506 506
 				switch ($match[2])
507 507
 				{
508
-					case 'D':
509
-						$length .= $txt['paid_mod_span_days'];
510
-						$num_length *= 86400;
511
-						break;
512
-					case 'W':
513
-						$length .= $txt['paid_mod_span_weeks'];
514
-						$num_length *= 604800;
515
-						break;
516
-					case 'M':
517
-						$length .= $txt['paid_mod_span_months'];
518
-						$num_length *= 2629743;
519
-						break;
520
-					case 'Y':
521
-						$length .= $txt['paid_mod_span_years'];
522
-						$num_length *= 31556926;
523
-						break;
524
-					default:
525
-						$length = '??';
508
+				case 'D':
509
+					$length .= $txt['paid_mod_span_days'];
510
+					$num_length *= 86400;
511
+					break;
512
+				case 'W':
513
+					$length .= $txt['paid_mod_span_weeks'];
514
+					$num_length *= 604800;
515
+					break;
516
+				case 'M':
517
+					$length .= $txt['paid_mod_span_months'];
518
+					$num_length *= 2629743;
519
+					break;
520
+				case 'Y':
521
+					$length .= $txt['paid_mod_span_years'];
522
+					$num_length *= 31556926;
523
+					break;
524
+				default:
525
+					$length = '??';
526 526
 				}
527 527
 			}
528 528
 
Please login to merge, or discard this patch.
sources/subs/Maillist.subs.php 1 patch
Switch Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -105,15 +105,15 @@
 block discarded – undo
105 105
 			// Build a link to the topic or message in case someone wants to take a look at that thread
106 106
 			switch ($row['message_type'])
107 107
 			{
108
-				case 't':
109
-					$postemail[$i]['link'] = $boardurl . '?topic=' . $row['message_id'];
110
-					break;
111
-				case 'm':
112
-					$postemail[$i]['link'] = $boardurl . '?msg=' . $row['message_id'];
113
-					break;
114
-				case 'p':
115
-					$postemail[$i]['subject'] = $txt['private'];
116
-					break;
108
+			case 't':
109
+				$postemail[$i]['link'] = $boardurl . '?topic=' . $row['message_id'];
110
+				break;
111
+			case 'm':
112
+				$postemail[$i]['link'] = $boardurl . '?msg=' . $row['message_id'];
113
+				break;
114
+			case 'p':
115
+				$postemail[$i]['subject'] = $txt['private'];
116
+				break;
117 117
 			}
118 118
 
119 119
 			$i++;
Please login to merge, or discard this patch.
sources/subs/Post.subs.php 1 patch
Switch Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -1152,32 +1152,32 @@  discard block
 block discarded – undo
1152 1152
 	switch ($editing)
1153 1153
 	{
1154 1154
 		// Modifying an existing message
1155
-		case 1:
1156
-			require_once(SUBSDIR . '/Messages.subs.php');
1155
+	case 1:
1156
+		require_once(SUBSDIR . '/Messages.subs.php');
1157 1157
 
1158
-			// Get the existing message.
1159
-			$message = messageDetails((int) $msg_id, (int) $topic);
1158
+		// Get the existing message.
1159
+		$message = messageDetails((int) $msg_id, (int) $topic);
1160 1160
 
1161
-			// The message they were trying to edit was most likely deleted.
1162
-			if ($message === false)
1163
-			{
1164
-				return false;
1165
-			}
1161
+		// The message they were trying to edit was most likely deleted.
1162
+		if ($message === false)
1163
+		{
1164
+			return false;
1165
+		}
1166 1166
 
1167
-			$errors = checkMessagePermissions($message['message']);
1167
+		$errors = checkMessagePermissions($message['message']);
1168 1168
 
1169
-			prepareMessageContext($message);
1169
+		prepareMessageContext($message);
1170 1170
 
1171
-			if (!empty($errors))
1172
-			{
1173
-				$message['errors'] = $errors;
1174
-			}
1171
+		if (!empty($errors))
1172
+		{
1173
+			$message['errors'] = $errors;
1174
+		}
1175 1175
 
1176
-			return $message;
1177
-		// Posting a quoted reply?
1178
-		case 2:
1179
-			// Make sure they _can_ quote this post, and if so get it.
1180
-			$request = $db->query('', '
1176
+		return $message;
1177
+	// Posting a quoted reply?
1178
+	case 2:
1179
+		// Make sure they _can_ quote this post, and if so get it.
1180
+		$request = $db->query('', '
1181 1181
 				SELECT
1182 1182
 					m.subject, COALESCE(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.body
1183 1183
 				FROM {db_prefix}messages AS m
@@ -1186,60 +1186,60 @@  discard block
 block discarded – undo
1186 1186
 				WHERE m.id_msg = {int:id_msg}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
1187 1187
 					AND m.approved = {int:is_approved}') . '
1188 1188
 				LIMIT 1',
1189
-				array(
1190
-					'id_msg' => $msg_id,
1191
-					'is_approved' => 1,
1192
-				)
1193
-			);
1194
-			if ($request->num_rows() == 0)
1195
-			{
1196
-				throw new \ElkArte\Exceptions\Exception('quoted_post_deleted', false);
1197
-			}
1198
-			list ($form_subject, $mname, $mdate, $form_message) = $request->fetch_row();
1199
-			$request->free_result();
1189
+			array(
1190
+				'id_msg' => $msg_id,
1191
+				'is_approved' => 1,
1192
+			)
1193
+		);
1194
+		if ($request->num_rows() == 0)
1195
+		{
1196
+			throw new \ElkArte\Exceptions\Exception('quoted_post_deleted', false);
1197
+		}
1198
+		list ($form_subject, $mname, $mdate, $form_message) = $request->fetch_row();
1199
+		$request->free_result();
1200 1200
 
1201
-			// Add 'Re: ' to the front of the quoted subject.
1202
-			$response_prefix = response_prefix();
1203
-			if (trim($response_prefix) != '' && Util::strpos($form_subject, trim($response_prefix)) !== 0)
1204
-			{
1205
-				$form_subject = $response_prefix . $form_subject;
1206
-			}
1201
+		// Add 'Re: ' to the front of the quoted subject.
1202
+		$response_prefix = response_prefix();
1203
+		if (trim($response_prefix) != '' && Util::strpos($form_subject, trim($response_prefix)) !== 0)
1204
+		{
1205
+			$form_subject = $response_prefix . $form_subject;
1206
+		}
1207 1207
 
1208
-			// Censor the message and subject.
1209
-			$form_message = censor($form_message);
1210
-			$form_subject = censor($form_subject);
1208
+		// Censor the message and subject.
1209
+		$form_message = censor($form_message);
1210
+		$form_subject = censor($form_subject);
1211 1211
 
1212
-			$form_message = un_preparsecode($form_message);
1213
-			$form_message = removeNestedQuotes($form_message);
1212
+		$form_message = un_preparsecode($form_message);
1213
+		$form_message = removeNestedQuotes($form_message);
1214 1214
 
1215
-			// Add a quote string on the front and end.
1216
-			$form_message = '[quote author=' . $mname . ' link=msg=' . (int) $msg_id . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
1215
+		// Add a quote string on the front and end.
1216
+		$form_message = '[quote author=' . $mname . ' link=msg=' . (int) $msg_id . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
1217 1217
 
1218
-			break;
1219
-		// Posting a reply without a quote?
1220
-		case 3:
1221
-			// Get the first message's subject.
1222
-			$form_subject = $first_subject;
1218
+		break;
1219
+	// Posting a reply without a quote?
1220
+	case 3:
1221
+		// Get the first message's subject.
1222
+		$form_subject = $first_subject;
1223 1223
 
1224
-			// Add 'Re: ' to the front of the subject.
1225
-			$response_prefix = response_prefix();
1226
-			if (trim($response_prefix) != '' && $form_subject != '' && Util::strpos($form_subject, trim($response_prefix)) !== 0)
1227
-			{
1228
-				$form_subject = $response_prefix . $form_subject;
1229
-			}
1224
+		// Add 'Re: ' to the front of the subject.
1225
+		$response_prefix = response_prefix();
1226
+		if (trim($response_prefix) != '' && $form_subject != '' && Util::strpos($form_subject, trim($response_prefix)) !== 0)
1227
+		{
1228
+			$form_subject = $response_prefix . $form_subject;
1229
+		}
1230 1230
 
1231
-			// Censor the subject.
1232
-			$form_subject = censor($form_subject);
1231
+		// Censor the subject.
1232
+		$form_subject = censor($form_subject);
1233 1233
 
1234
-			$form_message = '';
1234
+		$form_message = '';
1235 1235
 
1236
-			break;
1237
-		case 4:
1238
-		default:
1239
-			$form_subject = $first_subject;
1240
-			$form_message = '';
1236
+		break;
1237
+	case 4:
1238
+	default:
1239
+		$form_subject = $first_subject;
1240
+		$form_message = '';
1241 1241
 
1242
-			break;
1242
+		break;
1243 1243
 	}
1244 1244
 
1245 1245
 	return array($form_subject, $form_message);
Please login to merge, or discard this patch.
sources/subs/Sound.subs.php 1 patch
Switch Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -80,36 +80,36 @@
 block discarded – undo
80 80
 		$sound_letter = substr($sound_letter, strpos($sound_letter, 'data') + 8);
81 81
 		switch ($word[$i] === 's' ? 0 : mt_rand(0, 2))
82 82
 		{
83
-			case 0:
84
-				for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++)
83
+		case 0:
84
+			for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++)
85
+			{
86
+				for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++)
85 87
 				{
86
-					for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++)
87
-					{
88
-						$sound_word .= $word[$i] === 's' ? $sound_letter[$j] : chr(mt_rand(max(ord($sound_letter[$j]) - 1, 0x00), min(ord($sound_letter[$j]) + 1, 0xFF)));
89
-					}
88
+					$sound_word .= $word[$i] === 's' ? $sound_letter[$j] : chr(mt_rand(max(ord($sound_letter[$j]) - 1, 0x00), min(ord($sound_letter[$j]) + 1, 0xFF)));
90 89
 				}
91
-				break;
92
-			case 1:
93
-				for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2)
90
+			}
91
+			break;
92
+		case 1:
93
+			for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2)
94
+			{
95
+				$sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter[$j]) . (mt_rand(0, 3) === 0 ? $sound_letter[$j + 1] : $sound_letter[$j]) . (mt_rand(0, 3) === 0 ? $sound_letter[$j] : $sound_letter[$j + 1]) . $sound_letter[$j + 1] . (mt_rand(0, 3) == 0 ? $sound_letter[$j + 1] : '');
96
+			}
97
+			$sound_word .= str_repeat($sound_letter[$n], 2);
98
+			break;
99
+		case 2:
100
+			$shift = 0;
101
+			for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++)
102
+			{
103
+				if (mt_rand(0, 10) === 0)
94 104
 				{
95
-					$sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter[$j]) . (mt_rand(0, 3) === 0 ? $sound_letter[$j + 1] : $sound_letter[$j]) . (mt_rand(0, 3) === 0 ? $sound_letter[$j] : $sound_letter[$j + 1]) . $sound_letter[$j + 1] . (mt_rand(0, 3) == 0 ? $sound_letter[$j + 1] : '');
105
+					$shift += mt_rand(-3, 3);
96 106
 				}
97
-				$sound_word .= str_repeat($sound_letter[$n], 2);
98
-				break;
99
-			case 2:
100
-				$shift = 0;
101
-				for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++)
107
+				for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++)
102 108
 				{
103
-					if (mt_rand(0, 10) === 0)
104
-					{
105
-						$shift += mt_rand(-3, 3);
106
-					}
107
-					for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++)
108
-					{
109
-						$sound_word .= chr(min(max(ord($sound_letter[$j]) + $shift, 0x00), 0xFF));
110
-					}
109
+					$sound_word .= chr(min(max(ord($sound_letter[$j]) + $shift, 0x00), 0xFF));
111 110
 				}
112
-				break;
111
+			}
112
+			break;
113 113
 		}
114 114
 
115 115
 		$sound_word .= str_repeat(chr(0x80), mt_rand(10000, 10500));
Please login to merge, or discard this patch.
sources/subs/ManageAttachments.subs.php 1 patch
Switch Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -155,34 +155,34 @@
 block discarded – undo
155 155
 
156 156
 			switch ($type)
157 157
 			{
158
-				case 'id_member':
159
-				case 'id_attach':
160
-				case 'id_msg':
161
-					// @todo the !empty($restriction) is a trick to override the checks on $_POST['attach_del'] in Post.controller
162
-					// In theory it should not be necessary
163
-					if (!empty($restriction))
164
-					{
165
-						$new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')';
166
-					}
167
-					break;
168
-				case 'attachment_type':
169
-					$new_condition[] = 'a.attachment_type = {int:' . $real_type . '}';
170
-					break;
171
-				case 'poster_time':
172
-					$new_condition[] = 'm.poster_time < {int:' . $real_type . '}';
173
-					break;
174
-				case 'last_login':
175
-					$new_condition[] = 'mem.last_login < {int:' . $real_type . '}';
176
-					break;
177
-				case 'size':
178
-					$new_condition[] = 'a.size > {int:' . $real_type . '}';
179
-					break;
180
-				case 'id_topic':
181
-					$new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')';
182
-					break;
183
-				case 'do_logging':
184
-					$do_logging = $condition['id_attach'];
185
-					break;
158
+			case 'id_member':
159
+			case 'id_attach':
160
+			case 'id_msg':
161
+				// @todo the !empty($restriction) is a trick to override the checks on $_POST['attach_del'] in Post.controller
162
+				// In theory it should not be necessary
163
+				if (!empty($restriction))
164
+				{
165
+					$new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')';
166
+				}
167
+				break;
168
+			case 'attachment_type':
169
+				$new_condition[] = 'a.attachment_type = {int:' . $real_type . '}';
170
+				break;
171
+			case 'poster_time':
172
+				$new_condition[] = 'm.poster_time < {int:' . $real_type . '}';
173
+				break;
174
+			case 'last_login':
175
+				$new_condition[] = 'mem.last_login < {int:' . $real_type . '}';
176
+				break;
177
+			case 'size':
178
+				$new_condition[] = 'a.size > {int:' . $real_type . '}';
179
+				break;
180
+			case 'id_topic':
181
+				$new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')';
182
+				break;
183
+			case 'do_logging':
184
+				$do_logging = $condition['id_attach'];
185
+				break;
186 186
 			}
187 187
 
188 188
 			// Add the parameter!
Please login to merge, or discard this patch.