Symfony\Component\HttpKernel\Kernel::getBundle PHP Method

getBundle() public method

Returns a bundle and optionally its descendants by its name.
public getBundle ( string $name, boolean $first = true ) : Symfony\Component\HttpKernel\Bundle\BundleInterface | Array
$name string Bundle name
$first boolean Whether to return the first bundle only or together with its descendants
return Symfony\Component\HttpKernel\Bundle\BundleInterface | Array A BundleInterface instance or an array of BundleInterface instances if $first is false
    public function getBundle($name, $first = true)
    {
        if (!isset($this->bundleMap[$name])) {
            throw new \InvalidArgumentException(sprintf('Bundle "%s" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() function of your %s.php file?', $name, get_class($this)));
        }

        if (true === $first) {
            return $this->bundleMap[$name][0];
        }

        return $this->bundleMap[$name];
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getBundle($name, $first = true)
 {
     // if need to get this precise bundle
     if (strpos($name, '!') === 0) {
         $name = substr($name, 1);
         if (isset($this->bundleMap[$name])) {
             // current bundle is always the last
             $bundle = end($this->bundleMap[$name]);
             return $first ? $bundle : array($bundle);
         }
     }
     return parent::getBundle($name, $first);
 }