當前位置: 首頁>>代碼示例>>PHP>>正文


PHP VersionParser::parseConstraints方法代碼示例

本文整理匯總了PHP中Composer\Package\Version\VersionParser::parseConstraints方法的典型用法代碼示例。如果您正苦於以下問題:PHP VersionParser::parseConstraints方法的具體用法?PHP VersionParser::parseConstraints怎麽用?PHP VersionParser::parseConstraints使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Composer\Package\Version\VersionParser的用法示例。


在下文中一共展示了VersionParser::parseConstraints方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: checkPhpVersion

 /**
  * Checks PHP version
  *
  * @return array
  */
 public function checkPhpVersion()
 {
     try {
         $requiredVersion = $this->composerInformation->getRequiredPhpVersion();
     } catch (\Exception $e) {
         return [
             'responseType' => ResponseTypeInterface::RESPONSE_TYPE_ERROR,
             'data' => [
                 'error' => 'phpVersionError',
                 'message' => 'Cannot determine required PHP version: ' . $e->getMessage()
             ],
         ];
     }
     $multipleConstraints = $this->versionParser->parseConstraints($requiredVersion);
     try {
         $normalizedPhpVersion = $this->versionParser->normalize(PHP_VERSION);
     } catch (\UnexpectedValueException $e) {
         $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', PHP_VERSION);
         $normalizedPhpVersion = $this->versionParser->normalize($prettyVersion);
     }
     $currentPhpVersion = $this->versionParser->parseConstraints($normalizedPhpVersion);
     $responseType = ResponseTypeInterface::RESPONSE_TYPE_SUCCESS;
     if (!$multipleConstraints->matches($currentPhpVersion)) {
         $responseType = ResponseTypeInterface::RESPONSE_TYPE_ERROR;
     }
     return [
         'responseType' => $responseType,
         'data' => [
             'required' => $requiredVersion,
             'current' => PHP_VERSION,
         ],
     ];
 }
開發者ID:nblair,項目名稱:magescotch,代碼行數:38,代碼來源:PhpReadinessCheck.php

示例2: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$this->deploymentConfig->isAvailable()) {
         $output->writeln("<info>No information is available: the Magento application is not installed.</info>");
         return;
     }
     /** @var DbVersionInfo $dbVersionInfo */
     $dbVersionInfo = $this->objectManagerProvider->get()->get('Magento\\Framework\\Module\\DbVersionInfo');
     $outdated = $dbVersionInfo->getDbVersionErrors();
     if (!empty($outdated)) {
         $output->writeln("<info>The module code base doesn't match the DB schema and data.</info>");
         $versionParser = new VersionParser();
         $codebaseUpdateNeeded = false;
         foreach ($outdated as $row) {
             if (!$codebaseUpdateNeeded && $row[DbVersionInfo::KEY_CURRENT] !== 'none') {
                 // check if module code base update is needed
                 $currentVersion = $versionParser->parseConstraints($row[DbVersionInfo::KEY_CURRENT]);
                 $requiredVersion = $versionParser->parseConstraints('>' . $row[DbVersionInfo::KEY_REQUIRED]);
                 if ($requiredVersion->matches($currentVersion)) {
                     $codebaseUpdateNeeded = true;
                 }
             }
             $output->writeln(sprintf("<info>%20s %10s: %11s  ->  %-11s</info>", $row[DbVersionInfo::KEY_MODULE], $row[DbVersionInfo::KEY_TYPE], $row[DbVersionInfo::KEY_CURRENT], $row[DbVersionInfo::KEY_REQUIRED]));
         }
         if ($codebaseUpdateNeeded) {
             $output->writeln('<info>Some modules use code versions newer or older than the database. ' . "First update the module code, then run 'setup:upgrade'.</info>");
             // we must have an exit code higher than zero to indicate something was wrong
             return \Magento\Framework\Console\Cli::RETURN_FAILURE;
         } else {
             $output->writeln("<info>Run 'setup:upgrade' to update your DB schema and data.</info>");
         }
     } else {
         $output->writeln('<info>All modules are up to date.</info>');
     }
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:38,代碼來源:DbStatusCommand.php

示例3: isVersionMatching

 /**
  * Return true if $version matches $constraint (expressed as a Composer constraint string)
  *
  * @param  string $version
  * @param  string $constraint
  * @return bool
  */
 public function isVersionMatching($version, $constraint)
 {
     $versionParser = new VersionParser();
     $normalizedVersion = $versionParser->normalize($version);
     $versionAsContraint = $versionParser->parseConstraints($normalizedVersion);
     $linkConstraint = $versionParser->parseConstraints($constraint);
     return $linkConstraint->matches($versionAsContraint);
 }
開發者ID:kaayru,項目名稱:nodejs-installer,代碼行數:15,代碼來源:NodeJsVersionMatcher.php

示例4: selectPackage

 protected function selectPackage(IOInterface $io, $packageName, $version = null)
 {
     $io->writeError('<info>Searching for the specified package.</info>');
     if ($composer = $this->getComposer(false)) {
         $localRepo = $composer->getRepositoryManager()->getLocalRepository();
         $repos = new CompositeRepository(array_merge(array($localRepo), $composer->getRepositoryManager()->getRepositories()));
     } else {
         $defaultRepos = Factory::createDefaultRepositories($this->getIO());
         $io->writeError('No composer.json found in the current directory, searching packages from ' . implode(', ', array_keys($defaultRepos)));
         $repos = new CompositeRepository($defaultRepos);
     }
     $pool = new Pool();
     $pool->addRepository($repos);
     $parser = new VersionParser();
     $constraint = $version ? $parser->parseConstraints($version) : null;
     $packages = $pool->whatProvides($packageName, $constraint, true);
     if (count($packages) > 1) {
         $package = reset($packages);
         $io->writeError('<info>Found multiple matches, selected ' . $package->getPrettyString() . '.</info>');
         $io->writeError('Alternatives were ' . implode(', ', array_map(function ($p) {
             return $p->getPrettyString();
         }, $packages)) . '.');
         $io->writeError('<comment>Please use a more specific constraint to pick a different package.</comment>');
     } elseif ($packages) {
         $package = reset($packages);
         $io->writeError('<info>Found an exact match ' . $package->getPrettyString() . '.</info>');
     } else {
         $io->writeError('<error>Could not find a package matching ' . $packageName . '.</error>');
         return false;
     }
     return $package;
 }
開發者ID:VicDeo,項目名稱:poc,代碼行數:32,代碼來源:ArchiveCommand.php

示例5: getPackage

 /**
  * finds a package by name and version if provided
  *
  * @param  RepositoryInterface        $installedRepo
  * @param  RepositoryInterface        $repos
  * @param  string                     $name
  * @param  ConstraintInterface|string $version
  * @throws \InvalidArgumentException
  * @return array                      array(CompletePackageInterface, array of versions)
  */
 protected function getPackage(RepositoryInterface $installedRepo, RepositoryInterface $repos, $name, $version = null)
 {
     $name = strtolower($name);
     $constraint = is_string($version) ? $this->versionParser->parseConstraints($version) : $version;
     $policy = new DefaultPolicy();
     $pool = new Pool('dev');
     $pool->addRepository($repos);
     $matchedPackage = null;
     $versions = array();
     $matches = $pool->whatProvides($name, $constraint);
     foreach ($matches as $index => $package) {
         // skip providers/replacers
         if ($package->getName() !== $name) {
             unset($matches[$index]);
             continue;
         }
         // select an exact match if it is in the installed repo and no specific version was required
         if (null === $version && $installedRepo->hasPackage($package)) {
             $matchedPackage = $package;
         }
         $versions[$package->getPrettyVersion()] = $package->getVersion();
         $matches[$index] = $package->getId();
     }
     // select preferred package according to policy rules
     if (!$matchedPackage && $matches && ($preferred = $policy->selectPreferredPackages($pool, array(), $matches))) {
         $matchedPackage = $pool->literalToPackage($preferred[0]);
     }
     return array($matchedPackage, $versions);
 }
開發者ID:detain,項目名稱:composer,代碼行數:39,代碼來源:ShowCommand.php

示例6: phpVersionAction

 /**
  * Verifies php version
  *
  * @return JsonModel
  */
 public function phpVersionAction()
 {
     try {
         $requiredVersion = $this->phpInformation->getRequiredPhpVersion();
     } catch (\Exception $e) {
         return new JsonModel(['responseType' => ResponseTypeInterface::RESPONSE_TYPE_ERROR, 'data' => ['error' => 'phpVersionError', 'message' => 'Cannot determine required PHP version: ' . $e->getMessage()]]);
     }
     $multipleConstraints = $this->versionParser->parseConstraints($requiredVersion);
     $currentPhpVersion = new VersionConstraint('=', PHP_VERSION);
     $responseType = ResponseTypeInterface::RESPONSE_TYPE_SUCCESS;
     if (!$multipleConstraints->matches($currentPhpVersion)) {
         $responseType = ResponseTypeInterface::RESPONSE_TYPE_ERROR;
     }
     $data = ['responseType' => $responseType, 'data' => ['required' => $requiredVersion, 'current' => PHP_VERSION]];
     return new JsonModel($data);
 }
開發者ID:ViniciusAugusto,項目名稱:magento2,代碼行數:21,代碼來源:Environment.php

示例7: parse_basic_syntax

 public function parse_basic_syntax($args)
 {
     $version_parser = new VersionParser();
     $requires = array();
     foreach ($args as $requirement) {
         $name_length = strcspn($requirement, '>=|~');
         if (strlen($requirement) === $name_length) {
             // No version constraint specified, use wildcard
             $dependency_name = $requirement;
             $constraint_text = '*';
         } else {
             $dependency_name = substr($requirement, 0, $name_length);
             $constraint_text = substr($requirement, $name_length);
             // If the constraint is exactly '=', trim it for
             // Composer syntax compatibility
             if (strlen($constraint_text) >= 2 && $constraint_text[0] === '=' && is_numeric($constraint_text[1])) {
                 $constraint_text = substr($constraint_text, 1);
             }
         }
         if (strpos($dependency_name, '/') === false) {
             $dependency_name = 'wpackagist-plugin/' . $dependency_name;
         }
         $constraint = $version_parser->parseConstraints($constraint_text);
         $requires[] = new Link($this->plugin_name, $dependency_name, $constraint, 'requires', $constraint_text);
     }
     $this->setRequires($requires);
 }
開發者ID:rmccue,項目名稱:Courier,代碼行數:27,代碼來源:class-plugin.php

示例8: updateCompatibility

 private function updateCompatibility(Addon $addon, AddonVersion $version, CompletePackage $package)
 {
     $require = null;
     if ($package->getRequire()) {
         foreach ($package->getRequire() as $name => $link) {
             if ((string) $link == 'self.version') {
                 continue;
             }
             if ($name == 'silverstripe/framework') {
                 $require = $link;
                 break;
             }
             if ($name == 'silverstripe/cms') {
                 $require = $link;
             }
         }
     }
     if (!$require) {
         return;
     }
     $addon->CompatibleVersions()->removeAll();
     $version->CompatibleVersions()->removeAll();
     foreach ($this->silverstripes as $id => $link) {
         try {
             $constraint = $this->versionParser->parseConstraints($require);
             if ($link->matches($constraint)) {
                 $addon->CompatibleVersions()->add($id);
                 $version->CompatibleVersions()->add($id);
             }
         } catch (Exception $e) {
             // An exception here shouldn't prevent further updates.
             Debug::log($addon->Name . "\t" . $addon->ID . "\t" . $e->getMessage());
         }
     }
 }
開發者ID:newleeland,項目名稱:addons.silverstripe.org,代碼行數:35,代碼來源:AddonUpdater.php

示例9: has

 /**
  * Search for a given package version.
  *
  * Usage examples : Composition::has('php', '5.3.*') // PHP version
  *                  Composition::has('ext-memcache') // PHP extension
  *                  Composition::has('vendor/package', '>2.1') // Package version
  *
  * @param type $packageName  The package name
  * @param type $prettyString An optional version constraint
  *
  * @return boolean           Wether or not the package has been found.
  */
 public static function has($packageName, $prettyString = '*')
 {
     if (null === self::$pool) {
         if (null === self::$rootDir) {
             self::$rootDir = getcwd();
             if (!file_exists(self::$rootDir . '/composer.json')) {
                 throw new \RuntimeException('Unable to guess the project root dir, please specify it manually using the Composition::setRootDir method.');
             }
         }
         $minimumStability = 'dev';
         $config = new Config();
         $file = new JsonFile(self::$rootDir . '/composer.json');
         if ($file->exists()) {
             $projectConfig = $file->read();
             $config->merge($projectConfig);
             if (isset($projectConfig['minimum-stability'])) {
                 $minimumStability = $projectConfig['minimum-stability'];
             }
         }
         $vendorDir = self::$rootDir . '/' . $config->get('vendor-dir');
         $pool = new Pool($minimumStability);
         $pool->addRepository(new PlatformRepository());
         $pool->addRepository(new InstalledFilesystemRepository(new JsonFile($vendorDir . '/composer/installed.json')));
         $pool->addRepository(new InstalledFilesystemRepository(new JsonFile($vendorDir . '/composer/installed_dev.json')));
         self::$pool = $pool;
     }
     $parser = new VersionParser();
     $constraint = $parser->parseConstraints($prettyString);
     $packages = self::$pool->whatProvides($packageName, $constraint);
     return empty($packages) ? false : true;
 }
開發者ID:bamarni,項目名稱:composition,代碼行數:43,代碼來源:Composition.php

示例10: prepare

 protected function prepare()
 {
     if (Type::determinePickle($this->path, $matches) < 1) {
         throw new \Exception('Not a pickle git URI');
     }
     $this->name = $matches['package'];
     $extension = $this->fetchPackageJson();
     $versionParser = new VersionParser();
     if ($matches['version'] == '') {
         $versions = array_keys($extension['packages'][$this->name]);
         if (count($versions) > 1) {
             $versionToUse = $versions[1];
         } else {
             $versionToUse = $versions[0];
         }
     } else {
         $versionConstraints = $versionParser->parseConstraints($matches['version']);
         /* versions are sorted decreasing */
         foreach ($extension['packages'][$this->name] as $version => $release) {
             $constraint = new VersionConstraint('=', $versionParser->normalize($version));
             if ($versionConstraints->matches($constraint)) {
                 $versionToUse = $version;
                 break;
             }
         }
     }
     $package = $extension['packages'][$this->name][$versionToUse];
     $this->version = $versionToUse;
     $this->normalizedVersion = $versionParser->normalize($versionToUse);
     $this->name = $matches['package'];
     $this->prettyVersion = $this->version;
     $this->url = $package['source']['url'];
     $this->reference = $package['source']['reference'];
     $this->type = $package['source']['type'];
 }
開發者ID:jingdor,項目名稱:pickle,代碼行數:35,代碼來源:Pickle.php

示例11: getVersionConstraint

    /**
     * Get the link constraint of normalized version.
     *
     * @param string $normalizedVersion The normalized version
     *
     * @return LinkConstraintInterface The constraint
     */
    protected function getVersionConstraint($normalizedVersion)
    {
        if (preg_match('/^\d+(\.\d+)(\.\d+)(\.\d+)\-[A-Za-z0-9]+$/', $normalizedVersion)) {
            $normalizedVersion = substr($normalizedVersion, 0, strpos($normalizedVersion, '-'));
        }

        return $this->versionParser->parseConstraints($normalizedVersion);
    }
開發者ID:pombredanne,項目名稱:ArcherSys,代碼行數:15,代碼來源:VcsPackageFilter.php

示例12: addRootPackageRequirement

 /**
  * Add a requirement to the root package.
  *
  * @param array $requires
  * @param OptionalPackage $package
  * @return array
  */
 private function addRootPackageRequirement(array $requires, OptionalPackage $package)
 {
     $name = $package->getName();
     $constraint = $package->getConstraint();
     $description = $package->isDev() ? 'requires for development' : 'requires';
     $requires[$name] = new Link('__root__', $name, $this->versionParser->parseConstraints($constraint), $description, $constraint);
     return $requires;
 }
開發者ID:zendframework,項目名稱:zend-skeleton-installer,代碼行數:15,代碼來源:OptionalPackagesInstaller.php

示例13: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $file = Factory::getComposerFile();
     if (!file_exists($file) && !file_put_contents($file, "{\n}\n")) {
         $output->writeln('<error>' . $file . ' could not be created.</error>');
         return 1;
     }
     if (!is_readable($file)) {
         $output->writeln('<error>' . $file . ' is not readable.</error>');
         return 1;
     }
     if (!is_writable($file)) {
         $output->writeln('<error>' . $file . ' is not writable.</error>');
         return 1;
     }
     $json = new JsonFile($file);
     $composer = $json->read();
     $composerBackup = file_get_contents($json->getPath());
     $requirements = $this->determineRequirements($input, $output, $input->getArgument('packages'));
     $requireKey = $input->getOption('dev') ? 'require-dev' : 'require';
     $removeKey = $input->getOption('dev') ? 'require' : 'require-dev';
     $baseRequirements = array_key_exists($requireKey, $composer) ? $composer[$requireKey] : array();
     $requirements = $this->formatRequirements($requirements);
     // validate requirements format
     $versionParser = new VersionParser();
     foreach ($requirements as $constraint) {
         $versionParser->parseConstraints($constraint);
     }
     if (!$this->updateFileCleanly($json, $baseRequirements, $requirements, $requireKey, $removeKey)) {
         foreach ($requirements as $package => $version) {
             $baseRequirements[$package] = $version;
             if (isset($composer[$removeKey][$package])) {
                 unset($composer[$removeKey][$package]);
             }
         }
         $composer[$requireKey] = $baseRequirements;
         $json->write($composer);
     }
     $output->writeln('<info>' . $file . ' has been updated</info>');
     if ($input->getOption('no-update')) {
         return 0;
     }
     $updateDevMode = !$input->getOption('update-no-dev');
     // Update packages
     $composer = $this->getComposer();
     $composer->getDownloadManager()->setOutputProgress(!$input->getOption('no-progress'));
     $io = $this->getIO();
     $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'require', $input, $output);
     $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
     $install = Installer::create($io, $composer);
     $install->setVerbose($input->getOption('verbose'))->setPreferSource($input->getOption('prefer-source'))->setPreferDist($input->getOption('prefer-dist'))->setDevMode($updateDevMode)->setUpdate(true)->setUpdateWhitelist(array_keys($requirements))->setWhitelistDependencies($input->getOption('update-with-dependencies'));
     $status = $install->run();
     if ($status !== 0) {
         $output->writeln("\n" . '<error>Installation failed, reverting ' . $file . ' to its original content.</error>');
         file_put_contents($json->getPath(), $composerBackup);
     }
     return $status;
 }
開發者ID:aminembarki,項目名稱:composer,代碼行數:58,代碼來源:RequireCommand.php

示例14: getConflictMessages

 /**
  * Check if two modules are conflicted and get the message for display
  *
  * @param string $moduleA
  * @param string $moduleB
  * @return string[]
  */
 private function getConflictMessages($moduleA, $moduleB)
 {
     $messages = [];
     $versionParser = new VersionParser();
     if (isset($this->packageInfo->getConflict($moduleB)[$moduleA]) && $this->packageInfo->getConflict($moduleB)[$moduleA] && $this->packageInfo->getVersion($moduleA)) {
         $constraintA = $versionParser->parseConstraints($this->packageInfo->getConflict($moduleB)[$moduleA]);
         $constraintB = $versionParser->parseConstraints($this->packageInfo->getVersion($moduleA));
         if ($constraintA->matches($constraintB)) {
             $messages[] = "{$moduleB} conflicts with current {$moduleA} version " . $this->packageInfo->getVersion($moduleA) . ' (version should not be ' . $this->packageInfo->getConflict($moduleB)[$moduleA] . ')';
         }
     }
     if (isset($this->packageInfo->getConflict($moduleA)[$moduleB]) && $this->packageInfo->getConflict($moduleA)[$moduleB] && $this->packageInfo->getVersion($moduleB)) {
         $constraintA = $versionParser->parseConstraints($this->packageInfo->getConflict($moduleA)[$moduleB]);
         $constraintB = $versionParser->parseConstraints($this->packageInfo->getVersion($moduleB));
         if ($constraintA->matches($constraintB)) {
             $messages[] = "{$moduleA} conflicts with current {$moduleB} version " . $this->packageInfo->getVersion($moduleA) . ' (version should not be ' . $this->packageInfo->getConflict($moduleA)[$moduleB] . ')';
         }
     }
     return $messages;
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:27,代碼來源:ConflictChecker.php

示例15: execute

 /**
  * Require (install) a package.
  *
  * @param array $package Package names and version to require
  *                       - Format: ['name' => '', 'version' => '']
  *
  * @throws \Bolt\Exception\PackageManagerException
  *
  * @return int 0 on success or a positive error code on failure
  */
 public function execute(array $package)
 {
     $this->getComposer();
     $io = $this->getIO();
     /** @var \Bolt\Filesystem\Handler\JsonFile $jsonFile */
     $jsonFile = $this->getOptions()->composerJson();
     $newlyCreated = !$jsonFile->exists();
     if ($newlyCreated) {
         $this->app['extend.manager.json']->update();
     }
     // Format the package array
     $package = $this->formatRequirements($package);
     // Validate requirements format
     $versionParser = new VersionParser();
     foreach ($package as $constraint) {
         $versionParser->parseConstraints($constraint);
     }
     // Get a back up of the file contents
     $composerBackup = $jsonFile->parse();
     // Update our JSON file now with a specific version.
     // This is what Composer will read, and use, internally during the process.
     // After that is complete, we'll re-save with a constraint
     $this->updateComposerJson($jsonFile, $package, false);
     // JSON file has been created/updated, if we're not installing, exit
     if ($this->getOptions()->noUpdate()) {
         return 0;
     }
     // Reload Composer config
     $composer = $this->resetComposer();
     /** @var $install \Composer\Installer */
     $install = Installer::create($io, $composer)->setVerbose($this->getOptions()->verbose())->setPreferSource($this->getOptions()->preferSource())->setPreferDist($this->getOptions()->preferDist())->setDevMode(!$this->getOptions()->updateNoDev())->setOptimizeAutoloader($this->getOptions()->optimizeAutoloader())->setClassMapAuthoritative($this->getOptions()->classmapAuthoritative())->setUpdate($this->getOptions()->update())->setUpdateWhitelist(array_keys($package))->setWhitelistDependencies($this->getOptions()->updateWithDependencies())->setIgnorePlatformRequirements($this->getOptions()->ignorePlatformReqs())->setRunScripts(!$this->getOptions()->noScripts());
     try {
         $status = $install->run();
         if ($status !== 0) {
             if ($newlyCreated) {
                 // Installation failed, deleting JSON
                 $jsonFile->delete();
             } else {
                 // Installation failed, reverting JSON to its original content
                 $jsonFile->dump($composerBackup);
             }
         }
         // Update our JSON file now with a constraint
         $this->updateComposerJson($jsonFile, $package, true);
         return $status;
     } catch (\Exception $e) {
         // Installation failed, reverting JSON to its original content
         $jsonFile->dump($composerBackup);
         $msg = sprintf('%s recieved an error from Composer: %s in %s::%s', __METHOD__, $e->getMessage(), $e->getFile(), $e->getLine());
         $this->app['logger.system']->critical($msg, ['event' => 'exception', 'exception' => $e]);
         throw new PackageManagerException($e->getMessage(), $e->getCode(), $e);
     }
 }
開發者ID:bolt,項目名稱:bolt,代碼行數:63,代碼來源:RequirePackage.php


注:本文中的Composer\Package\Version\VersionParser::parseConstraints方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。