Installer.php 50 KB

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