]> git.immae.eu Git - github/wallabag/wallabag.git/blame - vendor/symfony/form/Symfony/Component/Form/Forms.php
gitignore vendor
[github/wallabag/wallabag.git] / vendor / symfony / form / Symfony / Component / Form / Forms.php
CommitLineData
4f5b44bd
NL
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
12namespace Symfony\Component\Form;
13
14use Symfony\Component\Form\Extension\Core\CoreExtension;
15
16/**
17 * Entry point of the Form component.
18 *
19 * Use this class to conveniently create new form factories:
20 *
21 * <code>
22 * use Symfony\Component\Form\Forms;
23 *
24 * $formFactory = Forms::createFormFactory();
25 *
26 * $form = $formFactory->createBuilder()
27 * ->add('firstName', 'text')
28 * ->add('lastName', 'text')
29 * ->add('age', 'integer')
30 * ->add('gender', 'choice', array(
31 * 'choices' => array('m' => 'Male', 'f' => 'Female'),
32 * ))
33 * ->getForm();
34 * </code>
35 *
36 * You can also add custom extensions to the form factory:
37 *
38 * <code>
39 * $formFactory = Forms::createFormFactoryBuilder()
40 * ->addExtension(new AcmeExtension())
41 * ->getFormFactory();
42 * </code>
43 *
44 * If you create custom form types or type extensions, it is
45 * generally recommended to create your own extensions that lazily
46 * load these types and type extensions. In projects where performance
47 * does not matter that much, you can also pass them directly to the
48 * form factory:
49 *
50 * <code>
51 * $formFactory = Forms::createFormFactoryBuilder()
52 * ->addType(new PersonType())
53 * ->addType(new PhoneNumberType())
54 * ->addTypeExtension(new FormTypeHelpTextExtension())
55 * ->getFormFactory();
56 * </code>
57 *
58 * Support for CSRF protection is provided by the CsrfExtension.
59 * This extension needs a CSRF provider with a strong secret
60 * (e.g. a 20 character long random string). The default
61 * implementation for this is DefaultCsrfProvider:
62 *
63 * <code>
64 * use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
65 * use Symfony\Component\Form\Extension\Csrf\CsrfProvider\DefaultCsrfProvider;
66 *
67 * $secret = 'V8a5Z97e...';
68 * $formFactory = Forms::createFormFactoryBuilder()
69 * ->addExtension(new CsrfExtension(new DefaultCsrfProvider($secret)))
70 * ->getFormFactory();
71 * </code>
72 *
73 * Support for the HttpFoundation is provided by the
74 * HttpFoundationExtension. You are also advised to load the CSRF
75 * extension with the driver for HttpFoundation's Session class:
76 *
77 * <code>
78 * use Symfony\Component\HttpFoundation\Session\Session;
79 * use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension;
80 * use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
81 * use Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider;
82 *
83 * $session = new Session();
84 * $secret = 'V8a5Z97e...';
85 * $formFactory = Forms::createFormFactoryBuilder()
86 * ->addExtension(new HttpFoundationExtension())
87 * ->addExtension(new CsrfExtension(new SessionCsrfProvider($session, $secret)))
88 * ->getFormFactory();
89 * </code>
90 *
91 * Support for the Validator component is provided by ValidatorExtension.
92 * This extension needs a validator object to function properly:
93 *
94 * <code>
95 * use Symfony\Component\Validator\Validation;
96 * use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
97 *
98 * $validator = Validation::createValidator();
99 * $formFactory = Forms::createFormFactoryBuilder()
100 * ->addExtension(new ValidatorExtension($validator))
101 * ->getFormFactory();
102 * </code>
103 *
104 * Support for the Templating component is provided by TemplatingExtension.
105 * This extension needs a PhpEngine object for rendering forms. As second
106 * argument you should pass the names of the default themes. Here is an
107 * example for using the default layout with "<div>" tags:
108 *
109 * <code>
110 * use Symfony\Component\Form\Extension\Templating\TemplatingExtension;
111 *
112 * $formFactory = Forms::createFormFactoryBuilder()
113 * ->addExtension(new TemplatingExtension($engine, null, array(
114 * 'FrameworkBundle:Form',
115 * )))
116 * ->getFormFactory();
117 * </code>
118 *
119 * The next example shows how to include the "<table>" layout:
120 *
121 * <code>
122 * use Symfony\Component\Form\Extension\Templating\TemplatingExtension;
123 *
124 * $formFactory = Forms::createFormFactoryBuilder()
125 * ->addExtension(new TemplatingExtension($engine, null, array(
126 * 'FrameworkBundle:Form',
127 * 'FrameworkBundle:FormTable',
128 * )))
129 * ->getFormFactory();
130 * </code>
131 *
132 * If you also loaded the CsrfExtension, you should pass the CSRF provider
133 * to the extension so that you can render CSRF tokens in your templates
134 * more easily:
135 *
136 * <code>
137 * use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
138 * use Symfony\Component\Form\Extension\Csrf\CsrfProvider\DefaultCsrfProvider;
139 * use Symfony\Component\Form\Extension\Templating\TemplatingExtension;
140 *
141 *
142 * $secret = 'V8a5Z97e...';
143 * $csrfProvider = new DefaultCsrfProvider($secret);
144 * $formFactory = Forms::createFormFactoryBuilder()
145 * ->addExtension(new CsrfExtension($csrfProvider))
146 * ->addExtension(new TemplatingExtension($engine, $csrfProvider, array(
147 * 'FrameworkBundle:Form',
148 * )))
149 * ->getFormFactory();
150 * </code>
151 *
152 * @author Bernhard Schussek <bschussek@gmail.com>
153 */
154final class Forms
155{
156 /**
157 * Creates a form factory with the default configuration.
158 *
159 * @return FormFactoryInterface The form factory.
160 */
161 public static function createFormFactory()
162 {
163 return self::createFormFactoryBuilder()->getFormFactory();
164 }
165
166 /**
167 * Creates a form factory builder with the default configuration.
168 *
169 * @return FormFactoryBuilderInterface The form factory builder.
170 */
171 public static function createFormFactoryBuilder()
172 {
173 $builder = new FormFactoryBuilder();
174 $builder->addExtension(new CoreExtension());
175
176 return $builder;
177 }
178
179 /**
180 * This class cannot be instantiated.
181 */
182 private function __construct()
183 {
184 }
185}