forked from lostedboy/symfony-form-standalone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormBuilder.php
81 lines (70 loc) · 1.99 KB
/
FormBuilder.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
<?php
/*
* This file is part of the SymfonyFormStandalone package.
*
* (c) Alexander Egurtsov <https://github.com/lostedboy/symfony-form-standalone/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Form\Standalone;
use Symfony\Component\Form\FormExtensionInterface;
use Symfony\Component\Form\FormTypeExtensionInterface;
use Symfony\Component\Form\Forms;
/**
* Class FormTemplating
*
* @author Alexander Egurtsov <[email protected]>
*/
class FormBuilder
{
/**
* @var \Symfony\Component\Form\FormFactoryBuilderInterface
*/
protected $formFactoryBuilder;
/**
* @param $className
* @param null $data
* @param array $options
* @return \Symfony\Component\Form\FormInterface
*/
public function create($className, $data = null, $options = [])
{
return $this->getFormFactory()->create($className, $data, $options);
}
/**
* @return \Symfony\Component\Form\FormFactoryInterface
*/
public function getFormFactory()
{
return $this->getFormFactoryBuilder()->getFormFactory();
}
/**
* @return \Symfony\Component\Form\FormFactoryBuilderInterface
*/
public function getFormFactoryBuilder()
{
if (!$this->formFactoryBuilder) {
$this->formFactoryBuilder = Forms::createFormFactoryBuilder();
}
return $this->formFactoryBuilder;
}
/**
* @param FormExtensionInterface $extension
* @return $this
*/
public function addExtension(FormExtensionInterface $extension)
{
$this->getFormFactoryBuilder()->addExtension($extension);
return $this;
}
/**
* @param FormTypeExtensionInterface $typeExtension
* @return $this
*/
public function addTypeExtension(FormTypeExtensionInterface $typeExtension)
{
$this->getFormFactoryBuilder()->addTypeExtension($typeExtension);
return $this;
}
}