本文整理汇总了PHP中Composer\Package\PackageInterface::getRequires方法的典型用法代码示例。如果您正苦于以下问题:PHP PackageInterface::getRequires方法的具体用法?PHP PackageInterface::getRequires怎么用?PHP PackageInterface::getRequires使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Package\PackageInterface
的用法示例。
在下文中一共展示了PackageInterface::getRequires方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validatePackage
/**
* @param PackageInterface $package
* @param bool $allowDevMaster
*
* @return \string[]
*/
public function validatePackage(PackageInterface $package, $allowDevMaster = false)
{
$errors = [];
$versionParser = new VersionParser();
/** @noinspection ExceptionsAnnotatingAndHandlingInspection */
$devMaster = new Constraint('==', $versionParser->normalize('dev-master'));
foreach ($package->getRequires() as $link) {
$linkConstraint = $link->getConstraint();
if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $link->getTarget())) {
continue;
}
if ($linkConstraint->matches($devMaster)) {
if ($allowDevMaster) {
continue;
}
$errors[] = sprintf('Package "%s" is required with branch constraint %s', $link->getTarget(), $linkConstraint->getPrettyString());
}
$constraints = [$linkConstraint];
if ($linkConstraint instanceof MultiConstraint) {
$constraints = (new ConstraintAccessor($linkConstraint))->getConstraints();
}
foreach ($constraints as $constraint) {
if ('dev-' === substr($constraint->getPrettyString(), 0, 4)) {
$errors[] = sprintf('Package "%s" is required with branch constraint %s', $link->getTarget(), $linkConstraint->getPrettyString());
}
}
}
return $errors;
}
示例2: collectLinks
private function collectLinks($noInstallRecommends, $installSuggests)
{
$links = $this->package->getRequires();
if (!$noInstallRecommends) {
$links = array_merge($links, $this->package->getRecommends());
}
if ($installSuggests) {
$links = array_merge($links, $this->package->getSuggests());
}
return $links;
}
示例3: checkDependencies
/**
* @param \Composer\IO\IOInterface $io
* @param \Composer\Package\PackageInterface $package
* @return bool
*/
public static function checkDependencies(IOInterface $io, PackageInterface $package)
{
$search = 'wp-cli/wp-cli';
$requires = $package->getRequires();
$requiresDev = $package->getDevRequires();
if (isset($requires[$search]) or isset($requiresDev[$search])) {
return true;
}
$io->writeError('<info>This package is a dependency of `wp-cli/wp-cli`. Skipping.</info>');
return false;
}
示例4: collectDependencies
protected function collectDependencies(Pool $pool, array $collected, PackageInterface $package)
{
$requires = array_merge($package->getRequires(), $package->getDevRequires());
foreach ($requires as $requireLink) {
$requiredPackage = $this->lookupInstalledPackage($pool, $requireLink);
if ($requiredPackage && !isset($collected[$requiredPackage->getName()])) {
$collected[$requiredPackage->getName()] = $requiredPackage;
$collected = $this->collectDependencies($pool, $collected, $requiredPackage);
}
}
return $collected;
}
示例5: filterRequiredPackages
private function filterRequiredPackages(RepositoryInterface $repo, PackageInterface $package, $bucket = array())
{
$requires = array_keys($package->getRequires());
$packageListNames = array_keys($bucket);
$packages = array_filter($repo->getPackages(), function ($package) use($requires, $packageListNames) {
return in_array($package->getName(), $requires) && !in_array($package->getName(), $packageListNames);
});
$bucket = $this->appendPackages($packages, $bucket);
foreach ($packages as $package) {
$bucket = $this->filterRequiredPackages($repo, $package, $bucket);
}
return $bucket;
}
示例6: isDependentPackage
/**
* Indicate whether a package has the target package as a dependency
*
* @param PackageInterface $package
* @param bool $devMode
* @return bool
*/
private function isDependentPackage(PackageInterface $package, $devMode = false)
{
$packages = $package->getRequires();
if ($devMode) {
$packages = array_merge($packages, $package->getDevRequires());
}
foreach ($packages as $link) {
/** @var \Composer\Package\Link $link */
if ($this->targetPackage === $link->getTarget()) {
return true;
}
}
return false;
}
示例7: buildDependencyGraph
/**
* Build the dependency graph with installed packages.
*
* @param RepositoryInterface $repository
* @param PackageInterface $package
* @param array $dependencyGraph
*/
protected function buildDependencyGraph(array $localPackages, RepositoryInterface $repository, PackageInterface $package, $requiredFrom, $requiredConstraint, array &$dependencyGraph, $isLast, $parents = 0, $stack = array())
{
$current = (object) array('package' => $package, 'required' => (object) array('from' => $requiredFrom, 'constraint' => $requiredConstraint, 'parents' => $parents), 'lastInLevel' => $isLast ? $parents - 1 : -1);
if (in_array($package->getName(), $stack)) {
$current->recursion = true;
$dependencyGraph[] = $current;
return;
}
$dependencyGraph[] = $current;
$stack[] = $package->getName();
$requires = $package->getRequires();
$requiresCount = count($requires);
$index = 0;
/** @var string $requireName */
/** @var \Composer\Package\Link $requireLink */
foreach ($requires as $requireName => $requireLink) {
if (isset($localPackages[$requireName])) {
$this->buildDependencyGraph($localPackages, $repository, $localPackages[$requireName], $package, $requireLink->getPrettyConstraint(), $dependencyGraph, ++$index == $requiresCount, $parents + 1, $stack);
} else {
$dependencyGraph[] = (object) array('package' => $requireName, 'required' => (object) array('from' => $package, 'constraint' => $requireLink->getPrettyConstraint(), 'parents' => $parents + 1), 'lastInLevel' => ++$index == $requiresCount ? $parents : -1);
}
}
}
示例8: isDependantPackage
/**
* Returns true if the supplied package requires the Composer Grunt bridge.
*
* @param PackageInterface $package The package to inspect.
* @param boolean|null $includeDevDependencies True if the dev dependencies should also be inspected.
*
* @return boolean True if the package requires the bridge.
*/
public function isDependantPackage(PackageInterface $package, $includeDevDependencies = null)
{
if (null === $includeDevDependencies) {
$includeDevDependencies = false;
}
foreach ($package->getRequires() as $link) {
if ('johnpbloch/composer-grunt-bridge' === $link->getTarget()) {
return true;
}
}
if ($includeDevDependencies) {
foreach ($package->getDevRequires() as $link) {
if ('johnpbloch/composer-grunt-bridge' === $link->getTarget()) {
return true;
}
}
}
return false;
}
示例9: searchInPackage
/**
* Search for dependencies in this package.
*
* @param PackageInterface $package The package to search in.
*
* @return void
*/
private function searchInPackage(PackageInterface $package)
{
$this->progress->advance();
if ($package instanceof AliasPackage || $this->searchInDevReleases && !$package->isDev() || $this->searchInReleases && $package->isDev()) {
return;
}
$this->progress->setMessage($package->getName());
$requires = $package->getRequires();
$this->searchInRequires($package, 'prod', $requires);
$requires = $package->getDevRequires();
$this->searchInRequires($package, 'dev', $requires);
}
示例10: doInstall
protected function doInstall($localRepo, $installedRepo, $aliases, $devMode = false)
{
$minimumStability = $this->package->getMinimumStability();
$stabilityFlags = $this->package->getStabilityFlags();
// initialize locker to create aliased packages
if (!$this->update && $this->locker->isLocked($devMode)) {
$lockedPackages = $this->locker->getLockedPackages($devMode);
$minimumStability = $this->locker->getMinimumStability();
$stabilityFlags = $this->locker->getStabilityFlags();
}
$this->whitelistUpdateDependencies($localRepo, $devMode, $this->package->getRequires(), $this->package->getDevRequires());
$this->io->write('<info>Loading composer repositories with package information</info>');
// creating repository pool
$pool = new Pool($minimumStability, $stabilityFlags);
$pool->addRepository($installedRepo);
foreach ($this->repositoryManager->getRepositories() as $repository) {
$pool->addRepository($repository);
}
// creating requirements request
$installFromLock = false;
$request = new Request($pool);
$constraint = new VersionConstraint('=', $this->package->getVersion());
$request->install($this->package->getName(), $constraint);
if ($this->update) {
$this->io->write('<info>Updating ' . ($devMode ? 'dev ' : '') . 'dependencies</info>');
$request->updateAll();
$links = $devMode ? $this->package->getDevRequires() : $this->package->getRequires();
foreach ($links as $link) {
$request->install($link->getTarget(), $link->getConstraint());
}
} elseif ($this->locker->isLocked($devMode)) {
$installFromLock = true;
$this->io->write('<info>Installing ' . ($devMode ? 'dev ' : '') . 'dependencies from lock file</info>');
if (!$this->locker->isFresh() && !$devMode) {
$this->io->write('<warning>Your lock file is out of sync with your composer.json, run "composer.phar update" to update dependencies</warning>');
}
foreach ($lockedPackages as $package) {
$version = $package->getVersion();
foreach ($aliases as $alias) {
if ($alias['package'] === $package->getName() && $alias['version'] === $package->getVersion()) {
$version = $alias['alias_normalized'];
break;
}
}
$constraint = new VersionConstraint('=', $version);
$request->install($package->getName(), $constraint);
}
} else {
$this->io->write('<info>Installing ' . ($devMode ? 'dev ' : '') . 'dependencies</info>');
$links = $devMode ? $this->package->getDevRequires() : $this->package->getRequires();
foreach ($links as $link) {
$request->install($link->getTarget(), $link->getConstraint());
}
}
// fix the version of all installed packages (+ platform) that are not
// in the current local repo to prevent rogue updates (e.g. non-dev
// updating when in dev)
foreach ($installedRepo->getPackages() as $package) {
if ($package->getRepository() === $localRepo) {
continue;
}
$constraint = new VersionConstraint('=', $package->getVersion());
$request->install($package->getName(), $constraint);
}
// if the updateWhitelist is enabled, packages not in it are also fixed
// to the version specified in the lock, or their currently installed version
if ($this->update && $this->updateWhitelist) {
if ($this->locker->isLocked($devMode)) {
$currentPackages = $this->locker->getLockedPackages($devMode);
} else {
$currentPackages = $installedRepo->getPackages();
}
// collect links from composer as well as installed packages
$candidates = array();
foreach ($links as $link) {
$candidates[$link->getTarget()] = true;
}
foreach ($localRepo->getPackages() as $package) {
$candidates[$package->getName()] = true;
}
// fix them to the version in lock (or currently installed) if they are not updateable
foreach ($candidates as $candidate => $dummy) {
foreach ($currentPackages as $curPackage) {
if ($curPackage->getName() === $candidate) {
if ($this->isUpdateable($curPackage)) {
break;
}
$constraint = new VersionConstraint('=', $curPackage->getVersion());
$request->install($curPackage->getName(), $constraint);
}
}
}
}
// prepare solver
$policy = new DefaultPolicy();
$solver = new Solver($policy, $pool, $installedRepo);
// solve dependencies
try {
$operations = $solver->solve($request);
} catch (SolverProblemsException $e) {
//.........这里部分代码省略.........
示例11: getRequired
/**
* Gets the required Links if needed.
*
* @param PackageInterface $package A package
*
* @return Link[]
*/
private function getRequired(PackageInterface $package)
{
$required = array();
if ($this->requireDependencies) {
$required = $package->getRequires();
}
if ($this->requireDevDependencies) {
$required = array_merge($required, $package->getDevRequires());
}
return $required;
}
示例12: doInstall
protected function doInstall($localRepo, $installedRepo, $aliases, $devMode = false)
{
// creating repository pool
$pool = new Pool();
$pool->addRepository($installedRepo);
foreach ($this->repositoryManager->getRepositories() as $repository) {
$pool->addRepository($repository);
}
// creating requirements request
$installFromLock = false;
$request = new Request($pool);
if ($this->update) {
$this->io->write('<info>Updating ' . ($devMode ? 'dev ' : '') . 'dependencies</info>');
$request->updateAll();
$links = $devMode ? $this->package->getDevRequires() : $this->package->getRequires();
foreach ($links as $link) {
$request->install($link->getTarget(), $link->getConstraint());
}
} elseif ($this->locker->isLocked($devMode)) {
$installFromLock = true;
$this->io->write('<info>Installing ' . ($devMode ? 'dev ' : '') . 'dependencies from lock file</info>');
if (!$this->locker->isFresh() && !$devMode) {
$this->io->write('<warning>Your lock file is out of sync with your composer.json, run "composer.phar update" to update dependencies</warning>');
}
foreach ($this->locker->getLockedPackages($devMode) as $package) {
$version = $package->getVersion();
foreach ($aliases as $alias) {
if ($alias['package'] === $package->getName() && $alias['version'] === $package->getVersion()) {
$version = $alias['alias'];
break;
}
}
$constraint = new VersionConstraint('=', $version);
$request->install($package->getName(), $constraint);
}
} else {
$this->io->write('<info>Installing ' . ($devMode ? 'dev ' : '') . 'dependencies</info>');
$links = $devMode ? $this->package->getDevRequires() : $this->package->getRequires();
foreach ($links as $link) {
$request->install($link->getTarget(), $link->getConstraint());
}
}
// fix the version all installed packages that are not in the current local repo to prevent rogue updates
foreach ($installedRepo->getPackages() as $package) {
if ($package->getRepository() === $localRepo || $package->getRepository() instanceof PlatformRepository) {
continue;
}
$constraint = new VersionConstraint('=', $package->getVersion());
$request->install($package->getName(), $constraint);
}
// prepare solver
$policy = new DefaultPolicy();
$solver = new Solver($policy, $pool, $installedRepo);
// solve dependencies
try {
$operations = $solver->solve($request);
} catch (SolverProblemsException $e) {
$this->io->write('<error>Your requirements could not be solved to an installable set of packages.</error>');
$this->io->write($e->getMessage());
return false;
}
// force dev packages to be updated if we update or install from a (potentially new) lock
if ($this->update || $installFromLock) {
foreach ($localRepo->getPackages() as $package) {
// skip non-dev packages
if (!$package->isDev()) {
continue;
}
// skip packages that will be updated/uninstalled
foreach ($operations as $operation) {
if ('update' === $operation->getJobType() && $operation->getInitialPackage()->equals($package) || 'uninstall' === $operation->getJobType() && $operation->getPackage()->equals($package)) {
continue 2;
}
}
// force update to latest on update
if ($this->update) {
$newPackage = $this->repositoryManager->findPackage($package->getName(), $package->getVersion());
if ($newPackage && $newPackage->getSourceReference() !== $package->getSourceReference()) {
$operations[] = new UpdateOperation($package, $newPackage);
}
} elseif ($installFromLock) {
// force update to locked version if it does not match the installed version
$lockData = $this->locker->getLockData();
unset($lockedReference);
foreach ($lockData['packages'] as $lockedPackage) {
if (!empty($lockedPackage['source-reference']) && strtolower($lockedPackage['package']) === $package->getName()) {
$lockedReference = $lockedPackage['source-reference'];
break;
}
}
if (isset($lockedReference) && $lockedReference !== $package->getSourceReference()) {
// changing the source ref to update to will be handled in the operations loop below
$operations[] = new UpdateOperation($package, $package);
}
}
}
}
// anti-alias local repository to allow updates to work fine
foreach ($localRepo->getPackages() as $package) {
if ($package instanceof AliasPackage) {
//.........这里部分代码省略.........
示例13: isDependantPackage
/**
* Returns true if the supplied package requires the Composer NPM bridge.
*
* @param PackageInterface $package The package to inspect.
* @param boolean $includeDevDependencies True if the dev dependencies should also be inspected.
*
* @return boolean True if the package requires the bridge.
*/
public function isDependantPackage(PackageInterface $package, $includeDevDependencies = false)
{
foreach ($package->getRequires() as $link) {
if ('eloquent/composer-npm-bridge' === $link->getTarget()) {
return true;
}
}
if ($includeDevDependencies) {
foreach ($package->getDevRequires() as $link) {
if ('eloquent/composer-npm-bridge' === $link->getTarget()) {
return true;
}
}
}
return false;
}
示例14: fillDependencyMap
/**
* Fill the dependency graph with installed packages.
*
* @param RepositoryInterface $repository
* @param PackageInterface $package
* @param array $dependencyMap
*/
protected function fillDependencyMap(PackageInterface $package, array &$dependencyMap, $inverted)
{
/** @var \Composer\Package\Link $requireLink */
foreach ($package->getRequires() as $requireLink) {
if ($inverted) {
$dependencyMap[$package->getName()][$requireLink->getTarget()] = $requireLink->getPrettyConstraint();
} else {
$dependencyMap[$requireLink->getTarget()][$package->getName()] = $requireLink->getPrettyConstraint();
}
}
}
示例15: getRequires
/**
* {@inheritdoc}
*/
public function getRequires()
{
return $this->package->getRequires();
}