Checklist before you upgrade your symfony2.0 to symfony2.1 version


Symfony upgraded version comes with lot of fixes issue. They have added lots of new features but i felt disappointed in terms of performance. The performance has been falls around 30 to 40% in symfony2.1 version.

The following things has been changed:-

1. Doctrine

The DoctrineBundle is moved from the Symfony repository to the Doctrine repository. Therefore you should change the namespace of this bundle in your AppKernel.php:

Before: new Symfony\Bundle\DoctrineBundle\DoctrineBundle()
After: new Doctrine\Bundle\DoctrineBundle\DoctrineBundle()

2. HttpFoundation

Locale management was moved from the Session class to the Request class.

Configuring the default locale

Before:

framework:
session:
default_locale: fr

After:

framework:
default_locale: fr


Retrieving the locale from a Twig template

Before: {{ app.request.session.locale }} or {{ app.session.locale }}

After: {{ app.request.locale }}

Retrieving the locale from a PHP template

Before: $view['session']->getLocale()

After: $view['request']->getLocale()

Retrieving the locale from PHP code

Before: $session->getLocale()

After: $request->getLocale()

3. Security

Symfony\Component\Security\Core\User\UserInterface::equals() has moved to Symfony\Component\Security\Core\User\EquatableInterface::isEqualTo().

You must rename the equals() method in your implementation of the User class to isEqualTo() and implement EquatableInterface. Apart from that, no other changes are required.

Alternatively, you may use the default implementation provided by AbstractToken::hasUserChanged() if you have no need of custom comparison logic. In this case, do not implement EquatableInterface and remove your comparison method.

Before:

class User implements UserInterface
{
// ...
public function equals(UserInterface $user) { /* ... */ }
// ...
}
After:

class User implements UserInterface, EquatableInterface
{
// ...
public function isEqualTo(UserInterface $user) { /* ... */ }
// ...
}

4. Session

The namespace of the Session class changed from Symfony\Component\HttpFoundation\Session to Symfony\Component\HttpFoundation\Session\Session.

Before

$request->get('session');

After

$session = new Session();
$session->start();


Using get to retrieve flash messages now returns an array.

Retrieving the flash messages from a Twig template

Before:

{% if app.session.hasFlash('notice') %}

{{ app.session.getFlash('notice') }}

{% endif %}

After:

{% for flashMessage in app.session.flashbag.get('notice') %}

{{ flashMessage }}

{% endfor %}

You can process all flash messages in a single loop with:

{% for type, flashMessages in app.session.flashbag.all() %}
{% for flashMessage in flashMessages %}

{{ flashMessage }}

{% endfor %}
{% endfor %}

Session handler drivers should implement \SessionHandlerInterface or extend from Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeHandlerInterface base class and renamed to Handler\FooSessionHandler. E.g. PdoSessionStorage becomes Handler\PdoSessionHandler.

Refactor code using $session->*flash*() methods to use $session->getFlashBag()->*().

5.FrameworkBundle

session options: lifetime, path, domain, secure, httponly were deprecated. Prefixed versions should now be used instead: cookie_lifetime, cookie_path, cookie_domain, cookie_secure, cookie_httponly

Before:

framework:
session:
lifetime: 3600
path: \
domain: example.com
secure: true
httponly: true
After:

framework:
session:
cookie_lifetime: 3600
cookie_path: \
cookie_domain: example.com
cookie_secure: true
cookie_httponly: true

Added handler_id, defaults to session.handler.native_file.

framework:
session:
storage_id: session.storage.native
handler_id: session.handler.native_file

To use mock session storage use the following. handler_id is irrelevant in this context.

framework:
session:
storage_id: session.storage.mock_file

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s