Installer.php 50 KB

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