1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Starkerxp\StructureBundle\Generator; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\HttpKernel\Bundle\Bundle; |
6
|
|
|
|
7
|
|
|
class ControllerGenerator extends AbstractGenerator |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
View Code Duplication |
public function generate(Bundle $bundle, $libelle, Bundle $bundleEntite, $libelleEntite) |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
$parameters = $this->getParamaters($bundle, $libelle); |
13
|
|
|
$parameters['nomService'] = strtolower( |
14
|
|
|
str_replace(['_Bundle', '@'], '', preg_replace('#\B([A-Z])#', '_\1', $parameters['namespaceBundle'])) |
15
|
|
|
); |
16
|
|
|
foreach ($this->getFichiers() as $fichier) { |
17
|
|
|
try { |
18
|
|
|
$this->kernel->locateResource("@StarkerxpStructureBundle/Resources/views/Gabarit/".$fichier.".twig"); |
19
|
|
|
} catch (\InvalidArgumentException $e) { |
20
|
|
|
throw new \InvalidArgumentException('Il manque un fichier de template'); |
21
|
|
|
} |
22
|
|
|
$target = $bundle->getPath().str_replace($this->getClef(), [$libelle, lcfirst($libelle)], $fichier); |
23
|
|
|
$this->traiterLeFichier($fichier, $target, $parameters); |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function getParamaters(Bundle $bundle, $libelle) |
28
|
|
|
{ |
29
|
|
|
return array( |
30
|
|
|
'nomController' => $libelle, |
31
|
|
|
'nomControllerCamelize' => preg_replace('#\B([A-Z])#', '_\1', $libelle), |
32
|
|
|
'namespace' => $bundle->getNamespace(), |
33
|
|
|
'namespaceBundle' => '@'.$bundle->getName(), |
34
|
|
|
'namespaceFQC' => str_replace('\\', '\\\\', $bundle->getNamespace()), |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getClef() |
39
|
|
|
{ |
40
|
|
|
return ['_nomController_', '_lnomController_']; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function getFichiers() |
44
|
|
|
{ |
45
|
|
|
return [ |
46
|
|
|
'/Controller/_nomController_Controller.php', |
47
|
|
|
'/Tests/Controller/_nomController_ControllerTest.php', |
48
|
|
|
'/Form/Type/_nomController_Type.php', |
49
|
|
|
'/Resources/config/routing.yml', // Il faut récupérer la locale par défaut afin de générer le bon fichier. |
50
|
|
|
//'/Resources/translations/_lnomController_._defaultLocale_.yml', // Il faut récupérer la locale par défaut afin de générer le bon fichier. |
51
|
|
|
]; |
52
|
|
|
} |
53
|
|
|
} |
|
|
|
|
54
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.