4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form
;
15 * The default implementation of FormFactoryBuilderInterface.
17 * @author Bernhard Schussek <bschussek@gmail.com>
19 class FormFactoryBuilder
implements FormFactoryBuilderInterface
22 * @var ResolvedFormTypeFactoryInterface
24 private $resolvedTypeFactory;
29 private $extensions = array();
34 private $types = array();
39 private $typeExtensions = array();
44 private $typeGuessers = array();
49 public function setResolvedTypeFactory(ResolvedFormTypeFactoryInterface
$resolvedTypeFactory)
51 $this->resolvedTypeFactory
= $resolvedTypeFactory;
59 public function addExtension(FormExtensionInterface
$extension)
61 $this->extensions
[] = $extension;
69 public function addExtensions(array $extensions)
71 $this->extensions
= array_merge($this->extensions
, $extensions);
79 public function addType(FormTypeInterface
$type)
81 $this->types
[$type->getName()] = $type;
89 public function addTypes(array $types)
91 foreach ($types as $type) {
92 $this->types
[$type->getName()] = $type;
101 public function addTypeExtension(FormTypeExtensionInterface
$typeExtension)
103 $this->typeExtensions
[$typeExtension->getExtendedType()][] = $typeExtension;
111 public function addTypeExtensions(array $typeExtensions)
113 foreach ($typeExtensions as $typeExtension) {
114 $this->typeExtensions
[$typeExtension->getExtendedType()][] = $typeExtension;
123 public function addTypeGuesser(FormTypeGuesserInterface
$typeGuesser)
125 $this->typeGuessers
[] = $typeGuesser;
133 public function addTypeGuessers(array $typeGuessers)
135 $this->typeGuessers
= array_merge($this->typeGuessers
, $typeGuessers);
143 public function getFormFactory()
145 $extensions = $this->extensions
;
147 if (count($this->types
) > 0 || count($this->typeExtensions
) > 0 || count($this->typeGuessers
) > 0) {
148 if (count($this->typeGuessers
) > 1) {
149 $typeGuesser = new FormTypeGuesserChain($this->typeGuessers
);
151 $typeGuesser = isset($this->typeGuessers
[0]) ? $this->typeGuessers
[0] : null;
154 $extensions[] = new PreloadedExtension($this->types
, $this->typeExtensions
, $typeGuesser);
157 $resolvedTypeFactory = $this->resolvedTypeFactory
?: new ResolvedFormTypeFactory();
158 $registry = new FormRegistry($extensions, $resolvedTypeFactory);
160 return new FormFactory($registry, $resolvedTypeFactory);