10000 merged branch bschussek/issue6558_2 (PR #6580) · symfony/symfony@c223eca · GitHub
[go: up one dir, main page]

Skip to content

Commit c223eca

Browse files
committed
merged branch bschussek/issue6558_2 (PR #6580)
This PR was merged into the master branch. Commits ------- bcc5552 [Form] Protected methods in FormConfigBuilder and FormBuilder from being called when it is turned into a FormConfigInterface instance fee1bf5 [Form] Introduced base ExceptionInterface Discussion ---------- [Form] Protected methods in FormConfigBuilder and FormBuilder Bug fix: yes Feature addition: no Backwards compatibility break: yes Symfony2 tests pass: yes Fixes the following tickets: - Todo: - License of the code: MIT Documentation PR: - When a form is created, a `FormConfigInterface` instance is passed to the constructor of `Form` and then accessible via `getConfig()`. For performance reasons, `FormBuilder` also implements `FormConfigInterface` and is passed here directly instead of copying its values to a new `FormConfig` instance, although protected from further modifications. In addition to the already existing guard clauses in the setters, this PR adds guard clauses to the getters of `FormBuilder` to prevent misuse of the "config" object giving unexpected results. Additionally, this PR introduces first improvements of the form's `Exception\` namespace as described in #6549. --------------------------------------------------------------------------- by mvrhov at 2013-01-05T18:19:04Z @bschussek I don't have the time to review this one, but please do not over optimize. We do a lot of weird things. e.g. I have the following code in one of my models. ```php public function validateEmail(ExecutionContextInterface $context) { if ((null !== $this->product) && (in_array($this->product->getType(), array(ProductTypeEnum::Software, ProductTypeEnum::Subscription)))) { /** @var $form Form */ $form = $context->getRoot(); if (($form instanceof Form) && ('foo' == $form->getConfig()->getOption('app_name'))) { $context->validate($this, 'email', 'Email'); } } } ``` --------------------------------------------------------------------------- by bschussek at 2013-01-05T18:46:17Z @mvrhov Absolutely no problem. Most people will use methods from `FormConfigInterface` on the result of `getConfig()`, because that's the type hinted return value, and that's the way it should be. I don't even know how many people are aware that `getConfig()` returns the builder object. This PR is for rare cases where people write forward-incompatible hacks by accessing `FormBuilder` methods like `get()`, `getParent()` or the like on `getConfig()` (I don't know why anyone would do this, but you never know...) --------------------------------------------------------------------------- by vicb at 2013-01-07T11:08:34Z > Backwards compatibility break: no Really ? --------------------------------------------------------------------------- by vicb at 2013-01-07T12:26:22Z Changing `FormException` from a class to an interface is a BC break (`new FormException()`) --------------------------------------------------------------------------- by bschussek at 2013-01-07T12:41:20Z @vicb Fair enough ;) I adapted the CHANGELOG and UPGRADE-2.2. --------------------------------------------------------------------------- by fabpot at 2013-01-07T15:50:03Z This PR break the tests. --------------------------------------------------------------------------- by bschussek at 2013-01-07T15:50:34Z I just fixed them and they run on my computer. I'm not sure why Travis fails again. --------------------------------------------------------------------------- by bschussek at 2013-01-07T15:56:41Z Travis merged the wrong commit. It merged 42c8987f350650a42d8c968d32cde50fc5d548c0 - see the merge commit here 766f7fe958ea69a302bed6298e55a3001a51e2b8 - when it should have merged cd3f4f9dfe43a526c23f30e16354ff11489b9db1.
2 parents c4a2a2b + bcc5552 commit c223eca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+262
-130
lines changed

UPGRADE-2.2.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@
5757

5858
* The PasswordType is now not trimmed by default.
5959

60+
* The class FormException is now an interface. The old class is still available
61+
under the name Symfony\Component\Form\Exception\Exception, but will probably
62+
be removed before 2.2. If you created FormException instances manually,
63+
you are now advised to create any of the other exceptions in the
64+
Symfony\Component\Form\Exception namespace or to create custom exception
65+
classes for your purpose.
66+
6067
#### Deprecations
6168

6269
* The methods `getParent()`, `setParent()` and `hasParent()` in

src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Form\ChoiceList;
1313

14-
use Symfony\Component\Form\Exception\FormException;
14+
use Symfony\Component\Form\Exception\Exception;
1515
use Symfony\Component\Form\Exception\StringCastException;
1616
use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList;
1717
use Doctrine\Common\Persistence\ObjectManager;
@@ -387,12 +387,12 @@ private function load()
387387
*
388388
* @return array The identifier values
389389
*
390-
* @throws FormException If the entity does not exist in Doctrine's identity map
390+
* @throws Exception If the entity does not exist in Doctrine's identity map
391391
*/
392392
private function getIdentifierValues($entity)
393393
{
394394
if (!$this->em->contains($entity)) {
395-
throw new FormException(
395+
throw new Exception(
396396
'Entities passed to the choice field must be managed. Maybe ' .
397397
'persist them in the entity manager?'
398398
);

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\Form\Type;
1313

1414
use Doctrine\Common\Persistence\ManagerRegistry;
15-
use Symfony\Component\Form\Exception\FormException;
15+
use Symfony\Component\Form\Exception\Exception;
1616
use Doctrine\Common\Persistence\ObjectManager;
1717
use Symfony\Component\Form\FormBuilderInterface;
1818
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList;
@@ -134,7 +134,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
134134
$em = $registry->getManagerForClass($options['class']);
135135

136136
if (null === $em) {
137-
throw new FormException(sprintf(
137+
throw new Exception(sprintf(
138138
'Class "%s" seems not to be a managed Doctrine entity. ' .
139139
'Did you forget to map it?',
140140
$options['class']

src/Symfony/Component/Form/AbstractExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Component\Form;
1313

14-
use Symfony\Component\Form\Exception\FormException;
14+
use Symfony\Component\Form\Exception\Exception;
1515
use Symfony\Component\Form\Exception\UnexpectedTypeException;
1616

1717
/**
@@ -53,7 +53,7 @@ public function getType($name)
5353
}
5454

5555
if (!isset($this->types[$name])) {
56-
throw new FormException(sprintf('The type "%s" can not be loaded by this extension', $name));
56+
throw new Exception(sprintf('The type "%s" can not be loaded by this extension', $name));
5757
}
5858

5959
return $this->types[$name];

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ CHANGELOG
99
* FormInterface::add() now accepts a FormInterface instance OR a field's name, type and options
1010
* removed special characters between the choice or text fields of DateType unless
1111
the option "format" is set to a custom value
12+
* deprecated FormException and introduced ExceptionInterface instead
13+
* [BC BREAK] FormException is now an interface
14+
* protected FormBuilder methods from being called when it is turned into a FormConfigInterface with getFormConfig()
1215

1316
2.1.0
1417
-----

src/Symfony/Component/Form/Exception/AlreadyBoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
namespace Symfony\Component\Form\Exception;
1313

14-
class AlreadyBoundException extends FormException
14+
class AlreadyBoundException extends Exception
1515
{
1616
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Form\Exception;
13+
14+
/**
15+
* Base BadMethodCallException for the Form component.
16+
*
17+
* @author Bernhard Schussek <bschussek@gmail.com>
18+
*/
19+
class BadMethodCallException extends \BadMethodCallException implements ExceptionInterface
20+
{
21+
}

src/Symfony/Component/Form/Exception/CreationException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
*
1717
* @author Bernhard Schussek <bschussek@gmail.com>
1818
*/
19-
class CreationException extends FormException
19+
class CreationException extends Exception
2020
{
2121
}

src/Symfony/Component/Form/Exception/ErrorMappingException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
namespace Symfony\Component\Form\Exception;
1313

14-
class ErrorMappingException extends FormException
14+
class ErrorMappingException extends Exception
1515
{
1616
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Form\Exception;
13+
14+
/**
15+
* Base exception class.
16+
*
17+
* @author Bernhard Schussek <bschussek@gmail.com>
18+
*
19+
* @deprecated This class is a replacement for when class FormException was
20+
* used previously. It should not be used and will be removed.
21+
* Occurrences of this class should be replaced by more specialized
22+
* exception classes, preferably derived from SPL exceptions.
23+
*/
24+
class Exception extends \Exception implements ExceptionInterface
25+
{
26+
}

0 commit comments

Comments
 (0)
0