-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTemplateService.php
More file actions
90 lines (78 loc) · 2.62 KB
/
TemplateService.php
File metadata and controls
90 lines (78 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
namespace Tbn\QueryBuilderRepositoryGeneratorBundle\Generator;
use Doctrine\ORM\Mapping\AssociationMapping;
use Doctrine\ORM\Mapping\ClassMetadata;
use Twig\Environment;
class TemplateService
{
public function __construct(
private $topRepositoryTemple,
private $columnTemplate,
private $bottomRepositoryTemplate,
private $associationTemplate,
private Environment $twig,
) {
}
public function renderTopClass(
string $extendClass,
string $namespace,
string $entityClasspath,
string $entityClassname,
?string $bundleName,
string $entityDql,
$idType,
): string {
$topClassparameter = array(
'namespace' => $namespace,
'entityClasspath' => $entityClasspath,
'entityClassname' => $entityClassname,
'extendClass' => $extendClass,
'bundleName' => $bundleName,
'entityDql' => $entityDql,
'idType' => $idType,
);
return $this->twig->render($this->topRepositoryTemple, $topClassparameter);
}
public function renderAssociation(
AssociationMapping $associationMapping,
string $entityDql,
ClassMetadata $targetEntityMetadata,
string $entityDqlTargeted,
string $entityClasspath,
): string {
$idType = null;
if (isset($targetEntityMetadata->fieldMappings['id'])) {
$idField = $targetEntityMetadata->fieldMappings['id'];
$idType = $idField['type'];
}
$fieldName = $associationMapping['fieldName'];
$parameters = array(
'entityDql' => $entityDql,
'column' => ucfirst($fieldName),
'columnDql' => $fieldName,
'idType' => $idType,
'targetEntity' => $associationMapping['targetEntity'],
'entityDqlTargeted' => $entityDqlTargeted,
'entityClasspath' => $entityClasspath,
);
return $this->twig->render($this->associationTemplate, $parameters);
}
public function renderField(
$fieldMapping,
$entityDql,
string $entityClasspath,
): string {
$fieldName = $fieldMapping['fieldName'];
$parameters = array(
'entityDql' => $entityDql,
'column' => ucfirst($fieldName),
'columnDql' => $fieldName,
'entityClasspath' => $entityClasspath,
);
return $this->twig->render($this->columnTemplate, $parameters);
}
public function renderBottomClass(): string
{
return $this->twig->render($this->bottomRepositoryTemplate);
}
}