Permalink
Browse files

merged branch colinfrei/deprecationErrors (PR #6180)

This PR was merged into the master branch.

Commits
-------

6b10550 Merge branch 'master' of github.com:symfony/symfony into deprecationErrors
1d82112 [Form] Fix two cases where deprecated methods were being used
b8cdbdc [Form] Catch deprecation errors that are caused by BC code
ebcb432 [Form] [FrameworkBundle] catch deprecation errors in tests
c21b12e [Form] handle BC use of deprecated stuff in non-test-methods.
fc2be6d [Form] catch deprecated errors in tests
800a032 [Form] replace bindRequest() with bind(), as bindRequest is deprecated
d5b2638 [Form] Trigger errors for deprecated methods in Form Component
f3d6966 [Validator] Stop using deprecated methods
d57ad32 [Form] Catch deprecation errors when using deprecated methods/classes in tests
3241157 [Validator] Trigger errors for deprecations
1f9eb7f return value of handleError
b35de9e Handle errors using a custom error handler
f49704b trigger errors for deprecated methods in HttpFoundation component

Discussion
----------

trigger_error() for deprecations

See also #6173 and #6139.

Started triggering errors in the HttpFoundation component.
It seems as if most of the time the error is just duplicating the text in the @deprecation comment.

Any opinions on if duplicating the text is acceptable, or if fetching the comment text to output the error makes sense?

---------------------------------------------------------------------------

by Seldaek at 2012-12-04T13:39:42Z

IMO it's fine to just duplicate the `@deprecated` note in the message, since anyway this code is meant to be completely deleted, this duplication should not do much harm.

---------------------------------------------------------------------------

by fabpot at 2012-12-06T08:22:21Z

@colinfrei I've merged PR #6173. Do you have time to implement the `trigger_error()` call everywhere? Thanks.

---------------------------------------------------------------------------

by colinfrei at 2012-12-06T08:36:55Z

Yep I'll finish that, probably until the beginning of next week.

---------------------------------------------------------------------------

by bschussek at 2012-12-10T10:15:12Z

Thank you for working on this!

---------------------------------------------------------------------------

by fabpot at 2012-12-12T11:08:53Z

@colinfrei: Is this PR finished? Can I merge it?

---------------------------------------------------------------------------

by colinfrei at 2012-12-12T12:09:19Z

@fabpot not quite - I lost some work due to a computer crash over the weekend. The only thing open is fixing the tests  for the Form Component and catching the cases where the Form Component intentionally uses deprecated stuff.

---------------------------------------------------------------------------

by colinfrei at 2012-12-15T07:32:28Z

@fabpot - finished adding trigger_errors and catching them in Tests and as needed.
Travis is failing, but that seems to be master being broken due to the Finder changes?

I changed a few cases where the code was using deprecated methods which wasn't necessary in my eyes, specifically   1d82112, 800a032, f3d6966
  • Loading branch information...
fabpot committed Dec 15, 2012
2 parents c3f1a46 + 6b10550 commit e3cc337b000dc4049e0e0ddb985d26ddb4abcd08
Showing with 525 additions and 63 deletions.
  1. +1 −0 src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php
  2. +2 −2 src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php
  3. +1 −0 src/Symfony/Bridge/Propel1/Form/PropelTypeGuesser.php
  4. +2 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperDivLayoutTest.php
  5. +2 −0 src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperTableLayoutTest.php
  6. +10 −0 src/Symfony/Component/Form/AbstractType.php
  7. +6 −0 src/Symfony/Component/Form/AbstractTypeExtension.php
  8. +4 −0 src/Symfony/Component/Form/CallbackValidator.php
  9. +2 −0 src/Symfony/Component/Form/Event/DataEvent.php
  10. +5 −0 src/Symfony/Component/Form/Extension/Core/Type/FieldType.php
  11. +1 −0 src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php
  12. +33 −1 src/Symfony/Component/Form/Form.php
  13. +2 −0 src/Symfony/Component/Form/FormBuilder.php
  14. +20 −0 src/Symfony/Component/Form/FormConfigBuilder.php
  15. +8 −0 src/Symfony/Component/Form/FormFactory.php
  16. +4 −0 src/Symfony/Component/Form/FormRegistry.php
  17. +2 −0 src/Symfony/Component/Form/FormTypeGuesserChain.php
  18. +27 −0 src/Symfony/Component/Form/FormView.php
  19. +2 −0 src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
  20. +12 −6 src/Symfony/Component/Form/Tests/CompoundFormTest.php
  21. +36 −0 src/Symfony/Component/Form/Tests/DeprecationErrorHandler.php
  22. +4 −4 src/Symfony/Component/Form/Tests/Extension/Core/EventListener/FixRadioInputListenerTest.php
  23. +4 −4 src/Symfony/Component/Form/Tests/Extension/Core/EventListener/FixUrlProtocolListenerTest.php
  24. +10 −10 src/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerTest.php
  25. +15 −15 src/Symfony/Component/Form/Tests/Extension/Core/EventListener/ResizeFormListenerTest.php
  26. +4 −4 src/Symfony/Component/Form/Tests/Extension/Core/EventListener/TrimListenerTest.php
  27. +2 −2 src/Symfony/Component/Form/Tests/Extension/Csrf/EventListener/CsrfValidationListenerTest.php
  28. +9 −9 src/Symfony/Component/Form/Tests/Extension/HttpFoundation/EventListener/BindRequestListenerTest.php
  29. +4 −4 src/Symfony/Component/Form/Tests/Extension/Validator/EventListener/ValidationListenerTest.php
  30. +6 −0 src/Symfony/Component/Form/Tests/FormFactoryTest.php
  31. +7 −0 src/Symfony/Component/Form/Tests/FormIntegrationTestCase.php
  32. +4 −0 src/Symfony/Component/Form/Tests/FormRegistryTest.php
  33. +2 −0 src/Symfony/Component/Form/Tests/SimpleFormTest.php
  34. +1 −1 src/Symfony/Component/Form/Util/VirtualFormAwareIterator.php
  35. +4 −0 src/Symfony/Component/HttpFoundation/Request.php
  36. +14 −0 src/Symfony/Component/HttpFoundation/Session/Session.php
  37. +19 −0 src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
  38. +33 −0 src/Symfony/Component/HttpFoundation/Tests/Session/SessionTest.php
  39. +7 −0 src/Symfony/Component/Validator/ConstraintValidator.php
  40. +7 −0 src/Symfony/Component/Validator/Constraints/Max.php
  41. +7 −0 src/Symfony/Component/Validator/Constraints/MaxLength.php
  42. +5 −0 src/Symfony/Component/Validator/Constraints/MaxLengthValidator.php
  43. +5 −0 src/Symfony/Component/Validator/Constraints/MaxValidator.php
  44. +7 −0 src/Symfony/Component/Validator/Constraints/Min.php
  45. +7 −0 src/Symfony/Component/Validator/Constraints/MinLength.php
  46. +5 −0 src/Symfony/Component/Validator/Constraints/MinLengthValidator.php
  47. +5 −0 src/Symfony/Component/Validator/Constraints/MinValidator.php
  48. +13 −1 src/Symfony/Component/Validator/ExecutionContext.php
  49. +14 −0 src/Symfony/Component/Validator/GraphWalker.php
  50. +2 −0 src/Symfony/Component/Validator/Mapping/ClassMetadataFactory.php
  51. +2 −0 src/Symfony/Component/Validator/Mapping/MemberMetadata.php
  52. +11 −0 src/Symfony/Component/Validator/Tests/ConstraintValidatorTest.php
  53. +17 −0 src/Symfony/Component/Validator/Tests/Constraints/AllValidatorTest.php
  54. +65 −0 src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php
  55. +2 −0 src/Symfony/Component/Validator/ValidationVisitor.php
  56. +10 −0 src/Symfony/Component/Validator/ValidatorContext.php
  57. +10 −0 src/Symfony/Component/Validator/ValidatorFactory.php
@@ -143,6 +143,7 @@ public function guessMaxLength($class, $property)
*/
public function guessMinLength($class, $property)
{
+ trigger_error('guessMinLength() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
}
/**
@@ -63,7 +63,7 @@ public function validate($entity, Constraint $constraint)
$em = $this->registry->getManagerForClass(get_class($entity));
}
- $className = $this->context->getCurrentClass();
+ $className = $this->context->getClassName();
$class = $em->getClassMetadata($className);
/* @var $class \Doctrine\Common\Persistence\Mapping\ClassMetadata */
@@ -120,6 +120,6 @@ public function validate($entity, Constraint $constraint)
$errorPath = null !== $constraint->errorPath ? $constraint->errorPath : $fields[0];
- $this->context->addViolationAtSubPath($errorPath, $constraint->message, array(), $criteria[$fields[0]]);
+ $this->context->addViolationAt($errorPath, $constraint->message, array(), $criteria[$fields[0]]);
}
}
@@ -126,6 +126,7 @@ public function guessMaxLength($class, $property)
*/
public function guessMinLength($class, $property)
{
+ trigger_error('guessMinLength() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
}
/**
@@ -68,6 +68,8 @@ protected function getExtensions()
protected function tearDown()
{
$this->engine = null;
+
+ parent::tearDown();
}
protected function renderEnctype(FormView $view)
@@ -69,6 +69,8 @@ protected function getExtensions()
protected function tearDown()
{
$this->engine = null;
+
+ parent::tearDown();
}
protected function renderEnctype(FormView $view)
@@ -51,8 +51,10 @@ public function finishView(FormView $view, FormInterface $form, array $options)
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
+ set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handleBC'));
$resolver->setDefaults($this->getDefaultOptions(array()));
$resolver->addAllowedValues($this->getAllowedOptionValues(array()));
+ restore_error_handler();
}
/**
@@ -67,6 +69,8 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
*/
public function getDefaultOptions(array $options)
{
+ trigger_error('getDefaultOptions() is deprecated since version 2.1 and will be removed in 2.3. Use setDefaultOptions() instead.', E_USER_DEPRECATED);
+
return array();
}
@@ -82,6 +86,8 @@ public function getDefaultOptions(array $options)
*/
public function getAllowedOptionValues(array $options)
{
+ trigger_error('getAllowedOptionValues() is deprecated since version 2.1 and will be removed in 2.3. Use setDefaultOptions() instead.', E_USER_DEPRECATED);
+
return array();
}
@@ -104,6 +110,8 @@ public function getParent()
*/
public function setExtensions(array $extensions)
{
+ trigger_error('setExtensions() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
+
$this->extensions = $extensions;
}
@@ -117,6 +125,8 @@ public function setExtensions(array $extensions)
*/
public function getExtensions()
{
+ trigger_error('getExtensions() is deprecated since version 2.1 and will be removed in 2.3. Use ResolvedFormTypeInterface::getTypeExtensions instead.', E_USER_DEPRECATED);
+
return $this->extensions;
}
}
@@ -44,8 +44,10 @@ public function finishView(FormView $view, FormInterface $form, array $options)
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
+ set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handleBC'));
$resolver->setDefaults($this->getDefaultOptions());
$resolver->addAllowedValues($this->getAllowedOptionValues());
+ restore_error_handler();
}
/**
@@ -58,6 +60,8 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
*/
public function getDefaultOptions()
{
+ trigger_error('getDefaultOptions() is deprecated since version 2.1 and will be removed in 2.3. Use setDefaultOptions() instead.', E_USER_DEPRECATED);
+
return array();
}
@@ -71,6 +75,8 @@ public function getDefaultOptions()
*/
public function getAllowedOptionValues()
{
+ trigger_error('getAllowedOptionValues() is deprecated since version 2.1 and will be removed in 2.3. Use setDefaultOptions() instead.', E_USER_DEPRECATED);
+
return array();
}
}
@@ -27,6 +27,8 @@ class CallbackValidator implements FormValidatorInterface
*/
public function __construct($callback)
{
+ trigger_error('CallbackValidator is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
+
$this->callback = $callback;
}
@@ -35,6 +37,8 @@ public function __construct($callback)
*/
public function validate(FormInterface $form)
{
+ trigger_error('validate() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
+
return call_user_func($this->callback, $form);
}
}
@@ -33,6 +33,8 @@ class DataEvent extends Event
*/
public function __construct(FormInterface $form, $data)
{
+ trigger_error('DataEvent is deprecated since version 2.1 and will be removed in 2.3. Code against \Symfony\Component\Form\FormEvent instead.', E_USER_DEPRECATED);
+
$this->form = $form;
$this->data = $data;
}
@@ -22,6 +22,11 @@
*/
class FieldType extends AbstractType
{
+ function __construct()
+ {
+ trigger_error('FieldType is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
+ }
+
/**
* {@inheritdoc}
*/
@@ -70,6 +70,7 @@ public function guessMaxLength($class, $property)
*/
public function guessMinLength($class, $property)
{
+ trigger_error('guessMinLength() is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
}
/**
@@ -210,6 +210,8 @@ public function getPropertyPath()
*/
public function getTypes()
{
+ trigger_error('getTypes() is deprecated since version 2.1 and will be removed in 2.3. Use getConfig() and FormConfigInterface::getType() instead.', E_USER_DEPRECATED);
+
$types = array();
for ($type = $this->config->getType(); null !== $type; $type = $type->getParent()) {
@@ -279,6 +281,8 @@ public function getParent()
*/
public function hasParent()
{
+ trigger_error('hasParent() is deprecated since version 2.1 and will be removed in 2.3. Use getParent() or inverse isRoot() instead.', E_USER_DEPRECATED);
+
return null !== $this->parent;
}
@@ -310,6 +314,8 @@ public function isRoot()
*/
public function hasAttribute($name)
{
+ trigger_error('hasAttribute() is deprecated since version 2.1 and will be removed in 2.3. Use getConfig() and FormConfigInterface::hasAttribute() instead.', E_USER_DEPRECATED);
+
return $this->config->hasAttribute($name);
}
@@ -325,6 +331,8 @@ public function hasAttribute($name)
*/
public function getAttribute($name)
{
+ trigger_error('getAttribute() is deprecated since version 2.1 and will be removed in 2.3. Use getConfig() and FormConfigInterface::getAttribute() instead.', E_USER_DEPRECATED);
+
return $this->config->getAttribute($name);
}
@@ -358,7 +366,9 @@ public function setData($modelData)
// Hook to change content of the data
if ($dispatcher->hasListeners(FormEvents::PRE_SET_DATA) || $dispatcher->hasListeners(FormEvents::SET_DATA)) {
+ set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handleBC'));
$event = new FormEvent($this, $modelData);
+ restore_error_handler();
$dispatcher->dispatch(FormEvents::PRE_SET_DATA, $event);
// BC until 2.3
$dispatcher->dispatch(FormEvents::SET_DATA, $event);
@@ -470,6 +480,8 @@ public function getViewData()
*/
public function getClientData()
{
+ trigger_error('getClientData() is deprecated since version 2.1 and will be removed in 2.3. Use getViewData() instead.', E_USER_DEPRECATED);
+
return $this->getViewData();
}
@@ -519,7 +531,9 @@ public function bind($submittedData)
// Hook to change content of the data bound by the browser
if ($dispatcher->hasListeners(FormEvents::PRE_BIND) || $dispatcher->hasListeners(FormEvents::BIND_CLIENT_DATA)) {
+ set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handleBC'));
$event = new FormEvent($this, $submittedData);
+ restore_error_handler();
$dispatcher->dispatch(FormEvents::PRE_BIND, $event);
// BC until 2.3
$dispatcher->dispatch(FormEvents::BIND_CLIENT_DATA, $event);
@@ -579,7 +593,9 @@ public function bind($submittedData)
// Hook to change content of the data into the normalized
// representation
if ($dispatcher->hasListeners(FormEvents::BIND) || $dispatcher->hasListeners(FormEvents::BIND_NORM_DATA)) {
+ set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handleBC'));
$event = new FormEvent($this, $normData);
+ restore_error_handler();
$dispatcher->dispatch(FormEvents::BIND, $event);
// BC until 2.3
$dispatcher->dispatch(FormEvents::BIND_NORM_DATA, $event);
@@ -603,9 +619,11 @@ public function bind($submittedData)
$dispatcher->dispatch(FormEvents::POST_BIND, $event);
}
+ set_error_handler(array('Symfony\Component\Form\Tests\DeprecationErrorHandler', 'handleBC'));
foreach ($this->config->getValidators() as $validator) {
$validator->validate($this);
}
+ restore_error_handler();
return $this;
}
@@ -627,6 +645,8 @@ public function bind($submittedData)
*/
public function bindRequest(Request $request)
{
+ trigger_error('bindRequest() is deprecated since version 2.1 and will be removed in 2.3. Use FormConfigInterface::bind() instead.', E_USER_DEPRECATED);
+
return $this->bind($request);
}
@@ -635,7 +655,7 @@ public function bindRequest(Request $request)
*/
public function addError(FormError $error)
{
- if ($this->parent && $this->getErrorBubbling()) {
+ if ($this->parent && $this->config->getErrorBubbling()) {
$this->parent->addError($error);
} else {
$this->errors[] = $error;
@@ -654,6 +674,8 @@ public function addError(FormError $error)
*/
public function getErrorBubbling()
{
+ trigger_error('getErrorBubbling() is deprecated since version 2.1 and will be removed in 2.3. Use getConfig() and FormConfigInterface::getErrorBubbling() instead.', E_USER_DEPRECATED);
+
return $this->config->getErrorBubbling();
}
@@ -725,6 +747,8 @@ public function isValid()
*/
public function hasErrors()
{
+ trigger_error('hasErrors() is deprecated since version 2.1 and will be removed in 2.3. Count getErrors() instead.', E_USER_DEPRECATED);
+
return count($this->errors) > 0;
}
@@ -774,6 +798,8 @@ public function getErrorsAsString($level = 0)
*/
public function getNormTransformers()
{
+ trigger_error('getNormTransformers() is deprecated since version 2.1 and will be removed in 2.3. Use getConfig() and FormConfigInterface::getModelTransformers() instead.', E_USER_DEPRECATED);
+
return $this->config->getModelTransformers();
}
@@ -787,6 +813,8 @@ public function getNormTransformers()
*/
public function getClientTransformers()
{
+ trigger_error('getClientTransformers() is deprecated since version 2.1 and will be removed in 2.3. Use getConfig() and FormConfigInterface::getViewTransformers() instead.', E_USER_DEPRECATED);
+
return $this->config->getViewTransformers();
}
@@ -808,6 +836,8 @@ public function all()
*/
public function getChildren()
{
+ trigger_error('getChilren() is deprecated since version 2.1 and will be removed in 2.3. Use all() instead.', E_USER_DEPRECATED);
+
return $this->all();
}
@@ -821,6 +851,8 @@ public function getChildren()
*/
public function hasChildren()
{
+ trigger_error('hasChildren() is deprecated since version 2.1 and will be removed in 2.3. Use count() instead.', E_USER_DEPRECATED);
+
return count($this->children) > 0;
}
@@ -295,6 +295,8 @@ public function getIterator()
*/
public function getTypes()
{
+ trigger_error('getTypes() is deprecated since version 2.1 and will be removed in 2.3. Use getConfig() and FormConfigInterface::getType() instead.', E_USER_DEPRECATED);
+
$types = array();
for ($type = $this->getType(); null !== $type; $type = $type->getParent()) {
Oops, something went wrong.

0 comments on commit e3cc337

Please sign in to comment.