Skip to content

Commit

Permalink
[Form] Completely decoupled CoreExtension from HttpFoundation
Browse files Browse the repository at this point in the history
  • Loading branch information
webmozart committed Jul 29, 2012
1 parent 50652a9 commit 173b929
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 19 deletions.
21 changes: 9 additions & 12 deletions src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml
Expand Up @@ -18,6 +18,7 @@
<!--
We don't need to be able to add more extensions.
* more types can be registered with the form.type tag
* more type extensions can be registered with the form.type_extension tag
* more type_guessers can be registered with the form.type.type_guesser tag
-->
<argument type="service" id="form.extension" />
Expand All @@ -32,20 +33,11 @@
<!-- DependencyInjectionExtension -->
<service id="form.extension" class="%form.extension.class%" public="false">
<argument type="service" id="service_container" />
<!--
All services with tag "form.type" are inserted here by
InitFormsPass
-->
<!-- All services with tag "form.type" are inserted here by FormPass -->
<argument type="collection" />
<!--
All services with tag "form.type_extension" are inserted here by
InitFormsPass
-->
<!-- All services with tag "form.type_extension" are inserted here by FormPass -->
<argument type="collection" />
<!--
All services with tag "form.type_guesser" are inserted here by
InitFormsPass
-->
<!-- All services with tag "form.type_guesser" are inserted here by FormPass -->
<argument type="collection" />
</service>

Expand Down Expand Up @@ -138,6 +130,11 @@
<tag name="form.type" alias="url" />
</service>

<!-- FormTypeHttpFoundationExtension -->
<service id="form.type_extension.form.http_foundation" class="Symfony\Component\Form\Extension\HttpFoundation\Type\FormTypeHttpFoundationExtension">
<tag name="form.type_extension" alias="form" />
</service>

<!-- FormTypeValidatorExtension -->
<service id="form.type_extension.form.validator" class="Symfony\Component\Form\Extension\Validator\Type\FormTypeValidatorExtension">
<tag name="form.type_extension" alias="form" />
Expand Down
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Form\Extension\Core;

use Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractExtension;

/**
Expand Down
2 changes: 0 additions & 2 deletions src/Symfony/Component/Form/Extension/Core/Type/FormType.php
Expand Up @@ -17,7 +17,6 @@
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Extension\Core\EventListener\BindRequestListener;
use Symfony\Component\Form\Extension\Core\EventListener\TrimListener;
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
use Symfony\Component\Form\Exception\FormException;
Expand Down Expand Up @@ -45,7 +44,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->setData(isset($options['data']) ? $options['data'] : null)
->setDataLocked(isset($options['data']))
->setDataMapper($options['compound'] ? new PropertyPathMapper() : null)
->addEventSubscriber(new BindRequestListener())
;

if ($options['trim']) {
Expand Down
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\Form\Extension\Core\EventListener;
namespace Symfony\Component\Form\Extension\HttpFoundation\EventListener;

use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormEvent;
Expand Down
@@ -0,0 +1,29 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Form\Extension\HttpFoundation;

use Symfony\Component\Form\AbstractExtension;

/**
* Integrates the HttpFoundation component with the Form library.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class HttpFoundationExtension extends AbstractExtension
{
protected function loadTypes()
{
return array(
new Type\FormTypeHttpFoundationExtension(),
);
}
}
@@ -0,0 +1,50 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Form\Extension\HttpFoundation\Type;

use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\HttpFoundation\EventListener\BindRequestListener;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class FormTypeHttpFoundationExtension extends AbstractTypeExtension
{
/**
* @var BindRequestListener
*/
private $listener;

public function __construct()
{
$this->listener = new BindRequestListener();
}

/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addEventSubscriber($this->listener);
}

/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return 'form';
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/Tests/CompoundFormTest.php
Expand Up @@ -14,7 +14,7 @@
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\Extension\Core\EventListener\BindRequestListener;
use Symfony\Component\Form\Extension\HttpFoundation\EventListener\BindRequestListener;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\EventDispatcher\EventDispatcher;
Expand Down
Expand Up @@ -9,9 +9,9 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\Form\Tests\Extension\Core\EventListener;
namespace Symfony\Component\Form\Tests\Extension\HttpFoundation\EventListener;

use Symfony\Component\Form\Extension\Core\EventListener\BindRequestListener;
use Symfony\Component\Form\Extension\HttpFoundation\EventListener\BindRequestListener;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormConfigBuilder;
use Symfony\Component\Form\FormEvent;
Expand Down

0 comments on commit 173b929

Please sign in to comment.