Added the support of form types defined as services

This commit is contained in:
Christophe Coevoet 2012-06-21 00:11:32 +02:00
parent c127a1c4bf
commit fd8ee2679a
3 changed files with 8 additions and 5 deletions

View File

@ -120,7 +120,7 @@ abstract class AbstractFormatter implements FormatterInterface
$data['requirements'] = $requirements; $data['requirements'] = $requirements;
if (null !== $formType = $apiDoc->getFormType()) { if (null !== $formType = $apiDoc->getFormType()) {
$data['parameters'] = $this->parser->parse(new $formType()); $data['parameters'] = $this->parser->parse($formType);
if ('PUT' === $method) { if ('PUT' === $method) {
// All parameters are optional with PUT (update) // All parameters are optional with PUT (update)

View File

@ -11,7 +11,6 @@
namespace Nelmio\ApiDocBundle\Parser; namespace Nelmio\ApiDocBundle\Parser;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder; use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormFactoryInterface;
@ -47,11 +46,14 @@ class FormTypeParser
* - required * - required
* - description * - description
* *
* @param AbstractType $type * @param string|\Symfony\Component\Form\FormTypeInterface $type
* @return array * @return array
*/ */
public function parse(AbstractType $type) public function parse($type)
{ {
if (is_string($type) && class_exists($type)) {
$type = new $type();
}
$form = $this->formFactory->create($type); $form = $this->formFactory->create($type);
$parameters = array(); $parameters = array();

View File

@ -95,7 +95,8 @@ The following properties are available:
* `filters`: an array of filters; * `filters`: an array of filters;
* `formType`: the Form Type associated to the method, useful for POST|PUT methods. * `formType`: the Form Type associated to the method, useful for POST|PUT methods, either as FQCN or
as form type (if it is registered in the form factory in the container)
Each _filter_ has to define a `name` parameter, but other parameters are free. Filters are often optional Each _filter_ has to define a `name` parameter, but other parameters are free. Filters are often optional
parameters, and you can document them as you want, but keep in mind to be consistent for the whole documentation. parameters, and you can document them as you want, but keep in mind to be consistent for the whole documentation.