public function loadBundles()
{
$appKernelPath = new \ReflectionClass('AppKernel');
$file = $appKernelPath->getFileName();
$content = file_get_contents($file);
preg_match('/function registerBundles.*/mis', $content, $match);
if (!isset($match[0])) {
throw new \LogicException('Method `registerBundles` not found in AppKernel class.');
}
$this->script = $match[0];
preg_match('/\\$bundles = array\\((.*)\\);/mis', $this->script, $match);
if (!isset($match[0])) {
preg_match('/\\$bundles = \\[(.*)\\);/mis', $this->script, $match);
}
if (!isset($match[0])) {
throw new \LogicException('In `registerBundles` of AppKernel class there is no $bundles = array(...) assignment.');
}
$inBundles = false;
$bundles = '';
$inBlockComment = false;
$inComment = false;
$this->length = strlen($this->script);
for ($this->position = 0; $this->position < $this->length; $this->position++) {
if ($inComment || $inBlockComment) {
//search for comment ends
if (!$inBlockComment && $inComment && $this->expect("\n")) {
$inComment = false;
}
if (!$inComment && $inBlockComment && $this->expect('*/')) {
$inBlockComment = false;
}
continue;
} else {
//search for comment starts
if (!$inBlockComment && $this->expect('//')) {
$inComment = true;
}
if (!$inComment && $this->expect('/*')) {
$inBlockComment = true;
}
}
if (!$inBundles) {
if ($this->expect('$')) {
if ($this->eat('$bundles')) {
$inBundles = true;
}
}
} else {
if ($this->expect(');')) {
break;
}
if ($this->eat('new ')) {
preg_match('/[a-zA-Z0-9\\\\_]+/', substr($this->script, $this->position), $match);
$bundles[] = $match[0];
}
}
}
$this->bundles = $bundles;
}