Installer.php 49 KB

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