Skip to content

Commit cf7aa3d

Browse files
Enable bundles autodiscovery by default and provide extra.symfony.bundles configuration for customizations
1 parent e4f5a26 commit cf7aa3d

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

src/Flex.php

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ function ($value) {
444444
}
445445
$value = strtolower($value[0]);
446446
if (!\in_array($value, ['y', 'n', 'a', 'p'])) {
447-
throw new \InvalidArgumentException('Invalid choice');
447+
throw new \InvalidArgumentException('Invalid choice.');
448448
}
449449

450450
return $value;
@@ -757,18 +757,42 @@ public function fetchRecipes(array $operations): array
757757
}
758758

759759
$noRecipe = !isset($manifests[$name]) || (isset($manifests[$name]['not_installable']) && $manifests[$name]['not_installable']);
760-
if ($noRecipe && 'symfony-bundle' === $package->getType()) {
761-
$manifest = [];
762-
$bundle = new SymfonyBundle($this->composer, $package, $job);
763-
if (null === $devPackages) {
764-
$devPackages = array_column($this->composer->getLocker()->getLockData()['packages-dev'], 'name');
765-
}
766-
$envs = \in_array($name, $devPackages) ? ['dev', 'test'] : ['all'];
767-
foreach ($bundle->getClassNames() as $class) {
768-
$manifest['manifest']['bundles'][$class] = $envs;
760+
if ($noRecipe) {
761+
$bundles = [];
762+
763+
$extra = $package->getExtra();
764+
if (isset($extra['symfony']['bundles'])) {
765+
$extraBundles = $extra['symfony']['bundles'];
766+
if (!\is_array($extraBundles)) {
767+
throw new \InvalidArgumentException(sprintf('Entry "bundles" under "extra.symfony" in the composer.json of package "%s" must be an array, "%s" given.', $name, \gettype($extraBundles)));
768+
}
769+
foreach ($extraBundles as $bundleClass => $envs) {
770+
if (!\is_array($envs)) {
771+
throw new \InvalidArgumentException(sprintf('Invalid envs for bundle "%s" under "extra.symfony.bundles": array expected, "%s" given in the composer.json of package "%s".', $bundleClass, \gettype($envs), $name));
772+
}
773+
foreach ($envs as $env) {
774+
if (!\is_string($env)) {
775+
throw new \InvalidArgumentException(sprintf('Bundle "%s" under "extra.symfony.bundles" should list Symfony envs as strings, "%s" found in the composer.json of package "%s".', $bundleClass, \gettype($env), $name));
776+
}
777+
}
778+
$bundles[$bundleClass] = $envs;
779+
}
780+
} else {
781+
if (null === $devPackages) {
782+
$devPackages = array_column($this->composer->getLocker()->getLockData()['packages-dev'], 'name');
783+
}
784+
$envs = \in_array($name, $devPackages) ? ['dev', 'test'] : ['all'];
785+
$bundle = new SymfonyBundle($this->composer, $package, $job);
786+
foreach ($bundle->getClassNames() as $bundleClass) {
787+
$bundles[$bundleClass] = $envs;
788+
}
769789
}
770-
if ($manifest) {
771-
$manifest['origin'] = sprintf('%s:%s@auto-generated recipe', $name, $package->getPrettyVersion());
790+
791+
if ($bundles) {
792+
$manifest = [
793+
'origin' => sprintf('%s:%s@auto-generated recipe', $name, $package->getPrettyVersion()),
794+
'manifest' => ['bundles' => $bundles],
795+
];
772796
$recipes[$name] = new Recipe($package, $name, $job, $manifest);
773797
}
774798
}

0 commit comments

Comments
 (0)