1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Starkerxp\StructureBundle\Generator; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\HttpKernel\Bundle\Bundle; |
6
|
|
|
|
7
|
|
|
class EntiteGenerator extends AbstractGenerator |
8
|
|
|
{ |
9
|
|
View Code Duplication |
public function generate(Bundle $bundle, $libelle) |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
$parameters = $this->getParamaters($bundle, $libelle); |
12
|
|
|
$parameters['nomService'] = strtolower( |
13
|
|
|
str_replace(['_Bundle', '@'], '', preg_replace('#\B([A-Z])#', '_\1', $parameters['namespaceBundle'])) |
14
|
|
|
); |
15
|
|
|
foreach ($this->getFichiers() as $fichier) { |
16
|
|
|
try { |
17
|
|
|
$this->kernel->locateResource("@StarkerxpStructureBundle/Resources/views/Gabarit/".$fichier.".twig"); |
18
|
|
|
} catch (\InvalidArgumentException $e) { |
19
|
|
|
throw new \InvalidArgumentException('Il manque un fichier de template'); |
20
|
|
|
} |
21
|
|
|
$target = $bundle->getPath().str_replace($this->getClef(), [$libelle, lcfirst($libelle)], $fichier); |
22
|
|
|
$this->traiterLeFichier($fichier, $target, $parameters); |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
public function getParamaters(Bundle $bundle, $libelle) |
28
|
|
|
{ |
29
|
|
|
return array( |
30
|
|
|
'nomEntity' => $libelle, |
31
|
|
|
'namespace' => $bundle->getNamespace(), |
32
|
|
|
'namespaceBundle' => '@'.$bundle->getName(), |
33
|
|
|
'namespaceFQC' => str_replace('\\', '\\\\', $bundle->getNamespace()), |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getClef() |
38
|
|
|
{ |
39
|
|
|
return ['_nomEntity_', '_lnomEntity_']; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getFichiers() |
43
|
|
|
{ |
44
|
|
|
return [ |
45
|
|
|
'/Resources/config/managers.yml', |
46
|
|
|
'/Entity/_nomEntity_.php', |
47
|
|
|
'/Manager/_nomEntity_Manager.php', |
48
|
|
|
'/Repository/_nomEntity_Repository.php', |
49
|
|
|
'/Tests/Manager/_nomEntity_ManagerTest.php', |
50
|
|
|
'/Tests/DataFixtures/_nomEntity_Manager/_nomEntity_Manager.yml', |
51
|
|
|
'/Tests/DataFixtures/_nomEntity_Manager/Default_nomEntity_.yml', |
52
|
|
|
]; |
53
|
|
|
} |
54
|
|
|
} |
|
|
|
|
55
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.