Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge 6758979 into 37c65a0
Browse files Browse the repository at this point in the history
  • Loading branch information
Geert Eltink committed Feb 8, 2018
2 parents 37c65a0 + 6758979 commit d2188a4
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/ComponentInstaller.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @see https://github.com/zendframework/zend-component-installer for the canonical source repository
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2015-2018 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-component-installer/blob/master/LICENSE.md New BSD License
*/

Expand Down Expand Up @@ -186,13 +186,18 @@ public function onPostPackageInstall(PackageEvent $event)

$dependencies = $this->loadModuleClassesDependencies($package);
$applicationModules = $this->findApplicationModules();
$composer = $this->composer;

$this->marshalInstallableModules($extra, $options)
->each(function ($module) use ($name) {
})
// Create injectors
->reduce(function ($injectors, $module) use ($options, $packageTypes) {
$injectors[$module] = $this->promptForConfigOption($module, $options, $packageTypes[$module]);
->reduce(function ($injectors, $module) use ($options, $packageTypes, $name, $composer) {
// Get extra from root package
$rootExtra = $this->getExtraMetadata($composer->getPackage()->getExtra());
$whitelist = $rootExtra['component-whitelist'] ?? [];
$packageType = $packageTypes[$module];
$injectors[$module] = $this->promptForConfigOption($module, $options, $packageType, $name, $whitelist);
return $injectors;
}, new Collection([]))
// Inject modules into configuration
Expand Down Expand Up @@ -407,14 +412,26 @@ private function marshalInstallableModules(array $extra, Collection $options)
* @param string $name
* @param Collection $options
* @param int $packageType
* @param string $packageName
* @param array $whitelist
* @return Injector\InjectorInterface
*/
private function promptForConfigOption($name, Collection $options, $packageType)
{
private function promptForConfigOption(
string $name,
Collection $options,
int $packageType,
string $packageName,
array $whitelist
) {
if ($cachedInjector = $this->getCachedInjector($packageType)) {
return $cachedInjector;
}

// If package is whitelisted, don't ask...
if (in_array($packageName, $whitelist, false)) {
return $options[1]->getInjector();
}

// Default to first discovered option; index 0 is always "Do not inject"
$default = $options->count() > 1 ? 1 : 0;
$ask = $options->reduce(function ($ask, $option, $index) {
Expand Down Expand Up @@ -483,7 +500,7 @@ private function promptToRememberOption(Injector\InjectorInterface $injector, $p
*/
private function injectModuleIntoConfig($package, $module, Injector\InjectorInterface $injector, $packageType)
{
$this->io->write(sprintf('<info>Installing %s from package %s</info>', $module, $package));
$this->io->write(sprintf('<info> Installing %s from package %s</info>', $module, $package));

try {
if (! $injector->inject($module, $packageType)) {
Expand Down Expand Up @@ -542,7 +559,7 @@ private function removePackageFromConfig($package, array $metadata, Collection $
private function removeModuleFromConfig($module, $package, Collection $injectors)
{
$injectors->each(function (InjectorInterface $injector) use ($module, $package) {
$this->io->write(sprintf('<info>Removing %s from package %s</info>', $module, $package));
$this->io->write(sprintf('<info> Removing %s from package %s</info>', $module, $package));

if ($injector->remove($module)) {
$this->io->write(sprintf(
Expand Down

0 comments on commit d2188a4

Please sign in to comment.