Beispiel #1
0
 /**
  * Adds a source path element
  *
  * @param   string element
  */
 public function addSourcePath($element)
 {
     $resolved = realpath($element);
     if (is_dir($resolved)) {
         $l = FileSystemClassLoader::instanceFor($resolved, false);
     } else {
         if (is_file($resolved)) {
             $l = ArchiveClassLoader::instanceFor($resolved, false);
         } else {
             throw new \lang\IllegalArgumentException('Sourcepath element [' . $element . '] not found');
         }
     }
     $this->sourcepath[$l->hashCode()] = $l;
 }
 /**
  * Gets base folder
  *
  * @param   io.Folder
  */
 public function setBase(Folder $base)
 {
     $this->base = new Folder($base, '..');
     // Scan base path. FIXME: Refactor this to use lang.ClassLoader
     // instead of duplication its sourcecode here
     foreach (array_filter(explode(PATH_SEPARATOR, scanpath(array($base->getURI()), getenv('HOME')))) as $element) {
         $resolved = realpath($element);
         if (is_dir($resolved)) {
             $this->cl[] = \lang\FileSystemClassLoader::instanceFor($resolved, false);
         } else {
             if (is_file($resolved)) {
                 $this->cl[] = \lang\archive\ArchiveClassLoader::instanceFor($resolved, false);
             }
         }
     }
 }
Beispiel #3
0
 /**
  * Register a class loader from a path
  *
  * @param   string element
  * @param   bool before default FALSE whether to register this as the first loader,
  *          NULL wheather to figure out position by inspecting $element
  * @return  lang.IClassLoader the registered loader
  * @throws  lang.ElementNotFoundException if the path cannot be found
  */
 public static function registerPath($element, $before = false)
 {
     if (null === $before && '!' === $element[0]) {
         $before = true;
         $element = substr($element, 1);
     } else {
         $before = (bool) $before;
     }
     if (is_dir($element)) {
         return self::registerLoader(FileSystemClassLoader::instanceFor($element), $before);
     } else {
         if (is_file($element)) {
             return self::registerLoader(ArchiveClassLoader::instanceFor($element), $before);
         }
     }
     throw new ElementNotFoundException('Element "' . $element . '" not found');
 }
 /**
  * Execute this action
  *
  * @param  string[] $args command line args
  * @return int exit code
  */
 public function perform($args)
 {
     $cwd = new FileCollection('.');
     // Parse args
     $i = 1;
     if ('-r' === $args[0]) {
         $remote = true;
         array_shift($args);
         $i++;
     } else {
         if ('-i' === $args[0]) {
             $remote = false;
             array_shift($args);
             $i++;
             $installed = new File($args[0] . '.json');
         } else {
             $installed = new File($args[0] . '.json');
             $remote = !$installed->exists();
         }
     }
     if (empty($args)) {
         Console::$err->writeLine('*** Missing argument #', $i, ': Module name');
         return 2;
     }
     sscanf(rtrim($args[0], '/'), '%[^@]@%s', $name, $version);
     $module = Module::valueOf($name);
     // Search for module
     if ($remote) {
         Console::writeLine('@', $this->api->getBase()->getURL());
         $request = create(new RestRequest('/vendors/{vendor}/modules/{module}'))->withSegment('vendor', $module->vendor)->withSegment('module', $module->name);
         try {
             $result = $this->api->execute($request)->data();
         } catch (RestException $e) {
             Console::$err->writeLine('*** Cannot find remote module ', $module, ': ', $e->getMessage());
             return 3;
         }
         $releases = $result['releases'];
     } else {
         Console::writeLine('@', $cwd->getURI());
         try {
             $result = self::$json->decodeFrom($installed->getInputStream());
         } catch (IOException $e) {
             Console::$err->writeLine('*** Cannot find installed module ', $module, ': ', $e->getMessage());
             return 3;
         }
         $releases = $this->installedReleases($cwd, $module);
     }
     Console::writeLine(new Module($result['vendor'], $result['module']), ': ', $result['info']);
     Console::writeLine($result['link']['url']);
     uksort($releases, function ($a, $b) {
         return version_compare($a, $b, '<');
     });
     Console::writeLine('Releases: ', sizeof($releases), ', list {');
     foreach ($releases as $version => $release) {
         $s = '';
         foreach ($release as $key => $value) {
             $s .= ', ' . $key . '= ' . \xp::stringOf($value);
         }
         Console::writeLine('  ', $version, ' (', substr($s, 2), ')');
     }
     Console::writeLine('}');
     // List active releases for local queries
     if (!$remote) {
         foreach (new FilteredIOCollectionIterator($cwd, new NameMatchesFilter('#^\\.' . $module->vendor . '\\.' . $module->name . '.*\\.pth#')) as $found) {
             $r = new StringReader($found->getInputStream());
             Console::writeLine('Selected: ', basename($found->getURI()), ', class path {');
             while (null !== ($line = $r->readLine())) {
                 $resolved = realpath($cwd->getURI() . ltrim($line, '!'));
                 if (is_dir($resolved)) {
                     $cl = \lang\FileSystemClassLoader::instanceFor($resolved, false);
                 } else {
                     if (is_file($resolved)) {
                         $cl = \lang\archive\ArchiveClassLoader::instanceFor($resolved, false);
                     }
                 }
                 Console::writeLine('  ', $cl);
             }
             Console::writeLine('}');
         }
         return 0;
     }
 }