当前位置: 首页>>代码示例>>PHP>>正文


PHP VersionParser::parseStability方法代码示例

本文整理汇总了PHP中Composer\Package\Version\VersionParser::parseStability方法的典型用法代码示例。如果您正苦于以下问题:PHP VersionParser::parseStability方法的具体用法?PHP VersionParser::parseStability怎么用?PHP VersionParser::parseStability使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Composer\Package\Version\VersionParser的用法示例。


在下文中一共展示了VersionParser::parseStability方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: update

 public function update()
 {
     $versions = $this->packagist->getPackageVersions('silverstripe/framework');
     foreach ($versions as $package) {
         $version = $package->getVersion();
         // Replace version by branch alias if applicable
         $extra = $package->getExtra();
         if (isset($extra['branch-alias'][$version])) {
             $version = $extra['branch-alias'][$version];
         }
         $stability = VersionParser::parseStability($version);
         $isDev = $stability === 'dev';
         if (!$isDev || in_array($version, $this->versionBlacklist)) {
             continue;
         }
         $match = preg_match('/^([0-9]+)\\.([0-9]+)\\.x-dev$/', $version, $matches);
         if (!$match) {
             continue;
         }
         $major = $matches[1];
         $minor = $matches[2];
         $record = SilverStripeVersion::get()->filter('Major', $major)->filter('Minor', $minor)->first();
         if (!$record) {
             $record = new SilverStripeVersion();
             $record->Name = "{$major}.{$minor}";
             $record->Major = $major;
             $record->Minor = $minor;
             $record->write();
         }
     }
 }
开发者ID:newleeland,项目名称:addons.silverstripe.org,代码行数:31,代码来源:SilverStripeVersionUpdater.php

示例2: __construct

 /**
  * All descendants' constructors should call this parent constructor
  *
  * @param PackageInterface $aliasOf       The package this package is an alias of
  * @param string           $version       The version the alias must report
  * @param string           $prettyVersion The alias's non-normalized version
  */
 public function __construct(PackageInterface $aliasOf, $version, $prettyVersion)
 {
     parent::__construct($aliasOf->getName());
     $this->version = $version;
     $this->prettyVersion = $prettyVersion;
     $this->aliasOf = $aliasOf;
     $this->stability = VersionParser::parseStability($version);
     $this->dev = $this->stability === 'dev';
     // replace self.version dependencies
     foreach (array('requires', 'devRequires') as $type) {
         $links = $aliasOf->{'get' . ucfirst($type)}();
         foreach ($links as $index => $link) {
             // link is self.version, but must be replacing also the replaced version
             if ('self.version' === $link->getPrettyConstraint()) {
                 $links[$index] = new Link($link->getSource(), $link->getTarget(), new VersionConstraint('=', $this->version), $type, $prettyVersion);
             }
         }
         $this->{$type} = $links;
     }
     // duplicate self.version provides
     foreach (array('conflicts', 'provides', 'replaces') as $type) {
         $links = $aliasOf->{'get' . ucfirst($type)}();
         $newLinks = array();
         foreach ($links as $link) {
             // link is self.version, but must be replacing also the replaced version
             if ('self.version' === $link->getPrettyConstraint()) {
                 $newLinks[] = new Link($link->getSource(), $link->getTarget(), new VersionConstraint('=', $this->version), $type, $prettyVersion);
             }
         }
         $this->{$type} = array_merge($links, $newLinks);
     }
 }
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:39,代码来源:AliasPackage.php

示例3: __construct

 public function __construct($name, $version, $prettyVersion)
 {
     parent::__construct($name);
     $this->version = $version;
     $this->prettyVersion = $prettyVersion;
     $this->stability = VersionParser::parseStability($version);
     $this->dev = $this->stability === 'dev';
 }
开发者ID:itillawarra,项目名称:cmfive,代码行数:8,代码来源:Package.php

示例4: latest

 public function latest(CompletePackage $package)
 {
     $response = json_decode($this->client->get('/packages/' . $package->getName() . '.json')->send()->getBody(), true);
     $versions = $response['package']['versions'];
     $stability = VersionParser::parseStability($package->getPrettyVersion());
     $versions = $this->trim->trim($versions, $stability);
     $versions = $this->sort->nameSort($versions);
     return array_shift($versions);
 }
开发者ID:luxifer,项目名称:dependensees,代码行数:9,代码来源:VersionsParser.php

示例5: extractReferences

 /**
  * Extract vcs revision from version constraint (dev-master#abc123).
  * @see \Composer\Package\Loader\RootPackageLoader::extractReferences()
  *
  * @param  array  $requires
  * @param  array  $references
  *
  * @return array
  */
 private function extractReferences(array $requires, array $references)
 {
     foreach ($requires as $reqName => $reqVersion) {
         $reqVersion = preg_replace('{^([^,\\s@]+) as .+$}', '$1', $reqVersion);
         if (preg_match('{^[^,\\s@]+?#([a-f0-9]+)$}', $reqVersion, $match) && VersionParser::parseStability($reqVersion) === 'dev') {
             $references[strtolower($reqName)] = $match[1];
         }
     }
     return $references;
 }
开发者ID:arcanedev,项目名称:composer,代码行数:19,代码来源:ReferencesTrait.php

示例6: __construct

 /**
  * All descendants' constructors should call this parent constructor
  *
  * @param PackageInterface $aliasOf       The package this package is an alias of
  * @param string           $version       The version the alias must report
  * @param string           $prettyVersion The alias's non-normalized version
  */
 public function __construct(PackageInterface $aliasOf, $version, $prettyVersion)
 {
     parent::__construct($aliasOf->getName());
     $this->version = $version;
     $this->prettyVersion = $prettyVersion;
     $this->aliasOf = $aliasOf;
     $this->stability = VersionParser::parseStability($version);
     $this->dev = $this->stability === 'dev';
     foreach (array('requires', 'devRequires', 'conflicts', 'provides', 'replaces') as $type) {
         $links = $aliasOf->{'get' . ucfirst($type)}();
         $this->{$type} = $this->replaceSelfVersionDependencies($links, $type);
     }
 }
开发者ID:mothership-ec,项目名称:composer,代码行数:20,代码来源:AliasPackage.php

示例7: findInlineStabilities

    /**
     * Find the lowest stability.
     *
     * @param string[] $stabilities The list of stability
     *
     * @return string The lowest stability
     */
    protected function findInlineStabilities(array $stabilities)
    {
        $lowestStability = 'stable';

        foreach ($stabilities as $stability) {
            $stability = $this->versionParser->normalizeStability($stability);
            $stability = $this->versionParser->parseStability($stability);

            if (Package::$stabilities[$stability] > Package::$stabilities[$lowestStability]) {
                $lowestStability = $stability;
            }
        }

        return $lowestStability;
    }
开发者ID:pombredanne,项目名称:ArcherSys,代码行数:22,代码来源:VcsPackageFilter.php

示例8: whatProvides

 public function whatProvides(Pool $pool, $name)
 {
     if (isset($this->providers[$name])) {
         return $this->providers[$name];
     }
     // skip platform packages
     if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $name) || '__root__' === $name) {
         return array();
     }
     if (null === $this->providerListing) {
         $this->loadProviderListings($this->loadRootServerFile());
     }
     if ($this->lazyProvidersUrl && !isset($this->providerListing[$name])) {
         $hash = null;
         $url = str_replace('%package%', $name, $this->lazyProvidersUrl);
         $cacheKey = false;
     } elseif ($this->providersUrl) {
         // package does not exist in this repo
         if (!isset($this->providerListing[$name])) {
             return array();
         }
         $hash = $this->providerListing[$name]['sha256'];
         $url = str_replace(array('%package%', '%hash%'), array($name, $hash), $this->providersUrl);
         $cacheKey = 'provider-' . strtr($name, '/', '$') . '.json';
     } else {
         // BC handling for old providers-includes
         $url = 'p/' . $name . '.json';
         // package does not exist in this repo
         if (!isset($this->providerListing[$url])) {
             return array();
         }
         $hash = $this->providerListing[$url]['sha256'];
         $cacheKey = null;
     }
     if ($cacheKey && $this->cache->sha256($cacheKey) === $hash) {
         $packages = json_decode($this->cache->read($cacheKey), true);
     } else {
         $packages = $this->fetchFile($url, $cacheKey, $hash);
     }
     $this->providers[$name] = array();
     foreach ($packages['packages'] as $versions) {
         foreach ($versions as $version) {
             // avoid loading the same objects twice
             if (isset($this->providersByUid[$version['uid']])) {
                 // skip if already assigned
                 if (!isset($this->providers[$name][$version['uid']])) {
                     // expand alias in two packages
                     if ($this->providersByUid[$version['uid']] instanceof AliasPackage) {
                         $this->providers[$name][$version['uid']] = $this->providersByUid[$version['uid']]->getAliasOf();
                         $this->providers[$name][$version['uid'] . '-alias'] = $this->providersByUid[$version['uid']];
                     } else {
                         $this->providers[$name][$version['uid']] = $this->providersByUid[$version['uid']];
                     }
                     // check for root aliases
                     if (isset($this->providersByUid[$version['uid'] . '-root'])) {
                         $this->providers[$name][$version['uid'] . '-root'] = $this->providersByUid[$version['uid'] . '-root'];
                     }
                 }
             } else {
                 if (isset($version['provide']) || isset($version['replace'])) {
                     // collect names
                     $names = array(strtolower($version['name']) => true);
                     if (isset($version['provide'])) {
                         foreach ($version['provide'] as $target => $constraint) {
                             $names[strtolower($target)] = true;
                         }
                     }
                     if (isset($version['replace'])) {
                         foreach ($version['replace'] as $target => $constraint) {
                             $names[strtolower($target)] = true;
                         }
                     }
                     $names = array_keys($names);
                 } else {
                     $names = array(strtolower($version['name']));
                 }
                 if (!$pool->isPackageAcceptable(strtolower($version['name']), VersionParser::parseStability($version['version']))) {
                     continue;
                 }
                 // load acceptable packages in the providers
                 $package = $this->createPackage($version, 'Composer\\Package\\Package');
                 $package->setRepository($this);
                 if ($package instanceof AliasPackage) {
                     $aliased = $package->getAliasOf();
                     $aliased->setRepository($this);
                     $this->providers[$name][$version['uid']] = $aliased;
                     $this->providers[$name][$version['uid'] . '-alias'] = $package;
                     // override provider with its alias so it can be expanded in the if block above
                     $this->providersByUid[$version['uid']] = $package;
                 } else {
                     $this->providers[$name][$version['uid']] = $package;
                     $this->providersByUid[$version['uid']] = $package;
                 }
                 // handle root package aliases
                 unset($rootAliasData);
                 if (isset($this->rootAliases[$package->getName()][$package->getVersion()])) {
                     $rootAliasData = $this->rootAliases[$package->getName()][$package->getVersion()];
                 } elseif ($package instanceof AliasPackage && isset($this->rootAliases[$package->getName()][$package->getAliasOf()->getVersion()])) {
                     $rootAliasData = $this->rootAliases[$package->getName()][$package->getAliasOf()->getVersion()];
                 }
//.........这里部分代码省略.........
开发者ID:aminembarki,项目名称:composer,代码行数:101,代码来源:ComposerRepository.php

示例9: execute

 /**
  * {@inheritdoc}
  *
  * @throws \InvalidArgumentException When the target directory does not exist or symlink cannot be used
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $targetArg = rtrim($input->getArgument('target'), '/');
     if (!is_dir($targetArg)) {
         throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target')));
     }
     $wantedVersion = $input->getOption('jquery-version');
     $vParser = new VersionParser();
     try {
         $jQueryVersionConstraint = $vParser->parseConstraints($wantedVersion);
     } catch (UnexpectedValueException $e) {
         $output->writeln('<error>Error:</error> <info>' . $wantedVersion . '</info> is not a valid version constraint.');
         return;
     }
     $minimalVersionConstraint = $vParser->parseConstraints('>=' . $this->minimalSupportedVersion);
     if (!$minimalVersionConstraint->matches($jQueryVersionConstraint)) {
         $output->writeln('<error>Error:</error> <info>' . $wantedVersion . '</info> is not supported. Minimal version is: ' . $this->minimalSupportedVersion);
         return;
     }
     $curl = new Curl();
     $curl->get('https://api.github.com' . '/repos/jquery/jquery/tags?per_page=100');
     $versionToInstall = $this->minimalSupportedVersion;
     foreach (json_decode($curl->response) as $release) {
         $tag = $release->name;
         if ($vParser->parseStability($tag) == 'stable') {
             try {
                 $constraint = $vParser->parseConstraints($tag);
                 if ($jQueryVersionConstraint->matches($constraint)) {
                     if (version_compare($vParser->normalize($tag), $versionToInstall) > 0) {
                         $versionToInstall = $tag;
                     }
                 } else {
                 }
             } catch (UnexpectedValueException $e) {
             }
         }
     }
     /** @var Filesystem $filesystem */
     $filesystem = $this->getContainer()->get('filesystem');
     // Create the bundles directory otherwise symlink will fail.
     $bundlesDir = $targetArg . '/bundles/';
     $filesystem->mkdir($bundlesDir, 0777);
     $output->writeln('Installing JQuery assets.');
     $targetDir = $bundlesDir . 'jquery-extra';
     $namespaceParts = explode('\\', __NAMESPACE__);
     array_pop($namespaceParts);
     $output->writeln(sprintf('Installing assets for <comment>%s</comment> into <comment>%s</comment>', implode('\\', $namespaceParts), $targetDir));
     $filesystem->remove($targetDir);
     $filesystem->mkdir($targetDir, 0777);
     $filesystem->mkdir($targetDir . '/tmp');
     $zip = file_get_contents('https://github.com/jquery/jquery/archive/' . $versionToInstall . '.zip');
     file_put_contents($targetDir . '/tmp/jquery.zip', $zip);
     $zip = new \ZipArchive();
     if ($zip->open($targetDir . '/tmp/jquery.zip') === TRUE) {
         $zip->extractTo($targetDir . '/tmp');
         $zip->close();
         if (file_exists($targetDir . '/tmp/jquery-' . $versionToInstall . '/dist')) {
             $filesystem->mirror($targetDir . '/tmp/jquery-' . $versionToInstall . '/dist', $targetDir);
         } else {
             foreach (array('jquery.js', 'jquery.min.js', 'jquery.min.map', 'jquery-migrate.js', 'jquery-migrate.min.js') as $file) {
                 if (file_exists($targetDir . '/tmp/jquery-' . $versionToInstall . '/' . $file)) {
                     $filesystem->copy($targetDir . '/tmp/jquery-' . $versionToInstall . '/' . $file, $targetDir . '/' . $file);
                 }
             }
         }
         $filesystem->remove($targetDir . '/tmp');
     } else {
         throw new FileException('File Error');
     }
 }
开发者ID:symfony-bundle,项目名称:jquery-bundle,代码行数:75,代码来源:JQueryAssetsInstallCommand.php

示例10: addRepository

 /**
  * Adds a repository and its packages to this package pool
  *
  * @param RepositoryInterface $repo        A package repository
  * @param array               $rootAliases
  */
 public function addRepository(RepositoryInterface $repo, $rootAliases = array())
 {
     if ($repo instanceof CompositeRepository) {
         $repos = $repo->getRepositories();
     } else {
         $repos = array($repo);
     }
     foreach ($repos as $repo) {
         $this->repositories[] = $repo;
         $exempt = $repo instanceof PlatformRepository || $repo instanceof InstalledRepositoryInterface;
         if ($repo instanceof ComposerRepository && $repo->hasProviders()) {
             $this->providerRepos[] = $repo;
             $repo->setRootAliases($rootAliases);
             $repo->resetPackageIds();
         } elseif ($repo instanceof StreamableRepositoryInterface) {
             foreach ($repo->getMinimalPackages() as $package) {
                 $name = $package['name'];
                 $version = $package['version'];
                 $stability = VersionParser::parseStability($version);
                 // collect names
                 $names = array($name => true);
                 if (isset($package['provide'])) {
                     foreach ($package['provide'] as $target => $constraint) {
                         $names[$target] = true;
                     }
                 }
                 if (isset($package['replace'])) {
                     foreach ($package['replace'] as $target => $constraint) {
                         $names[$target] = true;
                     }
                 }
                 $names = array_keys($names);
                 if ($exempt || $this->isPackageAcceptable($names, $stability)) {
                     $package['id'] = $this->id++;
                     $this->packages[] = $package;
                     foreach ($names as $provided) {
                         $this->packageByName[$provided][$package['id']] = $this->packages[$this->id - 2];
                     }
                     // handle root package aliases
                     unset($rootAliasData);
                     if (isset($rootAliases[$name][$version])) {
                         $rootAliasData = $rootAliases[$name][$version];
                     } elseif (isset($package['alias_normalized']) && isset($rootAliases[$name][$package['alias_normalized']])) {
                         $rootAliasData = $rootAliases[$name][$package['alias_normalized']];
                     }
                     if (isset($rootAliasData)) {
                         $alias = $package;
                         unset($alias['raw']);
                         $alias['version'] = $rootAliasData['alias_normalized'];
                         $alias['alias'] = $rootAliasData['alias'];
                         $alias['alias_of'] = $package['id'];
                         $alias['id'] = $this->id++;
                         $alias['root_alias'] = true;
                         $this->packages[] = $alias;
                         foreach ($names as $provided) {
                             $this->packageByName[$provided][$alias['id']] = $this->packages[$this->id - 2];
                         }
                     }
                     // handle normal package aliases
                     if (isset($package['alias'])) {
                         $alias = $package;
                         unset($alias['raw']);
                         $alias['version'] = $package['alias_normalized'];
                         $alias['alias'] = $package['alias'];
                         $alias['alias_of'] = $package['id'];
                         $alias['id'] = $this->id++;
                         $this->packages[] = $alias;
                         foreach ($names as $provided) {
                             $this->packageByName[$provided][$alias['id']] = $this->packages[$this->id - 2];
                         }
                     }
                 }
             }
         } else {
             foreach ($repo->getPackages() as $package) {
                 $names = $package->getNames();
                 $stability = $package->getStability();
                 if ($exempt || $this->isPackageAcceptable($names, $stability)) {
                     $package->setId($this->id++);
                     $this->packages[] = $package;
                     foreach ($names as $provided) {
                         $this->packageByName[$provided][] = $package;
                     }
                     // handle root package aliases
                     $name = $package->getName();
                     if (isset($rootAliases[$name][$package->getVersion()])) {
                         $alias = $rootAliases[$name][$package->getVersion()];
                         if ($package instanceof AliasPackage) {
                             $package = $package->getAliasOf();
                         }
                         $aliasPackage = new AliasPackage($package, $alias['alias_normalized'], $alias['alias']);
                         $aliasPackage->setRootPackageAlias(true);
                         $aliasPackage->setId($this->id++);
                         $package->getRepository()->addPackage($aliasPackage);
//.........这里部分代码省略.........
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:101,代码来源:Pool.php

示例11: trim

 public function trim($versions, $stability)
 {
     return array_filter($versions, function ($item) use($stability) {
         return $stability === VersionParser::parseStability($item['version']);
     });
 }
开发者ID:luxifer,项目名称:dependensees,代码行数:6,代码来源:VersionTrim.php

示例12: extractReferences

 private function extractReferences(array $requires, array $references)
 {
     foreach ($requires as $reqName => $reqVersion) {
         if (preg_match('{^[^,\\s@]+?#([a-f0-9]+)$}', $reqVersion, $match) && 'dev' === ($stabilityName = VersionParser::parseStability($reqVersion))) {
             $name = strtolower($reqName);
             $references[$name] = $match[1];
         }
     }
     return $references;
 }
开发者ID:rufinus,项目名称:composer,代码行数:10,代码来源:RootPackageLoader.php

示例13: whatProvides

 /**
  * @param  Pool        $pool
  * @param  string      $name          package name
  * @param  bool        $bypassFilters If set to true, this bypasses the stability filtering, and forces a recompute without cache
  * @return array|mixed
  */
 public function whatProvides(Pool $pool, $name, $bypassFilters = false)
 {
     if (isset($this->providers[$name]) && !$bypassFilters) {
         return $this->providers[$name];
     }
     // skip platform packages, root package and composer-plugin-api
     if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $name) || '__root__' === $name || 'composer-plugin-api' === $name) {
         return array();
     }
     if (null === $this->providerListing) {
         $this->loadProviderListings($this->loadRootServerFile());
     }
     $useLastModifiedCheck = false;
     if ($this->lazyProvidersUrl && !isset($this->providerListing[$name])) {
         $hash = null;
         $url = str_replace('%package%', $name, $this->lazyProvidersUrl);
         $cacheKey = 'provider-' . strtr($name, '/', '$') . '.json';
         $useLastModifiedCheck = true;
     } elseif ($this->providersUrl) {
         // package does not exist in this repo
         if (!isset($this->providerListing[$name])) {
             return array();
         }
         $hash = $this->providerListing[$name]['sha256'];
         $url = str_replace(array('%package%', '%hash%'), array($name, $hash), $this->providersUrl);
         $cacheKey = 'provider-' . strtr($name, '/', '$') . '.json';
     } else {
         return array();
     }
     $packages = null;
     if ($cacheKey) {
         if (!$useLastModifiedCheck && $hash && $this->cache->sha256($cacheKey) === $hash) {
             $packages = json_decode($this->cache->read($cacheKey), true);
         } elseif ($useLastModifiedCheck) {
             if ($contents = $this->cache->read($cacheKey)) {
                 $contents = json_decode($contents, true);
                 if (isset($contents['last-modified'])) {
                     $response = $this->fetchFileIfLastModified($url, $cacheKey, $contents['last-modified']);
                     if (true === $response) {
                         $packages = $contents;
                     } elseif ($response) {
                         $packages = $response;
                     }
                 }
             }
         }
     }
     if (!$packages) {
         try {
             $packages = $this->fetchFile($url, $cacheKey, $hash, $useLastModifiedCheck);
         } catch (TransportException $e) {
             // 404s are acceptable for lazy provider repos
             if ($e->getStatusCode() === 404 && $this->lazyProvidersUrl) {
                 $packages = array('packages' => array());
             } else {
                 throw $e;
             }
         }
     }
     $this->providers[$name] = array();
     foreach ($packages['packages'] as $versions) {
         foreach ($versions as $version) {
             // avoid loading the same objects twice
             if (isset($this->providersByUid[$version['uid']])) {
                 // skip if already assigned
                 if (!isset($this->providers[$name][$version['uid']])) {
                     // expand alias in two packages
                     if ($this->providersByUid[$version['uid']] instanceof AliasPackage) {
                         $this->providers[$name][$version['uid']] = $this->providersByUid[$version['uid']]->getAliasOf();
                         $this->providers[$name][$version['uid'] . '-alias'] = $this->providersByUid[$version['uid']];
                     } else {
                         $this->providers[$name][$version['uid']] = $this->providersByUid[$version['uid']];
                     }
                     // check for root aliases
                     if (isset($this->providersByUid[$version['uid'] . '-root'])) {
                         $this->providers[$name][$version['uid'] . '-root'] = $this->providersByUid[$version['uid'] . '-root'];
                     }
                 }
             } else {
                 if (!$bypassFilters && !$pool->isPackageAcceptable(strtolower($version['name']), VersionParser::parseStability($version['version']))) {
                     continue;
                 }
                 // load acceptable packages in the providers
                 $package = $this->createPackage($version, 'Composer\\Package\\CompletePackage');
                 $package->setRepository($this);
                 if ($package instanceof AliasPackage) {
                     $aliased = $package->getAliasOf();
                     $aliased->setRepository($this);
                     $this->providers[$name][$version['uid']] = $aliased;
                     $this->providers[$name][$version['uid'] . '-alias'] = $package;
                     // override provider with its alias so it can be expanded in the if block above
                     $this->providersByUid[$version['uid']] = $package;
                 } else {
                     $this->providers[$name][$version['uid']] = $package;
//.........这里部分代码省略.........
开发者ID:detain,项目名称:composer,代码行数:101,代码来源:ComposerRepository.php

示例14: handle

 /**
  * {@inheritdoc}
  *
  * @SuppressWarnings(PHPMD.LongVariable)
  */
 public function handle(\Input $input)
 {
     $packageName = $input->get('solve');
     $version = base64_decode(rawurldecode($input->get('version')));
     if ($input->post('mark') || $input->post('install')) {
         // make a backup
         copy(TL_ROOT . '/' . $this->configPathname, TL_ROOT . '/' . $this->configPathname . '~');
         // update requires
         $json = new JsonFile(TL_ROOT . '/' . $this->configPathname);
         $config = $json->read();
         if (!array_key_exists('require', $config)) {
             $config['require'] = array();
         }
         $config['require'][$packageName] = $version;
         $json->write($config);
         Messages::addInfo(sprintf($GLOBALS['TL_LANG']['composer_client']['added_candidate'], $packageName, $version));
         $_SESSION['COMPOSER_OUTPUT'] .= $this->io->getOutput();
         if ($input->post('install')) {
             $this->redirect('contao/main.php?do=composer&update=packages');
         }
         $this->redirect('contao/main.php?do=composer');
     }
     /** @var RootPackage $rootPackage */
     $rootPackage = $this->composer->getPackage();
     $installedRootPackage = clone $rootPackage;
     $installedRootPackage->setRequires(array());
     $installedRootPackage->setDevRequires(array());
     $repositoryManager = $this->getRepositoryManager();
     $localRepository = $repositoryManager->getLocalRepository();
     $platformRepo = new PlatformRepository();
     $installedRepository = new CompositeRepository(array($localRepository, new InstalledArrayRepository(array($installedRootPackage)), $platformRepo));
     $versionParser = new VersionParser();
     $constraint = $versionParser->parseConstraints($version);
     $stability = $versionParser->parseStability($version);
     $aliases = $this->getRootAliases($rootPackage);
     $this->aliasPlatformPackages($platformRepo, $aliases);
     $stabilityFlags = $rootPackage->getStabilityFlags();
     $stabilityFlags[$packageName] = BasePackage::$stabilities[$stability];
     $pool = $this->getPool($rootPackage->getMinimumStability(), $stabilityFlags);
     $pool->addRepository($installedRepository, $aliases);
     $policy = new DefaultPolicy($rootPackage->getPreferStable());
     $request = new Request($pool);
     // add root package
     $rootPackageConstraint = $this->createConstraint('=', $rootPackage->getVersion());
     $rootPackageConstraint->setPrettyString($rootPackage->getPrettyVersion());
     $request->install($rootPackage->getName(), $rootPackageConstraint);
     // add requirements
     $links = $rootPackage->getRequires();
     /** @var Link $link */
     foreach ($links as $link) {
         if ($link->getTarget() != $packageName) {
             $request->install($link->getTarget(), $link->getConstraint());
         }
     }
     /** @var PackageInterface $package */
     foreach ($installedRepository->getPackages() as $package) {
         $request->install($package->getName(), $this->createConstraint('=', $package->getVersion()));
     }
     $operations = array();
     try {
         $solver = new Solver($policy, $pool, $installedRepository);
         $beforeOperations = $solver->solve($request);
         $request->install($packageName, $constraint);
         $operations = $solver->solve($request);
         /** @var \Composer\DependencyResolver\Operation\SolverOperation $beforeOperation */
         foreach ($beforeOperations as $beforeOperation) {
             /** @var \Composer\DependencyResolver\Operation\InstallOperation $operation */
             foreach ($operations as $index => $operation) {
                 if ($operation->getPackage()->getName() != $packageName && $beforeOperation->__toString() == $operation->__toString()) {
                     unset($operations[$index]);
                 }
             }
         }
     } catch (SolverProblemsException $e) {
         Messages::addError(sprintf('<span style="white-space: pre-line">%s</span>', trim($e->getMessage())));
     }
     $template = new \BackendTemplate('be_composer_client_solve');
     $template->composer = $this->composer;
     $template->packageName = $packageName;
     $template->packageVersion = $version;
     $template->operations = $operations;
     return $template->parse();
 }
开发者ID:contao-community-alliance,项目名称:composer-client,代码行数:88,代码来源:SolveController.php

示例15: addPackage

 /**
  * Add a package
  *
  * @param IOInterface $io
  * @param $packageName
  * @param $packageVersion
  */
 private static function addPackage(IOInterface $io, $packageName, $packageVersion)
 {
     $io->write(sprintf("  - Adding package <info>%s</info> (<comment>%s</comment>)", $packageName, $packageVersion));
     // Create package link
     $link = new Link('__root__', $packageName, null, 'requires', $packageVersion);
     // Add package to the root package and composer.json requirements
     if (in_array($packageName, self::$config['require-dev'])) {
         unset(self::$composerDefinition['require'][$packageName]);
         unset(self::$composerRequires[$packageName]);
         self::$composerDefinition['require-dev'][$packageName] = $packageVersion;
         self::$composerDevRequires[$packageName] = $link;
     } else {
         unset(self::$composerDefinition['require-dev'][$packageName]);
         unset(self::$composerDevRequires[$packageName]);
         self::$composerDefinition['require'][$packageName] = $packageVersion;
         self::$composerRequires[$packageName] = $link;
     }
     // Set package stability if needed
     switch (VersionParser::parseStability($packageVersion)) {
         case 'dev':
             self::$stabilityFlags[$packageName] = BasePackage::STABILITY_DEV;
             break;
         case 'alpha':
             self::$stabilityFlags[$packageName] = BasePackage::STABILITY_ALPHA;
             break;
         case 'beta':
             self::$stabilityFlags[$packageName] = BasePackage::STABILITY_BETA;
             break;
         case 'RC':
             self::$stabilityFlags[$packageName] = BasePackage::STABILITY_RC;
             break;
     }
 }
开发者ID:mtymek,项目名称:zend-expressive-skeleton,代码行数:40,代码来源:OptionalPackages.php


注:本文中的Composer\Package\Version\VersionParser::parseStability方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。