Symfony\Component\HttpKernel\Kernel::initializeBundles PHP 메소드

initializeBundles() 보호된 메소드

- the bundles property maps a bundle name to the bundle instance, - the bundleMap property maps a bundle name to the bundle inheritance hierarchy (most derived bundle first).
protected initializeBundles ( )
    protected function initializeBundles()
    {
        // init bundles
        $this->bundles = array();
        $topMostBundles = array();
        $directChildren = array();

        foreach ($this->registerBundles() as $bundle) {
            $name = $bundle->getName();
            if (isset($this->bundles[$name])) {
                throw new \LogicException(sprintf('Trying to register two bundles with the same name "%s"', $name));
            }
            $this->bundles[$name] = $bundle;

            if ($parentName = $bundle->getParent()) {
                if (isset($directChildren[$parentName])) {
                    throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName]));
                }
                if ($parentName == $name) {
                    throw new \LogicException(sprintf('Bundle "%s" can not extend itself.', $name));
                }
                $directChildren[$parentName] = $name;
            } else {
                $topMostBundles[$name] = $bundle;
            }
        }

        // look for orphans
        if (count($diff = array_values(array_diff(array_keys($directChildren), array_keys($this->bundles))))) {
            throw new \LogicException(sprintf('Bundle "%s" extends bundle "%s", which is not registered.', $directChildren[$diff[0]], $diff[0]));
        }

        // inheritance
        $this->bundleMap = array();
        foreach ($topMostBundles as $name => $bundle) {
            $bundleMap = array($bundle);
            $hierarchy = array($name);

            while (isset($directChildren[$name])) {
                $name = $directChildren[$name];
                array_unshift($bundleMap, $this->bundles[$name]);
                $hierarchy[] = $name;
            }

            foreach ($hierarchy as $bundle) {
                $this->bundleMap[$bundle] = $bundleMap;
                array_pop($bundleMap);
            }
        }

    }

Usage Example

예제 #1
0
 /**
  * {@inheritdoc}
  */
 protected function initializeBundles()
 {
     parent::initializeBundles();
     // pass bundles to CumulativeResourceManager
     $bundles = array();
     foreach ($this->bundles as $name => $bundle) {
         $bundles[$name] = get_class($bundle);
     }
     CumulativeResourceManager::getInstance()->setBundles($bundles)->setAppRootDir($this->rootDir);
 }
All Usage Examples Of Symfony\Component\HttpKernel\Kernel::initializeBundles