public function activateAction($bundle)
{
Manager::prepareName($bundle);
$this->get('logger')->alert('ACTIVATE BUNDLE ' . $bundle);
$appKernelPath = new \ReflectionClass('AppKernel');
$file = $appKernelPath->getFileName();
$content = file_get_contents($file);
if (!class_exists($bundle)) {
throw new \RuntimeException('Bundle does not exist.');
}
if (false !== stripos($content, 'new ' . $bundle) || false !== stripos($content, 'new \\' . $bundle)) {
throw new \RuntimeException('Bundle already registered');
}
$newJarves = 'new Jarves\\JarvesBundle()';
$searchJarves = '/^(\\s*)' . preg_quote($newJarves) . '/m';
$result = preg_match($searchJarves, $content);
if (!$result) {
throw new \RuntimeException('Jarves bundle not found in AppKernel.');
}
$content = preg_replace($searchJarves, "\$1new " . $bundle . "(),\n\$1" . $newJarves, $content);
return !!file_put_contents($file, $content);
}