Installer.php 49 KB

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