Installer.php 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364
  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. // TODO reenable events
  333. //$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $this->devMode, $policy, $repositorySet, $installedRepo, $request);
  334. $pool = $repositorySet->createPool($request);
  335. // solve dependencies
  336. $solver = new Solver($policy, $pool, $this->io, $repositorySet);
  337. try {
  338. $lockTransaction = $solver->solve($request, $this->ignorePlatformReqs);
  339. $ruleSetSize = $solver->getRuleSetSize();
  340. $solver = null;
  341. } catch (SolverProblemsException $e) {
  342. $this->io->writeError('<error>Your requirements could not be resolved to an installable set of packages.</error>', true, IOInterface::QUIET);
  343. $this->io->writeError($e->getPrettyString($repositorySet, $request, $pool));
  344. if (!$this->devMode) {
  345. $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);
  346. }
  347. return max(1, $e->getCode());
  348. }
  349. // TODO should we warn people / error if plugins in vendor folder do not match contents of lock file before update?
  350. //$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $this->devMode, $policy, $repositorySet, $lockedRepository, $request, $lockTransaction);
  351. $this->io->writeError("Analyzed ".count($pool)." packages to resolve dependencies", true, IOInterface::VERBOSE);
  352. $this->io->writeError("Analyzed ".$ruleSetSize." rules to resolve dependencies", true, IOInterface::VERBOSE);
  353. if (!$lockTransaction->getOperations()) {
  354. $this->io->writeError('Nothing to modify in lock file');
  355. }
  356. $this->extractDevPackages($lockTransaction, $platformRepo, $aliases, $policy);
  357. // write lock
  358. $platformReqs = $this->extractPlatformRequirements($this->package->getRequires());
  359. $platformDevReqs = $this->extractPlatformRequirements($this->package->getDevRequires());
  360. if ($lockTransaction->getOperations()) {
  361. $installs = $updates = $uninstalls = array();
  362. foreach ($lockTransaction->getOperations() as $operation) {
  363. if ($operation instanceof InstallOperation) {
  364. $installs[] = $operation->getPackage()->getPrettyName().':'.$operation->getPackage()->getFullPrettyVersion();
  365. } elseif ($operation instanceof UpdateOperation) {
  366. $updates[] = $operation->getTargetPackage()->getPrettyName().':'.$operation->getTargetPackage()->getFullPrettyVersion();
  367. } elseif ($operation instanceof UninstallOperation) {
  368. $uninstalls[] = $operation->getPackage()->getPrettyName();
  369. }
  370. }
  371. $this->io->writeError(sprintf(
  372. "<info>Lock file operations: %d install%s, %d update%s, %d removal%s</info>",
  373. count($installs),
  374. 1 === count($installs) ? '' : 's',
  375. count($updates),
  376. 1 === count($updates) ? '' : 's',
  377. count($uninstalls),
  378. 1 === count($uninstalls) ? '' : 's'
  379. ));
  380. if ($installs) {
  381. $this->io->writeError("Installs: ".implode(', ', $installs), true, IOInterface::VERBOSE);
  382. }
  383. if ($updates) {
  384. $this->io->writeError("Updates: ".implode(', ', $updates), true, IOInterface::VERBOSE);
  385. }
  386. if ($uninstalls) {
  387. $this->io->writeError("Removals: ".implode(', ', $uninstalls), true, IOInterface::VERBOSE);
  388. }
  389. }
  390. foreach ($lockTransaction->getOperations() as $operation) {
  391. // collect suggestions
  392. if ($operation instanceof InstallOperation) {
  393. $this->suggestedPackagesReporter->addSuggestionsFromPackage($operation->getPackage());
  394. }
  395. // output op, but alias op only in debug verbosity
  396. if (false === strpos($operation->getOperationType(), 'Alias') || $this->io->isDebug()) {
  397. $this->io->writeError(' - ' . $operation->show(true));
  398. }
  399. }
  400. $updatedLock = $this->locker->setLockData(
  401. $lockTransaction->getNewLockPackages(false, $this->updateMirrors),
  402. $lockTransaction->getNewLockPackages(true, $this->updateMirrors),
  403. $platformReqs,
  404. $platformDevReqs,
  405. $aliases,
  406. $this->package->getMinimumStability(),
  407. $this->package->getStabilityFlags(),
  408. $this->preferStable || $this->package->getPreferStable(),
  409. $this->preferLowest,
  410. $this->config->get('platform') ?: array(),
  411. $this->writeLock && $this->executeOperations
  412. );
  413. if ($updatedLock && $this->writeLock && $this->executeOperations) {
  414. $this->io->writeError('<info>Writing lock file</info>');
  415. }
  416. // see https://github.com/composer/composer/issues/2764
  417. if ($this->executeOperations && count($lockTransaction->getOperations()) > 0) {
  418. $vendorDir = $this->config->get('vendor-dir');
  419. if (is_dir($vendorDir)) {
  420. // suppress errors as this fails sometimes on OSX for no apparent reason
  421. // see https://github.com/composer/composer/issues/4070#issuecomment-129792748
  422. @touch($vendorDir);
  423. }
  424. }
  425. if ($doInstall) {
  426. // TODO ensure lock is used from locker as-is, since it may not have been written to disk in case of executeOperations == false
  427. return $this->doInstall($localRepo, true);
  428. }
  429. return 0;
  430. }
  431. /**
  432. * Run the solver a second time on top of the existing update result with only the current result set in the pool
  433. * and see what packages would get removed if we only had the non-dev packages in the solver request
  434. */
  435. protected function extractDevPackages(LockTransaction $lockTransaction, $platformRepo, $aliases, $policy)
  436. {
  437. if (!$this->package->getDevRequires()) {
  438. return array();
  439. }
  440. $resultRepo = new ArrayRepository(array());
  441. $loader = new ArrayLoader(null, true);
  442. $dumper = new ArrayDumper();
  443. foreach ($lockTransaction->getNewLockPackages(false) as $pkg) {
  444. $resultRepo->addPackage($loader->load($dumper->dump($pkg)));
  445. }
  446. $repositorySet = $this->createRepositorySet(true, $platformRepo, $aliases);
  447. $repositorySet->addRepository($resultRepo);
  448. $request = $this->createRequest($this->fixedRootPackage, $platformRepo, null);
  449. $links = $this->package->getRequires();
  450. foreach ($links as $link) {
  451. $request->requireName($link->getTarget(), $link->getConstraint());
  452. }
  453. $pool = $repositorySet->createPool($request);
  454. //$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request);
  455. $solver = new Solver($policy, $pool, $this->io, $repositorySet);
  456. try {
  457. $nonDevLockTransaction = $solver->solve($request, $this->ignorePlatformReqs);
  458. //$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request, $ops);
  459. $solver = null;
  460. } catch (SolverProblemsException $e) {
  461. $this->io->writeError('<error>Unable to find a compatible set of packages based on your non-dev requirements alone.</error>', true, IOInterface::QUIET);
  462. $this->io->writeError($e->getPrettyString($repositorySet, $request, $pool));
  463. return max(1, $e->getCode());
  464. }
  465. $lockTransaction->setNonDevPackages($nonDevLockTransaction);
  466. }
  467. /**
  468. * @param RepositoryInterface $localRepo
  469. * @param bool $alreadySolved Whether the function is called as part of an update command or independently
  470. * @return int exit code
  471. */
  472. protected function doInstall(RepositoryInterface $localRepo, $alreadySolved = false)
  473. {
  474. $platformRepo = $this->createPlatformRepo(false);
  475. $lockedRepository = $this->locker->getLockedRepository($this->devMode);
  476. // creating repository set
  477. $policy = $this->createPolicy(false);
  478. // use aliases from lock file only, so empty root aliases here
  479. $repositorySet = $this->createRepositorySet(false, $platformRepo, array(), $lockedRepository);
  480. $repositorySet->addRepository($lockedRepository);
  481. $this->io->writeError('<info>Installing dependencies from lock file'.($this->devMode ? ' (including require-dev)' : '').'</info>');
  482. // verify that the lock file works with the current platform repository
  483. // we can skip this part if we're doing this as the second step after an update
  484. if (!$alreadySolved) {
  485. $this->io->writeError('<info>Verifying lock file contents can be installed on current platform.</info>');
  486. // creating requirements request
  487. $request = $this->createRequest($this->fixedRootPackage, $platformRepo, $lockedRepository);
  488. if (!$this->locker->isFresh()) {
  489. $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);
  490. }
  491. foreach ($lockedRepository->getPackages() as $package) {
  492. $request->fixPackage($package);
  493. }
  494. foreach ($this->locker->getPlatformRequirements($this->devMode) as $link) {
  495. $request->requireName($link->getTarget(), $link->getConstraint());
  496. }
  497. //$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $this->devMode, $policy, $repositorySet, $installedRepo, $request);
  498. $pool = $repositorySet->createPool($request);
  499. // solve dependencies
  500. $solver = new Solver($policy, $pool, $this->io, $repositorySet);
  501. try {
  502. $lockTransaction = $solver->solve($request, $this->ignorePlatformReqs);
  503. $solver = null;
  504. // 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
  505. if (0 !== count($lockTransaction->getOperations())) {
  506. $this->io->writeError('<error>Your lock file cannot be installed on this system without changes. Please run composer update.</error>', true, IOInterface::QUIET);
  507. // TODO actually display operations to explain what happened?
  508. return 1;
  509. }
  510. } catch (SolverProblemsException $e) {
  511. $this->io->writeError('<error>Your lock file does not contain a compatible set of packages. Please run composer update.</error>', true, IOInterface::QUIET);
  512. $this->io->writeError($e->getPrettyString($repositorySet, $request, $pool));
  513. return max(1, $e->getCode());
  514. }
  515. // TODO should we warn people / error if plugins in vendor folder do not match contents of lock file before update?
  516. //$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $this->devMode, $policy, $repositorySet, $installedRepo, $request, $lockTransaction);
  517. }
  518. // 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?
  519. $localRepoTransaction = new LocalRepoTransaction($lockedRepository, $localRepo);
  520. if (!$localRepoTransaction->getOperations()) {
  521. $this->io->writeError('Nothing to install, update or remove');
  522. }
  523. if ($localRepoTransaction->getOperations()) {
  524. $installs = $updates = $uninstalls = array();
  525. foreach ($localRepoTransaction->getOperations() as $operation) {
  526. if ($operation instanceof InstallOperation) {
  527. $installs[] = $operation->getPackage()->getPrettyName().':'.$operation->getPackage()->getFullPrettyVersion();
  528. } elseif ($operation instanceof UpdateOperation) {
  529. $updates[] = $operation->getTargetPackage()->getPrettyName().':'.$operation->getTargetPackage()->getFullPrettyVersion();
  530. } elseif ($operation instanceof UninstallOperation) {
  531. $uninstalls[] = $operation->getPackage()->getPrettyName();
  532. }
  533. }
  534. $this->io->writeError(sprintf(
  535. "<info>Package operations: %d install%s, %d update%s, %d removal%s</info>",
  536. count($installs),
  537. 1 === count($installs) ? '' : 's',
  538. count($updates),
  539. 1 === count($updates) ? '' : 's',
  540. count($uninstalls),
  541. 1 === count($uninstalls) ? '' : 's'
  542. ));
  543. if ($installs) {
  544. $this->io->writeError("Installs: ".implode(', ', $installs), true, IOInterface::VERBOSE);
  545. }
  546. if ($updates) {
  547. $this->io->writeError("Updates: ".implode(', ', $updates), true, IOInterface::VERBOSE);
  548. }
  549. if ($uninstalls) {
  550. $this->io->writeError("Removals: ".implode(', ', $uninstalls), true, IOInterface::VERBOSE);
  551. }
  552. }
  553. if ($this->executeOperations) {
  554. $this->installationManager->execute($localRepo, $localRepoTransaction->getOperations(), $this->devMode);
  555. } else {
  556. foreach ($localRepoTransaction->getOperations() as $operation) {
  557. // output op, but alias op only in debug verbosity
  558. if (false === strpos($operation->getOperationType(), 'Alias') || $this->io->isDebug()) {
  559. $this->io->writeError(' - ' . $operation->show(false));
  560. }
  561. }
  562. }
  563. return 0;
  564. }
  565. private function createPlatformRepo($forUpdate)
  566. {
  567. if ($forUpdate) {
  568. $platformOverrides = $this->config->get('platform') ?: array();
  569. } else {
  570. $platformOverrides = $this->locker->getPlatformOverrides();
  571. }
  572. return new PlatformRepository(array(), $platformOverrides);
  573. }
  574. /**
  575. * @param bool $forUpdate
  576. * @param PlatformRepository $platformRepo
  577. * @param array $rootAliases
  578. * @param RepositoryInterface|null $lockedRepository
  579. * @return RepositorySet
  580. */
  581. private function createRepositorySet($forUpdate, PlatformRepository $platformRepo, array $rootAliases = array(), $lockedRepository = null)
  582. {
  583. if ($forUpdate) {
  584. $minimumStability = $this->package->getMinimumStability();
  585. $stabilityFlags = $this->package->getStabilityFlags();
  586. $requires = array_merge($this->package->getRequires(), $this->package->getDevRequires());
  587. } else {
  588. $minimumStability = $this->locker->getMinimumStability();
  589. $stabilityFlags = $this->locker->getStabilityFlags();
  590. $requires = array();
  591. foreach ($lockedRepository->getPackages() as $package) {
  592. $constraint = new Constraint('=', $package->getVersion());
  593. $constraint->setPrettyString($package->getPrettyVersion());
  594. $requires[$package->getName()] = $constraint;
  595. }
  596. }
  597. $rootRequires = array();
  598. foreach ($requires as $req => $constraint) {
  599. // skip platform requirements from the root package to avoid filtering out existing platform packages
  600. if ($this->ignorePlatformReqs && preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $req)) {
  601. continue;
  602. }
  603. if ($constraint instanceof Link) {
  604. $rootRequires[$req] = $constraint->getConstraint();
  605. } else {
  606. $rootRequires[$req] = $constraint;
  607. }
  608. }
  609. $this->fixedRootPackage = clone $this->package;
  610. $this->fixedRootPackage->setRequires(array());
  611. $this->fixedRootPackage->setDevRequires(array());
  612. $repositorySet = new RepositorySet($minimumStability, $stabilityFlags, $rootAliases, $this->package->getReferences(), $rootRequires);
  613. $repositorySet->addRepository(new RootPackageRepository(array($this->fixedRootPackage)));
  614. $repositorySet->addRepository($platformRepo);
  615. if ($this->additionalFixedRepository) {
  616. $repositorySet->addRepository($this->additionalFixedRepository);
  617. }
  618. return $repositorySet;
  619. }
  620. /**
  621. * @return DefaultPolicy
  622. */
  623. private function createPolicy($forUpdate)
  624. {
  625. $preferStable = null;
  626. $preferLowest = null;
  627. if (!$forUpdate) {
  628. $preferStable = $this->locker->getPreferStable();
  629. $preferLowest = $this->locker->getPreferLowest();
  630. }
  631. // old lock file without prefer stable/lowest will return null
  632. // so in this case we use the composer.json info
  633. if (null === $preferStable) {
  634. $preferStable = $this->preferStable || $this->package->getPreferStable();
  635. }
  636. if (null === $preferLowest) {
  637. $preferLowest = $this->preferLowest;
  638. }
  639. return new DefaultPolicy($preferStable, $preferLowest);
  640. }
  641. /**
  642. * @param RootPackageInterface $rootPackage
  643. * @param PlatformRepository $platformRepo
  644. * @param RepositoryInterface|null $lockedRepository
  645. * @return Request
  646. */
  647. private function createRequest(RootPackageInterface $rootPackage, PlatformRepository $platformRepo, $lockedRepository = null)
  648. {
  649. $request = new Request($lockedRepository);
  650. $request->fixPackage($rootPackage, false);
  651. if ($rootPackage instanceof RootAliasPackage) {
  652. $request->fixPackage($rootPackage->getAliasOf(), false);
  653. }
  654. $fixedPackages = $platformRepo->getPackages();
  655. if ($this->additionalFixedRepository) {
  656. $fixedPackages = array_merge($fixedPackages, $this->additionalFixedRepository->getPackages());
  657. }
  658. // fix the version of all platform packages + additionally installed packages
  659. // to prevent the solver trying to remove or update those
  660. // TODO why not replaces?
  661. $provided = $rootPackage->getProvides();
  662. foreach ($fixedPackages as $package) {
  663. // skip platform packages that are provided by the root package
  664. if ($package->getRepository() !== $platformRepo
  665. || !isset($provided[$package->getName()])
  666. || !$provided[$package->getName()]->getConstraint()->matches(new Constraint('=', $package->getVersion()))
  667. ) {
  668. $request->fixPackage($package, false);
  669. }
  670. }
  671. return $request;
  672. }
  673. /**
  674. * @param bool $forUpdate
  675. * @return array
  676. */
  677. private function getRootAliases($forUpdate)
  678. {
  679. if ($forUpdate) {
  680. $aliases = $this->package->getAliases();
  681. } else {
  682. $aliases = $this->locker->getAliases();
  683. }
  684. $normalizedAliases = array();
  685. foreach ($aliases as $alias) {
  686. $normalizedAliases[$alias['package']][$alias['version']] = array(
  687. 'alias' => $alias['alias'],
  688. 'alias_normalized' => $alias['alias_normalized'],
  689. );
  690. }
  691. return $normalizedAliases;
  692. }
  693. /**
  694. * @param PackageInterface $package
  695. * @return bool
  696. */
  697. private function isUpdateable(PackageInterface $package)
  698. {
  699. if (!$this->updateWhitelist) {
  700. throw new \LogicException('isUpdateable should only be called when a whitelist is present');
  701. }
  702. foreach ($this->updateWhitelist as $whiteListedPattern => $void) {
  703. $patternRegexp = BasePackage::packageNameToRegexp($whiteListedPattern);
  704. if (preg_match($patternRegexp, $package->getName())) {
  705. return true;
  706. }
  707. }
  708. return false;
  709. }
  710. /**
  711. * @param array $links
  712. * @return array
  713. */
  714. private function extractPlatformRequirements($links)
  715. {
  716. $platformReqs = array();
  717. foreach ($links as $link) {
  718. if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $link->getTarget())) {
  719. $platformReqs[$link->getTarget()] = $link->getPrettyConstraint();
  720. }
  721. }
  722. return $platformReqs;
  723. }
  724. /**
  725. * Adds all dependencies of the update whitelist to the whitelist, too.
  726. *
  727. * Packages which are listed as requirements in the root package will be
  728. * skipped including their dependencies, unless they are listed in the
  729. * update whitelist themselves or $whitelistAllDependencies is true.
  730. *
  731. * @param RepositoryInterface $lockRepo Use the locked repo
  732. * As we want the most accurate package list to work with, and installed
  733. * repo might be empty but locked repo will always be current.
  734. * @param array $rootRequires An array of links to packages in require of the root package
  735. * @param array $rootDevRequires An array of links to packages in require-dev of the root package
  736. */
  737. private function whitelistUpdateDependencies($lockRepo, array $rootRequires, array $rootDevRequires)
  738. {
  739. $rootRequires = array_merge($rootRequires, $rootDevRequires);
  740. $skipPackages = array();
  741. if (!$this->whitelistAllDependencies) {
  742. foreach ($rootRequires as $require) {
  743. $skipPackages[$require->getTarget()] = true;
  744. }
  745. }
  746. $repositorySet = new RepositorySet('dev');
  747. $repositorySet->addRepository($lockRepo);
  748. $seen = array();
  749. $rootRequiredPackageNames = array_keys($rootRequires);
  750. foreach ($this->updateWhitelist as $packageName => $void) {
  751. $packageQueue = new \SplQueue;
  752. $nameMatchesRequiredPackage = false;
  753. $depPackages = $repositorySet->findPackages($packageName, null, RepositorySet::ALLOW_PROVIDERS_REPLACERS);
  754. $matchesByPattern = array();
  755. // check if the name is a glob pattern that did not match directly
  756. if (empty($depPackages)) {
  757. // add any installed package matching the whitelisted name/pattern
  758. $whitelistPatternSearchRegexp = BasePackage::packageNameToRegexp($packageName, '^%s$');
  759. foreach ($lockRepo->search($whitelistPatternSearchRegexp) as $installedPackage) {
  760. $matchesByPattern[] = $repositorySet->findPackages($installedPackage['name'], null, RepositorySet::ALLOW_PROVIDERS_REPLACERS);
  761. }
  762. // add root requirements which match the whitelisted name/pattern
  763. $whitelistPatternRegexp = BasePackage::packageNameToRegexp($packageName);
  764. foreach ($rootRequiredPackageNames as $rootRequiredPackageName) {
  765. if (preg_match($whitelistPatternRegexp, $rootRequiredPackageName)) {
  766. $nameMatchesRequiredPackage = true;
  767. break;
  768. }
  769. }
  770. }
  771. if (!empty($matchesByPattern)) {
  772. $depPackages = array_merge($depPackages, call_user_func_array('array_merge', $matchesByPattern));
  773. }
  774. if (count($depPackages) == 0 && !$nameMatchesRequiredPackage) {
  775. $this->io->writeError('<warning>Package "' . $packageName . '" listed for update is not installed. Ignoring.</warning>');
  776. }
  777. foreach ($depPackages as $depPackage) {
  778. $packageQueue->enqueue($depPackage);
  779. }
  780. while (!$packageQueue->isEmpty()) {
  781. $package = $packageQueue->dequeue();
  782. if (isset($seen[spl_object_hash($package)])) {
  783. continue;
  784. }
  785. $seen[spl_object_hash($package)] = true;
  786. $this->updateWhitelist[$package->getName()] = true;
  787. if (!$this->whitelistTransitiveDependencies && !$this->whitelistAllDependencies) {
  788. continue;
  789. }
  790. $requires = $package->getRequires();
  791. foreach ($requires as $require) {
  792. $requirePackages = $repositorySet->findPackages($require->getTarget(), null, RepositorySet::ALLOW_PROVIDERS_REPLACERS);
  793. foreach ($requirePackages as $requirePackage) {
  794. if (isset($this->updateWhitelist[$requirePackage->getName()])) {
  795. continue;
  796. }
  797. if (isset($skipPackages[$requirePackage->getName()]) && !preg_match(BasePackage::packageNameToRegexp($packageName), $requirePackage->getName())) {
  798. $this->io->writeError('<warning>Dependency "' . $requirePackage->getName() . '" is also a root requirement, but is not explicitly whitelisted. Ignoring.</warning>');
  799. continue;
  800. }
  801. $packageQueue->enqueue($requirePackage);
  802. }
  803. }
  804. }
  805. }
  806. }
  807. /**
  808. * Replace local repositories with InstalledArrayRepository instances
  809. *
  810. * This is to prevent any accidental modification of the existing repos on disk
  811. *
  812. * @param RepositoryManager $rm
  813. */
  814. private function mockLocalRepositories(RepositoryManager $rm)
  815. {
  816. $packages = array();
  817. foreach ($rm->getLocalRepository()->getPackages() as $package) {
  818. $packages[(string) $package] = clone $package;
  819. }
  820. foreach ($packages as $key => $package) {
  821. if ($package instanceof AliasPackage) {
  822. $alias = (string) $package->getAliasOf();
  823. $packages[$key] = new AliasPackage($packages[$alias], $package->getVersion(), $package->getPrettyVersion());
  824. }
  825. }
  826. $rm->setLocalRepository(
  827. new InstalledArrayRepository($packages)
  828. );
  829. }
  830. /**
  831. * Create Installer
  832. *
  833. * @param IOInterface $io
  834. * @param Composer $composer
  835. * @return Installer
  836. */
  837. public static function create(IOInterface $io, Composer $composer)
  838. {
  839. return new static(
  840. $io,
  841. $composer->getConfig(),
  842. $composer->getPackage(),
  843. $composer->getDownloadManager(),
  844. $composer->getRepositoryManager(),
  845. $composer->getLocker(),
  846. $composer->getInstallationManager(),
  847. $composer->getEventDispatcher(),
  848. $composer->getAutoloadGenerator()
  849. );
  850. }
  851. /**
  852. * @param RepositoryInterface $additionalFixedRepository
  853. * @return $this
  854. */
  855. public function setAdditionalFixedRepository(RepositoryInterface $additionalFixedRepository)
  856. {
  857. $this->additionalFixedRepository = $additionalFixedRepository;
  858. return $this;
  859. }
  860. /**
  861. * Whether to run in drymode or not
  862. *
  863. * @param bool $dryRun
  864. * @return Installer
  865. */
  866. public function setDryRun($dryRun = true)
  867. {
  868. $this->dryRun = (bool) $dryRun;
  869. return $this;
  870. }
  871. /**
  872. * Checks, if this is a dry run (simulation mode).
  873. *
  874. * @return bool
  875. */
  876. public function isDryRun()
  877. {
  878. return $this->dryRun;
  879. }
  880. /**
  881. * prefer source installation
  882. *
  883. * @param bool $preferSource
  884. * @return Installer
  885. */
  886. public function setPreferSource($preferSource = true)
  887. {
  888. $this->preferSource = (bool) $preferSource;
  889. return $this;
  890. }
  891. /**
  892. * prefer dist installation
  893. *
  894. * @param bool $preferDist
  895. * @return Installer
  896. */
  897. public function setPreferDist($preferDist = true)
  898. {
  899. $this->preferDist = (bool) $preferDist;
  900. return $this;
  901. }
  902. /**
  903. * Whether or not generated autoloader are optimized
  904. *
  905. * @param bool $optimizeAutoloader
  906. * @return Installer
  907. */
  908. public function setOptimizeAutoloader($optimizeAutoloader = false)
  909. {
  910. $this->optimizeAutoloader = (bool) $optimizeAutoloader;
  911. if (!$this->optimizeAutoloader) {
  912. // Force classMapAuthoritative off when not optimizing the
  913. // autoloader
  914. $this->setClassMapAuthoritative(false);
  915. }
  916. return $this;
  917. }
  918. /**
  919. * Whether or not generated autoloader considers the class map
  920. * authoritative.
  921. *
  922. * @param bool $classMapAuthoritative
  923. * @return Installer
  924. */
  925. public function setClassMapAuthoritative($classMapAuthoritative = false)
  926. {
  927. $this->classMapAuthoritative = (bool) $classMapAuthoritative;
  928. if ($this->classMapAuthoritative) {
  929. // Force optimizeAutoloader when classmap is authoritative
  930. $this->setOptimizeAutoloader(true);
  931. }
  932. return $this;
  933. }
  934. /**
  935. * Whether or not generated autoloader considers APCu caching.
  936. *
  937. * @param bool $apcuAutoloader
  938. * @return Installer
  939. */
  940. public function setApcuAutoloader($apcuAutoloader = false)
  941. {
  942. $this->apcuAutoloader = (bool) $apcuAutoloader;
  943. return $this;
  944. }
  945. /**
  946. * update packages
  947. *
  948. * @param bool $update
  949. * @return Installer
  950. */
  951. public function setUpdate($update = true)
  952. {
  953. $this->update = (bool) $update;
  954. return $this;
  955. }
  956. /**
  957. * enables dev packages
  958. *
  959. * @param bool $devMode
  960. * @return Installer
  961. */
  962. public function setDevMode($devMode = true)
  963. {
  964. $this->devMode = (bool) $devMode;
  965. return $this;
  966. }
  967. /**
  968. * set whether to run autoloader or not
  969. *
  970. * This is disabled implicitly when enabling dryRun
  971. *
  972. * @param bool $dumpAutoloader
  973. * @return Installer
  974. */
  975. public function setDumpAutoloader($dumpAutoloader = true)
  976. {
  977. $this->dumpAutoloader = (bool) $dumpAutoloader;
  978. return $this;
  979. }
  980. /**
  981. * set whether to run scripts or not
  982. *
  983. * This is disabled implicitly when enabling dryRun
  984. *
  985. * @param bool $runScripts
  986. * @return Installer
  987. */
  988. public function setRunScripts($runScripts = true)
  989. {
  990. $this->runScripts = (bool) $runScripts;
  991. return $this;
  992. }
  993. /**
  994. * set the config instance
  995. *
  996. * @param Config $config
  997. * @return Installer
  998. */
  999. public function setConfig(Config $config)
  1000. {
  1001. $this->config = $config;
  1002. return $this;
  1003. }
  1004. /**
  1005. * run in verbose mode
  1006. *
  1007. * @param bool $verbose
  1008. * @return Installer
  1009. */
  1010. public function setVerbose($verbose = true)
  1011. {
  1012. $this->verbose = (bool) $verbose;
  1013. return $this;
  1014. }
  1015. /**
  1016. * Checks, if running in verbose mode.
  1017. *
  1018. * @return bool
  1019. */
  1020. public function isVerbose()
  1021. {
  1022. return $this->verbose;
  1023. }
  1024. /**
  1025. * set ignore Platform Package requirements
  1026. *
  1027. * @param bool $ignorePlatformReqs
  1028. * @return Installer
  1029. */
  1030. public function setIgnorePlatformRequirements($ignorePlatformReqs = false)
  1031. {
  1032. $this->ignorePlatformReqs = (bool) $ignorePlatformReqs;
  1033. return $this;
  1034. }
  1035. /**
  1036. * Update the lock file to the exact same versions and references but use current remote metadata like URLs and mirror info
  1037. *
  1038. * @param bool $updateMirrors
  1039. * @return Installer
  1040. */
  1041. public function setUpdateMirrors($updateMirrors)
  1042. {
  1043. $this->updateMirrors = $updateMirrors;
  1044. return $this;
  1045. }
  1046. /**
  1047. * restrict the update operation to a few packages, all other packages
  1048. * that are already installed will be kept at their current version
  1049. *
  1050. * @param array $packages
  1051. * @return Installer
  1052. */
  1053. public function setUpdateWhitelist(array $packages)
  1054. {
  1055. $this->updateWhitelist = array_flip(array_map('strtolower', $packages));
  1056. return $this;
  1057. }
  1058. /**
  1059. * Should dependencies of whitelisted packages (but not direct dependencies) be updated?
  1060. *
  1061. * This will NOT whitelist any dependencies that are also directly defined
  1062. * in the root package.
  1063. *
  1064. * @param bool $updateTransitiveDependencies
  1065. * @return Installer
  1066. */
  1067. public function setWhitelistTransitiveDependencies($updateTransitiveDependencies = true)
  1068. {
  1069. $this->whitelistTransitiveDependencies = (bool) $updateTransitiveDependencies;
  1070. return $this;
  1071. }
  1072. /**
  1073. * Should all dependencies of whitelisted packages be updated recursively?
  1074. *
  1075. * This will whitelist any dependencies of the whitelisted packages, including
  1076. * those defined in the root package.
  1077. *
  1078. * @param bool $updateAllDependencies
  1079. * @return Installer
  1080. */
  1081. public function setWhitelistAllDependencies($updateAllDependencies = true)
  1082. {
  1083. $this->whitelistAllDependencies = (bool) $updateAllDependencies;
  1084. return $this;
  1085. }
  1086. /**
  1087. * Should packages be preferred in a stable version when updating?
  1088. *
  1089. * @param bool $preferStable
  1090. * @return Installer
  1091. */
  1092. public function setPreferStable($preferStable = true)
  1093. {
  1094. $this->preferStable = (bool) $preferStable;
  1095. return $this;
  1096. }
  1097. /**
  1098. * Should packages be preferred in a lowest version when updating?
  1099. *
  1100. * @param bool $preferLowest
  1101. * @return Installer
  1102. */
  1103. public function setPreferLowest($preferLowest = true)
  1104. {
  1105. $this->preferLowest = (bool) $preferLowest;
  1106. return $this;
  1107. }
  1108. /**
  1109. * Should the lock file be updated when updating?
  1110. *
  1111. * This is disabled implicitly when enabling dryRun
  1112. *
  1113. * @param bool $writeLock
  1114. * @return Installer
  1115. */
  1116. public function setWriteLock($writeLock = true)
  1117. {
  1118. $this->writeLock = (bool) $writeLock;
  1119. return $this;
  1120. }
  1121. /**
  1122. * Should the operations (package install, update and removal) be executed on disk?
  1123. *
  1124. * This is disabled implicitly when enabling dryRun
  1125. *
  1126. * @param bool $executeOperations
  1127. * @return Installer
  1128. */
  1129. public function setExecuteOperations($executeOperations = true)
  1130. {
  1131. $this->executeOperations = (bool) $executeOperations;
  1132. return $this;
  1133. }
  1134. /**
  1135. * Should suggestions be skipped?
  1136. *
  1137. * @param bool $skipSuggest
  1138. * @return Installer
  1139. */
  1140. public function setSkipSuggest($skipSuggest = true)
  1141. {
  1142. $this->skipSuggest = (bool) $skipSuggest;
  1143. return $this;
  1144. }
  1145. /**
  1146. * Disables plugins.
  1147. *
  1148. * Call this if you want to ensure that third-party code never gets
  1149. * executed. The default is to automatically install, and execute
  1150. * custom third-party installers.
  1151. *
  1152. * @return Installer
  1153. */
  1154. public function disablePlugins()
  1155. {
  1156. $this->installationManager->disablePlugins();
  1157. return $this;
  1158. }
  1159. /**
  1160. * @param SuggestedPackagesReporter $suggestedPackagesReporter
  1161. * @return Installer
  1162. */
  1163. public function setSuggestedPackagesReporter(SuggestedPackagesReporter $suggestedPackagesReporter)
  1164. {
  1165. $this->suggestedPackagesReporter = $suggestedPackagesReporter;
  1166. return $this;
  1167. }
  1168. }