8000 merged branch stof/enhance_deprecation (PR #6646) · pilot/symfony@7e2d2a6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7e2d2a6

Browse files
committed
merged branch stof/enhance_deprecation (PR symfony#6646)
This PR was merged into the master branch. Commits ------- 68257d3 Enhanced the triggering of E_USER_DEPRECATED errors Discussion ---------- Enhanced the triggering of E_USER_DEPRECATED errors Bug fix: no Feature addition: no Backwards compatibility break: no Deprecations: no Symfony2 tests pass: yes Fixes the following tickets: none - Removed useless error handlers around FormEvent as the triggering has been fixed in it. - Enhanced the triggering of deprecation errors for places where the BC method provide some user logic needing to be converted to a new way. For instance, AbstractType should trigger the error when the type extending it overwrites the deprecated methods instead of ``setDefaultOptions``, which was not the case previously. - Enhanced the deprecation messages to mention the replacement whenever possible. --------------------------------------------------------------------------- by stof at 2013-01-10T01:23:49Z @fabpot should I remove ``Symfony\Component\Form\Test\DeprecationErrorHandler::getFormEvent`` ? It is not used anymore in the testsuite and is not needed anymore as the constructor of FormEvent does not trigger the deprecation erronously. --------------------------------------------------------------------------- by fabpot at 2013-01-10T07:24:02Z @stof: yes, remove it then. Thanks. --------------------------------------------------------------------------- by stof at 2013-01-10T08:23:14Z done
2 parents 3e99f4e + 68257d3 commit 7e2d2a6

25 files changed

+116
-139
lines changed

src/Symfony/Component/Form/AbstractType.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,20 @@ public function finishView(FormView $view, FormInterface $form, array $options)
5151
*/
5252
public function setDefaultOptions(OptionsResolverInterface $resolver)
5353
{
54-
set_error_handler(array('Symfony\Component\Form\Test\DeprecationErrorHandler', 'handleBC'));
55-
$resolver->setDefaults($this->getDefaultOptions(array()));
56-
$resolver->addAllowedValues($this->getAllowedOptionValues(array()));
57-
restore_error_handler();
54+
$defaults = $this->getDefaultOptions(array());
55+
$allowedTypes = $this->getAllowedOptionValues(array());
56+
57+
if (!empty($defaults)) {
58+
trigger_error('getDefaultOptions() is deprecated since version 2.1 and will be removed in 2.3. Use setDefaultOptions() instead.', E_USER_DEPRECATED);
59+
60+
$resolver->setDefaults($defaults);
61+
}
62+
63+
if (!empty($allowedTypes)) {
64+
trigger_error('getAllowedOptionValues() is deprecated since version 2.1 and will be removed in 2.3. Use setDefaultOptions() instead.', E_USER_DEPRECATED);
65+
66+
$resolver->addAllowedValues($allowedTypes);
67+
}
5868
}
5969

6070
/**
@@ -69,8 +79,6 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
6979
*/
7080
public function getDefaultOptions(array $options)
7181
{
72-
trigger_error('getDefaultOptions() is deprecated since version 2.1 and will be removed in 2.3. Use setDefaultOptions() instead.', E_USER_DEPRECATED);
73-
7482
return array();
7583
}
7684

@@ -86,8 +94,6 @@ public function getDefaultOptions(array $options)
8694
*/
8795
public function getAllowedOptionValues(array $options)
8896
{
89-
trigger_error('getAllowedOptionValues() is deprecated since version 2.1 and will be removed in 2.3. Use setDefaultOptions() instead.', E_USER_DEPRECATED);
90-
9197
return array();
9298
}
9399

src/Symfony/Component/Form/AbstractTypeExtension.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,20 @@ public function finishView(FormView $view, FormInterface $form, array $options)
4444
*/
4545
public function setDefaultOptions(OptionsResolverInterface $resolver)
4646
{
47-
set_error_handler(array('Symfony\Component\Form\Test\DeprecationErrorHandler', 'handleBC'));
48-
$resolver->setDefaults($this->getDefaultOptions());
49-
$resolver->addAllowedValues($this->getAllowedOptionValues());
50-
restore_error_handler();
47+
$defaults = $this->getDefaultOptions(array());
48+
$allowedTypes = $this->getAllowedOptionValues(array());
49+
50+
if (!empty($defaults)) {
51+
trigger_error('getDefaultOptions() is deprecated since version 2.1 and will be removed in 2.3. Use setDefaultOptions() instead.', E_USER_DEPRECATED);
52+
53+
$resolver->setDefaults($defaults);
54+
}
55+
56+
if (!empty($allowedTypes)) {
57+
trigger_error('getAllowedOptionValues() is deprecated since version 2.1 and will be removed in 2.3. Use setDefaultOptions() instead.', E_USER_DEPRECATED);
58+
59+
$resolver->addAllowedValues($allowedTypes);
60+
}
5161
}
5262

5363
/**
@@ -60,8 +70,6 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
6070
*/
6171
public function getDefaultOptions()
6272
{
63-
trigger_error('getDefaultOptions() is deprecated since version 2.1 and will be removed in 2.3. Use setDefaultOptions() instead.', E_USER_DEPRECATED);
64-
6573
return array();
6674
}
6775

@@ -75,8 +83,6 @@ public function getDefaultOptions()
7583
*/
7684
public function getAllowedOptionValues()
7785
{
78-
trigger_error('getAllowedOptionValues() is deprecated since version 2.1 and will be removed in 2.3. Use setDefaultOptions() instead.', E_USER_DEPRECATED);
79-
8086
return array();
8187
}
8288
}

src/Symfony/Component/Form/CallbackValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CallbackValidator implements FormValidatorInterface
2727
*/
2828
public function __construct($callback)
2929
{
30-
trigger_error('CallbackValidator is deprecated since version 2.1 and will be removed in 2.3.', E_USER_DEPRECATED);
30+
trigger_error('CallbackValidator is deprecated since version 2.1 and will be removed in 2.3. Use the FormEvents::POST_BIND event instead.', E_USER_DEPRECATED);
3131

3232
$this->callback = $callback;
3333
}

src/Symfony/Component/Form/Form.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,12 @@ public function setData($modelData)
367367

368368
// Hook to change content of the data
369369
if ($dispatcher->hasListeners(FormEvents::PRE_SET_DATA) || $dispatcher->hasListeners(FormEvents::SET_DATA)) {
370-
set_error_handler(array('Symfony\Component\Form\Test\DeprecationErrorHandler', 'handleBC'));
371370
$event = new FormEvent($this, $modelData);
372-
restore_error_handler();
373371
$dispatcher->dispatch(FormEvents::PRE_SET_DATA, $event);
374372
// BC until 2.3
373+
if ($dispatcher->hasListeners(FormEvents::SET_DATA)) {
374+
trigger_error('The FormEvents::SET_DATA event is deprecated since 2.1 and will be removed in 2.3. Use the FormEvents::PRE_SET_DATA event instead.', E_USER_DEPRECATED);
375+
}
375376
$dispatcher->dispatch(FormEvents::SET_DATA, $event);
376377
$modelData = $event->getData();
377378
}
@@ -532,11 +533,12 @@ public function bind($submittedData)
532533

533534
// Hook to change content of the data bound by the browser
534535
if ($dispatcher->hasListeners(FormEvents::PRE_BIND) || $dispatcher->hasListeners(FormEvents::BIND_CLIENT_DATA)) {
535-
set_error_handler(array('Symfony\Component\Form\Test\DeprecationErrorHandler', 'handleBC'));
536536
$event = new FormEvent($this, $submittedData);
537-
restore_error_handler();
538537
$dispatcher->dispatch(FormEvents::PRE_BIND, $event);
539538
// BC until 2.3
539+
if ($dispatcher->hasListeners(FormEvents::BIND_CLIENT_DATA)) {
540+
trigger_error('The FormEvents::BIND_CLIENT_DATA event is deprecated since 2.1 and will be removed in 2.3. Use the FormEvents::PRE_BIND event instead.', E_USER_DEPRECATED);
541+
}
540542
$dispatcher->dispatch(FormEvents::BIND_CLIENT_DATA, $event);
541543
$submittedData = $event->getData();
542544
}
@@ -594,11 +596,12 @@ public function bind($submittedData)
594596
// Hook to change content of the data into the normalized
595597
// representation
596598
if ($dispatcher->hasListeners(FormEvents::BIND) || $dispatcher->hasListeners(FormEvents::BIND_NORM_DATA)) {
597-
set_error_handler(array('Symfony\Component\Form\Test\DeprecationErrorHandler', 'handleBC'));
598599
$event = new FormEvent($this, $normData);
599-
restore_error_handler();
600600
$dispatcher->dispatch(FormEvents::BIND, $event);
601601
// BC until 2.3
602+
if ($dispatcher->hasListeners(FormEvents::BIND_NORM_DATA)) {
603+
trigger_error('The FormEvents::BIND_NORM_DATA event is deprecated since 2.1 and will be removed in 2.3. Use the FormEvents::BIND event instead.', E_USER_DEPRECATED);
604+
}
602605
$dispatcher->dispatch(FormEvents::BIND_NORM_DATA, $event);
603606
$normData = $event->getData();
604607
}
@@ -621,10 +624,14 @@ public function bind($submittedData)
621624
}
622625

623626
set_error_handler(array('Symfony\Component\Form\Test\DeprecationErrorHandler', 'handleBC'));
624-
foreach ($this->config->getValidators() as $validator) {
627+
$validators = $this->config->getValidators();
628+
restore_error_handler();
629+
630+
foreach ($validators as $validator) {
631+
trigger_error(sprintf('FormConfigInterface::getValidators() is deprecated since 2.1 and will be removed in 2.3. Convert your %s class to a listener on the FormEvents::POST_BIND event.', get_class($validator)), E_USER_DEPRECATED);
632+
625633
$validator->validate($this);
626634
}
627-
restore_error_handler();
628635

629636
return $this;
630637
}

src/Symfony/Component/Form/FormBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,12 @@ public function getIterator()
301301
*/
302302
public function getTypes()
303303
{
304+
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);
305+
304306
if ($this->locked) {
305307
throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
306308
}
307309

308-
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);
309-
310310
$types = array();
311311

312312
for ($type = $this->getType(); null !== $type; $type = $type->getParent()) {

src/Symfony/Component/Form/Test/DeprecationErrorHandler.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
namespace Symfony\Component\Form\Test;
44

5-
use Symfony\Component\Form\FormInterface as NonTestFormInterface;
6-
use Symfony\Component\Form\FormEvent;
7-
85
class DeprecationErrorHandler
96
{
107
public static function handle($errorNumber, $message, $file, $line, $context)
@@ -24,13 +21,4 @@ public static function handleBC($errorNumber, $message, $file, $line, $context)
2421

2522
return false;
2623
}
27-
28-
public static function getFormEvent(NonTestFormInterface $form, $data)
29-
{
30-
set_error_handler(array('Symfony\Component\Form\Test\DeprecationErrorHandler', 'handle'));
31-
$event = new FormEvent($form, $data);
32-
restore_error_handler();
33-
34-
return $event;
35-
}
3624
}

src/Symfony/Component/Form/Tests/CompoundFormTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,7 @@ public function testRemove()
231231
$this->form->remove('foo');
232232

233233
$this->assertNull($child->getParent());
234-
set_error_handler(array('Symfony\Component\Form\Test\DeprecationErrorHandler', 'handle'));
235-
$this->assertFalse($this->form->hasChildren());
236-
restore_error_handler();
234+
$this->assertCount(0, $this->form);
237235
}
238236

239237
/**

src/Symfony/Component/Form/Tests/Extension/Core/EventListener/FixRadioInputListenerTest.php

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

1212
namespace Symfony\Component\Form\Tests\Extension\Core\EventListener;
1313

14+
use Symfony\Component\Form\FormEvent;
1415
use Symfony\Component\Form\Extension\Core\EventListener\FixRadioInputListener;
1516
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
16-
use Symfony\Component\Form\Test\DeprecationErrorHandler;
1717

1818
class FixRadioInputListenerTest extends \PHPUnit_Framework_TestCase
1919
{
@@ -42,7 +42,7 @@ public function testFixRadio()
4242
{
4343
$data = '1';
4444
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
45-
$event = DeprecationErrorHandler::getFormEvent($form, $data);
45+
$event = new FormEvent($form, $data);
4646

4747
$this->listener->preBind($event);
4848

@@ -53,7 +53,7 @@ public function testFixZero()
5353
{
5454
$data = '0';
5555
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
56-
$event = DeprecationErrorHandler::getFormEvent($form, $data);
56+
$event = new FormEvent($form, $data);
5757

5858
$this->listener->preBind($event);
5959

@@ -64,7 +64,7 @@ public function testIgnoreEmptyString()
6464
{
6565
$data = '';
6666
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
67-
$event = DeprecationErrorHandler::getFormEvent($form, $data);
67+
$event = new FormEvent($form, $data);
6868

6969
$this->listener->preBind($event);
7070

src/Symfony/Component/Form/Tests/Extension/Core/EventListener/FixUrlProtocolListenerTest.php

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

1212
namespace Symfony\Component\Form\Tests\Extension\Core\EventListener;
1313

14+
use Symfony\Component\Form\FormEvent;
1415
use Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener;
15-
use Symfony\Component\Form\Test\DeprecationErrorHandler;
1616

1717
class FixUrlProtocolListenerTest extends \PHPUnit_Framework_TestCase
1818
{
@@ -27,7 +27,7 @@ public function testFixHttpUrl()
2727
{
2828
$data = "www.symfony.com";
2929
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
30-
$event = DeprecationErrorHandler::getFormEvent($form, $data);
30+
$event = new FormEvent($form, $data);
3131

3232
$filter = new FixUrlProtocolListener('http');
3333
$filter->onBind($event);
@@ -39,7 +39,7 @@ public function testSkipKnownUrl()
3939
{
4040
$data = "http://www.symfony.com";
4141
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
42-
$event = DeprecationErrorHandler::getFormEvent($form, $data);
42+
$event = new FormEvent($form, $data);
4343

4444
$filter = new FixUrlProtocolListener('http');
4545
$filter->onBind($event);
@@ -51,7 +51,7 @@ public function testSkipOtherProtocol()
5151
{
5252
$data = "ftp://www.symfony.com";
5353
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
54-
$event = DeprecationErrorHandler::getFormEvent($form, $data);
54+
$event = new FormEvent($form, $data);
5555

5656
$filter = new FixUrlProtocolListener('http');
5757
$filter->onBind($event);

src/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerTest.php

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

1212
namespace Symfony\Component\Form\Tests\Extension\Core\EventListener;
1313

14+
use Symfony\Component\Form\FormEvent;
1415
use Symfony\Component\Form\Extension\Core\EventListener\MergeCollectionListener;
15-
use Symfony\Component\Form\Test\DeprecationErrorHandler;
1616

1717
abstract class MergeCollectionListenerTest extends \PHPUnit_Framework_TestCase
1818
{
@@ -84,7 +84,7 @@ public function testAddExtraEntriesIfAllowAdd($allowDelete)
8484

8585
$this->form->setData($originalData);
8686

87-
$event = DeprecationErrorHandler::getFormEvent($this->form, $newData);
87+
$event = new FormEvent($this->form, $newData);
8888
$listener->onBind($event);
8989

9090
// The original object was modified
@@ -108,7 +108,7 @@ public function testAddExtraEntriesIfAllowAddDontOverwriteExistingIndices($allow
108108

109109
$this->form->setData($originalData);
110110

111-
$event = DeprecationErrorHandler::getFormEvent($this->form, $newData);
111+
$event = new FormEvent($this->form, $newData);
112112
$listener->onBind($event);
113113

114114
// The original object was modified
@@ -133,7 +133,7 @@ public function testDoNothingIfNotAllowAdd($allowDelete)
133133

134134
$this->form->setData($originalData);
135135

136-
$event = DeprecationErrorHandler::getFormEvent($this->form, $newData);
136+
$event = new FormEvent($this->form, $newData);
137137
$listener->onBind($event);
138138

139139
// We still have the original object
@@ -157,7 +157,7 @@ public function testRemoveMissingEntriesIfAllowDelete($allowAdd)
157157

158158
$this->form->setData($originalData);
159159

160-
$event = DeprecationErrorHandler::getFormEvent($this->form, $newData);
160+
$event = new FormEvent($this->form, $newData);
161161
$listener->onBind($event);
162162

163163
// The original object was modified
@@ -182,7 +182,7 @@ public function testDoNothingIfNotAllowDelete($allowAdd)
182182

183183
$this->form->setData($originalData);
184184

185-
$event = DeprecationErrorHandler::getFormEvent($this->form, $newData);
185+
$event = new FormEvent($this->form, $newData);
186186
$listener->onBind($event);
187187

188188
// We still have the original object
@@ -201,7 +201,7 @@ public function testDoNothingIfNotAllowDelete($allowAdd)
201201
public function testRequireArrayOrTraversable($allowAdd, $allowDelete)
202202
{
203203
$newData = 'no array or traversable';
204-
$event = DeprecationErrorHandler::getFormEvent($this->form, $newData);
204+
$event = new FormEvent($this->form, $newData);
205205
$listener = new MergeCollectionListener($allowAdd, $allowDelete);
206206
$listener->onBind($event);
207207
}
@@ -215,7 +215,7 @@ public function testDealWithNullData()
215215

216216
$this->form->setData($originalData);
217217

218-
$event = DeprecationErrorHandler::getFormEvent($this->form, $newData);
218+
$event = new FormEvent($this->form, $newData);
219219
$listener->onBind($event);
220220

221221
$this->assertSame($originalData, $event->getData());
@@ -233,7 +233,7 @@ public function testDealWithNullOriginalDataIfAllowAdd($allowDelete)
233233

234234
$this->form->setData($originalData);
235235

236 864A -
$event = DeprecationErrorHandler::getFormEvent($this->form, $newData);
236+
$event = new FormEvent($this->form, $newData);
237237
$listener->onBind($event);
238238

239239
$this->assertSame($newData, $event->getData());
@@ -251,7 +251,7 @@ public function testDontDealWithNullOriginalDataIfNotAllowAdd($allowDelete)
251251

252252
$this->form->setData($originalData);
253253

254-
$event = DeprecationErrorHandler::getFormEvent($this->form, $newData);
254+
$event = new FormEvent($this->form, $newData);
255255
$listener->onBind($event);
256256

257257
$this->assertNull($event->getData());

0 commit comments

Comments
 (0)
0