Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 163 lines (132 sloc) 3.654 kB
bf274bb @webmozart [Form] Added entry point "Forms" for more convenient usage outside of…
webmozart authored
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
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 Symfony\Component\Form;
13
14 /**
15 * The default implementation of FormFactoryBuilderInterface.
16 *
17 * @author Bernhard Schussek <bschussek@gmail.com>
18 */
19 class FormFactoryBuilder implements FormFactoryBuilderInterface
20 {
21 /**
22 * @var ResolvedFormTypeFactoryInterface
23 */
24 private $resolvedTypeFactory;
25
26 /**
3645771 @stloyd [2.3][Form] Cleanup & fix phpdocs
stloyd authored
27 * @var FormExtensionInterface[]
bf274bb @webmozart [Form] Added entry point "Forms" for more convenient usage outside of…
webmozart authored
28 */
29 private $extensions = array();
30
31 /**
3645771 @stloyd [2.3][Form] Cleanup & fix phpdocs
stloyd authored
32 * @var FormTypeInterface[]
bf274bb @webmozart [Form] Added entry point "Forms" for more convenient usage outside of…
webmozart authored
33 */
34 private $types = array();
35
36 /**
3645771 @stloyd [2.3][Form] Cleanup & fix phpdocs
stloyd authored
37 * @var FormTypeExtensionInterface[]
bf274bb @webmozart [Form] Added entry point "Forms" for more convenient usage outside of…
webmozart authored
38 */
39 private $typeExtensions = array();
40
41 /**
3645771 @stloyd [2.3][Form] Cleanup & fix phpdocs
stloyd authored
42 * @var FormTypeGuesserInterface[]
bf274bb @webmozart [Form] Added entry point "Forms" for more convenient usage outside of…
webmozart authored
43 */
44 private $typeGuessers = array();
45
46 /**
47 * {@inheritdoc}
48 */
49 public function setResolvedTypeFactory(ResolvedFormTypeFactoryInterface $resolvedTypeFactory)
50 {
51 $this->resolvedTypeFactory = $resolvedTypeFactory;
52
53 return $this;
54 }
55
56 /**
57 * {@inheritdoc}
58 */
59 public function addExtension(FormExtensionInterface $extension)
60 {
61 $this->extensions[] = $extension;
62
63 return $this;
64 }
65
66 /**
67 * {@inheritdoc}
68 */
69 public function addExtensions(array $extensions)
70 {
71 $this->extensions = array_merge($this->extensions, $extensions);
72
73 return $this;
74 }
75
76 /**
77 * {@inheritdoc}
78 */
79 public function addType(FormTypeInterface $type)
80 {
3b14634 @webmozart [Form] Deprecated FormTypeInterface::getName() and passing of type in…
webmozart authored
81 $this->types[] = $type;
bf274bb @webmozart [Form] Added entry point "Forms" for more convenient usage outside of…
webmozart authored
82
83 return $this;
84 }
85
86 /**
87 * {@inheritdoc}
88 */
89 public function addTypes(array $types)
90 {
91 foreach ($types as $type) {
3b14634 @webmozart [Form] Deprecated FormTypeInterface::getName() and passing of type in…
webmozart authored
92 $this->types[] = $type;
bf274bb @webmozart [Form] Added entry point "Forms" for more convenient usage outside of…
webmozart authored
93 }
94
95 return $this;
96 }
97
98 /**
99 * {@inheritdoc}
100 */
101 public function addTypeExtension(FormTypeExtensionInterface $typeExtension)
102 {
103 $this->typeExtensions[$typeExtension->getExtendedType()][] = $typeExtension;
104
105 return $this;
106 }
107
108 /**
109 * {@inheritdoc}
110 */
111 public function addTypeExtensions(array $typeExtensions)
112 {
113 foreach ($typeExtensions as $typeExtension) {
114 $this->typeExtensions[$typeExtension->getExtendedType()][] = $typeExtension;
115 }
116
117 return $this;
118 }
119
120 /**
121 * {@inheritdoc}
122 */
123 public function addTypeGuesser(FormTypeGuesserInterface $typeGuesser)
124 {
125 $this->typeGuessers[] = $typeGuesser;
126
127 return $this;
128 }
129
130 /**
131 * {@inheritdoc}
132 */
133 public function addTypeGuessers(array $typeGuessers)
134 {
135 $this->typeGuessers = array_merge($this->typeGuessers, $typeGuessers);
136
137 return $this;
138 }
139
140 /**
141 * {@inheritdoc}
142 */
143 public function getFormFactory()
144 {
145 $extensions = $this->extensions;
146
147 if (count($this->types) > 0 || count($this->typeExtensions) > 0 || count($this->typeGuessers) > 0) {
189d01a @bamarni [Form] allowed no type guesser to be registered
bamarni authored
148 if (count($this->typeGuessers) > 1) {
149 $typeGuesser = new FormTypeGuesserChain($this->typeGuessers);
150 } else {
151 $typeGuesser = isset($this->typeGuessers[0]) ? $this->typeGuessers[0] : null;
152 }
bf274bb @webmozart [Form] Added entry point "Forms" for more convenient usage outside of…
webmozart authored
153
154 $extensions[] = new PreloadedExtension($this->types, $this->typeExtensions, $typeGuesser);
155 }
156
157 $resolvedTypeFactory = $this->resolvedTypeFactory ?: new ResolvedFormTypeFactory();
158 $registry = new FormRegistry($extensions, $resolvedTypeFactory);
159
160 return new FormFactory($registry, $resolvedTypeFactory);
161 }
162 }
Something went wrong with that request. Please try again.