| Total Complexity | 8 |
| Total Lines | 74 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 5 | class AliasLoader |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * The singleton instance of the loader. |
||
| 9 | * |
||
| 10 | * @var AliasLoader |
||
| 11 | */ |
||
| 12 | protected static $instance; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * The array of class aliases. |
||
| 16 | * |
||
| 17 | * @var array |
||
| 18 | */ |
||
| 19 | protected $aliases; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Indicates if a loader has been registered. |
||
| 23 | * |
||
| 24 | * @var bool |
||
| 25 | */ |
||
| 26 | protected $registered = false; |
||
| 27 | |||
| 28 | private function __construct(array $aliases) |
||
| 29 | { |
||
| 30 | $this->aliases = $aliases; |
||
| 31 | } |
||
| 32 | |||
| 33 | private function __clone() |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Get or create the singleton alias loader instance. |
||
| 39 | * |
||
| 40 | * @return AliasLoader |
||
| 41 | */ |
||
| 42 | public static function getInstance(array $aliases = []) |
||
| 43 | { |
||
| 44 | if (is_null(static::$instance)) { |
||
| 45 | return static::$instance = new static($aliases); |
||
| 46 | } |
||
| 47 | |||
| 48 | $aliases = array_merge(static::$instance->aliases, $aliases); |
||
| 49 | |||
| 50 | static::$instance->aliases = $aliases; |
||
| 51 | |||
| 52 | return static::$instance; |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Load a class alias if it is registered. |
||
| 57 | * |
||
| 58 | * @param string $alias |
||
| 59 | * |
||
| 60 | * @return bool|null |
||
| 61 | */ |
||
| 62 | public function load($alias) |
||
| 63 | { |
||
| 64 | if (isset($this->aliases[$alias])) { |
||
| 65 | return class_alias($this->aliases[$alias], $alias); |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Register the loader on the auto-loader stack. |
||
| 71 | * |
||
| 72 | * @return void |
||
| 73 | */ |
||
| 74 | public function register() |
||
| 79 | } |
||
| 80 | } |
||
| 81 | } |
||
| 82 |