Created
November 4, 2011 17:42
-
-
Save docteurklein/1339968 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Symfony\Component\HttpKernel\Kernel; | |
use Symfony\Component\Config\Loader\LoaderInterface; | |
use Symfony\Component\Finder\Finder; | |
class SmartKernel extends Kernel | |
{ | |
public function registerBundles() | |
{ | |
$finder = new Finder(); | |
$finder | |
->files() | |
->name('*Bundle.php') | |
->in(array( | |
'src', | |
'vendor/bundles', | |
'vendor/symfony/src/Symfony/Bundle', | |
)) | |
/*->sort(function(\SplFileInfo $a, \SplFileInfo $b) { | |
return strcmp($a->getRealpath(), $b->getRealpath()); | |
})*/ | |
; | |
$bundles = array(); | |
foreach ($finder as $file) { | |
$path = $this->trim($file->getPathName()); | |
$parentPath = $this->trim($file->getPath()); | |
foreach ($bundles as $parent => $bundle) { | |
if (strpos($path, $parent) === 0) { | |
// do not register bundles that are in already registered bundles | |
continue 2; | |
} | |
} | |
var_dump($path, $parentPath, strpos($path, $parentPath) === 0); | |
$namespace = str_replace('/', '\\', $path); | |
$bundles[$parentPath] = new $namespace; | |
} | |
return $bundles; | |
} | |
private function trim($path) | |
{ | |
$path = ltrim($path, 'src/'); | |
$path = ltrim($path, 'vendor/bundles/'); | |
$path = ltrim($path, 'symfony/src'); | |
$path = rtrim($path, '.php'); | |
return $path; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍