merged branch drak/bc (PR #6422)

This PR was merged into the master branch.

Commits
-------

7533deb [Form] Prevent trigger of E_USER_DEPRECATED for new API

Discussion
----------

[Form] Prevent trigger of E_USER_DEPRECATED for new API

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets:
Todo: -
License of the code: MIT

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

by stof at 2012-12-19T13:54:33Z

This is wrong as FormEvent extends DataEvent and so is also an instance.

Thus, DataEvent should never be constructed anymore (Sf2 does not instantiate it asnd there is no reason to dispatch it elsewhere). The BC is for typehints, and so the useful E_USER_DEPRECATED would be when DataEvent is used as typehint (which is not possible to detect AFAIK)

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

by drak at 2012-12-19T14:07:33Z

So in that case I should check specifically for two class names. Remember the intention here is to NOT trigger an error when the NEW class `FormEvent` is used. I'll update the PR.

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

by Tobion at 2012-12-19T14:25:42Z

I like the solution with an overridden constructor more because using the new stuff will not have the performance penalty of calling `get_class` at all.

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

by stof at 2012-12-19T14:52:47Z

@drak and why not simply ``if (!$this instanceof FormEvent)`` ?

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

by drak at 2012-12-19T15:58:28Z

@stof - if that's ok - I was just assuming other classes might have inherited.
@Tobion - the problem is the private name property we have to call parent which will ultimately call the deprecated constructor.

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

by drak at 2012-12-19T15:59:25Z

How about this?

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

by stof at 2012-12-19T16:51:26Z

@drak if your class inherit from DataEvent instead of FormEvent, it is logical to get a deprecation warning

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

by stof at 2012-12-19T16:52:50Z

@drak I think this allows removing some special error catching in a few places in Form tests (and also in the Form class if it was added)

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

by drak at 2012-12-19T17:33:51Z

@stof - yes, the whole idea is, if you inherit from FormEvent, no warning. anything else, gives warning - that's what we want right?

PR squashed and ready from my side.

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

by drak at 2012-12-20T14:00:13Z

ping @fabpot

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

by bschussek at 2012-12-28T15:19:40Z

👍
This commit is contained in:
Fabien Potencier 2012-12-28 23:57:58 +01:00
commit 3931131ebf

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Form\Event;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormEvent;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
@ -33,7 +34,9 @@ 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);
if (!$this instanceof FormEvent) {
trigger_error(sprintf('%s is deprecated since version 2.1 and will be removed in 2.3. Code against \Symfony\Component\Form\FormEvent instead.', get_class($this)), E_USER_DEPRECATED);
}
$this->form = $form;
$this->data = $data;