Installer.php 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer;
  12. use Composer\Autoload\AutoloadGenerator;
  13. use Composer\DependencyResolver\DefaultPolicy;
  14. use Composer\DependencyResolver\LocalRepoTransaction;
  15. use Composer\DependencyResolver\LockTransaction;
  16. use Composer\DependencyResolver\Operation\UpdateOperation;
  17. use Composer\DependencyResolver\Operation\InstallOperation;
  18. use Composer\DependencyResolver\Operation\UninstallOperation;
  19. use Composer\DependencyResolver\Operation\MarkAliasUninstalledOperation;
  20. use Composer\DependencyResolver\Operation\OperationInterface;
  21. use Composer\DependencyResolver\PolicyInterface;
  22. use Composer\DependencyResolver\Pool;
  23. use Composer\DependencyResolver\Request;
  24. use Composer\DependencyResolver\Rule;
  25. use Composer\DependencyResolver\Solver;
  26. use Composer\DependencyResolver\SolverProblemsException;
  27. use Composer\Downloader\DownloadManager;
  28. use Composer\EventDispatcher\EventDispatcher;
  29. use Composer\Installer\InstallationManager;
  30. use Composer\Installer\InstallerEvents;
  31. use Composer\Installer\NoopInstaller;
  32. use Composer\Installer\SuggestedPackagesReporter;
  33. use Composer\IO\IOInterface;
  34. use Composer\Package\AliasPackage;
  35. use Composer\Package\BasePackage;
  36. use Composer\Package\CompletePackage;
  37. use Composer\Package\Link;
  38. use Composer\Package\LinkConstraint\VersionConstraint;
  39. use Composer\Package\Loader\ArrayLoader;
  40. use Composer\Package\Dumper\ArrayDumper;
  41. use Composer\Package\Package;
  42. use Composer\Repository\ArrayRepository;
  43. use Composer\Repository\RepositorySet;
  44. use Composer\Semver\Constraint\Constraint;
  45. use Composer\Package\Locker;
  46. use Composer\Package\PackageInterface;
  47. use Composer\Package\RootPackageInterface;
  48. use Composer\Repository\CompositeRepository;
  49. use Composer\Repository\InstalledArrayRepository;
  50. use Composer\Repository\PlatformRepository;
  51. use Composer\Repository\RepositoryInterface;
  52. use Composer\Repository\RepositoryManager;
  53. use Composer\Repository\WritableRepositoryInterface;
  54. use Composer\Script\ScriptEvents;
  55. /**
  56. * @author Jordi Boggiano <j.boggiano@seld.be>
  57. * @author Beau Simensen <beau@dflydev.com>
  58. * @author Konstantin Kudryashov <ever.zet@gmail.com>
  59. * @author Nils Adermann <naderman@naderman.de>
  60. */
  61. class Installer
  62. {
  63. /**
  64. * @var IOInterface
  65. */
  66. protected $io;
  67. /**
  68. * @var Config
  69. */
  70. protected $config;
  71. /**
  72. * @var RootPackageInterface
  73. */
  74. protected $package;
  75. // TODO can we get rid of the below and just use the package itself?
  76. /**
  77. * @var RootPackageInterface
  78. */
  79. protected $fixedRootPackage;
  80. /**
  81. * @var DownloadManager
  82. */
  83. protected $downloadManager;
  84. /**
  85. * @var RepositoryManager
  86. */
  87. protected $repositoryManager;
  88. /**
  89. * @var Locker
  90. */
  91. protected $locker;
  92. /**
  93. * @var InstallationManager
  94. */
  95. protected $installationManager;
  96. /**
  97. * @var EventDispatcher
  98. */
  99. protected $eventDispatcher;
  100. /**
  101. * @var AutoloadGenerator
  102. */
  103. protected $autoloadGenerator;
  104. protected $preferSource = false;
  105. protected $preferDist = false;
  106. protected $optimizeAutoloader = false;
  107. protected $classMapAuthoritative = false;
  108. protected $apcuAutoloader = false;
  109. protected $devMode = false;
  110. protected $dryRun = false;
  111. protected $verbose = false;
  112. protected $update = false;
  113. protected $dumpAutoloader = true;
  114. protected $runScripts = true;
  115. protected $ignorePlatformReqs = false;
  116. protected $preferStable = false;
  117. protected $preferLowest = false;
  118. protected $skipSuggest = false;
  119. protected $writeLock;
  120. protected $executeOperations = true;
  121. /**
  122. * Array of package names/globs flagged for update
  123. *
  124. * @var array|null
  125. */
  126. protected $updateMirrors = false;
  127. protected $updateWhitelist = null;
  128. protected $whitelistTransitiveDependencies = false;
  129. protected $whitelistAllDependencies = false;
  130. /**
  131. * @var SuggestedPackagesReporter
  132. */
  133. protected $suggestedPackagesReporter;
  134. /**
  135. * @var RepositoryInterface
  136. */
  137. protected $additionalFixedRepository;
  138. /**
  139. * Constructor
  140. *
  141. * @param IOInterface $io
  142. * @param Config $config
  143. * @param RootPackageInterface $package
  144. * @param DownloadManager $downloadManager
  145. * @param RepositoryManager $repositoryManager
  146. * @param Locker $locker
  147. * @param InstallationManager $installationManager
  148. * @param EventDispatcher $eventDispatcher
  149. * @param AutoloadGenerator $autoloadGenerator
  150. */
  151. public function __construct(IOInterface $io, Config $config, RootPackageInterface $package, DownloadManager $downloadManager, RepositoryManager $repositoryManager, Locker $locker, InstallationManager $installationManager, EventDispatcher $eventDispatcher, AutoloadGenerator $autoloadGenerator)
  152. {
  153. $this->io = $io;
  154. $this->config = $config;
  155. $this->package = $package;
  156. $this->downloadManager = $downloadManager;
  157. $this->repositoryManager = $repositoryManager;
  158. $this->locker = $locker;
  159. $this->installationManager = $installationManager;
  160. $this->eventDispatcher = $eventDispatcher;
  161. $this->autoloadGenerator = $autoloadGenerator;
  162. $this->writeLock = $config->get('lock');
  163. }
  164. /**
  165. * Run installation (or update)
  166. *
  167. * @throws \Exception
  168. * @return int 0 on success or a positive error code on failure
  169. */
  170. public function run()
  171. {
  172. // Disable GC to save CPU cycles, as the dependency solver can create hundreds of thousands
  173. // of PHP objects, the GC can spend quite some time walking the tree of references looking
  174. // for stuff to collect while there is nothing to collect. This slows things down dramatically
  175. // and turning it off results in much better performance. Do not try this at home however.
  176. gc_collect_cycles();
  177. gc_disable();
  178. if ($this->updateWhitelist && $this->updateMirrors) {
  179. throw new \RuntimeException("The installer options updateMirrors and updateWhitelist are mutually exclusive.");
  180. }
  181. // Force update if there is no lock file present
  182. if (!$this->update && !$this->locker->isLocked()) {
  183. $this->io->writeError('<warning>No lock file found. Updating dependencies instead of installing from lock file. Use composer update over composer install if you do not have a lock file.</warning>');
  184. $this->update = true;
  185. }
  186. if ($this->dryRun) {
  187. $this->verbose = true;
  188. $this->runScripts = false;
  189. $this->executeOperations = false;
  190. $this->writeLock = false;
  191. $this->dumpAutoloader = false;
  192. $this->mockLocalRepositories($this->repositoryManager);
  193. }
  194. if ($this->runScripts) {
  195. $devMode = (int) $this->devMode;
  196. putenv("COMPOSER_DEV_MODE=$devMode");
  197. // dispatch pre event
  198. // should we treat this more strictly as running an update and then running an install, triggering events multiple times?
  199. $eventName = $this->update ? ScriptEvents::PRE_UPDATE_CMD : ScriptEvents::PRE_INSTALL_CMD;
  200. $this->eventDispatcher->dispatchScript($eventName, $this->devMode);
  201. }
  202. $this->downloadManager->setPreferSource($this->preferSource);
  203. $this->downloadManager->setPreferDist($this->preferDist);
  204. $localRepo = $this->repositoryManager->getLocalRepository();
  205. if (!$this->suggestedPackagesReporter) {
  206. $this->suggestedPackagesReporter = new SuggestedPackagesReporter($this->io);
  207. }
  208. try {
  209. if ($this->update) {
  210. // TODO introduce option to set doInstall to false (update lock file without vendor install)
  211. $res = $this->doUpdate($localRepo, true);
  212. } else {
  213. $res = $this->doInstall($localRepo);
  214. }
  215. if ($res !== 0) {
  216. return $res;
  217. }
  218. } catch (\Exception $e) {
  219. if ($this->executeOperations) {
  220. $this->installationManager->notifyInstalls($this->io);
  221. }
  222. throw $e;
  223. }
  224. if ($this->executeOperations) {
  225. $this->installationManager->notifyInstalls($this->io);
  226. }
  227. // output suggestions if we're in dev mode
  228. if ($this->update && $this->devMode && !$this->skipSuggest) {
  229. $this->suggestedPackagesReporter->output($this->locker->getLockedRepository($this->devMode));
  230. }
  231. // TODO probably makes more sense to do this on the lock file only?
  232. # Find abandoned packages and warn user
  233. foreach ($localRepo->getPackages() as $package) {
  234. if (!$package instanceof CompletePackage || !$package->isAbandoned()) {
  235. continue;
  236. }
  237. $replacement = is_string($package->getReplacementPackage())
  238. ? 'Use ' . $package->getReplacementPackage() . ' instead'
  239. : 'No replacement was suggested';
  240. $this->io->writeError(
  241. sprintf(
  242. "<warning>Package %s is abandoned, you should avoid using it. %s.</warning>",
  243. $package->getPrettyName(),
  244. $replacement
  245. )
  246. );
  247. }
  248. if ($this->dumpAutoloader) {
  249. // write autoloader
  250. if ($this->optimizeAutoloader) {
  251. $this->io->writeError('<info>Generating optimized autoload files</info>');
  252. } else {
  253. $this->io->writeError('<info>Generating autoload files</info>');
  254. }
  255. $this->autoloadGenerator->setDevMode($this->devMode);
  256. $this->autoloadGenerator->setClassMapAuthoritative($this->classMapAuthoritative);
  257. $this->autoloadGenerator->setApcu($this->apcuAutoloader);
  258. $this->autoloadGenerator->setRunScripts($this->runScripts);
  259. $this->autoloadGenerator->dump($this->config, $localRepo, $this->package, $this->installationManager, 'composer', $this->optimizeAutoloader);
  260. }
  261. if ($this->executeOperations) {
  262. // force binaries re-generation in case they are missing
  263. foreach ($localRepo->getPackages() as $package) {
  264. $this->installationManager->ensureBinariesPresence($package);
  265. }
  266. $vendorDir = $this->config->get('vendor-dir');
  267. if (is_dir($vendorDir)) {
  268. // suppress errors as this fails sometimes on OSX for no apparent reason
  269. // see https://github.com/composer/composer/issues/4070#issuecomment-129792748
  270. @touch($vendorDir);
  271. }
  272. }
  273. if ($this->runScripts) {
  274. // dispatch post event
  275. $eventName = $this->update ? ScriptEvents::POST_UPDATE_CMD : ScriptEvents::POST_INSTALL_CMD;
  276. $this->eventDispatcher->dispatchScript($eventName, $this->devMode);
  277. }
  278. // re-enable GC except on HHVM which triggers a warning here
  279. if (!defined('HHVM_VERSION')) {
  280. gc_enable();
  281. }
  282. return 0;
  283. }
  284. protected function doUpdate(RepositoryInterface $localRepo, $doInstall)
  285. {
  286. $platformRepo = $this->createPlatformRepo(true);
  287. $aliases = $this->getRootAliases(true);
  288. $lockedRepository = null;
  289. if ($this->locker->isLocked()) {
  290. $lockedRepository = $this->locker->getLockedRepository(true);
  291. }
  292. if ($this->updateWhitelist) {
  293. if (!$lockedRepository) {
  294. $this->io->writeError('<error>Cannot update only a partial set of packages without a lock file present.</error>', true, IOInterface::QUIET);
  295. return 1;
  296. }
  297. $this->whitelistUpdateDependencies(
  298. $lockedRepository,
  299. $this->package->getRequires(),
  300. $this->package->getDevRequires()
  301. );
  302. }
  303. $this->io->writeError('<info>Loading composer repositories with package information</info>');
  304. // creating repository set
  305. $policy = $this->createPolicy(true);
  306. $repositorySet = $this->createRepositorySet($platformRepo, $aliases);
  307. $repositories = $this->repositoryManager->getRepositories();
  308. foreach ($repositories as $repository) {
  309. $repositorySet->addRepository($repository);
  310. }
  311. if ($lockedRepository) {
  312. $repositorySet->addRepository($lockedRepository);
  313. }
  314. // TODO can we drop any locked packages that we have matching remote versions for?
  315. $request = $this->createRequest($this->fixedRootPackage, $platformRepo, $lockedRepository);
  316. if ($lockedRepository) {
  317. // TODO do we really always need this? Maybe only to skip fix() in updateWhitelist case cause these packages get removed on full update automatically?
  318. foreach ($lockedRepository->getPackages() as $lockedPackage) {
  319. if (!$repositorySet->isPackageAcceptable($lockedPackage->getNames(), $lockedPackage->getStability())) {
  320. $constraint = new Constraint('=', $lockedPackage->getVersion());
  321. $constraint->setPrettyString('(stability not acceptable)');
  322. // if we can get rid of this remove() here, we can generally get rid of remove support in the request
  323. $request->remove($lockedPackage->getName(), $constraint);
  324. }
  325. }
  326. }
  327. $this->io->writeError('<info>Updating dependencies</info>');
  328. $links = array_merge($this->package->getRequires(), $this->package->getDevRequires());
  329. // if we're updating mirrors we want to keep exactly the same versions installed which are in the lock file, but we want current remote metadata
  330. if ($this->updateMirrors) {
  331. foreach ($lockedRepository->getPackages() as $lockedPackage) {
  332. $request->install($lockedPackage->getName(), new Constraint('==', $lockedPackage->getVersion()));
  333. }
  334. } else {
  335. foreach ($links as $link) {
  336. $request->install($link->getTarget(), $link->getConstraint());
  337. }
  338. }
  339. // if the updateWhitelist is enabled, packages not in it are also fixed
  340. // to the version specified in the lock
  341. if ($this->updateWhitelist) {
  342. foreach ($lockedRepository->getPackages() as $lockedPackage) {
  343. // TODO should this really be checking acceptability here?
  344. if (!$this->isUpdateable($lockedPackage) && $repositorySet->isPackageAcceptable($lockedPackage->getNames(), $lockedPackage->getStability())) {
  345. // TODO add reason for fix?
  346. $request->fixPackage($lockedPackage);
  347. }
  348. }
  349. }
  350. // TODO reenable events
  351. //$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $this->devMode, $policy, $repositorySet, $installedRepo, $request);
  352. $pool = $repositorySet->createPool($request);
  353. // TODO ensure that the solver always picks most recent reference for dev packages, so they get updated even when just a new commit is pushed but version is unchanged
  354. // should already be solved by using the remote package in all cases in the pool
  355. // solve dependencies
  356. $solver = new Solver($policy, $pool, $this->io);
  357. try {
  358. $lockTransaction = $solver->solve($request, $this->ignorePlatformReqs);
  359. $ruleSetSize = $solver->getRuleSetSize();
  360. $solver = null;
  361. } catch (SolverProblemsException $e) {
  362. $this->io->writeError('<error>Your requirements could not be resolved to an installable set of packages.</error>', true, IOInterface::QUIET);
  363. $this->io->writeError($e->getMessage());
  364. if (!$this->devMode) {
  365. $this->io->writeError('<warning>Running update with --no-dev does not mean require-dev is ignored, it just means the packages will not be installed. If dev requirements are blocking the update you have to resolve those problems.</warning>', true, IOInterface::QUIET);
  366. }
  367. return max(1, $e->getCode());
  368. }
  369. // TODO should we warn people / error if plugins in vendor folder do not match contents of lock file before update?
  370. //$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $this->devMode, $policy, $repositorySet, $lockedRepository, $request, $lockTransaction);
  371. $this->io->writeError("Analyzed ".count($pool)." packages to resolve dependencies", true, IOInterface::VERBOSE);
  372. $this->io->writeError("Analyzed ".$ruleSetSize." rules to resolve dependencies", true, IOInterface::VERBOSE);
  373. if (!$lockTransaction->getOperations()) {
  374. $this->io->writeError('Nothing to modify in lock file');
  375. }
  376. $this->extractDevPackages($lockTransaction, $platformRepo, $aliases, $policy);
  377. // write lock
  378. $platformReqs = $this->extractPlatformRequirements($this->package->getRequires());
  379. $platformDevReqs = $this->extractPlatformRequirements($this->package->getDevRequires());
  380. if ($lockTransaction->getOperations()) {
  381. $installs = $updates = $uninstalls = array();
  382. foreach ($lockTransaction->getOperations() as $operation) {
  383. if ($operation instanceof InstallOperation) {
  384. $installs[] = $operation->getPackage()->getPrettyName().':'.$operation->getPackage()->getFullPrettyVersion();
  385. } elseif ($operation instanceof UpdateOperation) {
  386. $updates[] = $operation->getTargetPackage()->getPrettyName().':'.$operation->getTargetPackage()->getFullPrettyVersion();
  387. } elseif ($operation instanceof UninstallOperation) {
  388. $uninstalls[] = $operation->getPackage()->getPrettyName();
  389. }
  390. }
  391. $this->io->writeError(sprintf(
  392. "<info>Lock file operations: %d install%s, %d update%s, %d removal%s</info>",
  393. count($installs),
  394. 1 === count($installs) ? '' : 's',
  395. count($updates),
  396. 1 === count($updates) ? '' : 's',
  397. count($uninstalls),
  398. 1 === count($uninstalls) ? '' : 's'
  399. ));
  400. if ($installs) {
  401. $this->io->writeError("Installs: ".implode(', ', $installs), true, IOInterface::VERBOSE);
  402. }
  403. if ($updates) {
  404. $this->io->writeError("Updates: ".implode(', ', $updates), true, IOInterface::VERBOSE);
  405. }
  406. if ($uninstalls) {
  407. $this->io->writeError("Removals: ".implode(', ', $uninstalls), true, IOInterface::VERBOSE);
  408. }
  409. }
  410. foreach ($lockTransaction->getOperations() as $operation) {
  411. // collect suggestions
  412. $jobType = $operation->getJobType();
  413. if ($operation instanceof InstallOperation) {
  414. $this->suggestedPackagesReporter->addSuggestionsFromPackage($operation->getPackage());
  415. }
  416. // output op, but alias op only in debug verbosity
  417. if (false === strpos($operation->getJobType(), 'Alias') || $this->io->isDebug()) {
  418. $this->io->writeError(' - ' . $operation->show(true));
  419. }
  420. }
  421. $updatedLock = $this->locker->setLockData(
  422. $lockTransaction->getNewLockPackages(false, $this->updateMirrors),
  423. $lockTransaction->getNewLockPackages(true, $this->updateMirrors),
  424. $platformReqs,
  425. $platformDevReqs,
  426. $aliases,
  427. $this->package->getMinimumStability(),
  428. $this->package->getStabilityFlags(),
  429. $this->preferStable || $this->package->getPreferStable(),
  430. $this->preferLowest,
  431. $this->config->get('platform') ?: array(),
  432. $this->writeLock && $this->executeOperations
  433. );
  434. if ($updatedLock && $this->writeLock && $this->executeOperations) {
  435. $this->io->writeError('<info>Writing lock file</info>');
  436. }
  437. if ($doInstall) {
  438. // TODO ensure lock is used from locker as-is, since it may not have been written to disk in case of executeOperations == false
  439. return $this->doInstall($localRepo, true);
  440. }
  441. return 0;
  442. }
  443. /**
  444. * Run the solver a second time on top of the existing update result with only the current result set in the pool
  445. * and see what packages would get removed if we only had the non-dev packages in the solver request
  446. */
  447. protected function extractDevPackages(LockTransaction $lockTransaction, $platformRepo, $aliases, $policy)
  448. {
  449. if (!$this->package->getDevRequires()) {
  450. return array();
  451. }
  452. $resultRepo = new ArrayRepository(array());
  453. $loader = new ArrayLoader(null, true);
  454. $dumper = new ArrayDumper();
  455. foreach ($lockTransaction->getNewLockPackages(false) as $pkg) {
  456. $resultRepo->addPackage($loader->load($dumper->dump($pkg)));
  457. }
  458. $repositorySet = $this->createRepositorySet($platformRepo, $aliases, null);
  459. $repositorySet->addRepository($resultRepo);
  460. $request = $this->createRequest($this->fixedRootPackage, $platformRepo, null);
  461. $links = $this->package->getRequires();
  462. foreach ($links as $link) {
  463. $request->install($link->getTarget(), $link->getConstraint());
  464. }
  465. $pool = $repositorySet->createPool($request);
  466. //$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request);
  467. $solver = new Solver($policy, $pool, $this->io);
  468. try {
  469. $nonDevLockTransaction = $solver->solve($request, $this->ignorePlatformReqs);
  470. //$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request, $ops);
  471. $solver = null;
  472. } catch (SolverProblemsException $e) {
  473. $this->io->writeError('<error>Unable to find a compatible set of packages based on your non-dev requirements alone.</error>', true, IOInterface::QUIET);
  474. $this->io->writeError($e->getMessage());
  475. return max(1, $e->getCode());
  476. }
  477. $lockTransaction->setNonDevPackages($nonDevLockTransaction);
  478. }
  479. /**
  480. * @param RepositoryInterface $localRepo
  481. * @param bool $alreadySolved Whether the function is called as part of an update command or independently
  482. * @return int exit code
  483. */
  484. protected function doInstall(RepositoryInterface $localRepo, $alreadySolved = false)
  485. {
  486. $platformRepo = $this->createPlatformRepo(false);
  487. $aliases = $this->getRootAliases(false);
  488. $lockedRepository = $this->locker->getLockedRepository($this->devMode);
  489. // creating repository set
  490. $policy = $this->createPolicy(false);
  491. // use aliases from lock file only, so empty root aliases here
  492. $repositorySet = $this->createRepositorySet($platformRepo, array(), $lockedRepository);
  493. $repositorySet->addRepository($lockedRepository);
  494. $this->io->writeError('<info>Installing dependencies from lock file'.($this->devMode ? ' (including require-dev)' : '').'</info>');
  495. // verify that the lock file works with the current platform repository
  496. // we can skip this part if we're doing this as the second step after an update
  497. if (!$alreadySolved) {
  498. $this->io->writeError('<info>Verifying lock file contents can be installed on current platform.</info>');
  499. // creating requirements request
  500. $request = $this->createRequest($this->fixedRootPackage, $platformRepo, $lockedRepository);
  501. if (!$this->locker->isFresh()) {
  502. $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);
  503. }
  504. foreach ($lockedRepository->getPackages() as $package) {
  505. $request->fixPackage($package);
  506. }
  507. foreach ($this->locker->getPlatformRequirements($this->devMode) as $link) {
  508. $request->install($link->getTarget(), $link->getConstraint());
  509. }
  510. //$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $this->devMode, $policy, $repositorySet, $installedRepo, $request);
  511. $pool = $repositorySet->createPool($request);
  512. // solve dependencies
  513. $solver = new Solver($policy, $pool, $this->io);
  514. try {
  515. $lockTransaction = $solver->solve($request, $this->ignorePlatformReqs);
  516. $solver = null;
  517. // installing the locked packages on this platform resulted in lock modifying operations, there wasn't a conflict, but the lock file as-is seems to not work on this system
  518. if (0 !== count($lockTransaction->getOperations())) {
  519. $this->io->writeError('<error>Your lock file cannot be installed on this system without changes. Please run composer update.</error>', true, IOInterface::QUIET);
  520. // TODO actually display operations to explain what happened?
  521. return 1;
  522. }
  523. } catch (SolverProblemsException $e) {
  524. $this->io->writeError('<error>Your lock file does not contain a compatible set of packages. Please run composer update.</error>', true, IOInterface::QUIET);
  525. $this->io->writeError($e->getMessage());
  526. return max(1, $e->getCode());
  527. }
  528. // TODO should we warn people / error if plugins in vendor folder do not match contents of lock file before update?
  529. //$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $this->devMode, $policy, $repositorySet, $installedRepo, $request, $lockTransaction);
  530. }
  531. // 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?
  532. $localRepoTransaction = new LocalRepoTransaction($lockedRepository, $localRepo);
  533. if (!$localRepoTransaction->getOperations()) {
  534. $this->io->writeError('Nothing to install, update or remove');
  535. }
  536. if ($localRepoTransaction->getOperations()) {
  537. $installs = $updates = $uninstalls = array();
  538. foreach ($localRepoTransaction->getOperations() as $operation) {
  539. if ($operation instanceof InstallOperation) {
  540. $installs[] = $operation->getPackage()->getPrettyName().':'.$operation->getPackage()->getFullPrettyVersion();
  541. } elseif ($operation instanceof UpdateOperation) {
  542. $updates[] = $operation->getTargetPackage()->getPrettyName().':'.$operation->getTargetPackage()->getFullPrettyVersion();
  543. } elseif ($operation instanceof UninstallOperation) {
  544. $uninstalls[] = $operation->getPackage()->getPrettyName();
  545. }
  546. }
  547. $this->io->writeError(sprintf(
  548. "<info>Package operations: %d install%s, %d update%s, %d removal%s</info>",
  549. count($installs),
  550. 1 === count($installs) ? '' : 's',
  551. count($updates),
  552. 1 === count($updates) ? '' : 's',
  553. count($uninstalls),
  554. 1 === count($uninstalls) ? '' : 's'
  555. ));
  556. if ($installs) {
  557. $this->io->writeError("Installs: ".implode(', ', $installs), true, IOInterface::VERBOSE);
  558. }
  559. if ($updates) {
  560. $this->io->writeError("Updates: ".implode(', ', $updates), true, IOInterface::VERBOSE);
  561. }
  562. if ($uninstalls) {
  563. $this->io->writeError("Removals: ".implode(', ', $uninstalls), true, IOInterface::VERBOSE);
  564. }
  565. }
  566. if ($this->executeOperations) {
  567. $this->installationManager->execute($localRepo, $localRepoTransaction->getOperations(), $this->devMode);
  568. } else {
  569. foreach ($localRepoTransaction->getOperations() as $operation) {
  570. // output op, but alias op only in debug verbosity
  571. if (false === strpos($operation->getJobType(), 'Alias') || $this->io->isDebug()) {
  572. $this->io->writeError(' - ' . $operation->show(false));
  573. }
  574. }
  575. }
  576. return 0;
  577. }
  578. private function createPlatformRepo($forUpdate)
  579. {
  580. if ($forUpdate) {
  581. $platformOverrides = $this->config->get('platform') ?: array();
  582. } else {
  583. $platformOverrides = $this->locker->getPlatformOverrides();
  584. }
  585. return new PlatformRepository(array(), $platformOverrides);
  586. }
  587. /**
  588. * @param array $rootAliases
  589. * @param RepositoryInterface|null $lockedRepository
  590. * @return RepositorySet
  591. */
  592. private function createRepositorySet(PlatformRepository $platformRepo, array $rootAliases = array(), $lockedRepository = null)
  593. {
  594. $this->aliasPlatformPackages($platformRepo, $rootAliases);
  595. // TODO what's the point of rootConstraints at all, we generate the package pool taking them into account anyway?
  596. // TODO maybe we can drop the lockedRepository here
  597. // TODO if this gets called in doInstall, this->update is still true?!
  598. if ($this->update) {
  599. $minimumStability = $this->package->getMinimumStability();
  600. $stabilityFlags = $this->package->getStabilityFlags();
  601. $requires = array_merge($this->package->getRequires(), $this->package->getDevRequires());
  602. } else {
  603. $minimumStability = $this->locker->getMinimumStability();
  604. $stabilityFlags = $this->locker->getStabilityFlags();
  605. $requires = array();
  606. foreach ($lockedRepository->getPackages() as $package) {
  607. $constraint = new Constraint('=', $package->getVersion());
  608. $constraint->setPrettyString($package->getPrettyVersion());
  609. $requires[$package->getName()] = $constraint;
  610. }
  611. }
  612. $rootRequires = array();
  613. foreach ($requires as $req => $constraint) {
  614. // skip platform requirements from the root package to avoid filtering out existing platform packages
  615. if ($this->ignorePlatformReqs && preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $req)) {
  616. continue;
  617. }
  618. if ($constraint instanceof Link) {
  619. $rootRequires[$req] = $constraint->getConstraint();
  620. } else {
  621. $rootRequires[$req] = $constraint;
  622. }
  623. }
  624. $this->fixedRootPackage = clone $this->package;
  625. $this->fixedRootPackage->setRequires(array());
  626. $this->fixedRootPackage->setDevRequires(array());
  627. $repositorySet = new RepositorySet($rootAliases, $this->package->getReferences(), $minimumStability, $stabilityFlags, $rootRequires);
  628. $repositorySet->addRepository(new InstalledArrayRepository(array($this->fixedRootPackage)));
  629. $repositorySet->addRepository($platformRepo);
  630. if ($this->additionalFixedRepository) {
  631. $repositorySet->addRepository($this->additionalFixedRepository);
  632. }
  633. return $repositorySet;
  634. }
  635. /**
  636. * @return DefaultPolicy
  637. */
  638. private function createPolicy($forUpdate)
  639. {
  640. $preferStable = null;
  641. $preferLowest = null;
  642. if (!$forUpdate) {
  643. $preferStable = $this->locker->getPreferStable();
  644. $preferLowest = $this->locker->getPreferLowest();
  645. }
  646. // old lock file without prefer stable/lowest will return null
  647. // so in this case we use the composer.json info
  648. if (null === $preferStable) {
  649. $preferStable = $this->preferStable || $this->package->getPreferStable();
  650. }
  651. if (null === $preferLowest) {
  652. $preferLowest = $this->preferLowest;
  653. }
  654. return new DefaultPolicy($preferStable, $preferLowest);
  655. }
  656. /**
  657. * @param RootPackageInterface $rootPackage
  658. * @param PlatformRepository $platformRepo
  659. * @param RepositoryInterface|null $lockedRepository
  660. * @return Request
  661. */
  662. private function createRequest(RootPackageInterface $rootPackage, PlatformRepository $platformRepo, $lockedRepository = null)
  663. {
  664. $request = new Request($lockedRepository);
  665. $request->fixPackage($rootPackage, false);
  666. $fixedPackages = $platformRepo->getPackages();
  667. if ($this->additionalFixedRepository) {
  668. $fixedPackages = array_merge($fixedPackages, $this->additionalFixedRepository->getPackages());
  669. }
  670. // fix the version of all platform packages + additionally installed packages
  671. // to prevent the solver trying to remove or update those
  672. // TODO why not replaces?
  673. $provided = $rootPackage->getProvides();
  674. foreach ($fixedPackages as $package) {
  675. // skip platform packages that are provided by the root package
  676. if ($package->getRepository() !== $platformRepo
  677. || !isset($provided[$package->getName()])
  678. || !$provided[$package->getName()]->getConstraint()->matches(new Constraint('=', $package->getVersion()))
  679. ) {
  680. $request->fixPackage($package, false);
  681. }
  682. }
  683. return $request;
  684. }
  685. /**
  686. * @param bool $forUpdate
  687. * @return array
  688. */
  689. private function getRootAliases($forUpdate)
  690. {
  691. if ($forUpdate) {
  692. $aliases = $this->package->getAliases();
  693. } else {
  694. $aliases = $this->locker->getAliases();
  695. }
  696. $normalizedAliases = array();
  697. foreach ($aliases as $alias) {
  698. $normalizedAliases[$alias['package']][$alias['version']] = array(
  699. 'alias' => $alias['alias'],
  700. 'alias_normalized' => $alias['alias_normalized'],
  701. );
  702. }
  703. return $normalizedAliases;
  704. }
  705. /**
  706. * @param PlatformRepository $platformRepo
  707. * @param array $aliases
  708. */
  709. private function aliasPlatformPackages(PlatformRepository $platformRepo, $aliases)
  710. {
  711. // TODO should the repository set do this?
  712. foreach ($aliases as $packageName => $versions) {
  713. foreach ($versions as $version => $alias) {
  714. $packages = $platformRepo->findPackages($packageName, $version);
  715. foreach ($packages as $package) {
  716. $aliasPackage = new AliasPackage($package, $alias['alias_normalized'], $alias['alias']);
  717. $aliasPackage->setRootPackageAlias(true);
  718. $platformRepo->addPackage($aliasPackage);
  719. }
  720. }
  721. }
  722. }
  723. /**
  724. * @param PackageInterface $package
  725. * @return bool
  726. */
  727. private function isUpdateable(PackageInterface $package)
  728. {
  729. if (!$this->updateWhitelist) {
  730. throw new \LogicException('isUpdateable should only be called when a whitelist is present');
  731. }
  732. foreach ($this->updateWhitelist as $whiteListedPattern => $void) {
  733. $patternRegexp = BasePackage::packageNameToRegexp($whiteListedPattern);
  734. if (preg_match($patternRegexp, $package->getName())) {
  735. return true;
  736. }
  737. }
  738. return false;
  739. }
  740. /**
  741. * @param array $links
  742. * @return array
  743. */
  744. private function extractPlatformRequirements($links)
  745. {
  746. $platformReqs = array();
  747. foreach ($links as $link) {
  748. if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $link->getTarget())) {
  749. $platformReqs[$link->getTarget()] = $link->getPrettyConstraint();
  750. }
  751. }
  752. return $platformReqs;
  753. }
  754. /**
  755. * Adds all dependencies of the update whitelist to the whitelist, too.
  756. *
  757. * Packages which are listed as requirements in the root package will be
  758. * skipped including their dependencies, unless they are listed in the
  759. * update whitelist themselves or $whitelistAllDependencies is true.
  760. *
  761. * @param RepositoryInterface $lockRepo Use the locked repo
  762. * As we want the most accurate package list to work with, and installed
  763. * repo might be empty but locked repo will always be current.
  764. * @param array $rootRequires An array of links to packages in require of the root package
  765. * @param array $rootDevRequires An array of links to packages in require-dev of the root package
  766. */
  767. private function whitelistUpdateDependencies($lockRepo, array $rootRequires, array $rootDevRequires)
  768. {
  769. $rootRequires = array_merge($rootRequires, $rootDevRequires);
  770. $skipPackages = array();
  771. if (!$this->whitelistAllDependencies) {
  772. foreach ($rootRequires as $require) {
  773. $skipPackages[$require->getTarget()] = true;
  774. }
  775. }
  776. $repositorySet = new RepositorySet(array(), array(), 'dev');
  777. $repositorySet->addRepository($lockRepo);
  778. $seen = array();
  779. $rootRequiredPackageNames = array_keys($rootRequires);
  780. foreach ($this->updateWhitelist as $packageName => $void) {
  781. $packageQueue = new \SplQueue;
  782. $nameMatchesRequiredPackage = false;
  783. $depPackages = $repositorySet->findPackages($packageName, null, false);
  784. $matchesByPattern = array();
  785. // check if the name is a glob pattern that did not match directly
  786. if (empty($depPackages)) {
  787. // add any installed package matching the whitelisted name/pattern
  788. $whitelistPatternSearchRegexp = BasePackage::packageNameToRegexp($packageName, '^%s$');
  789. foreach ($lockRepo->search($whitelistPatternSearchRegexp) as $installedPackage) {
  790. $matchesByPattern[] = $repositorySet->findPackages($installedPackage['name'], null, false);
  791. }
  792. // add root requirements which match the whitelisted name/pattern
  793. $whitelistPatternRegexp = BasePackage::packageNameToRegexp($packageName);
  794. foreach ($rootRequiredPackageNames as $rootRequiredPackageName) {
  795. if (preg_match($whitelistPatternRegexp, $rootRequiredPackageName)) {
  796. $nameMatchesRequiredPackage = true;
  797. break;
  798. }
  799. }
  800. }
  801. if (!empty($matchesByPattern)) {
  802. $depPackages = array_merge($depPackages, call_user_func_array('array_merge', $matchesByPattern));
  803. }
  804. if (count($depPackages) == 0 && !$nameMatchesRequiredPackage) {
  805. $this->io->writeError('<warning>Package "' . $packageName . '" listed for update is not installed. Ignoring.</warning>');
  806. }
  807. foreach ($depPackages as $depPackage) {
  808. $packageQueue->enqueue($depPackage);
  809. }
  810. while (!$packageQueue->isEmpty()) {
  811. $package = $packageQueue->dequeue();
  812. if (isset($seen[spl_object_hash($package)])) {
  813. continue;
  814. }
  815. $seen[spl_object_hash($package)] = true;
  816. $this->updateWhitelist[$package->getName()] = true;
  817. if (!$this->whitelistTransitiveDependencies && !$this->whitelistAllDependencies) {
  818. continue;
  819. }
  820. $requires = $package->getRequires();
  821. foreach ($requires as $require) {
  822. $requirePackages = $repositorySet->findPackages($require->getTarget(), null, false);
  823. foreach ($requirePackages as $requirePackage) {
  824. if (isset($this->updateWhitelist[$requirePackage->getName()])) {
  825. continue;
  826. }
  827. if (isset($skipPackages[$requirePackage->getName()]) && !preg_match(BasePackage::packageNameToRegexp($packageName), $requirePackage->getName())) {
  828. $this->io->writeError('<warning>Dependency "' . $requirePackage->getName() . '" is also a root requirement, but is not explicitly whitelisted. Ignoring.</warning>');
  829. continue;
  830. }
  831. $packageQueue->enqueue($requirePackage);
  832. }
  833. }
  834. }
  835. }
  836. }
  837. /**
  838. * Replace local repositories with InstalledArrayRepository instances
  839. *
  840. * This is to prevent any accidental modification of the existing repos on disk
  841. *
  842. * @param RepositoryManager $rm
  843. */
  844. private function mockLocalRepositories(RepositoryManager $rm)
  845. {
  846. $packages = array();
  847. foreach ($rm->getLocalRepository()->getPackages() as $package) {
  848. $packages[(string) $package] = clone $package;
  849. }
  850. foreach ($packages as $key => $package) {
  851. if ($package instanceof AliasPackage) {
  852. $alias = (string) $package->getAliasOf();
  853. $packages[$key] = new AliasPackage($packages[$alias], $package->getVersion(), $package->getPrettyVersion());
  854. }
  855. }
  856. $rm->setLocalRepository(
  857. new InstalledArrayRepository($packages)
  858. );
  859. }
  860. /**
  861. * Create Installer
  862. *
  863. * @param IOInterface $io
  864. * @param Composer $composer
  865. * @return Installer
  866. */
  867. public static function create(IOInterface $io, Composer $composer)
  868. {
  869. return new static(
  870. $io,
  871. $composer->getConfig(),
  872. $composer->getPackage(),
  873. $composer->getDownloadManager(),
  874. $composer->getRepositoryManager(),
  875. $composer->getLocker(),
  876. $composer->getInstallationManager(),
  877. $composer->getEventDispatcher(),
  878. $composer->getAutoloadGenerator()
  879. );
  880. }
  881. /**
  882. * @param RepositoryInterface $additionalFixedRepository
  883. * @return $this
  884. */
  885. public function setAdditionalFixedRepository(RepositoryInterface $additionalFixedRepository)
  886. {
  887. $this->additionalFixedRepository = $additionalFixedRepository;
  888. return $this;
  889. }
  890. /**
  891. * Whether to run in drymode or not
  892. *
  893. * @param bool $dryRun
  894. * @return Installer
  895. */
  896. public function setDryRun($dryRun = true)
  897. {
  898. $this->dryRun = (bool) $dryRun;
  899. return $this;
  900. }
  901. /**
  902. * Checks, if this is a dry run (simulation mode).
  903. *
  904. * @return bool
  905. */
  906. public function isDryRun()
  907. {
  908. return $this->dryRun;
  909. }
  910. /**
  911. * prefer source installation
  912. *
  913. * @param bool $preferSource
  914. * @return Installer
  915. */
  916. public function setPreferSource($preferSource = true)
  917. {
  918. $this->preferSource = (bool) $preferSource;
  919. return $this;
  920. }
  921. /**
  922. * prefer dist installation
  923. *
  924. * @param bool $preferDist
  925. * @return Installer
  926. */
  927. public function setPreferDist($preferDist = true)
  928. {
  929. $this->preferDist = (bool) $preferDist;
  930. return $this;
  931. }
  932. /**
  933. * Whether or not generated autoloader are optimized
  934. *
  935. * @param bool $optimizeAutoloader
  936. * @return Installer
  937. */
  938. public function setOptimizeAutoloader($optimizeAutoloader = false)
  939. {
  940. $this->optimizeAutoloader = (bool) $optimizeAutoloader;
  941. if (!$this->optimizeAutoloader) {
  942. // Force classMapAuthoritative off when not optimizing the
  943. // autoloader
  944. $this->setClassMapAuthoritative(false);
  945. }
  946. return $this;
  947. }
  948. /**
  949. * Whether or not generated autoloader considers the class map
  950. * authoritative.
  951. *
  952. * @param bool $classMapAuthoritative
  953. * @return Installer
  954. */
  955. public function setClassMapAuthoritative($classMapAuthoritative = false)
  956. {
  957. $this->classMapAuthoritative = (bool) $classMapAuthoritative;
  958. if ($this->classMapAuthoritative) {
  959. // Force optimizeAutoloader when classmap is authoritative
  960. $this->setOptimizeAutoloader(true);
  961. }
  962. return $this;
  963. }
  964. /**
  965. * Whether or not generated autoloader considers APCu caching.
  966. *
  967. * @param bool $apcuAutoloader
  968. * @return Installer
  969. */
  970. public function setApcuAutoloader($apcuAutoloader = false)
  971. {
  972. $this->apcuAutoloader = (bool) $apcuAutoloader;
  973. return $this;
  974. }
  975. /**
  976. * update packages
  977. *
  978. * @param bool $update
  979. * @return Installer
  980. */
  981. public function setUpdate($update = true)
  982. {
  983. $this->update = (bool) $update;
  984. return $this;
  985. }
  986. /**
  987. * enables dev packages
  988. *
  989. * @param bool $devMode
  990. * @return Installer
  991. */
  992. public function setDevMode($devMode = true)
  993. {
  994. $this->devMode = (bool) $devMode;
  995. return $this;
  996. }
  997. /**
  998. * set whether to run autoloader or not
  999. *
  1000. * This is disabled implicitly when enabling dryRun
  1001. *
  1002. * @param bool $dumpAutoloader
  1003. * @return Installer
  1004. */
  1005. public function setDumpAutoloader($dumpAutoloader = true)
  1006. {
  1007. $this->dumpAutoloader = (bool) $dumpAutoloader;
  1008. return $this;
  1009. }
  1010. /**
  1011. * set whether to run scripts or not
  1012. *
  1013. * This is disabled implicitly when enabling dryRun
  1014. *
  1015. * @param bool $runScripts
  1016. * @return Installer
  1017. */
  1018. public function setRunScripts($runScripts = true)
  1019. {
  1020. $this->runScripts = (bool) $runScripts;
  1021. return $this;
  1022. }
  1023. /**
  1024. * set the config instance
  1025. *
  1026. * @param Config $config
  1027. * @return Installer
  1028. */
  1029. public function setConfig(Config $config)
  1030. {
  1031. $this->config = $config;
  1032. return $this;
  1033. }
  1034. /**
  1035. * run in verbose mode
  1036. *
  1037. * @param bool $verbose
  1038. * @return Installer
  1039. */
  1040. public function setVerbose($verbose = true)
  1041. {
  1042. $this->verbose = (bool) $verbose;
  1043. return $this;
  1044. }
  1045. /**
  1046. * Checks, if running in verbose mode.
  1047. *
  1048. * @return bool
  1049. */
  1050. public function isVerbose()
  1051. {
  1052. return $this->verbose;
  1053. }
  1054. /**
  1055. * set ignore Platform Package requirements
  1056. *
  1057. * @param bool $ignorePlatformReqs
  1058. * @return Installer
  1059. */
  1060. public function setIgnorePlatformRequirements($ignorePlatformReqs = false)
  1061. {
  1062. $this->ignorePlatformReqs = (bool) $ignorePlatformReqs;
  1063. return $this;
  1064. }
  1065. /**
  1066. * Update the lock file to the exact same versions and references but use current remote metadata like URLs and mirror info
  1067. *
  1068. * @param bool $updateMirrors
  1069. * @return Installer
  1070. */
  1071. public function setUpdateMirrors($updateMirrors)
  1072. {
  1073. $this->updateMirrors = $updateMirrors;
  1074. return $this;
  1075. }
  1076. /**
  1077. * restrict the update operation to a few packages, all other packages
  1078. * that are already installed will be kept at their current version
  1079. *
  1080. * @param array $packages
  1081. * @return Installer
  1082. */
  1083. public function setUpdateWhitelist(array $packages)
  1084. {
  1085. $this->updateWhitelist = array_flip(array_map('strtolower', $packages));
  1086. return $this;
  1087. }
  1088. /**
  1089. * Should dependencies of whitelisted packages (but not direct dependencies) be updated?
  1090. *
  1091. * This will NOT whitelist any dependencies that are also directly defined
  1092. * in the root package.
  1093. *
  1094. * @param bool $updateTransitiveDependencies
  1095. * @return Installer
  1096. */
  1097. public function setWhitelistTransitiveDependencies($updateTransitiveDependencies = true)
  1098. {
  1099. $this->whitelistTransitiveDependencies = (bool) $updateTransitiveDependencies;
  1100. return $this;
  1101. }
  1102. /**
  1103. * Should all dependencies of whitelisted packages be updated recursively?
  1104. *
  1105. * This will whitelist any dependencies of the whitelisted packages, including
  1106. * those defined in the root package.
  1107. *
  1108. * @param bool $updateAllDependencies
  1109. * @return Installer
  1110. */
  1111. public function setWhitelistAllDependencies($updateAllDependencies = true)
  1112. {
  1113. $this->whitelistAllDependencies = (bool) $updateAllDependencies;
  1114. return $this;
  1115. }
  1116. /**
  1117. * Should packages be preferred in a stable version when updating?
  1118. *
  1119. * @param bool $preferStable
  1120. * @return Installer
  1121. */
  1122. public function setPreferStable($preferStable = true)
  1123. {
  1124. $this->preferStable = (bool) $preferStable;
  1125. return $this;
  1126. }
  1127. /**
  1128. * Should packages be preferred in a lowest version when updating?
  1129. *
  1130. * @param bool $preferLowest
  1131. * @return Installer
  1132. */
  1133. public function setPreferLowest($preferLowest = true)
  1134. {
  1135. $this->preferLowest = (bool) $preferLowest;
  1136. return $this;
  1137. }
  1138. /**
  1139. * Should the lock file be updated when updating?
  1140. *
  1141. * This is disabled implicitly when enabling dryRun
  1142. *
  1143. * @param bool $writeLock
  1144. * @return Installer
  1145. */
  1146. public function setWriteLock($writeLock = true)
  1147. {
  1148. $this->writeLock = (bool) $writeLock;
  1149. return $this;
  1150. }
  1151. /**
  1152. * Should the operations (package install, update and removal) be executed on disk?
  1153. *
  1154. * This is disabled implicitly when enabling dryRun
  1155. *
  1156. * @param bool $executeOperations
  1157. * @return Installer
  1158. */
  1159. public function setExecuteOperations($executeOperations = true)
  1160. {
  1161. $this->executeOperations = (bool) $executeOperations;
  1162. return $this;
  1163. }
  1164. /**
  1165. * Should suggestions be skipped?
  1166. *
  1167. * @param bool $skipSuggest
  1168. * @return Installer
  1169. */
  1170. public function setSkipSuggest($skipSuggest = true)
  1171. {
  1172. $this->skipSuggest = (bool) $skipSuggest;
  1173. return $this;
  1174. }
  1175. /**
  1176. * Disables plugins.
  1177. *
  1178. * Call this if you want to ensure that third-party code never gets
  1179. * executed. The default is to automatically install, and execute
  1180. * custom third-party installers.
  1181. *
  1182. * @return Installer
  1183. */
  1184. public function disablePlugins()
  1185. {
  1186. $this->installationManager->disablePlugins();
  1187. return $this;
  1188. }
  1189. /**
  1190. * @param SuggestedPackagesReporter $suggestedPackagesReporter
  1191. * @return Installer
  1192. */
  1193. public function setSuggestedPackagesReporter(SuggestedPackagesReporter $suggestedPackagesReporter)
  1194. {
  1195. $this->suggestedPackagesReporter = $suggestedPackagesReporter;
  1196. return $this;
  1197. }
  1198. }