Skip to content

Commit 29e37aa

Browse files
committed
bug #8 Generate a different controller when Twig is not installed (javiereguiluz)
This PR was squashed before being merged into the 1.0-dev branch (closes #8). Discussion ---------- Generate a different controller when Twig is not installed It fixes #6 and replaces #7. Commits ------- eb8da45 Generate a different controller when Twig is not installed
2 parents dafab61 + eb8da45 commit 29e37aa

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/Command/MakeControllerCommand.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111

1212
namespace Symfony\Bundle\MakerBundle\Command;
1313

14+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
1415
use Symfony\Bundle\MakerBundle\ConsoleStyle;
1516
use Symfony\Bundle\MakerBundle\DependencyBuilder;
1617
use Symfony\Bundle\MakerBundle\Generator;
1718
use Symfony\Bundle\MakerBundle\Str;
1819
use Symfony\Bundle\MakerBundle\Validator;
20+
use Symfony\Bundle\TwigBundle\TwigBundle;
1921
use Symfony\Component\Console\Input\InputArgument;
2022
use Symfony\Component\Routing\RouterInterface;
21-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
2223

2324
/**
2425
* @author Javier Eguiluz <[email protected]>
@@ -60,8 +61,10 @@ protected function getParameters(): array
6061

6162
protected function getFiles(array $params): array
6263
{
64+
$skeletonFile = $this->isTwigInstalled() ? 'ControllerWithTwig.php.txt' : 'Controller.php.txt';
65+
6366
return [
64-
__DIR__.'/../Resources/skeleton/controller/Controller.php.txt' => 'src/Controller/'.$params['controller_class_name'].'.php'
67+
__DIR__.'/../Resources/skeleton/controller/'.$skeletonFile => 'src/Controller/'.$params['controller_class_name'].'.php'
6568
];
6669
}
6770

@@ -87,4 +90,9 @@ protected function configureDependencies(DependencyBuilder $dependencies)
8790
'annotations'
8891
);
8992
}
93+
94+
private function isTwigInstalled()
95+
{
96+
return class_exists(TwigBundle::class);
97+
}
9098
}

src/Resources/skeleton/controller/Controller.php.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class {{ controller_class_name }} extends Controller
1313
*/
1414
public function index()
1515
{
16-
// replace this line with your own code!
17-
return $this->render('@Maker/demoPage.html.twig', [ 'path' => str_replace($this->getParameter('kernel.project_dir').'/', '', __FILE__) ]);
16+
return new Response('Welcome to your new controller!');
1817
}
1918
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Controller;
4+
5+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7+
use Symfony\Component\HttpFoundation\Response;
8+
9+
class {{ controller_class_name }} extends Controller
10+
{
11+
/**
12+
* @Route("{{ route_path }}", name="{{ route_name }}")
13+
*/
14+
public function index()
15+
{
16+
// replace this line with your own code!
17+
return $this->render('@Maker/demoPage.html.twig', [ 'path' => str_replace($this->getParameter('kernel.project_dir').'/', '', __FILE__) ]);
18+
}
19+
}

0 commit comments

Comments
 (0)