1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Sonata Project package. |
7
|
|
|
* |
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Sonata\DoctrineMongoDBAdminBundle\Guesser; |
15
|
|
|
|
16
|
|
|
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; |
17
|
|
|
use Doctrine\ODM\MongoDB\Types\Type; |
18
|
|
|
use Sonata\AdminBundle\Model\ModelManagerInterface; |
19
|
|
|
use Symfony\Component\Form\Guess\Guess; |
20
|
|
|
use Symfony\Component\Form\Guess\TypeGuess; |
21
|
|
|
|
22
|
|
|
class TypeGuesser extends AbstractTypeGuesser |
23
|
|
|
{ |
24
|
|
|
public function guessType($class, $property, ModelManagerInterface $modelManager) |
25
|
|
|
{ |
26
|
|
|
if (!$ret = $this->getParentMetadataForProperty($class, $property, $modelManager)) { |
27
|
|
|
return new TypeGuess('text', [], Guess::LOW_CONFIDENCE); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
[$metadata, $propertyName, $parentAssociationMappings] = $ret; |
31
|
|
|
|
32
|
|
|
if ($metadata->hasAssociation($propertyName)) { |
33
|
|
|
$mapping = $metadata->fieldMappings[$propertyName]; |
|
|
|
|
34
|
|
|
|
35
|
|
|
switch ($mapping['type']) { |
36
|
|
|
case ClassMetadata::ONE: |
37
|
|
|
return new TypeGuess('mongo_one', [], Guess::HIGH_CONFIDENCE); |
38
|
|
|
|
39
|
|
|
case ClassMetadata::MANY: |
40
|
|
|
return new TypeGuess('mongo_many', [], Guess::HIGH_CONFIDENCE); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
switch ($metadata->getTypeOfField($propertyName)) { |
45
|
|
|
case Type::COLLECTION: |
46
|
|
|
case Type::HASH: |
47
|
|
|
return new TypeGuess('array', [], Guess::HIGH_CONFIDENCE); |
48
|
|
|
case 'array': |
49
|
|
|
@trigger_error( |
50
|
|
|
'The array type is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x, to be removed in 4.0.'. |
51
|
|
|
E_USER_DEPRECATED |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
return new TypeGuess('array', [], Guess::HIGH_CONFIDENCE); |
55
|
|
|
case Type::BOOL: |
56
|
|
|
case Type::BOOLEAN: |
57
|
|
|
return new TypeGuess('boolean', [], Guess::HIGH_CONFIDENCE); |
58
|
|
|
case 'datetime': |
59
|
|
|
@trigger_error( |
60
|
|
|
'The datetime type is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x, to be removed in 4.0.'. |
61
|
|
|
E_USER_DEPRECATED |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
return new TypeGuess('datetime', [], Guess::HIGH_CONFIDENCE); |
65
|
|
|
case 'vardatetime': |
66
|
|
|
@trigger_error( |
67
|
|
|
'The vardatetime type is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x, to be removed in 4.0.'. |
68
|
|
|
E_USER_DEPRECATED |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
return new TypeGuess('datetime', [], Guess::HIGH_CONFIDENCE); |
72
|
|
|
case 'datetimetz': |
73
|
|
|
@trigger_error( |
74
|
|
|
'The datetimetz type is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x, to be removed in 4.0.'. |
75
|
|
|
E_USER_DEPRECATED |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
return new TypeGuess('datetime', [], Guess::HIGH_CONFIDENCE); |
79
|
|
|
case Type::TIMESTAMP: |
80
|
|
|
return new TypeGuess('datetime', [], Guess::HIGH_CONFIDENCE); |
81
|
|
|
case Type::DATE: |
82
|
|
|
// NEXT_MAJOR: Use only the constant when dropping support for doctrine/mongodb-odm 1.3. |
83
|
|
|
// case Type::DATE_IMMUTABLE: |
84
|
|
|
case 'date_immutable': |
85
|
|
|
return new TypeGuess('date', [], Guess::HIGH_CONFIDENCE); |
86
|
|
|
case 'decimal': |
87
|
|
|
@trigger_error( |
88
|
|
|
'The decimal type is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x, to be removed in 4.0.'. |
89
|
|
|
E_USER_DEPRECATED |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
return new TypeGuess('number', [], Guess::MEDIUM_CONFIDENCE); |
93
|
|
|
case Type::FLOAT: |
94
|
|
|
return new TypeGuess('number', [], Guess::MEDIUM_CONFIDENCE); |
95
|
|
|
case Type::INTEGER: |
96
|
|
|
case Type::INT: |
97
|
|
|
return new TypeGuess('integer', [], Guess::MEDIUM_CONFIDENCE); |
98
|
|
|
case 'bigint': |
99
|
|
|
@trigger_error( |
100
|
|
|
'The bigint type is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x, to be removed in 4.0.'. |
101
|
|
|
E_USER_DEPRECATED |
102
|
|
|
); |
103
|
|
|
|
104
|
|
|
return new TypeGuess('integer', [], Guess::MEDIUM_CONFIDENCE); |
105
|
|
|
case 'smallint': |
106
|
|
|
@trigger_error( |
107
|
|
|
'The smallint type is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x, to be removed in 4.0.'. |
108
|
|
|
E_USER_DEPRECATED |
109
|
|
|
); |
110
|
|
|
|
111
|
|
|
return new TypeGuess('integer', [], Guess::MEDIUM_CONFIDENCE); |
112
|
|
|
case Type::STRING: |
113
|
|
|
return new TypeGuess('text', [], Guess::MEDIUM_CONFIDENCE); |
114
|
|
|
case 'text': |
115
|
|
|
@trigger_error( |
116
|
|
|
'The text type is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x, to be removed in 4.0.'. |
117
|
|
|
E_USER_DEPRECATED |
118
|
|
|
); |
119
|
|
|
|
120
|
|
|
return new TypeGuess('textarea', [], Guess::MEDIUM_CONFIDENCE); |
121
|
|
|
case 'time': |
122
|
|
|
@trigger_error( |
123
|
|
|
'The time type is deprecated since sonata-project/doctrine-mongodb-admin-bundle 3.x, to be removed in 4.0.'. |
124
|
|
|
E_USER_DEPRECATED |
125
|
|
|
); |
126
|
|
|
|
127
|
|
|
return new TypeGuess('time', [], Guess::HIGH_CONFIDENCE); |
128
|
|
|
default: |
129
|
|
|
return new TypeGuess('text', [], Guess::LOW_CONFIDENCE); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.
The variable may have been renamed without also renaming all references.