} catch (IOException e) {
e.printStackTrace();
return;
}
final PsiFileFactory factory = PsiFileFactory.getInstance(project);
String bundleName = "Acme\\DemoBundle";
SymfonyBundleUtil symfonyBundleUtil = new SymfonyBundleUtil(project);
SymfonyBundle symfonyBundle = symfonyBundleUtil.getContainingBundle(initialBaseDir);
if(symfonyBundle != null) {
bundleName = StringUtils.strip(symfonyBundle.getNamespaceName(), "\\");
String path = symfonyBundle.getRelative(initialBaseDir.getVirtualFile());
if(path != null) {
bundleName = bundleName.concat("\\" + path);
}
}
content = content.replace("{{ Namespace }}", bundleName).replace("{{ ControllerName }}", fileName);
fileName = fileName.concat("Controller.php");
if(initialBaseDir.findFile(fileName) != null) {
Messages.showInfoMessage("File exists", "Error");
return;
}
final PsiFile file = factory.createFileFromText(fileName, PhpFileType.INSTANCE, content);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
CodeStyleManager.getInstance(project).reformat(file);