Untested but you could try something like
use SymfonyComponentHttpKernelKernel;
use SymfonyComponentConfigLoaderLoaderInterface;
use SymfonyComponentFinderFinder;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new SymfonyBundleFrameworkBundleFrameworkBundle(),
//... default bundles
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new SymfonyBundleWebProfilerBundleWebProfilerBundle();
// ... debug and development bundles
}
$searchPath = __DIR__.'/../src';
$finder = new Finder();
$finder->files()
->in($searchPath)
->name('*Bundle.php');
foreach ($finder as $file) {
$path = substr($file->getRealpath(), strlen($searchPath) + 1, -4);
$parts = explode('/', $path);
$class = array_pop($parts);
$namespace = implode('\', $parts);
$class = $namespace.'\'.$class;
$bundles[] = new $class();
}
return $bundles;
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…