Commit fbfa8e49 authored by Fabien Potencier's avatar Fabien Potencier

updated FormExtension to work with the latest Symfony version

parent e05cc948
...@@ -14,35 +14,38 @@ namespace Silex\Extension; ...@@ -14,35 +14,38 @@ namespace Silex\Extension;
use Silex\Application; use Silex\Application;
use Silex\ExtensionInterface; use Silex\ExtensionInterface;
use Symfony\Component\HttpFoundation\File\TemporaryStorage; use Symfony\Component\HttpFoundation\File\TemporaryStorage;
use Symfony\Component\Form\CsrfProvider\DefaultCsrfProvider; use Symfony\Component\Form\Extension\Csrf\CsrfProvider\DefaultCsrfProvider;
use Symfony\Component\Form\Type\Loader\DefaultTypeLoader;
use Symfony\Component\Form\FormFactory; use Symfony\Component\Form\FormFactory;
use Symfony\Component\Form\Extension\Core\CoreExtension;
use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
class FormExtension implements ExtensionInterface class FormExtension implements ExtensionInterface
{ {
public function register(Application $app) public function register(Application $app)
{ {
$app['form.csrf.secret'] = '12345'; $app['form.csrf_secret'] = '12345';
$app['form.storage.secret'] = 'abcdef'; $app['form.storage_secret'] = 'abcdef';
$app['form.factory'] = $app->share(function () use ($app) { $app['form.factory'] = $app->share(function () use ($app) {
return new FormFactory($app['form.type_loader']); $extensions = array(
}); new CoreExtension($app['form.storage']),
new CsrfExtension($app['form.csrf_provider']),
);
$app['form.type_loader'] = $app->share(function () use ($app) { if (isset($app['validator'])) {
if (!isset($app['validator'])) { $extensions[] = new ValidatorExtension($app['validator']);
throw new \RuntimeException(sprintf('The FormExtension needs the ValidationExtension to be registered.'));
} }
return new DefaultTypeLoader($app['validator'], $app['form.csrf.provider'], $app['form.storage']); return new FormFactory($extensions);
}); });
$app['form.csrf.provider'] = $app->share(function () use ($app) { $app['form.csrf_provider'] = $app->share(function () use ($app) {
return new DefaultCsrfProvider($app['form.csrf.secret']); return new DefaultCsrfProvider($app['form.csrf_secret']);
}); });
$app['form.storage'] = $app->share(function () use ($app) { $app['form.storage'] = $app->share(function () use ($app) {
return new TemporaryStorage($app['form.storage.secret']); return new TemporaryStorage($app['form.storage_secret']);
}); });
if (isset($app['form.class_path'])) { if (isset($app['form.class_path'])) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment