Example #1
0
 protected function createPackage($extra)
 {
     $package = new CompletePackage('test/package', '1.0.0.0', '1.0.0');
     $package->setExtra($extra);
     $package->setTargetDir('Some/Namespace');
     return $package;
 }
Example #2
0
 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);
     }
 }
Example #3
0
 /**
  * Returns the list of installed plugin packages, with extra information
  * relative to their options. Local packages (i.e. not manager by composer)
  * are also included in the list.
  *
  * @return CompletePackageInterface[]
  */
 public function getPluginList()
 {
     $repoPackages = $this->getInstalledByType(self::CLAROLINE_PLUGIN_TYPE);
     $registeredPlugins = $this->om->getRepository('ClarolineCoreBundle:Plugin')->findAll();
     $packages = [];
     foreach ($registeredPlugins as $plugin) {
         $targetPackage = null;
         $isInRepo = true;
         // looks for the corresponding package
         foreach ($repoPackages as $package) {
             $packageParts = explode('/', $package->getName());
             $bundleParts = explode('-', $packageParts[1]);
             $vendorName = $packageParts[0];
             $bundleName = '';
             foreach ($bundleParts as $part) {
                 $bundleName .= $part;
             }
             if (strtoupper($plugin->getVendorName()) === strtoupper($vendorName) && strtoupper($plugin->getBundleName()) === strtoupper($bundleName)) {
                 $targetPackage = $package;
                 break;
             }
         }
         // builds a "fake" package if the plugin is not managed by composer
         if (!$targetPackage) {
             $isInRepo = false;
             $vendorName = strtolower($plugin->getVendorName());
             $bundleParts = preg_split('/(?=[A-Z])/', $plugin->getBundleName());
             array_shift($bundleParts);
             $bundleName = strtolower(implode('-', $bundleParts));
             $targetPackage = new CompletePackage("{$vendorName}/{$bundleName}", '9999999-dev', 'unknown / local');
         }
         // adds plugin options info in the "extra" attribute
         $extra = $targetPackage->getExtra();
         $extra['is_in_repo'] = $isInRepo;
         $extra['has_options'] = $plugin->hasOptions();
         $extra['plugin_short_name'] = $plugin->getShortName();
         $targetPackage->setExtra($extra);
         $packages[] = $targetPackage;
     }
     return $packages;
 }
Example #4
0
 public function testDoNotAddInstalledRunOnce3()
 {
     RunonceManager::clearRunonces();
     $package = new CompletePackage('test/package', '1.0.0.0', '1.0.0');
     $package->setExtra(array('contao' => array('sources' => array('test' => 'system/modules/test'), 'runonce' => array('system/runonce.php'))));
     $package->setTargetDir('Some/Namespace');
     RunonceManager::addRunonces($package, $this->rootDir);
     $this->assertEquals(array(), RunonceManager::getRunonces(), 'Installed runonce has been added.');
     $this->assertEmpty(RunonceManager::getRunonces(), 'Installed runonce has been added.');
 }