1 | <?php |
||
29 | class TypeGuesser implements TypeGuesserInterface |
||
30 | { |
||
31 | /** |
||
32 | * @var ManagerRegistry |
||
33 | */ |
||
34 | protected $registry; |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | private $cache; |
||
40 | |||
41 | /** |
||
42 | * @param ManagerRegistry $registry |
||
43 | */ |
||
44 | public function __construct(ManagerRegistry $registry) |
||
45 | { |
||
46 | $this->registry = $registry; |
||
47 | $this->cache = array(); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * {@inheritDoc} |
||
52 | */ |
||
53 | public function guessType($class, $property, ModelManagerInterface $modelManager) |
||
54 | { |
||
55 | if (!$metadata = $this->getMetadata($class)) { |
||
56 | return new TypeGuess('text', array(), Guess::LOW_CONFIDENCE); |
||
57 | } |
||
58 | |||
59 | if ($metadata->hasAssociation($property)) { |
||
60 | $mapping = $metadata->mappings[$property]; |
||
61 | |||
62 | switch ($mapping['type']) { |
||
63 | case ClassMetadata::MANY_TO_MANY: |
||
64 | case 'referrers': |
||
65 | return new TypeGuess('doctrine_phpcr_many_to_many', array(), Guess::HIGH_CONFIDENCE); |
||
66 | |||
67 | case ClassMetadata::MANY_TO_ONE: |
||
68 | case 'parent': |
||
69 | return new TypeGuess('doctrine_phpcr_many_to_one', array(), Guess::HIGH_CONFIDENCE); |
||
70 | |||
71 | case 'children': |
||
72 | return new TypeGuess('doctrine_phpcr_one_to_many', array(), Guess::HIGH_CONFIDENCE); |
||
73 | |||
74 | case 'child': |
||
75 | return new TypeGuess('doctrine_phpcr_one_to_one', array(), Guess::HIGH_CONFIDENCE); |
||
76 | } |
||
77 | } |
||
78 | |||
79 | // TODO: missing multivalue support |
||
80 | switch ($metadata->getTypeOfField($property)) { |
||
81 | case 'boolean': |
||
82 | return new TypeGuess('boolean', array(), Guess::HIGH_CONFIDENCE); |
||
83 | case 'date': |
||
84 | return new TypeGuess('date', array(), Guess::HIGH_CONFIDENCE); |
||
85 | |||
86 | case 'decimal': |
||
87 | case 'double': |
||
88 | return new TypeGuess('number', array(), Guess::MEDIUM_CONFIDENCE); |
||
89 | case 'integer': |
||
90 | case 'long': |
||
91 | return new TypeGuess('integer', array(), Guess::MEDIUM_CONFIDENCE); |
||
92 | case 'string': |
||
93 | return new TypeGuess('string', array(), Guess::HIGH_CONFIDENCE); |
||
94 | case 'binary': |
||
95 | case 'uri': |
||
96 | return new TypeGuess('string', array(), Guess::MEDIUM_CONFIDENCE); |
||
97 | } |
||
98 | |||
99 | return new TypeGuess('text', array(), Guess::LOW_CONFIDENCE); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * @param string $class |
||
104 | * |
||
105 | * @return mixed |
||
106 | */ |
||
107 | protected function getMetadata($class) |
||
124 | } |
||
125 |