Skip to content

Commit

Permalink
Merge pull request #53 from laminas/2.8.x-merge-up-into-3.0.x_cygXgFlr
Browse files Browse the repository at this point in the history
Merge release 2.8.0 into 3.0.x
  • Loading branch information
boesing committed Jul 3, 2022
2 parents b18208d + 6954e2a commit 6af4680
Show file tree
Hide file tree
Showing 3 changed files with 247 additions and 61 deletions.
20 changes: 11 additions & 9 deletions docs/book/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,25 @@ will need to have a line that instantiates either a
Configuration providers are added at the **top** of the
`ConfigManager`/`ConfigAggregator` provider array.

## Whitelisting packages to autoinstall
## Marking packages to auto-install

At the root package level, you can indicate that certain packages that supply
config providers and/or modules should automatically inject configuration,
instead of prompting for installation, via the `component-whitelist` setting.
instead of prompting for installation, via the `component-auto-installs` setting.
This value should be an array of package names.

```json
"extra": {
{
"extra": {
"laminas": {
"component-whitelist": [
"mezzio/mezzio",
"mezzio/mezzio-helper",
"mezzio/mezzio-fastrouterouter",
"mezzio/mezzio-platesrenderer"
]
"component-auto-installs": [
"mezzio/mezzio",
"mezzio/mezzio-helper",
"mezzio/mezzio-fastrouterouter",
"mezzio/mezzio-platesrenderer"
]
}
}
}
```

Expand Down
33 changes: 23 additions & 10 deletions src/ComponentInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
* @internal
*
* @psalm-type ComposerExtraComponentInstallerProjectArrayType = array{
* component-whitelist?: non-empty-list<non-empty-string>
* component-whitelist?: non-empty-list<non-empty-string>,
* component-auto-installs?: non-empty-list<non-empty-string>
* }
* @psalm-type ComposerExtraComponentInstallerArrayType = array{
* component?:non-empty-array<non-empty-string>,
Expand Down Expand Up @@ -495,22 +496,22 @@ private function marshalInstallableComponents(array $extra, Collection $options)
* @param Collection<int,ConfigOption> $options
* @param InjectorInterface::TYPE_* $packageType
* @param non-empty-string $packageName
* @param list<non-empty-string> $whitelist
* @param list<non-empty-string> $autoInstallations
*/
private function promptForConfigOption(
string $name,
Collection $options,
int $packageType,
string $packageName,
array $whitelist,
array $autoInstallations,
bool $requireDev = false
): InjectorInterface {
if ($cachedInjector = $this->getCachedInjector($packageType)) {
return $cachedInjector;
}

// If package is whitelisted, don't ask...
if (in_array($packageName, $whitelist, true)) {
// If package is allowed to be auto-installed, don't ask...
if (in_array($packageName, $autoInstallations, true)) {
$injector = $options->get(1)->getInjector();
if ($requireDev && $options->has(2)) {
return $options->get(2)->getInjector();
Expand Down Expand Up @@ -948,9 +949,11 @@ private function addPackageToConfig(

// Get extra from root package
/** @var array<string,mixed> $rootPackageExtra */
$rootPackageExtra = $this->composer->getPackage()->getExtra();
$rootExtra = $this->getExtraMetadata($rootPackageExtra, true);
$whitelist = $rootExtra['component-whitelist'] ?? [];
$rootPackageExtra = $this->composer->getPackage()->getExtra();
$rootExtra = $this->getExtraMetadata($rootPackageExtra, true);
$autoInstallations = $rootExtra['component-auto-installs']
?? $rootExtra['component-whitelist']
?? [];

$this->marshalInstallableComponents($extra, $options)
// Create injectors
Expand All @@ -961,7 +964,7 @@ private function addPackageToConfig(
$requireDev,
$dependencies,
$applicationModules,
$whitelist
$autoInstallations
): void {
$packageType = $packageTypes->get($component);

Expand All @@ -970,7 +973,7 @@ private function addPackageToConfig(
$options,
$packageType,
$name,
$whitelist,
$autoInstallations,
$requireDev
);

Expand Down Expand Up @@ -1056,6 +1059,16 @@ private function filterComponentInstallerSpecificValuesFromComposerExtra(
= $maybeLaminasSpecificConfiguration['component-whitelist'];
}

if (
isset($maybeLaminasSpecificConfiguration['component-auto-installs'])
&& $this->isNonEmptyListContainingNonEmptyStrings(
$maybeLaminasSpecificConfiguration['component-auto-installs']
)
) {
$laminasSpecificConfiguration['component-auto-installs']
= $maybeLaminasSpecificConfiguration['component-auto-installs'];
}

return $laminasSpecificConfiguration;
}

Expand Down

0 comments on commit 6af4680

Please sign in to comment.