@@ -102,13 +102,13 @@ snippet adds CSRF protection to the form factory::
102
102
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider;
103
103
use Symfony\Component\HttpFoundation\Session\Session;
104
104
105
- // generate a CSRF secret, which you *may* want to set as a constant
106
- define('CSRF_SECRET', '<generated token>') ;
105
+ // generate a CSRF secret from somewhere
106
+ $csrfSecret = '<generated token>';
107
107
108
108
// create a Session object from the HttpFoundation component
109
109
$session = new Session();
110
110
111
- $csrfProvider = new SessionCsrfProvider($session, CSRF_SECRET );
111
+ $csrfProvider = new SessionCsrfProvider($session, $csrfSecret );
112
112
113
113
$formFactory = Forms::createFormFactoryBuilder()
114
114
// ...
@@ -132,7 +132,7 @@ and validated when binding the form.
132
132
133
133
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\DefaultCsrfProvider;
134
134
135
- $csrfProvider = new DefaultCsrfProvider(CSRF_SECRET );
135
+ $csrfProvider = new DefaultCsrfProvider($csrfSecret );
136
136
137
137
Twig Templating
138
138
~~~~~~~~~~~~~~~
@@ -167,19 +167,19 @@ to bootstrap or access Twig and add the :class:`Symfony\\Bridge\\Twig\\Extension
167
167
168
168
// the Twig file that holds all the default markup for rendering forms
169
169
// this file comes with TwigBridge
170
- define('DEFAULT_FORM_THEME', 'form_div_layout.html.twig') ;
170
+ $defaultFormTheme = 'form_div_layout.html.twig';
171
171
172
- define('VENDOR_DIR', realpath(__DIR__ . '/../vendor') );
172
+ $vendorDir = realpath(__DIR__ . '/../vendor');
173
173
// the path to TwigBridge so Twig can locate the form_div_layout.html.twig file
174
- define('VENDOR_TWIG_BRIDGE_DIR', VENDOR_DIR . '/symfony/twig-bridge/Symfony/Bridge/Twig') ;
174
+ $vendorTwigBridgeDir = $vendorDir . '/symfony/twig-bridge/Symfony/Bridge/Twig';
175
175
// the path to your other templates
176
- define('VIEWS_DIR', realpath(__DIR__ . '/../views') );
176
+ $viewsDir = realpath(__DIR__ . '/../views');
177
177
178
178
$twig = new Twig_Environment(new Twig_Loader_Filesystem(array(
179
- VIEWS_DIR ,
180
- VENDOR_TWIG_BRIDGE_DIR . '/Resources/views/Form',
179
+ $viewsDir ,
180
+ $vendorTwigBridgeDir . '/Resources/views/Form',
181
181
)));
182
- $formEngine = new TwigRendererEngine(array(DEFAULT_FORM_THEME ));
182
+ $formEngine = new TwigRendererEngine(array($defaultFormTheme ));
183
183
$formEngine->setEnvironment($twig);
184
184
// add the FormExtension to Twig
185
185
$twig->addExtension(new FormExtension(new TwigRenderer($formEngine, $csrfProvider)));
@@ -294,23 +294,23 @@ Your integration with the Validation component will look something like this::
294
294
use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
295
295
use Symfony\Component\Validator\Validation;
296
296
297
- define('VENDOR_DIR', realpath(__DIR__ . '/../vendor') );
298
- define('VENDOR_FORM_DIR', VENDOR_DIR . '/symfony/form/Symfony/Component/Form') ;
299
- define('VENDOR_VALIDATOR_DIR', VENDOR_DIR . '/symfony/validator/Symfony/Component/Validator') ;
297
+ $vendorDir = realpath(__DIR__ . '/../vendor');
298
+ $vendorFormDir = $vendorDir . '/symfony/form/Symfony/Component/Form';
299
+ $vendorValidatorDir = $vendorDir . '/symfony/validator/Symfony/Component/Validator';
300
300
301
301
// create the validator - details will vary
302
302
$validator = Validation::createValidator();
303
303
304
304
// there are built-in translations for the core error messages
305
305
$translator->addResource(
306
306
'xlf',
307
- VENDOR_FORM_DIR . '/Resources/translations/validators.en.xlf',
307
+ $vendorFormDir . '/Resources/translations/validators.en.xlf',
308
308
'en',
309
309
'validators'
310
310
);
311
311
$translator->addResource(
312
312
'xlf',
313
- VENDOR_VALIDATOR_DIR . '/Resources/translations/validators.en.xlf',
313
+ $vendorValidatorDir . '/Resources/translations/validators.en.xlf',
314
314
'en',
315
315
'validators'
316
316
);
0 commit comments