Installer.php 49 KB

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