-
Notifications
You must be signed in to change notification settings - Fork 9
/
MandangoTypeGuesser.php
107 lines (94 loc) · 2.99 KB
/
MandangoTypeGuesser.php
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/*
* This file is part of Mandango.
*
* (c) Pablo Díez <pablodip@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Mandango\MandangoBundle\Form;
use Symfony\Component\Form\FormTypeGuesserInterface;
use Symfony\Component\Form\Guess\Guess;
use Symfony\Component\Form\Guess\TypeGuess;
use Mandango\MetadataFactory;
/**
* MandangoTypeGuesser
*
* @author Pablo Díez <pablodip@gmail.com>
*/
class MandangoTypeGuesser implements FormTypeGuesserInterface
{
private $metadataFactory;
/**
* Constructor.
*
* @param Mandango\MetadataFactory $metadata The Mandango's metadata.
*/
public function __construct(MetadataFactory $metadataFactory)
{
$this->metadataFactory = $metadataFactory;
}
/**
* @inheritDoc
*/
public function guessType($class, $property)
{
if (!$this->metadataFactory->hasClass($class)) {
return;
}
$metadata = $this->metadataFactory->getClass($class);
// field
if (isset($metadata['fields'][$property])) {
switch ($metadata['fields'][$property]['type']) {
case 'bin_data':
return new TypeGuess('file', array(), Guess::MEDIUM_CONFIDENCE);
case 'boolean':
return new TypeGuess('checkbox', array(), Guess::HIGH_CONFIDENCE);
case 'date':
return new TypeGuess('date', array(), Guess::MEDIUM_CONFIDENCE);
case 'float':
return new TypeGuess('number', array(), Guess::MEDIUM_CONFIDENCE);
case 'integer':
return new TypeGuess('integer', array(), Guess::MEDIUM_CONFIDENCE);
case 'raw':
return new TypeGuess('text', array(), Guess::MEDIUM_CONFIDENCE);
case 'serialized':
return new TypeGuess('text', array(), Guess::MEDIUM_CONFIDENCE);
case 'string':
return new TypeGuess('text', array(), Guess::MEDIUM_CONFIDENCE);
}
}
// referencesOne
if (isset($metadata['referencesOne'][$property])) {
return new TypeGuess('mandango_document', array(
'class' => $metadata['referencesOne'][$property]['class'],
), Guess::HIGH_CONFIDENCE);
}
// referencesMany
if (isset($metadata['referencesMany'][$property])) {
return new TypeGuess('mandango_document', array(
'class' => $metadata['referencesMany'][$property]['class'],
'multiple' => true,
), Guess::HIGH_CONFIDENCE);
}
}
/**
* @inheritDoc
*/
public function guessRequired($class, $property)
{
}
/**
* @inheritDoc
*/
public function guessMaxLength($class, $property)
{
}
/**
* @inheritDoc
*/
public function guessMinLength($class, $property)
{
}
}