@@ -102,13 +102,13 @@ snippet adds CSRF protection to the form factory::
102102 use Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider;
103103 use Symfony\Component\HttpFoundation\Session\Session;
104104
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>';
107107
108108 // create a Session object from the HttpFoundation component
109109 $session = new Session();
110110
111- $csrfProvider = new SessionCsrfProvider($session, CSRF_SECRET );
111+ $csrfProvider = new SessionCsrfProvider($session, $csrfSecret );
112112
113113 $formFactory = Forms::createFormFactoryBuilder()
114114 // ...
@@ -132,7 +132,7 @@ and validated when binding the form.
132132
133133 use Symfony\Component\Form\Extension\Csrf\CsrfProvider\DefaultCsrfProvider;
134134
135- $csrfProvider = new DefaultCsrfProvider(CSRF_SECRET );
135+ $csrfProvider = new DefaultCsrfProvider($csrfSecret );
136136
137137Twig Templating
138138~~~~~~~~~~~~~~~
@@ -167,19 +167,19 @@ to bootstrap or access Twig and add the :class:`Symfony\\Bridge\\Twig\\Extension
167167
168168 // the Twig file that holds all the default markup for rendering forms
169169 // this file comes with TwigBridge
170- define('DEFAULT_FORM_THEME', 'form_div_layout.html.twig') ;
170+ $defaultFormTheme = 'form_div_layout.html.twig';
171171
172- define('VENDOR_DIR', realpath(__DIR__ . '/../vendor') );
172+ $vendorDir = realpath(__DIR__ . '/../vendor');
173173 // 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';
175175 // the path to your other templates
176- define('VIEWS_DIR', realpath(__DIR__ . '/../views') );
176+ $viewsDir = realpath(__DIR__ . '/../views');
177177
178178 $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',
181181 )));
182- $formEngine = new TwigRendererEngine(array(DEFAULT_FORM_THEME ));
182+ $formEngine = new TwigRendererEngine(array($defaultFormTheme ));
183183 $formEngine->setEnvironment($twig);
184184 // add the FormExtension to Twig
185185 $twig->addExtension(new FormExtension(new TwigRenderer($formEngine, $csrfProvider)));
@@ -294,23 +294,23 @@ Your integration with the Validation component will look something like this::
294294 use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
295295 use Symfony\Component\Validator\Validation;
296296
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';
300300
301301 // create the validator - details will vary
302302 $validator = Validation::createValidator();
303303
304304 // there are built-in translations for the core error messages
305305 $translator->addResource(
306306 'xlf',
307- VENDOR_FORM_DIR . '/Resources/translations/validators.en.xlf',
307+ $vendorFormDir . '/Resources/translations/validators.en.xlf',
308308 'en',
309309 'validators'
310310 );
311311 $translator->addResource(
312312 'xlf',
313- VENDOR_VALIDATOR_DIR . '/Resources/translations/validators.en.xlf',
313+ $vendorValidatorDir . '/Resources/translations/validators.en.xlf',
314314 'en',
315315 'validators'
316316 );
0 commit comments