Changeset View
Changeset View
Standalone View
Standalone View
src/moduleutils/PhutilBootloader.php
| <?php | <?php | ||||
| /** | /** | ||||
| * IMPORTANT: Do not call any libphutil functions in this class, including | * IMPORTANT: Do not call any libphutil functions in this class, including | ||||
| * functions like @{function:id}, @{function:idx} and @{function:pht}. They | * functions like @{function:id}, @{function:idx} and @{function:pht}. They | ||||
| * may not have loaded yet. | * may not have loaded yet. | ||||
| */ | */ | ||||
| final class PhutilBootloader { | final class PhutilBootloader { | ||||
| private static $instance; | private static $instance; | ||||
| private $registeredLibraries = array(); | private $registeredLibraries = array(); | ||||
| private $libraryMaps = array(); | private $libraryMaps = array(); | ||||
| private $extensionMaps = array(); | private $extensionMaps = array(); | ||||
| private $extendedMaps = array(); | |||||
| private $currentLibrary = null; | private $currentLibrary = null; | ||||
| private $classTree = array(); | private $classTree = array(); | ||||
| private $inMemoryMaps = array(); | private $inMemoryMaps = array(); | ||||
| public static function getInstance() { | public static function getInstance() { | ||||
| if (!self::$instance) { | if (!self::$instance) { | ||||
| self::$instance = new PhutilBootloader(); | self::$instance = new PhutilBootloader(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | final class PhutilBootloader { | ||||
| } | } | ||||
| public function registerLibraryMap(array $map) { | public function registerLibraryMap(array $map) { | ||||
| $this->libraryMaps[$this->currentLibrary] = $map; | $this->libraryMaps[$this->currentLibrary] = $map; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getLibraryMap($name) { | public function getLibraryMap($name) { | ||||
| if (isset($this->extendedMaps[$name])) { | |||||
| return $this->extendedMaps[$name]; | |||||
| } | |||||
| if (empty($this->libraryMaps[$name])) { | if (empty($this->libraryMaps[$name])) { | ||||
| $root = $this->getLibraryRoot($name); | $root = $this->getLibraryRoot($name); | ||||
| $this->currentLibrary = $name; | $this->currentLibrary = $name; | ||||
| if (isset($this->inMemoryMaps[$name])) { | if (isset($this->inMemoryMaps[$name])) { | ||||
| $this->libraryMaps[$name] = $this->inMemoryMaps[$name]; | $this->libraryMaps[$name] = $this->inMemoryMaps[$name]; | ||||
| } else { | } else { | ||||
| $okay = include $root.'/__phutil_library_map__.php'; | $okay = include $root.'/__phutil_library_map__.php'; | ||||
| Show All 37 Lines | if (isset($this->extensionMaps[$name])) { | ||||
| foreach (array('function', 'class', 'xmap') as $dict_key) { | foreach (array('function', 'class', 'xmap') as $dict_key) { | ||||
| if (!isset($emap[$dict_key])) { | if (!isset($emap[$dict_key])) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| $map[$dict_key] += $emap[$dict_key]; | $map[$dict_key] += $emap[$dict_key]; | ||||
| } | } | ||||
| } | } | ||||
| $this->extendedMaps[$name] = $map; | |||||
| return $map; | return $map; | ||||
| } | } | ||||
| public function getLibraryMapWithoutExtensions($name) { | public function getLibraryMapWithoutExtensions($name) { | ||||
| // This just does all the checks to make sure the library is valid, then | // This just does all the checks to make sure the library is valid, then | ||||
| // we throw away the result. | // we throw away the result. | ||||
| $this->getLibraryMap($name); | $this->getLibraryMap($name); | ||||
| ▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | foreach ($add_classes + $add_interfaces as $class => $ignored) { | ||||
| if (count($xmap) == 1) { | if (count($xmap) == 1) { | ||||
| $xmap = head($xmap); | $xmap = head($xmap); | ||||
| } | } | ||||
| $this->extensionMaps[$library]['xmap'][$class] = $xmap; | $this->extensionMaps[$library]['xmap'][$class] = $xmap; | ||||
| } | } | ||||
| } | } | ||||
| // Clear the extended library cache (should one exist) so we know that | |||||
| // we need to rebuild it. | |||||
| unset($this->extendedMaps[$library]); | |||||
| } | } | ||||
| } | } | ||||