1
|
|
|
<?php |
2
|
|
|
namespace SEOstats\Common; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* PSR-0 Autoloader |
6
|
|
|
* |
7
|
|
|
* @package SEOstats |
8
|
|
|
* @author Stephan Schmitz <[email protected]> |
9
|
|
|
* @copyright Copyright (c) 2010 - present Stephan Schmitz |
10
|
|
|
* @license http://eyecatchup.mit-license.org/ MIT License |
11
|
|
|
* @updated 2013/02/03 |
12
|
|
|
*/ |
13
|
|
|
class AutoLoader |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string The namespace prefix for this instance. |
17
|
|
|
*/ |
18
|
|
|
protected $namespace = ''; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string The filesystem prefix to use for this instance |
22
|
|
|
*/ |
23
|
|
|
protected $path = ''; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Build the instance of the autoloader |
27
|
|
|
* |
28
|
|
|
* @param string $namespace The prefixed namespace this instance will load |
29
|
|
|
* @param string $path The filesystem path to the root of the namespace |
30
|
|
|
*/ |
31
|
|
|
public function __construct($namespace, $path) |
32
|
|
|
{ |
33
|
|
|
$this->namespace = ltrim($namespace, '\\'); |
34
|
|
|
$this->path = rtrim($path, '/\\') . DIRECTORY_SEPARATOR; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Try to load a class |
39
|
|
|
* |
40
|
|
|
* @param string $class The class name to load |
|
|
|
|
41
|
|
|
* |
42
|
|
|
* @return boolean If the loading was successful |
43
|
|
|
*/ |
44
|
|
|
public function load($className) |
45
|
|
|
{ |
46
|
|
|
$class = ltrim($className, '\\'); |
47
|
|
|
|
48
|
|
|
if (strpos($class, $this->namespace) !== 0) { |
49
|
|
|
return false; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$nsparts = explode('\\', $class); |
53
|
|
|
$class = array_pop($nsparts); |
54
|
|
|
$nsparts[] = ''; |
55
|
|
|
$path = $this->path . implode(DIRECTORY_SEPARATOR, $nsparts); |
56
|
|
|
$path .= str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; |
57
|
|
|
|
58
|
|
|
if (!is_readable($path)) { |
59
|
|
|
return false; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
require $path; |
63
|
|
|
|
64
|
|
|
return class_exists($className,false); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Register the autoloader to PHP |
69
|
|
|
* |
70
|
|
|
* @return boolean The status of the registration |
71
|
|
|
*/ |
72
|
|
|
public function register() |
73
|
|
|
{ |
74
|
|
|
return spl_autoload_register(array($this, 'load')); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Unregister the autoloader to PHP |
79
|
|
|
* |
80
|
|
|
* @return boolean The status of the unregistration |
81
|
|
|
*/ |
82
|
|
|
public function unregister() |
83
|
|
|
{ |
84
|
|
|
return spl_autoload_unregister(array($this, 'load')); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.