Add FormServiceProvider

This commit is contained in:
Romain Neutron
2013-03-05 15:37:48 +01:00
parent f17572097c
commit 937caa8da7

View File

@@ -106,6 +106,7 @@ use Neutron\Silex\Provider\FilesystemServiceProvider;
use Neutron\ReCaptcha\ReCaptchaServiceProvider;
use PHPExiftool\PHPExiftoolServiceProvider;
use Silex\Application as SilexApplication;
use Silex\Provider\FormServiceProvider;
use Silex\Provider\MonologServiceProvider;
use Silex\Provider\SessionServiceProvider;
use Silex\Provider\TwigServiceProvider;
@@ -129,6 +130,11 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\Form\FormTypeInterface;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\Exception\FormException;
class Application extends SilexApplication
{
@@ -257,6 +263,7 @@ class Application extends SilexApplication
'cache' => realpath(__DIR__ . '/../../../../../../tmp/cache_twig/'),
)
));
$this->register(new FormServiceProvider());
$this->setupTwig();
$this->register(new UnoconvServiceProvider());
@@ -386,6 +393,25 @@ class Application extends SilexApplication
};
}
/**
* Returns a form.
*
* @see FormFactory::create()
*
* @param string|FormTypeInterface $type The type of the form
* @param mixed $data The initial data
* @param array $options The options
* @param FormBuilderInterface $parent The parent builder
*
* @return FormInterface The form named after the type
*
* @throws FormException if any given option is not applicable to the given type
*/
public function form($type = 'form', $data = null, array $options = array(), FormBuilderInterface $parent = null)
{
return $this['form.factory']->create($type, $data, $options, $parent);
}
/**
* Generates a path from the given parameters.
*