protected function initialize()
 {
     parent::initialize();
     if (!extension_loaded('openssl') && 'https' === substr($this->url, 0, 5)) {
         throw new \RuntimeException('You must enable the openssl extension in your php.ini to load information from ' . $this->url);
     }
     try {
         $json = new JsonFile($this->url . '/packages.json', new RemoteFilesystem($this->io));
         $data = $json->read();
         if (!empty($data['notify'])) {
             if ('/' === $data['notify'][0]) {
                 $this->notifyUrl = preg_replace('{(https?://[^/]+).*}i', '$1' . $data['notify'], $this->url);
             } else {
                 $this->notifyUrl = $data['notify'];
             }
         }
         $this->cache->write('packages.json', json_encode($data));
     } catch (\Exception $e) {
         if ($contents = $this->cache->read('packages.json')) {
             $this->io->write('<warning>' . $this->url . ' could not be loaded, package information was loaded from the local cache and may be out of date</warning>');
             $data = json_decode($contents, true);
         } else {
             throw $e;
         }
     }
     $loader = new ArrayLoader();
     $this->loadRepository($loader, $data);
 }
 protected function initialize()
 {
     parent::initialize();
     $versionParser = new VersionParser();
     try {
         $prettyVersion = PHP_VERSION;
         $version = $versionParser->normalize($prettyVersion);
     } catch (\UnexpectedValueException $e) {
         $prettyVersion = preg_replace('#^(.+?)(-.+)?$#', '$1', PHP_VERSION);
         $version = $versionParser->normalize($prettyVersion);
     }
     $php = new MemoryPackage('php', $version, $prettyVersion);
     $php->setDescription('The PHP interpreter');
     parent::addPackage($php);
     foreach (get_loaded_extensions() as $name) {
         if (in_array($name, array('standard', 'Core'))) {
             continue;
         }
         $reflExt = new \ReflectionExtension($name);
         try {
             $prettyVersion = $reflExt->getVersion();
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             $prettyVersion = '0';
             $version = $versionParser->normalize($prettyVersion);
         }
         $ext = new MemoryPackage('ext-' . $name, $version, $prettyVersion);
         $ext->setDescription('The ' . $name . ' PHP extension');
         parent::addPackage($ext);
     }
 }
Exemple #3
0
 protected function initialize()
 {
     parent::initialize();
     $this->io->write('Initializing PEAR repository ' . $this->url);
     $this->initializeChannel();
     $this->io->write('Packages names will be prefixed with: pear-' . $this->channel . '/');
     // try to load as a composer repo
     try {
         $json = new JsonFile($this->url . '/packages.json', new RemoteFilesystem($this->io));
         $packages = $json->read();
         if ($this->io->isVerbose()) {
             $this->io->write('Repository is Composer-compatible, loading via packages.json instead of PEAR protocol');
         }
         $loader = new ArrayLoader();
         foreach ($packages as $data) {
             foreach ($data['versions'] as $rev) {
                 if (strpos($rev['name'], 'pear-' . $this->channel) !== 0) {
                     $rev['name'] = 'pear-' . $this->channel . '/' . $rev['name'];
                 }
                 $this->addPackage($loader->load($rev));
                 if ($this->io->isVerbose()) {
                     $this->io->write('Loaded ' . $rev['name'] . ' ' . $rev['version']);
                 }
             }
         }
         return;
     } catch (\Exception $e) {
     }
     $this->fetchFromServer();
 }
 /**
  * Initializes repository (reads file, or remote address).
  */
 protected function initialize()
 {
     parent::initialize();
     if (!$this->file->exists()) {
         return;
     }
     $packages = $this->file->read();
     if (!is_array($packages)) {
         throw new \UnexpectedValueException('Could not parse package list from the ' . $this->file->getPath() . ' repository');
     }
     $loader = new ArrayLoader();
     foreach ($packages as $packageData) {
         $package = $loader->load($packageData);
         // package was installed as alias, so we only add the alias
         if ($this instanceof InstalledRepositoryInterface && !empty($packageData['installed-as-alias'])) {
             $alias = $packageData['installed-as-alias'];
             $package->setAlias($alias);
             $package->setPrettyAlias($alias);
             $package->setInstalledAsAlias(true);
             $this->addPackage($this->createAliasPackage($package, $alias, $alias));
         } else {
             // only add regular package - if it's not an installed repo the alias will be created on the fly
             $this->addPackage($package);
         }
     }
 }
 /**
  * Initializes repository (reads file, or remote address).
  */
 protected function initialize()
 {
     parent::initialize();
     $loader = new ArrayLoader();
     foreach ($this->config as $package) {
         $package = $loader->load($package);
         $this->addPackage($package);
     }
 }
 protected function initialize()
 {
     parent::initialize();
     set_error_handler(function ($severity, $message, $file, $line) {
         throw new \ErrorException($message, $severity, $severity, $file, $line);
     });
     $this->streamContext = StreamContextFactory::getContext();
     $this->fetchFromServer();
     restore_error_handler();
 }
 /**
  * Initializes repository (reads file, or remote address).
  */
 protected function initialize()
 {
     parent::initialize();
     if (!is_numeric(key($this->config))) {
         $this->config = array($this->config);
     }
     $loader = new ArrayLoader();
     foreach ($this->config as $package) {
         $package = $loader->load($package);
         $this->addPackage($package);
     }
 }
 /**
  * Initializes repository (reads file, or remote address).
  */
 protected function initialize()
 {
     parent::initialize();
     $loader = new ValidatingArrayLoader(new ArrayLoader(null, true), false);
     foreach ($this->config as $package) {
         try {
             $package = $loader->load($package);
         } catch (\Exception $e) {
             throw new InvalidRepositoryException('A repository of type "package" contains an invalid package definition: ' . $e->getMessage() . "\n\nInvalid package definition:\n" . json_encode($package));
         }
         $this->addPackage($package);
     }
 }
 /**
  * Initializes repository (reads file, or remote address).
  */
 protected function initialize()
 {
     parent::initialize();
     if (!$this->file->exists()) {
         return;
     }
     $packages = $this->file->read();
     if (!is_array($packages)) {
         throw new \UnexpectedValueException('Could not parse package list from the ' . $this->file->getPath() . ' repository');
     }
     $loader = new ArrayLoader();
     foreach ($packages as $package) {
         $this->addPackage($loader->load($package));
     }
 }
 protected function initialize()
 {
     parent::initialize();
     $json = new JsonFile($this->url . '/packages.json');
     $packages = $json->read();
     if (!$packages) {
         throw new \UnexpectedValueException('Could not parse package list from the ' . $this->url . ' repository');
     }
     $loader = new ArrayLoader();
     foreach ($packages as $data) {
         foreach ($data['versions'] as $rev) {
             $this->addPackage($loader->load($rev));
         }
     }
 }
 protected function initialize()
 {
     parent::initialize();
     $loader = new ArrayLoader(null, true);
     $directories = glob($this->directory . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR | GLOB_NOSORT);
     foreach ($directories as $directory) {
         if (!file_exists($directory . DIRECTORY_SEPARATOR . 'composer.json')) {
             continue;
         }
         $jsonFile = new JsonFile($directory . DIRECTORY_SEPARATOR . 'composer.json');
         $packageData = $jsonFile->read();
         $packageData['version'] = '1.0';
         $package = $loader->load($packageData);
         $this->addPackage($package);
     }
 }
Exemple #12
0
 protected function initialize()
 {
     parent::initialize();
     $this->io->writeError('Initializing PEAR repository ' . $this->url);
     $reader = new ChannelReader($this->rfs);
     try {
         $channelInfo = $reader->read($this->url);
     } catch (\Exception $e) {
         $this->io->writeError('<warning>PEAR repository from ' . $this->url . ' could not be loaded. ' . $e->getMessage() . '</warning>');
         return;
     }
     $packages = $this->buildComposerPackages($channelInfo, $this->versionParser);
     foreach ($packages as $package) {
         $this->addPackage($package);
     }
 }
 /**
  * Initializes repository (reads file, or remote address).
  */
 protected function initialize()
 {
     parent::initialize();
     if (!$this->file->exists()) {
         return;
     }
     try {
         $packages = $this->file->read();
         if (!is_array($packages)) {
             throw new \UnexpectedValueException('Could not parse package list from the repository');
         }
     } catch (\Exception $e) {
         throw new InvalidRepositoryException('Invalid repository data in ' . $this->file->getPath() . ', packages could not be loaded: [' . get_class($e) . '] ' . $e->getMessage());
     }
     $loader = new ArrayLoader();
     foreach ($packages as $packageData) {
         $package = $loader->load($packageData);
         $this->addPackage($package);
     }
 }
 protected function initialize()
 {
     parent::initialize();
     try {
         $json = new JsonFile($this->url . '/packages.json', new RemoteFilesystem($this->io));
         $data = $json->read();
         if (!empty($data['notify'])) {
             $this->notifyUrl = preg_replace('{(https?://[^/]+).*}i', '$1' . $data['notify'], $this->url);
         }
         $this->cache->write('packages.json', json_encode($data));
     } catch (\Exception $e) {
         if ($contents = $this->cache->read('packages.json')) {
             $this->io->write('<warning>' . $this->url . ' could not be loaded, package information was loaded from the local cache and may be out of date</warning>');
             $data = json_decode($contents, true);
         } else {
             throw $e;
         }
     }
     $loader = new ArrayLoader();
     $this->loadRepository($loader, $data);
 }
Exemple #15
0
 /**
  * Initializes path repository.
  *
  * This method will basically read the folder and add the found package.
  */
 protected function initialize()
 {
     parent::initialize();
     $path = $this->getPath();
     $composerFilePath = $path . 'composer.json';
     if (!file_exists($composerFilePath)) {
         throw new \RuntimeException(sprintf('No `composer.json` file found in path repository "%s"', $path));
     }
     $json = file_get_contents($composerFilePath);
     $package = JsonFile::parseJson($json, $composerFilePath);
     $package['dist'] = array('type' => 'path', 'url' => $this->url, 'reference' => '');
     if (!isset($package['version'])) {
         $package['version'] = $this->versionGuesser->guessVersion($package, $path) ?: 'dev-master';
     }
     if (is_dir($path . '/.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) {
         $package['dist']['reference'] = trim($output);
     }
     $package = $this->loader->load($package);
     $this->addPackage($package);
 }
 /**
  * {@inheritDoc}
  */
 protected function initialize()
 {
     parent::initialize();
     $repoData = $this->loadDataFromServer();
     foreach ($repoData as $package) {
         $this->addPackage($this->createPackage($package, 'Composer\\Package\\CompletePackage'));
     }
 }
Exemple #17
0
 protected function initialize()
 {
     parent::initialize();
     $versionParser = new VersionParser();
     $prettyVersion = PluginInterface::PLUGIN_API_VERSION;
     $version = $versionParser->normalize($prettyVersion);
     $composerPluginApi = new CompletePackage('composer-plugin-api', $version, $prettyVersion);
     $composerPluginApi->setDescription('The Composer Plugin API');
     parent::addPackage($composerPluginApi);
     try {
         $prettyVersion = PHP_VERSION;
         $version = $versionParser->normalize($prettyVersion);
     } catch (\UnexpectedValueException $e) {
         $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', PHP_VERSION);
         $version = $versionParser->normalize($prettyVersion);
     }
     $php = new CompletePackage('php', $version, $prettyVersion);
     $php->setDescription('The PHP interpreter');
     parent::addPackage($php);
     if (PHP_INT_SIZE === 8) {
         $php64 = new CompletePackage('php-64bit', $version, $prettyVersion);
         $php64->setDescription('The PHP interpreter (64bit)');
         parent::addPackage($php64);
     }
     $loadedExtensions = get_loaded_extensions();
     foreach ($loadedExtensions as $name) {
         if (in_array($name, array('standard', 'Core'))) {
             continue;
         }
         $reflExt = new \ReflectionExtension($name);
         try {
             $prettyVersion = $reflExt->getVersion();
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             $prettyVersion = '0';
             $version = $versionParser->normalize($prettyVersion);
         }
         $packageName = $this->buildPackageName($name);
         $ext = new CompletePackage($packageName, $version, $prettyVersion);
         $ext->setDescription('The ' . $name . ' PHP extension');
         parent::addPackage($ext);
     }
     foreach ($loadedExtensions as $name) {
         $prettyVersion = null;
         switch ($name) {
             case 'curl':
                 $curlVersion = curl_version();
                 $prettyVersion = $curlVersion['version'];
                 break;
             case 'iconv':
                 $prettyVersion = ICONV_VERSION;
                 break;
             case 'intl':
                 $name = 'ICU';
                 if (defined('INTL_ICU_VERSION')) {
                     $prettyVersion = INTL_ICU_VERSION;
                 } else {
                     $reflector = new \ReflectionExtension('intl');
                     ob_start();
                     $reflector->info();
                     $output = ob_get_clean();
                     preg_match('/^ICU version => (.*)$/m', $output, $matches);
                     $prettyVersion = $matches[1];
                 }
                 break;
             case 'libxml':
                 $prettyVersion = LIBXML_DOTTED_VERSION;
                 break;
             case 'openssl':
                 $prettyVersion = preg_replace_callback('{^(?:OpenSSL\\s*)?([0-9.]+)([a-z]?).*}', function ($match) {
                     return $match[1] . (empty($match[2]) ? '' : '.' . (ord($match[2]) - 96));
                 }, OPENSSL_VERSION_TEXT);
                 break;
             case 'pcre':
                 $prettyVersion = preg_replace('{^(\\S+).*}', '$1', PCRE_VERSION);
                 break;
             case 'uuid':
                 $prettyVersion = phpversion('uuid');
                 break;
             case 'xsl':
                 $prettyVersion = LIBXSLT_DOTTED_VERSION;
                 break;
             default:
                 continue 2;
         }
         try {
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             continue;
         }
         $lib = new CompletePackage('lib-' . $name, $version, $prettyVersion);
         $lib->setDescription('The ' . $name . ' PHP library');
         parent::addPackage($lib);
     }
     if (defined('HHVM_VERSION')) {
         try {
             $prettyVersion = HHVM_VERSION;
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', HHVM_VERSION);
             $version = $versionParser->normalize($prettyVersion);
         }
         $hhvm = new CompletePackage('hhvm', $version, $prettyVersion);
         $hhvm->setDescription('The HHVM Runtime (64bit)');
         parent::addPackage($hhvm);
     }
 }
 protected function initialize()
 {
     parent::initialize();
     $versionParser = new VersionParser();
     try {
         $prettyVersion = PHP_VERSION;
         $version = $versionParser->normalize($prettyVersion);
     } catch (\UnexpectedValueException $e) {
         $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', PHP_VERSION);
         $version = $versionParser->normalize($prettyVersion);
     }
     $php = new CompletePackage('php', $version, $prettyVersion);
     $php->setDescription('The PHP interpreter');
     parent::addPackage($php);
     if (PHP_INT_SIZE === 8) {
         $php64 = new CompletePackage('php-64bit', $version, $prettyVersion);
         $php64->setDescription('The PHP interpreter (64bit)');
         parent::addPackage($php64);
     }
     $loadedExtensions = get_loaded_extensions();
     // Extensions scanning
     foreach ($loadedExtensions as $name) {
         if (in_array($name, array('standard', 'Core'))) {
             continue;
         }
         $reflExt = new \ReflectionExtension($name);
         try {
             $prettyVersion = $reflExt->getVersion();
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             $prettyVersion = '0';
             $version = $versionParser->normalize($prettyVersion);
         }
         $ext = new CompletePackage('ext-' . $name, $version, $prettyVersion);
         $ext->setDescription('The ' . $name . ' PHP extension');
         parent::addPackage($ext);
     }
     // Another quick loop, just for possible libraries
     // Doing it this way to know that functions or constants exist before
     // relying on them.
     foreach ($loadedExtensions as $name) {
         $prettyVersion = null;
         switch ($name) {
             case 'curl':
                 $curlVersion = curl_version();
                 $prettyVersion = $curlVersion['version'];
                 break;
             case 'iconv':
                 $prettyVersion = ICONV_VERSION;
                 break;
             case 'intl':
                 $name = 'ICU';
                 if (defined('INTL_ICU_VERSION')) {
                     $prettyVersion = INTL_ICU_VERSION;
                 } else {
                     $reflector = new \ReflectionExtension('intl');
                     ob_start();
                     $reflector->info();
                     $output = ob_get_clean();
                     preg_match('/^ICU version => (.*)$/m', $output, $matches);
                     $prettyVersion = $matches[1];
                 }
                 break;
             case 'libxml':
                 $prettyVersion = LIBXML_DOTTED_VERSION;
                 break;
             case 'openssl':
                 $prettyVersion = preg_replace_callback('{^(?:OpenSSL\\s*)?([0-9.]+)([a-z]?).*}', function ($match) {
                     return $match[1] . (empty($match[2]) ? '' : '.' . (ord($match[2]) - 96));
                 }, OPENSSL_VERSION_TEXT);
                 break;
             case 'pcre':
                 $prettyVersion = preg_replace('{^(\\S+).*}', '$1', PCRE_VERSION);
                 break;
             case 'uuid':
                 $prettyVersion = phpversion('uuid');
                 break;
             case 'xsl':
                 $prettyVersion = LIBXSLT_DOTTED_VERSION;
                 break;
             default:
                 // None handled extensions have no special cases, skip
                 continue 2;
         }
         try {
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             continue;
         }
         $lib = new CompletePackage('lib-' . $name, $version, $prettyVersion);
         $lib->setDescription('The ' . $name . ' PHP library');
         parent::addPackage($lib);
     }
 }
 protected function initialize()
 {
     parent::initialize();
     $versionParser = new VersionParser();
     // Add each of the override versions as options.
     // Later we might even replace the extensions instead.
     foreach ($this->overrides as $override) {
         // Check that it's a platform package.
         if (!preg_match(self::PLATFORM_PACKAGE_REGEX, $override['name'])) {
             throw new \InvalidArgumentException('Invalid platform package name in config.platform: ' . $override['name']);
         }
         $version = $versionParser->normalize($override['version']);
         $package = new CompletePackage($override['name'], $version, $override['version']);
         $package->setDescription('Package overridden via config.platform');
         $package->setExtra(array('config.platform' => true));
         parent::addPackage($package);
     }
     $prettyVersion = PluginInterface::PLUGIN_API_VERSION;
     $version = $versionParser->normalize($prettyVersion);
     $composerPluginApi = new CompletePackage('composer-plugin-api', $version, $prettyVersion);
     $composerPluginApi->setDescription('The Composer Plugin API');
     $this->addPackage($composerPluginApi);
     try {
         $prettyVersion = PHP_VERSION;
         $version = $versionParser->normalize($prettyVersion);
     } catch (\UnexpectedValueException $e) {
         $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', PHP_VERSION);
         $version = $versionParser->normalize($prettyVersion);
     }
     $php = new CompletePackage('php', $version, $prettyVersion);
     $php->setDescription('The PHP interpreter');
     $this->addPackage($php);
     if (PHP_INT_SIZE === 8) {
         $php64 = new CompletePackage('php-64bit', $version, $prettyVersion);
         $php64->setDescription('The PHP interpreter, 64bit');
         $this->addPackage($php64);
     }
     $loadedExtensions = get_loaded_extensions();
     // Extensions scanning
     foreach ($loadedExtensions as $name) {
         if (in_array($name, array('standard', 'Core'))) {
             continue;
         }
         $reflExt = new \ReflectionExtension($name);
         try {
             $prettyVersion = $reflExt->getVersion();
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             $prettyVersion = '0';
             $version = $versionParser->normalize($prettyVersion);
         }
         $packageName = $this->buildPackageName($name);
         $ext = new CompletePackage($packageName, $version, $prettyVersion);
         $ext->setDescription('The ' . $name . ' PHP extension');
         $this->addPackage($ext);
     }
     // Another quick loop, just for possible libraries
     // Doing it this way to know that functions or constants exist before
     // relying on them.
     foreach ($loadedExtensions as $name) {
         $prettyVersion = null;
         $description = 'The ' . $name . ' PHP library';
         switch ($name) {
             case 'curl':
                 $curlVersion = curl_version();
                 $prettyVersion = $curlVersion['version'];
                 break;
             case 'iconv':
                 $prettyVersion = ICONV_VERSION;
                 break;
             case 'intl':
                 $name = 'ICU';
                 if (defined('INTL_ICU_VERSION')) {
                     $prettyVersion = INTL_ICU_VERSION;
                 } else {
                     $reflector = new \ReflectionExtension('intl');
                     ob_start();
                     $reflector->info();
                     $output = ob_get_clean();
                     preg_match('/^ICU version => (.*)$/m', $output, $matches);
                     $prettyVersion = $matches[1];
                 }
                 break;
             case 'libxml':
                 $prettyVersion = LIBXML_DOTTED_VERSION;
                 break;
             case 'openssl':
                 $prettyVersion = preg_replace_callback('{^(?:OpenSSL\\s*)?([0-9.]+)([a-z]*).*}', function ($match) {
                     if (empty($match[2])) {
                         return $match[1];
                     }
                     // OpenSSL versions add another letter when they reach Z.
                     // e.g. OpenSSL 0.9.8zh 3 Dec 2015
                     if (!preg_match('{^z*[a-z]$}', $match[2])) {
                         // 0.9.8abc is garbage
                         return 0;
                     }
                     $len = strlen($match[2]);
                     $patchVersion = ($len - 1) * 26;
                     // All Z
                     $patchVersion += ord($match[2][$len - 1]) - 96;
                     return $match[1] . '.' . $patchVersion;
                 }, OPENSSL_VERSION_TEXT);
                 $description = OPENSSL_VERSION_TEXT;
                 break;
             case 'pcre':
                 $prettyVersion = preg_replace('{^(\\S+).*}', '$1', PCRE_VERSION);
                 break;
             case 'uuid':
                 $prettyVersion = phpversion('uuid');
                 break;
             case 'xsl':
                 $prettyVersion = LIBXSLT_DOTTED_VERSION;
                 break;
             default:
                 // None handled extensions have no special cases, skip
                 continue 2;
         }
         try {
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             continue;
         }
         $lib = new CompletePackage('lib-' . $name, $version, $prettyVersion);
         $lib->setDescription($description);
         $this->addPackage($lib);
     }
     if (defined('HHVM_VERSION')) {
         try {
             $prettyVersion = HHVM_VERSION;
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', HHVM_VERSION);
             $version = $versionParser->normalize($prettyVersion);
         }
         $hhvm = new CompletePackage('hhvm', $version, $prettyVersion);
         $hhvm->setDescription('The HHVM Runtime (64bit)');
         $this->addPackage($hhvm);
     }
 }
Exemple #20
0
 protected function initialize()
 {
     parent::initialize();
     $this->scanDir();
 }
Exemple #21
0
 protected function initialize()
 {
     parent::initialize();
     $versionParser = new VersionParser();
     try {
         $prettyVersion = PHP_VERSION;
         $version = $versionParser->normalize($prettyVersion);
     } catch (\UnexpectedValueException $e) {
         $prettyVersion = preg_replace('#^(.+?)(-.+)?$#', '$1', PHP_VERSION);
         $version = $versionParser->normalize($prettyVersion);
     }
     $php = new MemoryPackage('php', $version, $prettyVersion);
     $php->setDescription('The PHP interpreter');
     parent::addPackage($php);
     $loadedExtensions = get_loaded_extensions();
     // Extensions scanning
     foreach ($loadedExtensions as $name) {
         if (in_array($name, array('standard', 'Core'))) {
             continue;
         }
         $reflExt = new \ReflectionExtension($name);
         try {
             $prettyVersion = $reflExt->getVersion();
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             $prettyVersion = '0';
             $version = $versionParser->normalize($prettyVersion);
         }
         $ext = new MemoryPackage('ext-' . $name, $version, $prettyVersion);
         $ext->setDescription('The ' . $name . ' PHP extension');
         parent::addPackage($ext);
     }
     // Another quick loop, just for possible libraries
     // Doing it this way to know that functions or constants exist before
     // relying on them.
     foreach ($loadedExtensions as $name) {
         switch ($name) {
             case 'curl':
                 $curlVersion = curl_version();
                 $prettyVersion = $curlVersion['version'];
                 break;
             case 'iconv':
                 $prettyVersion = ICONV_VERSION;
                 break;
             case 'libxml':
                 $prettyVersion = LIBXML_DOTTED_VERSION;
                 break;
             case 'openssl':
                 $prettyVersion = preg_replace_callback('{^(?:OpenSSL\\s*)?([0-9.]+)([a-z]?).*}', function ($match) {
                     return $match[1] . (empty($match[2]) ? '' : '.' . (ord($match[2]) - 96));
                 }, OPENSSL_VERSION_TEXT);
                 break;
             case 'pcre':
                 $prettyVersion = preg_replace('{^(\\S+).*}', '$1', PCRE_VERSION);
                 break;
             case 'uuid':
                 $prettyVersion = phpversion('uuid');
                 break;
             case 'xsl':
                 $prettyVersion = LIBXSLT_DOTTED_VERSION;
                 break;
             default:
                 // None handled extensions have no special cases, skip
                 continue 2;
         }
         try {
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             continue;
         }
         $lib = new MemoryPackage('lib-' . $name, $version, $prettyVersion);
         $lib->setDescription('The ' . $name . ' PHP library');
         parent::addPackage($lib);
     }
 }
 protected function initialize()
 {
     parent::initialize();
     $this->scanDirectory($this->lookup);
 }
Exemple #23
0
 /**
  * Initializes path repository.
  *
  * This method will basically read the folder and add the found package.
  */
 protected function initialize()
 {
     parent::initialize();
     foreach ($this->getUrlMatches() as $url) {
         $path = realpath($url) . DIRECTORY_SEPARATOR;
         $composerFilePath = $path . 'composer.json';
         if (!file_exists($composerFilePath)) {
             continue;
         }
         $json = file_get_contents($composerFilePath);
         $package = JsonFile::parseJson($json, $composerFilePath);
         $package['dist'] = array('type' => 'path', 'url' => $url, 'reference' => sha1($json));
         if (!isset($package['version'])) {
             $package['version'] = $this->versionGuesser->guessVersion($package, $path) ?: 'dev-master';
         }
         $output = '';
         if (is_dir($path . DIRECTORY_SEPARATOR . '.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) {
             $package['dist']['reference'] = trim($output);
         }
         $package = $this->loader->load($package);
         $this->addPackage($package);
     }
 }
 /**
  * Initializes path repository.
  *
  * This method will basically read the folder and add the found package.
  */
 protected function initialize()
 {
     parent::initialize();
     foreach ($this->getUrlMatches() as $url) {
         $path = realpath($url) . DIRECTORY_SEPARATOR;
         $composerFilePath = $path . 'composer.json';
         if (!file_exists($composerFilePath)) {
             continue;
         }
         $json = file_get_contents($composerFilePath);
         $package = JsonFile::parseJson($json, $composerFilePath);
         $package['dist'] = array('type' => 'path', 'url' => $url, 'reference' => '');
         if (!isset($package['version'])) {
             $package['version'] = $this->versionGuesser->guessVersion($package, $path) ?: 'dev-master';
         }
         $output = '';
         if (is_dir($path . DIRECTORY_SEPARATOR . '.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) {
             $package['dist']['reference'] = trim($output);
         } else {
             $package['dist']['reference'] = Locker::getContentHash($json);
         }
         $package = $this->loader->load($package);
         $this->addPackage($package);
     }
     if (count($this->getPackages()) == 0) {
         throw new \RuntimeException(sprintf('No `composer.json` file found in any path repository in "%s"', $this->url));
     }
 }
 protected function initialize()
 {
     parent::initialize();
     $verbose = $this->verbose;
     $driver = $this->getDriver();
     if (!$driver) {
         throw new \InvalidArgumentException('No driver found to handle VCS repository ' . $this->url);
     }
     $this->versionParser = new VersionParser();
     if (!$this->loader) {
         $this->loader = new ArrayLoader($this->versionParser);
     }
     try {
         if ($driver->hasComposerFile($driver->getRootIdentifier())) {
             $data = $driver->getComposerInformation($driver->getRootIdentifier());
             $this->packageName = !empty($data['name']) ? $data['name'] : null;
         }
     } catch (\Exception $e) {
         if ($verbose) {
             $this->io->write('<error>Skipped parsing ' . $driver->getRootIdentifier() . ', ' . $e->getMessage() . '</error>');
         }
     }
     foreach ($driver->getTags() as $tag => $identifier) {
         $msg = 'Reading composer.json of <info>' . ($this->packageName ?: $this->url) . '</info> (<comment>' . $tag . '</comment>)';
         if ($verbose) {
             $this->io->write($msg);
         } else {
             $this->io->overwrite($msg, false);
         }
         // strip the release- prefix from tags if present
         $tag = str_replace('release-', '', $tag);
         if (!($parsedTag = $this->validateTag($tag))) {
             if ($verbose) {
                 $this->io->write('<warning>Skipped tag ' . $tag . ', invalid tag name</warning>');
             }
             continue;
         }
         try {
             if (!($data = $driver->getComposerInformation($identifier))) {
                 if ($verbose) {
                     $this->io->write('<warning>Skipped tag ' . $tag . ', no composer file</warning>');
                 }
                 continue;
             }
             // manually versioned package
             if (isset($data['version'])) {
                 $data['version_normalized'] = $this->versionParser->normalize($data['version']);
             } else {
                 // auto-versioned package, read value from tag
                 $data['version'] = $tag;
                 $data['version_normalized'] = $parsedTag;
             }
             // make sure tag packages have no -dev flag
             $data['version'] = preg_replace('{[.-]?dev$}i', '', $data['version']);
             $data['version_normalized'] = preg_replace('{(^dev-|[.-]?dev$)}i', '', $data['version_normalized']);
             // broken package, version doesn't match tag
             if ($data['version_normalized'] !== $parsedTag) {
                 if ($verbose) {
                     $this->io->write('<warning>Skipped tag ' . $tag . ', tag (' . $parsedTag . ') does not match version (' . $data['version_normalized'] . ') in composer.json</warning>');
                 }
                 continue;
             }
             if ($verbose) {
                 $this->io->write('Importing tag ' . $tag . ' (' . $data['version_normalized'] . ')');
             }
             $this->addPackage($this->loader->load($this->preProcess($driver, $data, $identifier)));
         } catch (\Exception $e) {
             if ($verbose) {
                 $this->io->write('<warning>Skipped tag ' . $tag . ', ' . ($e instanceof TransportException ? 'no composer file was found' : $e->getMessage()) . '</warning>');
             }
             continue;
         }
     }
     if (!$verbose) {
         $this->io->overwrite('', false);
     }
     foreach ($driver->getBranches() as $branch => $identifier) {
         $msg = 'Reading composer.json of <info>' . ($this->packageName ?: $this->url) . '</info> (<comment>' . $branch . '</comment>)';
         if ($verbose) {
             $this->io->write($msg);
         } else {
             $this->io->overwrite($msg, false);
         }
         if (!($parsedBranch = $this->validateBranch($branch))) {
             if ($verbose) {
                 $this->io->write('<warning>Skipped branch ' . $branch . ', invalid name</warning>');
             }
             continue;
         }
         try {
             if (!($data = $driver->getComposerInformation($identifier))) {
                 if ($verbose) {
                     $this->io->write('<warning>Skipped branch ' . $branch . ', no composer file</warning>');
                 }
                 continue;
             }
             // branches are always auto-versioned, read value from branch name
             $data['version'] = $branch;
             $data['version_normalized'] = $parsedBranch;
             // make sure branch packages have a dev flag
             if ('dev-' === substr($parsedBranch, 0, 4) || '9999999-dev' === $parsedBranch) {
                 $data['version'] = 'dev-' . $data['version'];
             } else {
                 $data['version'] = preg_replace('{(\\.9{7})+}', '.x', $parsedBranch);
             }
             if ($verbose) {
                 $this->io->write('Importing branch ' . $branch . ' (' . $data['version'] . ')');
             }
             $packageData = $this->preProcess($driver, $data, $identifier);
             $package = $this->loader->load($packageData);
             if ($this->loader instanceof ValidatingArrayLoader && $this->loader->getWarnings()) {
                 throw new InvalidPackageException($this->loader->getErrors(), $this->loader->getWarnings(), $packageData);
             }
             $this->addPackage($package);
         } catch (TransportException $e) {
             if ($verbose) {
                 $this->io->write('<warning>Skipped branch ' . $branch . ', no composer file was found</warning>');
             }
             continue;
         } catch (\Exception $e) {
             if (!$verbose) {
                 $this->io->write('');
             }
             $this->branchErrorOccurred = true;
             $this->io->write('<error>Skipped branch ' . $branch . ', ' . $e->getMessage() . '</error>');
             $this->io->write('');
             continue;
         }
     }
     $driver->cleanup();
     if (!$verbose) {
         $this->io->overwrite('', false);
     }
     if (!$this->getPackages()) {
         throw new InvalidRepositoryException('No valid composer.json was found in any branch or tag of ' . $this->url . ', could not load a package from it.');
     }
 }
Exemple #26
0
 protected function initialize()
 {
     parent::initialize();
     $verbose = $this->verbose;
     $driver = $this->getDriver();
     if (!$driver) {
         throw new \InvalidArgumentException('No driver found to handle VCS repository ' . $this->url);
     }
     $this->versionParser = new VersionParser();
     $loader = new ArrayLoader();
     try {
         if ($driver->hasComposerFile($driver->getRootIdentifier())) {
             $data = $driver->getComposerInformation($driver->getRootIdentifier());
             $this->packageName = !empty($data['name']) ? $data['name'] : null;
         }
     } catch (\Exception $e) {
         if ($verbose) {
             $this->io->write('Skipped parsing ' . $driver->getRootIdentifier() . ', ' . $e->getMessage());
         }
     }
     foreach ($driver->getTags() as $tag => $identifier) {
         $msg = 'Get composer info for <info>' . ($this->packageName ?: $this->url) . '</info> (<comment>' . $tag . '</comment>)';
         if ($verbose) {
             $this->io->write($msg);
         } else {
             $this->io->overwrite($msg, false);
         }
         if (!($parsedTag = $this->validateTag($tag))) {
             if ($verbose) {
                 $this->io->write('Skipped tag ' . $tag . ', invalid tag name');
             }
             continue;
         }
         try {
             if (!($data = $driver->getComposerInformation($identifier))) {
                 if ($verbose) {
                     $this->io->write('Skipped tag ' . $tag . ', no composer file');
                 }
                 continue;
             }
         } catch (\Exception $e) {
             if ($verbose) {
                 $this->io->write('Skipped tag ' . $tag . ', ' . ($e instanceof TransportException ? 'no composer file was found' : $e->getMessage()));
             }
             continue;
         }
         // manually versioned package
         if (isset($data['version'])) {
             $data['version_normalized'] = $this->versionParser->normalize($data['version']);
         } else {
             // auto-versionned package, read value from tag
             $data['version'] = $tag;
             $data['version_normalized'] = $parsedTag;
         }
         // make sure tag packages have no -dev flag
         $data['version'] = preg_replace('{[.-]?dev$}i', '', $data['version']);
         $data['version_normalized'] = preg_replace('{(^dev-|[.-]?dev$)}i', '', $data['version_normalized']);
         // broken package, version doesn't match tag
         if ($data['version_normalized'] !== $parsedTag) {
             if ($verbose) {
                 $this->io->write('Skipped tag ' . $tag . ', tag (' . $parsedTag . ') does not match version (' . $data['version_normalized'] . ') in composer.json');
             }
             continue;
         }
         if ($verbose) {
             $this->io->write('Importing tag ' . $tag . ' (' . $data['version_normalized'] . ')');
         }
         $this->addPackage($loader->load($this->preProcess($driver, $data, $identifier)));
     }
     $this->io->overwrite('', false);
     foreach ($driver->getBranches() as $branch => $identifier) {
         $msg = 'Get composer info for <info>' . ($this->packageName ?: $this->url) . '</info> (<comment>' . $branch . '</comment>)';
         if ($verbose) {
             $this->io->write($msg);
         } else {
             $this->io->overwrite($msg, false);
         }
         if (!($parsedBranch = $this->validateBranch($branch))) {
             if ($verbose) {
                 $this->io->write('Skipped branch ' . $branch . ', invalid name');
             }
             continue;
         }
         try {
             if (!($data = $driver->getComposerInformation($identifier))) {
                 if ($verbose) {
                     $this->io->write('Skipped branch ' . $branch . ', no composer file');
                 }
                 continue;
             }
         } catch (TransportException $e) {
             if ($verbose) {
                 $this->io->write('Skipped branch ' . $branch . ', no composer file was found');
             }
             continue;
         } catch (\Exception $e) {
             $this->io->write('Skipped branch ' . $branch . ', ' . $e->getMessage());
             continue;
         }
         // branches are always auto-versionned, read value from branch name
         $data['version'] = $branch;
         $data['version_normalized'] = $parsedBranch;
         // make sure branch packages have a dev flag
         if ('dev-' === substr($parsedBranch, 0, 4) || '9999999-dev' === $parsedBranch) {
             $data['version'] = 'dev-' . $data['version'];
         } else {
             $data['version'] = preg_replace('{(\\.9{7})+}', '.x', $parsedBranch);
         }
         if ($verbose) {
             $this->io->write('Importing branch ' . $branch . ' (' . $data['version'] . ')');
         }
         $this->addPackage($loader->load($this->preProcess($driver, $data, $identifier)));
     }
     $this->io->overwrite('', false);
 }