|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the ONGR package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) NFQ Technologies UAB <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace ONGR\ElasticsearchBundle\Generator; |
|
13
|
|
|
|
|
14
|
|
|
use Doctrine\ORM\Mapping\ClassMetadataInfo; |
|
15
|
|
|
use Doctrine\ORM\Tools\EntityGenerator; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Document Generator |
|
19
|
|
|
*/ |
|
20
|
|
|
class DocumentGenerator extends EntityGenerator |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
private $documentType; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected static $setMethodTemplate = |
|
31
|
|
|
'/** |
|
32
|
|
|
* <description> |
|
33
|
|
|
* |
|
34
|
|
|
* @param <variableType> $<variableName> |
|
35
|
|
|
*/ |
|
36
|
|
|
public function <methodName>(<methodTypeHint>$<variableName><variableDefault>) |
|
37
|
|
|
{ |
|
38
|
|
|
<spaces>$this-><fieldName> = $<variableName>; |
|
39
|
|
|
}'; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* {@inheritdoc} |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function generateEntityUse() |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->generateAnnotations ? ("\n" . 'use ONGR\ElasticsearchBundle\Annotation as ES;' . "\n") : ''; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
|
|
protected function generateEntityDocBlock(ClassMetadataInfo $metadata) |
|
53
|
|
|
{ |
|
54
|
|
|
$lines = []; |
|
55
|
|
|
$lines[] = '/**'; |
|
56
|
|
|
$lines[] = ' * ' . $this->getClassName($metadata); |
|
57
|
|
|
|
|
58
|
|
|
if ($this->generateAnnotations) { |
|
59
|
|
|
$lines[] = ' *'; |
|
60
|
|
|
|
|
61
|
|
|
$lines[] = sprintf( |
|
62
|
|
|
' * @%sDocument(%s)', |
|
63
|
|
|
$this->annotationsPrefix, |
|
64
|
|
|
$this->documentType != lcfirst($this->getClassName($metadata)) |
|
65
|
|
|
? sprintf('type="%s"', $this->documentType) : '' |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$lines[] = ' */'; |
|
70
|
|
|
|
|
71
|
|
|
return implode("\n", $lines); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* {@inheritdoc} |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, ClassMetadataInfo $metadata) |
|
78
|
|
|
{ |
|
79
|
|
|
$lines = []; |
|
80
|
|
|
$lines[] = $this->spaces . '/**'; |
|
81
|
|
|
$lines[] = $this->spaces . ' * @var ' . $this->getType($fieldMapping['type']); |
|
82
|
|
|
|
|
83
|
|
|
if ($this->generateAnnotations) { |
|
84
|
|
|
$lines[] = $this->spaces . ' *'; |
|
85
|
|
|
|
|
86
|
|
|
$column = []; |
|
87
|
|
|
if (isset($fieldMapping['property_name']) && $fieldMapping['property_name'] != $fieldMapping['fieldName']) { |
|
88
|
|
|
$column[] = 'name="' . $fieldMapping['property_name'] . '"'; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if (isset($fieldMapping['property_type'])) { |
|
92
|
|
|
$column[] = 'type="' . $fieldMapping['property_type'] . '"'; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
if (isset($fieldMapping['property_options']) && $fieldMapping['property_options']) { |
|
96
|
|
|
$column[] = 'options={' . $fieldMapping['property_options'] . '}'; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
$lines[] = $this->spaces . ' * @' . $this->annotationsPrefix . $fieldMapping['annotation'] . '(' |
|
100
|
|
|
. implode(', ', $column) . ')'; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$lines[] = $this->spaces . ' */'; |
|
104
|
|
|
|
|
105
|
|
|
return implode("\n", $lines); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Sets document type |
|
110
|
|
|
* |
|
111
|
|
|
* @param string $documentType |
|
112
|
|
|
* |
|
113
|
|
|
* @return DocumentGenerator |
|
114
|
|
|
*/ |
|
115
|
|
|
public function setDocumentType($documentType) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->documentType = $documentType; |
|
118
|
|
|
|
|
119
|
|
|
return $this; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|