Installer.php 48 KB

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