public function registerLibrary($name, $path)
 {
     if (basename($path) != '__phutil_library_init__.php') {
         throw new PhutilBootloaderException('Only directories with a __phutil_library_init__.php file may be ' . 'registered as libphutil libraries.');
     }
     $path = dirname($path);
     // Detect attempts to load the same library multiple times from different
     // locations. This might mean you're doing something silly like trying to
     // include two different versions of something, or it might mean you're
     // doing something subtle like running a different version of 'arc' on a
     // working copy of Arcanist.
     if (isset($this->registeredLibraries[$name])) {
         $old_path = $this->registeredLibraries[$name];
         if ($old_path != $path) {
             throw new PhutilLibraryConflictException($name, $old_path, $path);
         }
     }
     $this->registeredLibraries[$name] = $path;
     // For libphutil v2 libraries, load all functions when we load the library.
     if (!class_exists('PhutilSymbolLoader', false)) {
         $root = $this->getLibraryRoot('phutil');
         $this->executeInclude($root . '/symbols/PhutilSymbolLoader.php');
     }
     $loader = new PhutilSymbolLoader();
     $loader->setLibrary($name)->setType('function');
     try {
         $loader->selectAndLoadSymbols();
     } catch (PhutilBootloaderException $ex) {
         // Ignore this, it happens if a global function's file is removed or
         // similar. Worst case is that we fatal when calling the function, which
         // is no worse than fataling here.
     } catch (PhutilMissingSymbolException $ex) {
         // Ignore this, it happens if a global function is removed. Everything
         // else loaded so proceed forward: worst case is a fatal when we
         // hit a function call to a function which no longer exists, which is
         // no worse than fataling here.
     }
     if (empty($_SERVER['PHUTIL_DISABLE_RUNTIME_EXTENSIONS'])) {
         $extdir = $path . DIRECTORY_SEPARATOR . 'extensions';
         if (Filesystem::pathExists($extdir)) {
             $extensions = id(new FileFinder($extdir))->withSuffix('php')->withType('f')->withFollowSymlinks(true)->setForceMode('php')->find();
             foreach ($extensions as $extension) {
                 $this->loadExtension($name, $path, $extdir . DIRECTORY_SEPARATOR . $extension);
             }
         }
     }
     return $this;
 }
Пример #2
0
 public function registerLibrary($name, $path)
 {
     if (basename($path) != '__phutil_library_init__.php') {
         throw new PhutilBootloaderException('Only directories with a __phutil_library_init__.php file may be ' . 'registered as libphutil libraries.');
     }
     $path = dirname($path);
     // Detect attempts to load the same library multiple times from different
     // locations. This might mean you're doing something silly like trying to
     // include two different versions of something, or it might mean you're
     // doing something subtle like running a different version of 'arc' on a
     // working copy of Arcanist.
     if (isset($this->registeredLibraries[$name])) {
         $old_path = $this->registeredLibraries[$name];
         if ($old_path != $path) {
             throw new PhutilLibraryConflictException($name, $old_path, $path);
         }
     }
     $this->registeredLibraries[$name] = $path;
     // TODO: Remove this once we drop libphutil v1 support.
     $version = $this->getLibraryFormatVersion($name);
     if ($version == 1) {
         return $this;
     }
     // For libphutil v2 libraries, load all functions when we load the library.
     if (!class_exists('PhutilSymbolLoader', false)) {
         $root = $this->getLibraryRoot('phutil');
         $this->executeInclude($root . '/symbols/PhutilSymbolLoader.php');
     }
     $loader = new PhutilSymbolLoader();
     $loader->setLibrary($name)->setType('function');
     try {
         $loader->selectAndLoadSymbols();
     } catch (PhutilMissingSymbolException $ex) {
         // Ignore this, it happens if a global function is removed. Everything
         // else loaded so proceed forward: worst case is a fatal when we
         // hit a function call to a function which no longer exists, which is
         // no worse than fataling here.
     }
     return $this;
 }