Get bundle instances given the namespace stack.

@param KernelInterface $kernel
@param array           $bundles

@return BundleInterface[]
774622
protected function getBundleInstances(
        KernelInterface $kernel,
        array $bundles
    ): array {
        $bundleStack = $this
            ->resolveAndReturnBundleDependencies(
                $kernel,
                $bundles
            );

        $builtBundles = [];
        foreach ($bundleStack as $bundle) {
            $builtBundles[] = $this
                ->getBundleDefinitionInstance($bundle);
        }

        return $builtBundles;
    }
1280331
protected function getRequiredClientBundleCodeGenerators($bundle)
    {
        return [
            $this->createClientDependencyProviderCodeGenerator($bundle),
            $this->createClientFactoryCodeGenerator($bundle),
            $this->createClientCodeGenerator($bundle),
            $this->createClientInterfaceCodeGenerator($bundle),
            $this->createStubCodeGenerator($bundle),
            $this->createStubInterfaceCodeGenerator($bundle),
            $this->createGatewayControllerCodeGenerator($bundle),
        ];
    }
923668
private function getNamespaceAutoComplete(Kernel $kernel)
    {
        $ret = array();
        foreach ($kernel->getBundles() as $k => $v) {
            $ret[] = $this->fixNamespace($v->getNamespace());
        }

        return $ret;
    }
1038631
private function encodeBundle(ResourceBundleInterface $bundle): array
    {
        $encodedBundle = [];
        foreach ($bundle->getKeys() as $key) {
            $encodedBundle[$key] = $this->getBundleValue($bundle, (string)$key);
        }

        return $encodedBundle;
    }
1150327
public static function loadAll(array $bundles)
    {
        foreach ($bundles as $bundle) {
            if (!$bundle instanceof BundleInterface) {
                throw new InvalidArgumentException('Bundle must be instance of "Rad\Core\BundleInterface".');
            }

            self::load($bundle);
        }
    }
391143
@Override
    public Collection<ResourceBundle> bundles() {
        Set<ResourceBundle> bundles = new LinkedHashSet<>();
        for (I18nExtension extension : extensions) {
            bundles.add(extension.bundle());
        }
        return bundles;
    }
639130
private function parseBundles(array $bundles, array &$configs): void
    {
        foreach ($bundles as $options) {
            // Only one value given, must be class name
            if (!\is_array($options)) {
                $options = ['bundle' => $options];
            }

            if (!isset($options['bundle'])) {
                throw new \RuntimeException(
                    sprintf('Missing class name for bundle config (%s)', json_encode($options))
                );
            }

            if (!empty($options['optional']) && !class_exists($options['bundle'])) {
                continue;
            }

            $config = new BundleConfig($options['bundle']);

            if (isset($options['replace'])) {
                $config->setReplace($options['replace']);
            }

            if (isset($options['development'])) {
                if (true === $options['development']) {
                    $config->setLoadInProduction(false);
                } elseif (false === $options['development']) {
                    $config->setLoadInDevelopment(false);
                }
            }

            if (isset($options['load-after'])) {
                $config->setLoadAfter($options['load-after']);
            }

            $configs[] = $config;
        }
    }
1082410
protected function getBundleByName($bundleName)
    {
        /** @var Kernel $kernel */
        $kernel = $this->getApplication()->getKernel();

        $bundles = $kernel->getBundle($bundleName, false);

        return $bundles[count($bundles) - 1];
    }
476464
public function validateBundleName($bundle)
    {
        // strtolower all bundle names
        $bundles = array_map('strtolower', array_keys($this->kernel->getBundles()));

        if (in_array(strtolower(trim($bundle)), $bundles)) {
            return true;
        }

        throw new \Exception(sprintf('bundle "%s" not found in available bundles: %s', $bundle, implode(', ', $bundles)));
    }
487113
public function initializeBundles()
    {
        $config = $this->getContainer()->singleton('kernel.config');
        $routing = $this->getContainer()->singleton('kernel.routing');

        $this->bundles = $this->registerBundles();

        foreach ($this->bundles as $bundle) {
            $bundle->setContainer($this->getContainer());
            $bundle->registerRouting($routing, $this->getEnvironment());
            $bundle->registerConfiguration($config, $this->getEnvironment());
        }

        unset($config, $routing);
    }
679754
protected function getBundleNameFromEntity($rootEntityName)
    {
        $bundles = $this->getContainer()->get('kernel')->getBundles();
        $bundleName = '';

        foreach ($bundles as $type => $bundle) {
            $className = get_class($bundle);

            $namespaceParts = explode('\\', $className);
            array_pop($namespaceParts);
            $bundleNamespace = implode('\\', $namespaceParts);
            $entityBundleNamespace = substr($rootEntityName, 0, strpos($rootEntityName, '\\Entity\\'));

            if ($bundleNamespace === $entityBundleNamespace) {
                $bundleName = $type;
            }
        }

        return $bundleName;
    }
77781
@Override
    public Collection<Bundle> getBundles() {
        if (mfDetails == null)
            throw new IllegalStateException("Method called outside of provisioining operation or without a registered service");

        Collection<Bundle> bundles = featureBundles.get();

        if (bundles == null) {
            bundles = new ArrayList<Bundle>();

            Collection<FeatureResource> bundlesInFeature = mfDetails.getConstituents(SubsystemContentType.BUNDLE_TYPE);

            BundleContext ctx = FrameworkUtil.getBundle(FrameworkUtil.class).getBundleContext();

            // symbolic name to bundle map. 
            for (FeatureResource bundle : bundlesInFeature) {
                String location = bundle.getLocation();
                Bundle b = ctx.getBundle(location);
                if (b != null) {
                    bundles.add(b);
                }
            }

            // make an unmodifiable version.
            bundles = Collections.unmodifiableCollection(bundles);

            // store it away if it hasn't already been read. If this is read by another
            // thread at once then this thread will get this collection, and others will
            // the winner's.
            featureBundles.compareAndSet(null, bundles);
        }

        return bundles;
    }
511294
public function findClasses($bundles, $directory = '', $type = '')
    {
        $finder = Finder::create()->files()->name('*.php')->sortByName()->ignoreUnreadableDirs();
        $found  = false;

        foreach ($bundles as $bundle) {
            $path = rtrim($bundle->getPath(), DIRECTORY_SEPARATOR);

            if (true === empty($directory)) {
                $found = true;
                $finder->in($path);
                continue;
            }

            if (false === is_array($directory)) {
                $directory = [$directory];
            }

            foreach ($directory as $dir) {
                $pathname = sprintf('%s%s%s', $path, DIRECTORY_SEPARATOR, trim($dir, DIRECTORY_SEPARATOR));
                if (true === is_dir($pathname)) {
                    $found = true;
                    $finder->in($pathname);
                }
            }
        }

        if (false === $found) {
            return [];
        }

        $files = [];
        foreach ($finder as $file) {
            $files[] = $file->getPathname();
        }

        $classes = [];
        foreach ($files as $file) {
            foreach ($bundles as $bundle) {
                if (null !== $class = $this->getClassFromFileAndBundle($file, $bundle)) {
                    $classes[] = $class;
                    continue;
                }
            }
        }

        $classes = array_filter($classes, function ($e) {
            return class_exists($e);
        });

        if (false === empty($type)) {
            if (false === (class_exists($type) || interface_exists($type))) {
                throw new \InvalidArgumentException(sprintf('Class or interface "%s" unknown', $type));
            }
            $classes = array_filter($classes, function ($e) use ($type) {
                return is_subclass_of($e, $type);
            });
        }

        return $classes;
    }
732418
public function getAttributeIds($bundle = null)
    {
        $attributes = $this->attributes($bundle);
        $ids = [];

        foreach ($attributes as $name => $info) {
            $ids[] = $info['id'];
        }

        return $ids;
    }
270672
public function bundleExists($bundle)
    {
        $kernelBundles = $this->getConfigurationPool()->getContainer()->getParameter('kernel.bundles');
        if (array_key_exists($bundle, $kernelBundles)) {
            return true;
        }
        if (in_array($bundle, $kernelBundles)) {
            return true;
        }

        return false;
    }
366918
@Override
	protected List<JoinableResourceBundle> filterBundlesToRender(List<JoinableResourceBundle> bundles) {
		List<JoinableResourceBundle> filteredBundles = new ArrayList<>();
		for (JoinableResourceBundle bundle : bundles) {
			if (bundle.getInclusionPattern().isIncludeOnDebug()) {
				filteredBundles.add(bundle);
			}
		}
		return filteredBundles;
	}
800173
public function findAll()
    {
        if (null !== $this->yamls) {
            return $this->yamls;
        }

        $yamls = array();

        foreach ($this->kernel->getBundles() as $name => $bundle) {
            foreach ($this->find($bundle) as $yaml) {
                $yamls[$yaml] = $yaml;
            }
        }

        return $this->yamls = $yamls;
    }