本文整理汇总了PHP中Composer\Installer\InstallationManager::isPackageInstalled方法的典型用法代码示例。如果您正苦于以下问题:PHP InstallationManager::isPackageInstalled方法的具体用法?PHP InstallationManager::isPackageInstalled怎么用?PHP InstallationManager::isPackageInstalled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Installer\InstallationManager
的用法示例。
在下文中一共展示了InstallationManager::isPackageInstalled方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: install
public static function install(Event $event)
{
if (!self::init($event)) {
return;
}
$notInstalled = 0;
if (!empty(self::$toInstall)) {
self::$io->write('<info>Installing platform-specific dependencies</info>');
foreach (self::$toInstall as $package) {
if (!self::$installer->isPackageInstalled(self::$localRepo, $package)) {
self::$installer->install(self::$localRepo, new InstallOperation($package));
self::updateBinary($package);
} else {
$notInstalled++;
}
}
}
if (empty(self::$toInstall) || $notInstalled > 0) {
self::$io->write('Nothing to install or update in platform-specific dependencies');
}
}
示例2: doInstall
protected function doInstall($localRepo, $installedRepo, $platformRepo, $aliases, $withDevReqs)
{
// init vars
$lockedRepository = null;
$repositories = null;
// initialize locker to create aliased packages
$installFromLock = false;
if (!$this->update && $this->locker->isLocked()) {
$installFromLock = true;
try {
$lockedRepository = $this->locker->getLockedRepository($withDevReqs);
} catch (\RuntimeException $e) {
// if there are dev requires, then we really can not install
if ($this->package->getDevRequires()) {
throw $e;
}
// no require-dev in composer.json and the lock file was created with no dev info, so skip them
$lockedRepository = $this->locker->getLockedRepository();
}
}
$this->whitelistUpdateDependencies($localRepo, $withDevReqs, $this->package->getRequires(), $this->package->getDevRequires());
$this->io->writeError('<info>Loading composer repositories with package information</info>');
// creating repository pool
$policy = $this->createPolicy();
$pool = $this->createPool($withDevReqs, $lockedRepository);
$pool->addRepository($installedRepo, $aliases);
if ($installFromLock) {
$pool->addRepository($lockedRepository, $aliases);
}
if (!$installFromLock) {
$repositories = $this->repositoryManager->getRepositories();
foreach ($repositories as $repository) {
$pool->addRepository($repository, $aliases);
}
}
// creating requirements request
$request = $this->createRequest($pool, $this->package, $platformRepo);
if (!$installFromLock) {
// remove unstable packages from the localRepo if they don't match the current stability settings
$removedUnstablePackages = array();
foreach ($localRepo->getPackages() as $package) {
if (!$pool->isPackageAcceptable($package->getNames(), $package->getStability()) && $this->installationManager->isPackageInstalled($localRepo, $package)) {
$removedUnstablePackages[$package->getName()] = true;
$request->remove($package->getName(), new VersionConstraint('=', $package->getVersion()));
}
}
}
if ($this->update) {
$this->io->writeError('<info>Updating dependencies' . ($withDevReqs ? ' (including require-dev)' : '') . '</info>');
$request->updateAll();
if ($withDevReqs) {
$links = array_merge($this->package->getRequires(), $this->package->getDevRequires());
} else {
$links = $this->package->getRequires();
}
foreach ($links as $link) {
$request->install($link->getTarget(), $link->getConstraint());
}
// 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->updateWhitelist) {
if ($this->locker->isLocked()) {
try {
$currentPackages = $this->locker->getLockedRepository($withDevReqs)->getPackages();
} catch (\RuntimeException $e) {
// fetch only non-dev packages from lock if doing a dev update fails due to a previously incomplete lock file
$currentPackages = $this->locker->getLockedRepository()->getPackages();
}
} else {
$currentPackages = $installedRepo->getPackages();
}
// collect packages to fixate from root requirements 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) && !isset($removedUnstablePackages[$curPackage->getName()])) {
$constraint = new VersionConstraint('=', $curPackage->getVersion());
$request->install($curPackage->getName(), $constraint);
}
break;
}
}
}
}
} elseif ($installFromLock) {
$this->io->writeError('<info>Installing dependencies' . ($withDevReqs ? ' (including require-dev)' : '') . ' from lock file</info>');
if (!$this->locker->isFresh()) {
$this->io->writeError('<warning>Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.</warning>');
}
foreach ($lockedRepository->getPackages() as $package) {
$version = $package->getVersion();
if (isset($aliases[$package->getName()][$version])) {
//.........这里部分代码省略.........
示例3: purgePackages
/**
* @param WritableRepositoryInterface $repo repository to purge packages from
* @param Installer\InstallationManager $im manager to check whether packages are still installed
*/
protected function purgePackages(WritableRepositoryInterface $repo, Installer\InstallationManager $im)
{
foreach ($repo->getPackages() as $package) {
if (!$im->isPackageInstalled($repo, $package)) {
$repo->removePackage($package);
}
}
}
示例4: doInstall
/**
* @param RepositoryInterface $localRepo
* @param RepositoryInterface $installedRepo
* @param PlatformRepository $platformRepo
* @param array $aliases
* @return array [int, PackageInterfaces[]|null] with the exit code and an array of dev packages on update, or null on install
*/
protected function doInstall($localRepo, $installedRepo, $platformRepo, $aliases)
{
// init vars
$lockedRepository = null;
$repositories = null;
// initialize locked repo if we are installing from lock or in a partial update
// and a lock file is present as we need to force install non-whitelisted lock file
// packages in that case
if (!$this->update || !empty($this->updateWhitelist) && $this->locker->isLocked()) {
try {
$lockedRepository = $this->locker->getLockedRepository($this->devMode);
} catch (\RuntimeException $e) {
// if there are dev requires, then we really can not install
if ($this->package->getDevRequires()) {
throw $e;
}
// no require-dev in composer.json and the lock file was created with no dev info, so skip them
$lockedRepository = $this->locker->getLockedRepository();
}
}
$this->whitelistUpdateDependencies($localRepo, $this->package->getRequires(), $this->package->getDevRequires());
$this->io->writeError('<info>Loading composer repositories with package information</info>');
// creating repository pool
$policy = $this->createPolicy();
$pool = $this->createPool($this->update ? null : $lockedRepository);
$pool->addRepository($installedRepo, $aliases);
if ($this->update) {
$repositories = $this->repositoryManager->getRepositories();
foreach ($repositories as $repository) {
$pool->addRepository($repository, $aliases);
}
}
// Add the locked repository after the others in case we are doing a
// partial update so missing packages can be found there still.
// For installs from lock it's the only one added so it is first
if ($lockedRepository) {
$pool->addRepository($lockedRepository, $aliases);
}
// creating requirements request
$request = $this->createRequest($this->package, $platformRepo);
if ($this->update) {
// remove unstable packages from the localRepo if they don't match the current stability settings
$removedUnstablePackages = array();
foreach ($localRepo->getPackages() as $package) {
if (!$pool->isPackageAcceptable($package->getNames(), $package->getStability()) && $this->installationManager->isPackageInstalled($localRepo, $package)) {
$removedUnstablePackages[$package->getName()] = true;
$request->remove($package->getName(), new Constraint('=', $package->getVersion()));
}
}
$this->io->writeError('<info>Updating dependencies' . ($this->devMode ? ' (including require-dev)' : '') . '</info>');
$request->updateAll();
$links = array_merge($this->package->getRequires(), $this->package->getDevRequires());
foreach ($links as $link) {
$request->install($link->getTarget(), $link->getConstraint());
}
// 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->updateWhitelist) {
$currentPackages = $this->getCurrentPackages($installedRepo);
// collect packages to fixate from root requirements as well as installed packages
$candidates = array();
foreach ($links as $link) {
$candidates[$link->getTarget()] = true;
$rootRequires[$link->getTarget()] = $link;
}
foreach ($currentPackages 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) && !isset($removedUnstablePackages[$curPackage->getName()])) {
$constraint = new Constraint('=', $curPackage->getVersion());
$description = $this->locker->isLocked() ? '(locked at' : '(installed at';
$requiredAt = isset($rootRequires[$candidate]) ? ', required as ' . $rootRequires[$candidate]->getPrettyConstraint() : '';
$constraint->setPrettyString($description . ' ' . $curPackage->getPrettyVersion() . $requiredAt . ')');
$request->install($curPackage->getName(), $constraint);
}
break;
}
}
}
}
} else {
$this->io->writeError('<info>Installing dependencies' . ($this->devMode ? ' (including require-dev)' : '') . ' from lock file</info>');
if (!$this->locker->isFresh()) {
$this->io->writeError('<warning>Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.</warning>', true, IOInterface::QUIET);
}
foreach ($lockedRepository->getPackages() as $package) {
$version = $package->getVersion();
if (isset($aliases[$package->getName()][$version])) {
$version = $aliases[$package->getName()][$version]['alias_normalized'];
//.........这里部分代码省略.........
示例5: purgePackages
/**
* @param Repository\RepositoryManager $rm
* @param Installer\InstallationManager $im
*/
protected function purgePackages(Repository\RepositoryManager $rm, Installer\InstallationManager $im)
{
$repo = $rm->getLocalRepository();
foreach ($repo->getPackages() as $package) {
if (!$im->isPackageInstalled($repo, $package)) {
$repo->removePackage($package);
}
}
}
示例6: getFilterOperator
/**
* Get the filter root constraint operator.
*
* @param PackageInterface $package
*
* @return string
*/
private function getFilterOperator(PackageInterface $package)
{
return $this->installationManager->isPackageInstalled($this->installedRepository, $package) ? '>' : '>=';
}
示例7: purgePackages
/**
* @param Repository\RepositoryManager $rm
* @param Installer\InstallationManager $im
*/
protected function purgePackages(Repository\RepositoryManager $rm, Installer\InstallationManager $im)
{
foreach ($rm->getLocalRepositories() as $repo) {
/* @var $repo Repository\WritableRepositoryInterface */
foreach ($repo->getPackages() as $package) {
if (!$im->isPackageInstalled($repo, $package)) {
$repo->removePackage($package);
}
}
}
}