| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfAutoloadAgain |
|---|
| 20 |
{ |
|---|
| 21 |
static protected |
|---|
| 22 |
$instance = null; |
|---|
| 23 |
|
|---|
| 24 |
protected |
|---|
| 25 |
$registered = false, |
|---|
| 26 |
$reloaded = false; |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
* Returns the singleton autoloader. |
|---|
| 30 |
* |
|---|
| 31 |
* @return sfAutoloadAgain |
|---|
| 32 |
*/ |
|---|
| 33 |
static public function getInstance() |
|---|
| 34 |
{ |
|---|
| 35 |
if (null === self::$instance) |
|---|
| 36 |
{ |
|---|
| 37 |
self::$instance = new self(); |
|---|
| 38 |
} |
|---|
| 39 |
|
|---|
| 40 |
return self::$instance; |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
* Constructor. |
|---|
| 45 |
*/ |
|---|
| 46 |
protected function __construct() |
|---|
| 47 |
{ |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
* Reloads the autoloader. |
|---|
| 52 |
* |
|---|
| 53 |
* @param string $class |
|---|
| 54 |
* |
|---|
| 55 |
* @return boolean |
|---|
| 56 |
*/ |
|---|
| 57 |
public function autoload($class) |
|---|
| 58 |
{ |
|---|
| 59 |
|
|---|
| 60 |
if ($this->reloaded) |
|---|
| 61 |
{ |
|---|
| 62 |
return false; |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
$autoloads = spl_autoload_functions(); |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
if (version_compare(PHP_VERSION, '5.2.11', '>=')) |
|---|
| 69 |
{ |
|---|
| 70 |
foreach ($autoloads as $position => $autoload) |
|---|
| 71 |
{ |
|---|
| 72 |
if (is_array($autoload) && $this === $autoload[0]) |
|---|
| 73 |
{ |
|---|
| 74 |
break; |
|---|
| 75 |
} |
|---|
| 76 |
} |
|---|
| 77 |
} |
|---|
| 78 |
else |
|---|
| 79 |
{ |
|---|
| 80 |
$position = array_search(array(__CLASS__, 'autoload'), $autoloads, true); |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
if (isset($autoloads[$position + 1])) |
|---|
| 84 |
{ |
|---|
| 85 |
$this->unregister(); |
|---|
| 86 |
$this->register(); |
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
spl_autoload_call($class); |
|---|
| 90 |
|
|---|
| 91 |
return class_exists($class, false) || interface_exists($class, false); |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
$autoload = sfAutoload::getInstance(); |
|---|
| 95 |
$autoload->reloadClasses(true); |
|---|
| 96 |
|
|---|
| 97 |
$this->reloaded = true; |
|---|
| 98 |
|
|---|
| 99 |
return $autoload->autoload($class); |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
* Returns true if the autoloader is registered. |
|---|
| 104 |
* |
|---|
| 105 |
* @return boolean |
|---|
| 106 |
*/ |
|---|
| 107 |
public function isRegistered() |
|---|
| 108 |
{ |
|---|
| 109 |
return $this->registered; |
|---|
| 110 |
} |
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
* Registers the autoloader function. |
|---|
| 114 |
*/ |
|---|
| 115 |
public function register() |
|---|
| 116 |
{ |
|---|
| 117 |
if (!$this->isRegistered()) |
|---|
| 118 |
{ |
|---|
| 119 |
spl_autoload_register(array($this, 'autoload')); |
|---|
| 120 |
$this->registered = true; |
|---|
| 121 |
} |
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
* Unregisters the autoloader function. |
|---|
| 126 |
*/ |
|---|
| 127 |
public function unregister() |
|---|
| 128 |
{ |
|---|
| 129 |
spl_autoload_unregister(array($this, 'autoload')); |
|---|
| 130 |
$this->registered = false; |
|---|
| 131 |
} |
|---|
| 132 |
} |
|---|
| 133 |
|
|---|