Merge pull request #8566 from Seldaek/installer-events
Restore installer events and add a PRE_POOL_CREATE hook for pluginspull/8669/head
commit
4bb314e4af
|
@ -43,8 +43,8 @@ Composer fires the following named events during its execution process:
|
||||||
|
|
||||||
### Installer Events
|
### Installer Events
|
||||||
|
|
||||||
- **pre-dependencies-solving**: occurs before the dependencies are resolved.
|
- **pre-operations-exec**: occurs before the install/upgrade/.. operations
|
||||||
- **post-dependencies-solving**: occurs after the dependencies have been resolved.
|
are executed when installing a lock file.
|
||||||
|
|
||||||
### Package Events
|
### Package Events
|
||||||
|
|
||||||
|
@ -66,6 +66,8 @@ Composer fires the following named events during its execution process:
|
||||||
- **pre-command-run**: occurs before a command is executed and allows you to
|
- **pre-command-run**: occurs before a command is executed and allows you to
|
||||||
manipulate the `InputInterface` object's options and arguments to tweak
|
manipulate the `InputInterface` object's options and arguments to tweak
|
||||||
a command's behavior.
|
a command's behavior.
|
||||||
|
- **pre-pool-create**: occurs before the Pool of packages is created, and lets
|
||||||
|
you filter the list of packages which is going to enter the Solver.
|
||||||
|
|
||||||
> **Note:** Composer makes no assumptions about the state of your dependencies
|
> **Note:** Composer makes no assumptions about the state of your dependencies
|
||||||
> prior to `install` or `update`. Therefore, you should not specify scripts
|
> prior to `install` or `update`. Therefore, you should not specify scripts
|
||||||
|
|
|
@ -21,6 +21,9 @@ use Composer\Repository\PlatformRepository;
|
||||||
use Composer\Repository\RootPackageRepository;
|
use Composer\Repository\RootPackageRepository;
|
||||||
use Composer\Semver\Constraint\Constraint;
|
use Composer\Semver\Constraint\Constraint;
|
||||||
use Composer\Semver\Constraint\MultiConstraint;
|
use Composer\Semver\Constraint\MultiConstraint;
|
||||||
|
use Composer\EventDispatcher\EventDispatcher;
|
||||||
|
use Composer\Plugin\PrePoolCreateEvent;
|
||||||
|
use Composer\Plugin\PluginEvents;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Nils Adermann <naderman@naderman.de>
|
* @author Nils Adermann <naderman@naderman.de>
|
||||||
|
@ -31,6 +34,7 @@ class PoolBuilder
|
||||||
private $stabilityFlags;
|
private $stabilityFlags;
|
||||||
private $rootAliases;
|
private $rootAliases;
|
||||||
private $rootReferences;
|
private $rootReferences;
|
||||||
|
private $eventDispatcher;
|
||||||
|
|
||||||
private $aliasMap = array();
|
private $aliasMap = array();
|
||||||
private $nameConstraints = array();
|
private $nameConstraints = array();
|
||||||
|
@ -38,12 +42,13 @@ class PoolBuilder
|
||||||
private $packages = array();
|
private $packages = array();
|
||||||
private $unacceptableFixedPackages = array();
|
private $unacceptableFixedPackages = array();
|
||||||
|
|
||||||
public function __construct(array $acceptableStabilities, array $stabilityFlags, array $rootAliases, array $rootReferences)
|
public function __construct(array $acceptableStabilities, array $stabilityFlags, array $rootAliases, array $rootReferences, EventDispatcher $eventDispatcher = null)
|
||||||
{
|
{
|
||||||
$this->acceptableStabilities = $acceptableStabilities;
|
$this->acceptableStabilities = $acceptableStabilities;
|
||||||
$this->stabilityFlags = $stabilityFlags;
|
$this->stabilityFlags = $stabilityFlags;
|
||||||
$this->rootAliases = $rootAliases;
|
$this->rootAliases = $rootAliases;
|
||||||
$this->rootReferences = $rootReferences;
|
$this->rootReferences = $rootReferences;
|
||||||
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildPool(array $repositories, Request $request)
|
public function buildPool(array $repositories, Request $request)
|
||||||
|
@ -132,6 +137,23 @@ class PoolBuilder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->eventDispatcher) {
|
||||||
|
$prePoolCreateEvent = new PrePoolCreateEvent(
|
||||||
|
PluginEvents::PRE_POOL_CREATE,
|
||||||
|
$repositories,
|
||||||
|
$request,
|
||||||
|
$this->acceptableStabilities,
|
||||||
|
$this->stabilityFlags,
|
||||||
|
$this->rootAliases,
|
||||||
|
$this->rootReferences,
|
||||||
|
$this->packages,
|
||||||
|
$this->unacceptableFixedPackages
|
||||||
|
);
|
||||||
|
$this->eventDispatcher->dispatch($prePoolCreateEvent->getName(), $prePoolCreateEvent);
|
||||||
|
$this->packages = $prePoolCreateEvent->getPackages();
|
||||||
|
$this->unacceptableFixedPackages = $prePoolCreateEvent->getUnacceptableFixedPackages();
|
||||||
|
}
|
||||||
|
|
||||||
$pool = new Pool($this->packages, $this->unacceptableFixedPackages);
|
$pool = new Pool($this->packages, $this->unacceptableFixedPackages);
|
||||||
|
|
||||||
$this->aliasMap = array();
|
$this->aliasMap = array();
|
||||||
|
|
|
@ -14,6 +14,8 @@ namespace Composer\EventDispatcher;
|
||||||
|
|
||||||
use Composer\DependencyResolver\PolicyInterface;
|
use Composer\DependencyResolver\PolicyInterface;
|
||||||
use Composer\DependencyResolver\Request;
|
use Composer\DependencyResolver\Request;
|
||||||
|
use Composer\DependencyResolver\Pool;
|
||||||
|
use Composer\DependencyResolver\Transaction;
|
||||||
use Composer\Installer\InstallerEvent;
|
use Composer\Installer\InstallerEvent;
|
||||||
use Composer\IO\IOInterface;
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Composer;
|
use Composer\Composer;
|
||||||
|
@ -117,20 +119,17 @@ class EventDispatcher
|
||||||
/**
|
/**
|
||||||
* Dispatch a installer event.
|
* Dispatch a installer event.
|
||||||
*
|
*
|
||||||
* @param string $eventName The constant in InstallerEvents
|
* @param string $eventName The constant in InstallerEvents
|
||||||
* @param bool $devMode Whether or not we are in dev mode
|
* @param bool $devMode Whether or not we are in dev mode
|
||||||
* @param PolicyInterface $policy The policy
|
* @param bool $executeOperations True if operations will be executed, false in --dry-run
|
||||||
* @param RepositorySet $repositorySet The repository set
|
* @param Transaction $transaction The transaction contains the list of operations
|
||||||
* @param RepositoryInterface $localRepo The installed repository
|
|
||||||
* @param Request $request The request
|
|
||||||
* @param array $operations The list of operations
|
|
||||||
*
|
*
|
||||||
* @return int return code of the executed script if any, for php scripts a false return
|
* @return int return code of the executed script if any, for php scripts a false return
|
||||||
* value is changed to 1, anything else to 0
|
* value is changed to 1, anything else to 0
|
||||||
*/
|
*/
|
||||||
public function dispatchInstallerEvent($eventName, $devMode, PolicyInterface $policy, RepositorySet $repositorySet, RepositoryInterface $localRepo, Request $request, array $operations = array())
|
public function dispatchInstallerEvent($eventName, $devMode, $executeOperations, Transaction $transaction)
|
||||||
{
|
{
|
||||||
return $this->doDispatch(new InstallerEvent($eventName, $this->composer, $this->io, $devMode, $policy, $repositorySet, $localRepo, $request, $operations));
|
return $this->doDispatch(new InstallerEvent($eventName, $this->composer, $this->io, $devMode, $executeOperations, $transaction));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -381,10 +381,7 @@ class Installer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO reenable events
|
$pool = $repositorySet->createPool($request, $this->eventDispatcher);
|
||||||
//$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $this->devMode, $policy, $repositorySet, $installedRepo, $request);
|
|
||||||
|
|
||||||
$pool = $repositorySet->createPool($request);
|
|
||||||
|
|
||||||
// solve dependencies
|
// solve dependencies
|
||||||
$solver = new Solver($policy, $pool, $this->io, $repositorySet);
|
$solver = new Solver($policy, $pool, $this->io, $repositorySet);
|
||||||
|
@ -402,9 +399,6 @@ class Installer
|
||||||
return max(1, $e->getCode());
|
return max(1, $e->getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO should we warn people / error if plugins in vendor folder do not match contents of lock file before update?
|
|
||||||
//$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $this->devMode, $policy, $repositorySet, $lockedRepository, $request, $lockTransaction);
|
|
||||||
|
|
||||||
$this->io->writeError("Analyzed ".count($pool)." packages to resolve dependencies", true, IOInterface::VERBOSE);
|
$this->io->writeError("Analyzed ".count($pool)." packages to resolve dependencies", true, IOInterface::VERBOSE);
|
||||||
$this->io->writeError("Analyzed ".$ruleSetSize." rules to resolve dependencies", true, IOInterface::VERBOSE);
|
$this->io->writeError("Analyzed ".$ruleSetSize." rules to resolve dependencies", true, IOInterface::VERBOSE);
|
||||||
|
|
||||||
|
@ -524,13 +518,11 @@ class Installer
|
||||||
$request->requireName($link->getTarget(), $link->getConstraint());
|
$request->requireName($link->getTarget(), $link->getConstraint());
|
||||||
}
|
}
|
||||||
|
|
||||||
$pool = $repositorySet->createPool($request);
|
$pool = $repositorySet->createPool($request, $this->eventDispatcher);
|
||||||
|
|
||||||
//$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request);
|
|
||||||
$solver = new Solver($policy, $pool, $this->io, $repositorySet);
|
$solver = new Solver($policy, $pool, $this->io, $repositorySet);
|
||||||
try {
|
try {
|
||||||
$nonDevLockTransaction = $solver->solve($request, $this->ignorePlatformReqs);
|
$nonDevLockTransaction = $solver->solve($request, $this->ignorePlatformReqs);
|
||||||
//$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request, $ops);
|
|
||||||
$solver = null;
|
$solver = null;
|
||||||
} catch (SolverProblemsException $e) {
|
} catch (SolverProblemsException $e) {
|
||||||
$this->io->writeError('<error>Unable to find a compatible set of packages based on your non-dev requirements alone.</error>', true, IOInterface::QUIET);
|
$this->io->writeError('<error>Unable to find a compatible set of packages based on your non-dev requirements alone.</error>', true, IOInterface::QUIET);
|
||||||
|
@ -549,22 +541,22 @@ class Installer
|
||||||
*/
|
*/
|
||||||
protected function doInstall(RepositoryInterface $localRepo, $alreadySolved = false)
|
protected function doInstall(RepositoryInterface $localRepo, $alreadySolved = false)
|
||||||
{
|
{
|
||||||
$platformRepo = $this->createPlatformRepo(false);
|
|
||||||
$lockedRepository = $this->locker->getLockedRepository($this->devMode);
|
|
||||||
|
|
||||||
// creating repository set
|
|
||||||
$policy = $this->createPolicy(false);
|
|
||||||
// use aliases from lock file only, so empty root aliases here
|
|
||||||
$repositorySet = $this->createRepositorySet(false, $platformRepo, array(), $lockedRepository);
|
|
||||||
$repositorySet->addRepository($lockedRepository);
|
|
||||||
|
|
||||||
$this->io->writeError('<info>Installing dependencies from lock file'.($this->devMode ? ' (including require-dev)' : '').'</info>');
|
$this->io->writeError('<info>Installing dependencies from lock file'.($this->devMode ? ' (including require-dev)' : '').'</info>');
|
||||||
|
|
||||||
|
$lockedRepository = $this->locker->getLockedRepository($this->devMode);
|
||||||
|
|
||||||
// verify that the lock file works with the current platform repository
|
// verify that the lock file works with the current platform repository
|
||||||
// we can skip this part if we're doing this as the second step after an update
|
// we can skip this part if we're doing this as the second step after an update
|
||||||
if (!$alreadySolved) {
|
if (!$alreadySolved) {
|
||||||
$this->io->writeError('<info>Verifying lock file contents can be installed on current platform.</info>');
|
$this->io->writeError('<info>Verifying lock file contents can be installed on current platform.</info>');
|
||||||
|
|
||||||
|
$platformRepo = $this->createPlatformRepo(false);
|
||||||
|
// creating repository set
|
||||||
|
$policy = $this->createPolicy(false);
|
||||||
|
// use aliases from lock file only, so empty root aliases here
|
||||||
|
$repositorySet = $this->createRepositorySet(false, $platformRepo, array(), $lockedRepository);
|
||||||
|
$repositorySet->addRepository($lockedRepository);
|
||||||
|
|
||||||
// creating requirements request
|
// creating requirements request
|
||||||
$request = $this->createRequest($this->fixedRootPackage, $platformRepo, $lockedRepository);
|
$request = $this->createRequest($this->fixedRootPackage, $platformRepo, $lockedRepository);
|
||||||
|
|
||||||
|
@ -580,9 +572,7 @@ class Installer
|
||||||
$request->requireName($link->getTarget(), $link->getConstraint());
|
$request->requireName($link->getTarget(), $link->getConstraint());
|
||||||
}
|
}
|
||||||
|
|
||||||
//$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $this->devMode, $policy, $repositorySet, $installedRepo, $request);
|
$pool = $repositorySet->createPool($request, $this->eventDispatcher);
|
||||||
|
|
||||||
$pool = $repositorySet->createPool($request);
|
|
||||||
|
|
||||||
// solve dependencies
|
// solve dependencies
|
||||||
$solver = new Solver($policy, $pool, $this->io, $repositorySet);
|
$solver = new Solver($policy, $pool, $this->io, $repositorySet);
|
||||||
|
@ -602,13 +592,11 @@ class Installer
|
||||||
|
|
||||||
return max(1, $e->getCode());
|
return max(1, $e->getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO should we warn people / error if plugins in vendor folder do not match contents of lock file before update?
|
|
||||||
//$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $this->devMode, $policy, $repositorySet, $installedRepo, $request, $lockTransaction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO in how far do we need to do anything here to ensure dev packages being updated to latest in lock without version change are treated correctly?
|
// TODO in how far do we need to do anything here to ensure dev packages being updated to latest in lock without version change are treated correctly?
|
||||||
$localRepoTransaction = new LocalRepoTransaction($lockedRepository, $localRepo);
|
$localRepoTransaction = new LocalRepoTransaction($lockedRepository, $localRepo);
|
||||||
|
$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_OPERATIONS_EXEC, $this->devMode, $this->executeOperations, $localRepoTransaction);
|
||||||
|
|
||||||
if (!$localRepoTransaction->getOperations()) {
|
if (!$localRepoTransaction->getOperations()) {
|
||||||
$this->io->writeError('Nothing to install, update or remove');
|
$this->io->writeError('Nothing to install, update or remove');
|
||||||
|
|
|
@ -14,18 +14,13 @@ namespace Composer\Installer;
|
||||||
|
|
||||||
use Composer\Composer;
|
use Composer\Composer;
|
||||||
use Composer\DependencyResolver\PolicyInterface;
|
use Composer\DependencyResolver\PolicyInterface;
|
||||||
use Composer\DependencyResolver\Operation\OperationInterface;
|
|
||||||
use Composer\DependencyResolver\Request;
|
use Composer\DependencyResolver\Request;
|
||||||
|
use Composer\DependencyResolver\Pool;
|
||||||
|
use Composer\DependencyResolver\Transaction;
|
||||||
use Composer\EventDispatcher\Event;
|
use Composer\EventDispatcher\Event;
|
||||||
use Composer\IO\IOInterface;
|
use Composer\IO\IOInterface;
|
||||||
use Composer\Repository\RepositoryInterface;
|
|
||||||
use Composer\Repository\RepositorySet;
|
use Composer\Repository\RepositorySet;
|
||||||
|
|
||||||
/**
|
|
||||||
* An event for all installer.
|
|
||||||
*
|
|
||||||
* @author François Pluchino <francois.pluchino@gmail.com>
|
|
||||||
*/
|
|
||||||
class InstallerEvent extends Event
|
class InstallerEvent extends Event
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -44,29 +39,14 @@ class InstallerEvent extends Event
|
||||||
private $devMode;
|
private $devMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var PolicyInterface
|
* @var bool
|
||||||
*/
|
*/
|
||||||
private $policy;
|
private $executeOperations;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var RepositorySet
|
* @var Transaction
|
||||||
*/
|
*/
|
||||||
private $repositorySet;
|
private $transaction;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var RepositoryInterface
|
|
||||||
*/
|
|
||||||
private $localRepo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Request
|
|
||||||
*/
|
|
||||||
private $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var OperationInterface[]
|
|
||||||
*/
|
|
||||||
private $operations;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
@ -75,24 +55,18 @@ class InstallerEvent extends Event
|
||||||
* @param Composer $composer
|
* @param Composer $composer
|
||||||
* @param IOInterface $io
|
* @param IOInterface $io
|
||||||
* @param bool $devMode
|
* @param bool $devMode
|
||||||
* @param PolicyInterface $policy
|
* @param bool $executeOperations
|
||||||
* @param RepositorySet $repositorySet
|
* @param Transaction $transaction
|
||||||
* @param RepositoryInterface $localRepo
|
|
||||||
* @param Request $request
|
|
||||||
* @param OperationInterface[] $operations
|
|
||||||
*/
|
*/
|
||||||
public function __construct($eventName, Composer $composer, IOInterface $io, $devMode, PolicyInterface $policy, RepositorySet $repositorySet, RepositoryInterface $localRepo, Request $request, array $operations = array())
|
public function __construct($eventName, Composer $composer, IOInterface $io, $devMode, $executeOperations, Transaction $transaction)
|
||||||
{
|
{
|
||||||
parent::__construct($eventName);
|
parent::__construct($eventName);
|
||||||
|
|
||||||
$this->composer = $composer;
|
$this->composer = $composer;
|
||||||
$this->io = $io;
|
$this->io = $io;
|
||||||
$this->devMode = $devMode;
|
$this->devMode = $devMode;
|
||||||
$this->policy = $policy;
|
$this->executeOperations = $executeOperations;
|
||||||
$this->repositorySet = $repositorySet;
|
$this->transaction = $transaction;
|
||||||
$this->localRepo = $localRepo;
|
|
||||||
$this->request = $request;
|
|
||||||
$this->operations = $operations;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,42 +94,18 @@ class InstallerEvent extends Event
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return PolicyInterface
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function getPolicy()
|
public function isExecutingOperations()
|
||||||
{
|
{
|
||||||
return $this->policy;
|
return $this->executeOperations;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return RepositorySet
|
* @return Transaction|null
|
||||||
*/
|
*/
|
||||||
public function getRepositorySet()
|
public function getTransaction()
|
||||||
{
|
{
|
||||||
return $this->repositorySet;
|
return $this->transaction;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return RepositoryInterface
|
|
||||||
*/
|
|
||||||
public function getLocalRepo()
|
|
||||||
{
|
|
||||||
return $this->localRepo;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Request
|
|
||||||
*/
|
|
||||||
public function getRequest()
|
|
||||||
{
|
|
||||||
return $this->request;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return OperationInterface[]
|
|
||||||
*/
|
|
||||||
public function getOperations()
|
|
||||||
{
|
|
||||||
return $this->operations;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,32 +12,15 @@
|
||||||
|
|
||||||
namespace Composer\Installer;
|
namespace Composer\Installer;
|
||||||
|
|
||||||
/**
|
|
||||||
* The Installer Events.
|
|
||||||
*
|
|
||||||
* @author François Pluchino <francois.pluchino@gmail.com>
|
|
||||||
*/
|
|
||||||
class InstallerEvents
|
class InstallerEvents
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The PRE_DEPENDENCIES_SOLVING event occurs as a installer begins
|
* The PRE_OPERATIONS_EXEC event occurs before the lock file gets
|
||||||
* resolve operations.
|
* installed and operations are executed.
|
||||||
*
|
*
|
||||||
* The event listener method receives a
|
* The event listener method receives an Composer\Installer\InstallerEvent instance.
|
||||||
* Composer\Installer\InstallerEvent instance.
|
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
const PRE_DEPENDENCIES_SOLVING = 'pre-dependencies-solving';
|
const PRE_OPERATIONS_EXEC = 'pre-operations-exec';
|
||||||
|
|
||||||
/**
|
|
||||||
* The POST_DEPENDENCIES_SOLVING event occurs as a installer after
|
|
||||||
* resolve operations.
|
|
||||||
*
|
|
||||||
* The event listener method receives a
|
|
||||||
* Composer\Installer\InstallerEvent instance.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
const POST_DEPENDENCIES_SOLVING = 'post-dependencies-solving';
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,4 +58,15 @@ class PluginEvents
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
const PRE_COMMAND_RUN = 'pre-command-run';
|
const PRE_COMMAND_RUN = 'pre-command-run';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The PRE_POOL_CREATE event occurs before the Pool of packages is created, and lets
|
||||||
|
* you filter the list of packages which is going to enter the Solver
|
||||||
|
*
|
||||||
|
* The event listener method receives a
|
||||||
|
* Composer\Plugin\PrePoolCreateEvent instance.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
const PRE_POOL_CREATE = 'pre-pool-create';
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,158 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Composer.
|
||||||
|
*
|
||||||
|
* (c) Nils Adermann <naderman@naderman.de>
|
||||||
|
* Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Composer\Plugin;
|
||||||
|
|
||||||
|
use Composer\EventDispatcher\Event;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Composer\Repository\RepositoryInterface;
|
||||||
|
use Composer\DependencyResolver\Request;
|
||||||
|
use Composer\Package\PackageInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The pre command run event.
|
||||||
|
*
|
||||||
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
*/
|
||||||
|
class PrePoolCreateEvent extends Event
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var RepositoryInterface[]
|
||||||
|
*/
|
||||||
|
private $repositories;
|
||||||
|
/**
|
||||||
|
* @var Request
|
||||||
|
*/
|
||||||
|
private $request;
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $acceptableStabilities;
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $stabilityFlags;
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $rootAliases;
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $rootReferences;
|
||||||
|
/**
|
||||||
|
* @var PackageInterface[]
|
||||||
|
*/
|
||||||
|
private $packages;
|
||||||
|
/**
|
||||||
|
* @var PackageInterface[]
|
||||||
|
*/
|
||||||
|
private $unacceptableFixedPackages;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name The event name
|
||||||
|
* @param RepositoryInterface[] $repositories
|
||||||
|
*/
|
||||||
|
public function __construct($name, array $repositories, Request $request, array $acceptableStabilities, array $stabilityFlags, array $rootAliases, array $rootReferences, array $packages, array $unacceptableFixedPackages)
|
||||||
|
{
|
||||||
|
parent::__construct($name);
|
||||||
|
|
||||||
|
$this->repositories = $repositories;
|
||||||
|
$this->request = $request;
|
||||||
|
$this->acceptableStabilities = $acceptableStabilities;
|
||||||
|
$this->stabilityFlags = $stabilityFlags;
|
||||||
|
$this->rootAliases = $rootAliases;
|
||||||
|
$this->rootReferences = $rootReferences;
|
||||||
|
$this->packages = $packages;
|
||||||
|
$this->unacceptableFixedPackages = $unacceptableFixedPackages;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return RepositoryInterface[]
|
||||||
|
*/
|
||||||
|
public function getRepositories()
|
||||||
|
{
|
||||||
|
return $this->repositories;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Request
|
||||||
|
*/
|
||||||
|
public function getRequest()
|
||||||
|
{
|
||||||
|
return $this->request;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getAcceptableStabilities()
|
||||||
|
{
|
||||||
|
return $this->acceptableStabilities;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getStabilityFlags()
|
||||||
|
{
|
||||||
|
return $this->stabilityFlags;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getRootAliases()
|
||||||
|
{
|
||||||
|
return $this->rootAliases;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getRootReferences()
|
||||||
|
{
|
||||||
|
return $this->rootReferences;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return PackageInterface[]
|
||||||
|
*/
|
||||||
|
public function getPackages()
|
||||||
|
{
|
||||||
|
return $this->packages;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return PackageInterface[]
|
||||||
|
*/
|
||||||
|
public function getUnacceptableFixedPackages()
|
||||||
|
{
|
||||||
|
return $this->unacceptableFixedPackages;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param PackageInterface[] $packages
|
||||||
|
*/
|
||||||
|
public function setPackages(array $packages)
|
||||||
|
{
|
||||||
|
$this->packages = $packages;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param PackageInterface[] $packages
|
||||||
|
*/
|
||||||
|
public function setUnacceptableFixedPackages(array $packages)
|
||||||
|
{
|
||||||
|
$this->unacceptableFixedPackages = $packages;
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ namespace Composer\Repository;
|
||||||
use Composer\DependencyResolver\Pool;
|
use Composer\DependencyResolver\Pool;
|
||||||
use Composer\DependencyResolver\PoolBuilder;
|
use Composer\DependencyResolver\PoolBuilder;
|
||||||
use Composer\DependencyResolver\Request;
|
use Composer\DependencyResolver\Request;
|
||||||
|
use Composer\EventDispatcher\EventDispatcher;
|
||||||
use Composer\Package\BasePackage;
|
use Composer\Package\BasePackage;
|
||||||
use Composer\Package\Version\VersionParser;
|
use Composer\Package\Version\VersionParser;
|
||||||
use Composer\Repository\CompositeRepository;
|
use Composer\Repository\CompositeRepository;
|
||||||
|
@ -188,9 +189,9 @@ class RepositorySet
|
||||||
*
|
*
|
||||||
* @return Pool
|
* @return Pool
|
||||||
*/
|
*/
|
||||||
public function createPool(Request $request)
|
public function createPool(Request $request, EventDispatcher $eventDispatcher = null)
|
||||||
{
|
{
|
||||||
$poolBuilder = new PoolBuilder($this->acceptableStabilities, $this->stabilityFlags, $this->rootAliases, $this->rootReferences);
|
$poolBuilder = new PoolBuilder($this->acceptableStabilities, $this->stabilityFlags, $this->rootAliases, $this->rootReferences, $eventDispatcher);
|
||||||
|
|
||||||
foreach ($this->repositories as $repo) {
|
foreach ($this->repositories as $repo) {
|
||||||
if ($repo instanceof InstalledRepositoryInterface && !$this->allowInstalledRepositories) {
|
if ($repo instanceof InstalledRepositoryInterface && !$this->allowInstalledRepositories) {
|
||||||
|
|
|
@ -565,13 +565,9 @@ class EventDispatcherTest extends TestCase
|
||||||
->method('getListeners')
|
->method('getListeners')
|
||||||
->will($this->returnValue(array()));
|
->will($this->returnValue(array()));
|
||||||
|
|
||||||
$policy = $this->getMockBuilder('Composer\DependencyResolver\PolicyInterface')->getMock();
|
$transaction = $this->getMockBuilder('Composer\DependencyResolver\LockTransaction')->disableOriginalConstructor()->getMock();
|
||||||
$repositorySet = $this->getMockBuilder('Composer\Repository\RepositorySet')->disableOriginalConstructor()->getMock();
|
|
||||||
$installedRepo = $this->getMockBuilder('Composer\Repository\CompositeRepository')->disableOriginalConstructor()->getMock();
|
|
||||||
$request = $this->getMockBuilder('Composer\DependencyResolver\Request')->disableOriginalConstructor()->getMock();
|
|
||||||
|
|
||||||
$dispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, true, $policy, $repositorySet, $installedRepo, $request);
|
$dispatcher->dispatchInstallerEvent(InstallerEvents::PRE_OPERATIONS_EXEC, true, true, $transaction);
|
||||||
$dispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, true, $policy, $repositorySet, $installedRepo, $request, array());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function call()
|
public static function call()
|
||||||
|
|
|
@ -21,21 +21,14 @@ class InstallerEventTest extends TestCase
|
||||||
{
|
{
|
||||||
$composer = $this->getMockBuilder('Composer\Composer')->getMock();
|
$composer = $this->getMockBuilder('Composer\Composer')->getMock();
|
||||||
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
||||||
$policy = $this->getMockBuilder('Composer\DependencyResolver\PolicyInterface')->getMock();
|
$transaction = $this->getMockBuilder('Composer\DependencyResolver\LockTransaction')->disableOriginalConstructor()->getMock();
|
||||||
$repositorySet = $this->getMockBuilder('Composer\Repository\RepositorySet')->disableOriginalConstructor()->getMock();
|
$event = new InstallerEvent('EVENT_NAME', $composer, $io, true, true, $transaction);
|
||||||
$localRepo = $this->getMockBuilder('Composer\Repository\CompositeRepository')->disableOriginalConstructor()->getMock();
|
|
||||||
$request = $this->getMockBuilder('Composer\DependencyResolver\Request')->disableOriginalConstructor()->getMock();
|
|
||||||
$operations = array($this->getMockBuilder('Composer\DependencyResolver\Operation\OperationInterface')->getMock());
|
|
||||||
$event = new InstallerEvent('EVENT_NAME', $composer, $io, true, $policy, $repositorySet, $localRepo, $request, $operations);
|
|
||||||
|
|
||||||
$this->assertSame('EVENT_NAME', $event->getName());
|
$this->assertSame('EVENT_NAME', $event->getName());
|
||||||
$this->assertInstanceOf('Composer\Composer', $event->getComposer());
|
$this->assertInstanceOf('Composer\Composer', $event->getComposer());
|
||||||
$this->assertInstanceOf('Composer\IO\IOInterface', $event->getIO());
|
$this->assertInstanceOf('Composer\IO\IOInterface', $event->getIO());
|
||||||
$this->assertTrue($event->isDevMode());
|
$this->assertTrue($event->isDevMode());
|
||||||
$this->assertInstanceOf('Composer\DependencyResolver\PolicyInterface', $event->getPolicy());
|
$this->assertTrue($event->isExecutingOperations());
|
||||||
$this->assertInstanceOf('Composer\Repository\RepositorySet', $event->getRepositorySet());
|
$this->assertInstanceOf('Composer\DependencyResolver\Transaction', $event->getTransaction());
|
||||||
$this->assertInstanceOf('Composer\Repository\RepositoryInterface', $event->getLocalRepo());
|
|
||||||
$this->assertInstanceOf('Composer\DependencyResolver\Request', $event->getRequest());
|
|
||||||
$this->assertCount(1, $event->getOperations());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue