本文整理汇总了PHP中Composer\Composer::getLocker方法的典型用法代码示例。如果您正苦于以下问题:PHP Composer::getLocker方法的具体用法?PHP Composer::getLocker怎么用?PHP Composer::getLocker使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Composer
的用法示例。
在下文中一共展示了Composer::getLocker方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor
*
* @param Filesystem $filesystem
*/
public function __construct(Filesystem $filesystem)
{
$vendor = $filesystem->getDirectoryRead(DirectoryList::CONFIG)->getAbsolutePath('vendor_path.php');
$vendorPath = $filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath() . (include $vendor);
// Create Composer
$io = new \Composer\IO\BufferIO();
$this->composer = ComposerFactory::create($io, $vendorPath . '/../composer.json');
$this->locker = $this->composer->getLocker();
}
示例2: init
/**
* {@inheritdoc}
*/
public function init()
{
// Retrieve the configuration variables.
$this->config = $this->composer->getConfig();
if (isset($this->config)) {
if ($this->config->has('component-dir')) {
$this->componentDir = $this->config->get('component-dir');
}
}
// Get the available packages.
$allPackages = array();
/** @var \Composer\Package\Locker $locker */
$locker = $this->composer->getLocker();
if ($locker !== null && $locker->isLocked()) {
$lockData = $locker->getLockData();
$allPackages = $lockData['packages'];
// Also merge in any of the development packages.
$dev = isset($lockData['packages-dev']) ? $lockData['packages-dev'] : array();
foreach ($dev as $package) {
$allPackages[] = $package;
}
}
// Only add those packages that we can reasonably
// assume are components into our packages list
/** @var \Composer\Package\RootPackageInterface $rootPackage */
$rootPackage = $this->composer->getPackage();
$rootExtras = $rootPackage ? $rootPackage->getExtra() : array();
$customComponents = isset($rootExtras['component']) ? $rootExtras['component'] : array();
foreach ($allPackages as $package) {
$name = $package['name'];
if (isset($customComponents[$name]) && is_array($customComponents[$name])) {
$package['extra'] = array('component' => $customComponents[$name]);
$this->packages[] = $package;
} else {
$extra = isset($package['extra']) ? $package['extra'] : array();
if (isset($extra['component']) && is_array($extra['component'])) {
$this->packages[] = $package;
}
}
}
// Add the root package to the packages list.
$root = $this->composer->getPackage();
if ($root) {
$dumper = new ArrayDumper();
$package = $dumper->dump($root);
$package['is-root'] = true;
$this->packages[] = $package;
}
return true;
}
示例3: __construct
/**
* Constructor
*
* @param Filesystem $filesystem
* @param BufferIoFactory $bufferIoFactory
* @throws \Exception
*/
public function __construct(Filesystem $filesystem, BufferIoFactory $bufferIoFactory)
{
// composer.json is in same directory as vendor
$vendorPath = $filesystem->getDirectoryRead(DirectoryList::CONFIG)->getAbsolutePath('vendor_path.php');
$vendorDir = (require "{$vendorPath}");
$composerJson = $filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath() . "/{$vendorDir}/../composer.json";
$composerJsonRealPath = realpath($composerJson);
if ($composerJsonRealPath === false) {
throw new \Exception('Composer file not found: ' . $composerJson);
}
putenv('COMPOSER_HOME=' . $filesystem->getDirectoryRead(DirectoryList::COMPOSER_HOME)->getAbsolutePath());
// Create Composer
$this->composer = ComposerFactory::create($bufferIoFactory->create(), $composerJson);
$this->locker = $this->composer->getLocker();
}
示例4: testSetGetLocker
public function testSetGetLocker()
{
$composer = new Composer();
$locker = $this->getMockBuilder('Composer\\Package\\Locker')->disableOriginalConstructor()->getMock();
$composer->setLocker($locker);
$this->assertSame($locker, $composer->getLocker());
}
示例5: __construct
/**
* Constructor
*
* @param MagentoComposerApplicationFactory $applicationFactory
* @throws \Exception
*/
public function __construct(
MagentoComposerApplicationFactory $applicationFactory
) {
$this->application = $applicationFactory->create();
$this->composer = $this->application->createComposer();
$this->locker = $this->composer->getLocker();
}
示例6: getLockerData
/**
* Returns locker data for given package
*
* @param BasePackage
* @return string
*/
private function getLockerData(BasePackage $package)
{
$data = $this->composer->getLocker()->getLockData();
foreach ((array) $data['packages'] as $pkgData) {
if ($pkgData['name'] == $package->getName()) {
return $pkgData;
}
}
return NULL;
}
示例7: create
/**
* Create Installer
*
* @param IOInterface $io
* @param Composer $composer
* @param EventDispatcher $eventDispatcher
* @param AutoloadGenerator $autoloadGenerator
* @return Installer
*/
public static function create(IOInterface $io, Composer $composer, EventDispatcher $eventDispatcher = null, AutoloadGenerator $autoloadGenerator = null)
{
$eventDispatcher = $eventDispatcher ?: new EventDispatcher($composer, $io);
$autoloadGenerator = $autoloadGenerator ?: new AutoloadGenerator();
return new static($io, $composer->getConfig(), $composer->getPackage(), $composer->getDownloadManager(), $composer->getRepositoryManager(), $composer->getLocker(), $composer->getInstallationManager(), $eventDispatcher, $autoloadGenerator);
}
示例8: create
/**
* Create Installer
*
* @param IOInterface $io
* @param Composer $composer
* @return Installer
*/
public static function create(IOInterface $io, Composer $composer)
{
return new static($io, $composer->getConfig(), $composer->getPackage(), $composer->getDownloadManager(), $composer->getRepositoryManager(), $composer->getLocker(), $composer->getInstallationManager(), $composer->getEventDispatcher(), $composer->getAutoloadGenerator());
}
示例9: createInstaller
/**
* Create an Installer instance.
*
* Private static factory, to allow slip-streaming in a mock as needed for
* testing.
*/
private static function createInstaller(Composer $composer, IOInterface $io, PackageInterface $package)
{
$eventDispatcher = new EventDispatcher($composer, $io);
return new ComposerInstaller($io, $composer->getConfig(), $package, $composer->getDownloadManager(), $composer->getRepositoryManager(), $composer->getLocker(), $composer->getInstallationManager(), $eventDispatcher, $composer->getAutoloadGenerator());
}
示例10: install
public function install(IOInterface $io, Composer $composer, EventDispatcher $eventDispatcher, $preferSource = false, $dryRun = false, $verbose = false, $noInstallRecommends = false, $installSuggests = false, $update = false, RepositoryInterface $additionalInstalledRepository = null)
{
if ($dryRun) {
$verbose = true;
}
if ($preferSource) {
$composer->getDownloadManager()->setPreferSource(true);
}
// create local repo, this contains all packages that are installed in the local project
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
// create installed repo, this contains all local packages + platform packages (php & extensions)
$installedRepo = new CompositeRepository(array($localRepo, new PlatformRepository()));
if ($additionalInstalledRepository) {
$installedRepo->addRepository($additionalInstalledRepository);
}
// creating repository pool
$pool = new Pool();
$pool->addRepository($installedRepo);
foreach ($composer->getRepositoryManager()->getRepositories() as $repository) {
$pool->addRepository($repository);
}
// dispatch pre event
if (!$dryRun) {
$eventName = $update ? ScriptEvents::PRE_UPDATE_CMD : ScriptEvents::PRE_INSTALL_CMD;
$eventDispatcher->dispatchCommandEvent($eventName);
}
// creating requirements request
$installFromLock = false;
$request = new Request($pool);
if ($update) {
$io->write('<info>Updating dependencies</info>');
$installedPackages = $installedRepo->getPackages();
$links = $this->collectLinks($composer->getPackage(), $noInstallRecommends, $installSuggests);
$request->updateAll();
foreach ($links as $link) {
$request->install($link->getTarget(), $link->getConstraint());
}
} elseif ($composer->getLocker()->isLocked()) {
$installFromLock = true;
$io->write('<info>Installing from lock file</info>');
if (!$composer->getLocker()->isFresh()) {
$io->write('<warning>Your lock file is out of sync with your composer.json, run "composer.phar update" to update dependencies</warning>');
}
foreach ($composer->getLocker()->getLockedPackages() as $package) {
$constraint = new VersionConstraint('=', $package->getVersion());
$request->install($package->getName(), $constraint);
}
} else {
$io->write('<info>Installing dependencies</info>');
$links = $this->collectLinks($composer->getPackage(), $noInstallRecommends, $installSuggests);
foreach ($links as $link) {
$request->install($link->getTarget(), $link->getConstraint());
}
}
// prepare solver
$installationManager = $composer->getInstallationManager();
$policy = new DependencyResolver\DefaultPolicy();
$solver = new DependencyResolver\Solver($policy, $pool, $installedRepo);
// solve dependencies
$operations = $solver->solve($request);
// execute operations
if (!$operations) {
$io->write('<info>Nothing to install/update</info>');
}
// force dev packages to be updated to latest reference on update
if ($update) {
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() && $package === $operation->getInitialPackage() || 'uninstall' === $operation->getJobType() && $package === $operation->getPackage()) {
continue 2;
}
}
// force update
$newPackage = $composer->getRepositoryManager()->findPackage($package->getName(), $package->getVersion());
if ($newPackage && $newPackage->getSourceReference() !== $package->getSourceReference()) {
$operations[] = new UpdateOperation($package, $newPackage);
}
}
}
foreach ($operations as $operation) {
if ($verbose) {
$io->write((string) $operation);
}
if (!$dryRun) {
$eventDispatcher->dispatchPackageEvent(constant('Composer\\Script\\ScriptEvents::PRE_PACKAGE_' . strtoupper($operation->getJobType())), $operation);
// if installing from lock, restore dev packages' references to their locked state
if ($installFromLock) {
$package = null;
if ('update' === $operation->getJobType()) {
$package = $operation->getTargetPackage();
} elseif ('install' === $operation->getJobType()) {
$package = $operation->getPackage();
}
if ($package && $package->isDev()) {
$lockData = $composer->getLocker()->getLockData();
//.........这里部分代码省略.........
示例11: generateVersionsClass
private static function generateVersionsClass(Composer $composer) : string
{
return sprintf(self::$generatedClassTemplate, var_export(iterator_to_array(self::getVersions($composer->getLocker(), $composer->getPackage())), true));
}
示例12: getVersion
/**
* Returns the PhantomJS version number.
*
* Firstly, we search for a version number in the local repository,
* secondly, in the root package.
* A version specification of "dev-master#<commit-reference>" is disallowed.
*
* @param Composer $composer
* @return string $version Version
*/
public static function getVersion($composer)
{
// try getting the version from the local repository
$packages = $composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages();
foreach ($packages as $package) {
if ($package->getName() === self::PACKAGE_NAME) {
$version = $package->getPrettyVersion();
break;
}
}
// let's take a look at the aliases
if ($package->getVersion() === '9999999-dev') {
// this indicates the version alias???
$aliases = $composer->getLocker()->getAliases();
foreach ($aliases as $idx => $alias) {
if ($alias['package'] === self::PACKAGE_NAME) {
return $alias['alias'];
}
}
}
// let's take a look at the root package
if (!empty($version)) {
$version = self::getRequiredVersion($composer->getPackage());
}
// fallback to the hardcoded latest version, if "dev-master" was set
if ($version === 'dev-master') {
return self::getLatestPhantomJsVersion();
}
// grab version from commit-reference, e.g. "dev-master#<commit-ref> as version"
if (preg_match('/dev-master#(?:.*)(\\d.\\d.\\d)/i', $version, $matches)) {
return $matches[1];
}
// grab version from a Composer patch version tag with a patch level, like "1.9.8-p02"
if (preg_match('/(\\d.\\d.\\d)(?:(?:-p\\d{2})?)/i', $version, $matches)) {
return $matches[1];
}
return $version;
}