23 KiB
How to update your project?
This document explains how to upgrade from one Symfony2 version to the next one. It only discusses changes that need to be done when using the "public" API of the framework. If you "hack" the core, you should probably follow the timeline closely anyway.
RC3 to RC4
- Annotation classes must be annotated with @Annotation (see the validator constraints for examples)
beta5 to RC1
-
Renamed
Symfony\Bundle\FrameworkBundle\Command\CommandtoSymfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand -
Removed the routing
AnnotGlobLoaderclass -
Some blocks in the Twig Form templates have been renamed to avoid collisions:
container_attributestowidget_container_attributesattributestowidget_attributesoptionstowidget_choice_options
-
Event changes:
-
All listeners must now be tagged with
kernel.event_listenerinstead ofkernel.listener. -
Kernel events are now properly prefixed with
kernelinstead ofcore:-
Before:
<tag name="kernel.listener" event="core.request" method="onCoreRequest" /> -
After:
<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" />
Note: the method can of course remain as
onCoreRequest, but renaming it as well for consistency with future projects makes sense. -
-
The
Symfony\Component\HttpKernel\CoreEventsclass has been renamed toSymfony\Component\HttpKernel\KernelEvents
-
-
TrueValidatorandFalseValidatorconstraints validators no longer accepts any value as valid data.
beta4 to beta5
-
UserProviderInterface::loadUser()has been renamed toUserProviderInterface::refreshUser()to make the goal of the method clearer. -
The
$kernelproperty onWebTestCaseis now static. Change any instances of$this->kernelin your functional tests toself::$kernel. -
The AsseticBundle has been moved to its own repository (it still bundled with Symfony SE).
-
Yaml Component:
- Exception classes have been moved to their own namespace
Yaml::load()has been renamed toYaml::parse()
-
The File classes from
HttpFoundationhave been refactored:-
Symfony\Component\HttpFoundation\File\Filehas a new API:-
It now extends
\SplFileInfo:- former
getName()equivalent isgetBasename(), - former
getDirectory()equivalent isgetPath(), - former
getPath()equivalent isgetRealPath().
- former
-
the
move()method now creates the target directory when it does not exist, -
getExtension()andguessExtension()do not return the extension with a leading.anymore
-
-
Symfony\Component\HttpFoundation\File\UploadedFilehas a new API:-
The constructor has a new Boolean parameter that must be set to true in test mode only in order to be able to move the file. This parameter is not intended to be set to true from outside of the core files.
-
getMimeType()now always returns the mime type of the underlying file. UsegetClientMimeType()to get the mime type from the request. -
getSize()now always returns the size of the underlying file. UsegetClientSize()to get the file size from the request. -
Use
getClientOriginalName()to retrieve the original name from the request.
-
-
-
The
extensionssetting for Twig has been removed. There is now only one way to register Twig extensions, via thetwig.extensiontag. -
The stack of Monolog handlers now bubbles the records by default. To stop the propagation you need to configure the bubbling explicitly.
-
Expanded the
SerializerInterface, while reducing the number of public methods in the Serializer class itself breaking BC and adding component specific Exception classes. -
The
FileTypeForm class has been heavily changed:-
The temporary storage has been removed.
-
The file type
typeoption has also been removed (the new behavior is the same as when thetypewas set tofilebefore). -
The file input is now rendered as any other input field.
-
-
The
emoption of the DoctrineEntityTypeclass now takes the entity manager name instead of the EntityManager instance. If you don't pass this option, the default Entity Manager will be used as before. -
In the Console component:
Command::getFullname()andCommand::getNamespace()have been removed (Command::getName()behavior is now the same as the oldCommand::getFullname()). -
Default Twig form templates have been moved to the Twig bridge. Here is how you can reference them now from a template or in a configuration setting:
Before:
TwigBundle:Form:div_layout.html.twigAfter:
form_div_layout.html.twig -
All settings regarding the cache warmers have been removed.
-
Response::isRedirected()has been merged withResponse::isRedirect()
beta3 to beta4
-
Client::getProfilerhas been removed in favor ofClient::getProfile, which returns an instance ofProfile. -
Some
UniversalClassLoadermethods have been renamed:registerPrefixFallbacktoregisterPrefixFallbacksregisterNamespaceFallbacktoregisterNamespaceFallbacks
-
The event system has been made more flexible. A listener can now be any valid PHP callable.
-
EventDispatcher::addListener($eventName, $listener, $priority = 0):$eventNameis the event name (cannot be an array anymore),$listeneris a PHP callable.
-
The events classes and constants have been renamed:
-
Old class name
Symfony\Component\Form\Eventsand constants:Events::preBind = 'preBind' Events::postBind = 'postBind' Events::preSetData = 'preSetData' Events::postSetData = 'postSetData' Events::onBindClientData = 'onBindClientData' Events::onBindNormData = 'onBindNormData' Events::onSetData = 'onSetData' -
New class name
Symfony\Component\Form\FormEventsand constants:FormEvents::PRE_BIND = 'form.pre_bind' FormEvents::POST_BIND = 'form.post_bind' FormEvents::PRE_SET_DATA = 'form.pre_set_data' FormEvents::POST_SET_DATA = 'form.post_set_data' FormEvents::BIND_CLIENT_DATA = 'form.bind_client_data' FormEvents::BIND_NORM_DATA = 'form.bind_norm_data' FormEvents::SET_DATA = 'form.set_data' -
Old class name
Symfony\Component\HttpKernel\Eventsand constants:Events::onCoreRequest = 'onCoreRequest' Events::onCoreException = 'onCoreException' Events::onCoreView = 'onCoreView' Events::onCoreController = 'onCoreController' Events::onCoreResponse = 'onCoreResponse' -
New class name
Symfony\Component\HttpKernel\CoreEventsand constants:CoreEvents::REQUEST = 'core.request' CoreEvents::EXCEPTION = 'core.exception' CoreEvents::VIEW = 'core.view' CoreEvents::CONTROLLER = 'core.controller' CoreEvents::RESPONSE = 'core.response' -
Old class name
Symfony\Component\Security\Http\Eventsand constants:Events::onSecurityInteractiveLogin = 'onSecurityInteractiveLogin' Events::onSecuritySwitchUser = 'onSecuritySwitchUser' -
New class name
Symfony\Component\Security\Http\SecurityEventsand constants:SecurityEvents::INTERACTIVE_LOGIN = 'security.interactive_login' SecurityEvents::SWITCH_USER = 'security.switch_user'
-
-
addListenerServicenow only takes a single event name as its first argument, -
Tags in configuration must now set the method to call:
-
Before:
<tag name="kernel.listener" event="onCoreRequest" /> -
After:
<tag name="kernel.listener" event="core.request" method="onCoreRequest" />
-
-
Subscribers must now always return a hash:
-
Before:
public static function getSubscribedEvents() { return Events::onBindNormData; } -
After:
public static function getSubscribedEvents() { return array(FormEvents::BIND_NORM_DATA => 'onBindNormData'); }
-
-
-
Form
DateTypeparametersingle-textchanged tosingle_text -
Form field label helpers now accepts setting attributes, i.e.:
{{ form_label(form.name, 'Custom label', { 'attr': {'class': 'name_field'} }) }}
- In order to use Swiftmailer, you should now register its "init.php" file via
the autoloader ("app/autoloader.php") and remove the
Swift_prefix from the autoloader. For an example on how this should be done, see the Standard Distribution autoload.php.
beta2 to beta3
-
The settings under
framework.annotationshave changed slightly:Before:
framework: annotations: cache: file file_cache: debug: true dir: /fooAfter:
framework: annotations: cache: file debug: true file_cache_dir: /foo
beta1 to beta2
-
The annotation parsing process has been changed (it now uses Doctrine Common 3.0). All annotations which are used in a class must now be imported (just like you import PHP namespaces with the "use" statement):
Before:
<?php
/**
* @orm:Entity
*/
class AcmeUser
{
/**
* @orm:Id
* @orm:GeneratedValue(strategy = "AUTO")
* @orm:Column(type="integer")
* @var integer
*/
private $id;
/**
* @orm:Column(type="string", nullable=false)
* @assert:NotBlank
* @var string
*/
private $name;
}
After:
<?php
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
*/
class AcmeUser
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*
* @var integer
*/
private $id;
/**
* @ORM\Column(type="string", nullable=false)
* @Assert\NotBlank
*
* @var string
*/
private $name;
}
- The
Setconstraint has been removed as it is not required anymore.
Before:
<?php
/**
* @orm:Entity
*/
class AcmeEntity
{
/**
* @assert:Set({@assert:Callback(...), @assert:Callback(...)})
*/
private $foo;
}
After:
<?php
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints\Callback;
/**
* @ORM\Entity
*/
class AcmeEntity
{
/**
* @Callback(...)
* @Callback(...)
*/
private $foo;
}
-
The config under
framework.validation.annotationshas been removed and was replaced with a boolean flagframework.validation.enable_annotationswhich defaults to false. -
Forms must now be explicitly enabled (automatically done in Symfony SE):
framework: form: ~Which is equivalent to:
framework: form: enabled: true -
The Routing Exceptions have been moved:
Before:
Symfony\Component\Routing\Matcher\Exception\Exception Symfony\Component\Routing\Matcher\Exception\NotFoundException Symfony\Component\Routing\Matcher\Exception\MethodNotAllowedExceptionAfter:
Symfony\Component\Routing\Exception\Exception Symfony\Component\Routing\Exception\NotFoundException Symfony\Component\Routing\Exception\MethodNotAllowedException -
The form component's
csrf_page_idoption has been renamed tointention. -
The
error_handlersetting has been removed. TheErrorHandlerclass is now managed directly by Symfony SE inAppKernel. -
The Doctrine metadata files has moved from
Resources/config/doctrine/metadata/orm/toResources/config/doctrine, the extension from.dcm.ymlto.orm.yml, and the file name has been changed to the short class name.Before:
Resources/config/doctrine/metadata/orm/Bundle.Entity.dcm.xml Resources/config/doctrine/metadata/orm/Bundle.Entity.dcm.ymlAfter:
Resources/config/doctrine/Entity.orm.xml Resources/config/doctrine/Entity.orm.yml -
With the introduction of a new Doctrine Registry class, the following parameters have been removed (replaced by methods on the
doctrineservice):doctrine.orm.entity_managersdoctrine.orm.default_entity_managerdoctrine.dbal.default_connection
Before:
$container->getParameter('doctrine.orm.entity_managers') $container->getParameter('doctrine.orm.default_entity_manager') $container->getParameter('doctrine.orm.default_connection')After:
$container->get('doctrine')->getEntityManagerNames() $container->get('doctrine')->getDefaultEntityManagerName() $container->get('doctrine')->getDefaultConnectionName()But you don't really need to use these methods anymore, as to get an entity manager, you can now use the registry directly:
Before:
$em = $this->get('doctrine.orm.entity_manager'); $em = $this->get('doctrine.orm.foobar_entity_manager');After:
$em = $this->get('doctrine')->getEntityManager(); $em = $this->get('doctrine')->getEntityManager('foobar'); -
The
doctrine:generate:entitiesarguments and options changed. Run./app/console doctrine:generate:entities --helpfor more information about the new syntax. -
The
doctrine:generate:repositoriescommand has been removed. The functionality has been moved to thedoctrine:generate:entities. -
Doctrine event subscribers now use a unique "doctrine.event_subscriber" tag. Doctrine event listeners also use a unique "doctrine.event_listener" tag. To specify a connection, use the optional "connection" attribute.
Before:
listener: class: MyEventListener tags: - { name: doctrine.common.event_listener, event: name } - { name: doctrine.dbal.default_event_listener, event: name } subscriber: class: MyEventSubscriber tags: - { name: doctrine.common.event_subscriber } - { name: doctrine.dbal.default_event_subscriber }After:
listener: class: MyEventListener tags: - { name: doctrine.event_listener, event: name } # register for all connections - { name: doctrine.event_listener, event: name, connection: default } # only for the default connection subscriber: class: MyEventSubscriber tags: - { name: doctrine.event_subscriber } # register for all connections - { name: doctrine.event_subscriber, connection: default } # only for the default connection -
Application translations are now stored in the
Resourcesdirectory:Before:
app/translations/catalogue.fr.xmlAfter:
app/Resources/translations/catalogue.fr.xml -
The option
modifiableof thecollectionform type was split into two optionsallow_addandallow_delete.Before:
$builder->add('tags', 'collection', array( 'type' => 'text', 'modifiable' => true, ));After:
$builder->add('tags', 'collection', array( 'type' => 'text', 'allow_add' => true, 'allow_delete' => true, )); -
Request::hasSession()has been renamed toRequest::hasPreviousSession(). The methodhasSession()still exists, but only checks if the request contains a session object, not if the session was started in a previous request. -
Serializer: The NormalizerInterface's
supports()method has been split in two methods:supportsNormalization()andsupportsDenormalization(). -
ParameterBag::getDeep()has been removed, and is replaced with a boolean flag on theParameterBag::get()method. -
Serializer:
AbstractEncoder&AbstractNormalizerwere renamed toSerializerAwareEncoder&SerializerAwareNormalizer. -
Serializer: The
$propertiesargument has been dropped from all interfaces. -
Form: Renamed option value
textofwidgetoption of thedatetype was renamed tosingle-text.textindicates to use separate text boxes now (like for thetimetype). -
Form: Renamed view variable
nametofull_name. The variablenamenow contains the local, short name (equivalent to$form->getName()).
PR12 to beta1
-
The CSRF secret configuration has been moved to a mandatory global
secretsetting (as the secret is now used for everything and not just CSRF):Before:
framework: csrf_protection: secret: S3cr3tAfter:
framework: secret: S3cr3t -
The
File::getWebPath()andFile::rename()methods have been removed, as well as theframework.document_rootconfiguration setting. -
The
File::getDefaultExtension()method has been renamed toFile::guessExtension(). The renamed method now returns null if it cannot guess the extension. -
The
sessionconfiguration has been refactored:-
The
classoption has been removed (use thesession.classparameter instead); -
The PDO session storage configuration has been removed (a cookbook recipe is in the work);
-
The
storage_idoption now takes a service id instead of just part of it.
-
-
The
DoctrineMigrationsBundleandDoctrineFixturesBundlebundles have been moved to their own repositories. -
The form framework has been refactored extensively (more information in the documentation).
-
The
transtag does not accept a message as an argument anymore:{% trans "foo" %} {% trans foo %}Use the long version the tags or the filter instead:
{% trans %}foo{% endtrans %} {{ foo|trans }}This has been done to clarify the usage of the tag and filter and also to make it clearer when the automatic output escaping rules are applied (see the doc for more information).
-
Some methods in the DependencyInjection component's
ContainerBuilderandDefinitionclasses have been renamed to be more specific and consistent:Before:
$container->remove('my_definition'); $definition->setArgument(0, 'foo');After:
$container->removeDefinition('my_definition'); $definition->replaceArgument(0, 'foo'); -
In the rememberme configuration, the
token_provider keynow expects a real service id instead of only a suffix.
PR11 to PR12
-
HttpFoundation\Cookie::getExpire()was renamed togetExpiresTime() -
XML configurations have been normalized. All tags with only one attribute have been converted to tag content:
Before:
<bundle name="MyBundle" /> <app:engine id="twig" /> <twig:extension id="twig.extension.debug" />After:
<bundle>MyBundle</bundle> <app:engine>twig</app:engine> <twig:extension>twig.extension.debug</twig:extension> -
Fixes a critical security issue which allowed all users to switch to arbitrary accounts when the SwitchUserListener was activated. Configurations which do not use the SwitchUserListener are not affected.
-
The Dependency Injection Container now strongly validates the references of all your services at the end of its compilation process. If you have invalid references this will result in a compile-time exception instead of a run-time exception (the previous behavior).
PR10 to PR11
-
Extension configuration classes should now implement the
Symfony\Component\Config\Definition\ConfigurationInterfaceinterface. Note that the BC is kept but implementing this interface in your extensions will allow for further developments. -
The
fingerscrossedMonolog option has been renamed tofingers_crossed.
PR9 to PR10
-
Bundle logical names earned back their
Bundlesuffix:Controllers:
Blog:Post:show->BlogBundle:Post:showTemplates:
Blog:Post:show.html.twig->BlogBundle:Post:show.html.twigResources:
@Blog/Resources/config/blog.xml->@BlogBundle/Resources/config/blog.xmlDoctrine:
$em->find('Blog:Post', $id)->$em->find('BlogBundle:Post', $id) -
ZendBundlehas been replaced byMonologBundle. Have a look at the changes made to Symfony SE to see how to upgrade your projects: https://github.com/symfony/symfony-standard/pull/30/files -
Almost all core bundles parameters have been removed. You should use the settings exposed by the bundle extension configuration instead.
-
Some core bundles service names changed for better consistency.
-
Namespace for validators has changed from
validationtoassert(it was announced for PR9 but it was not the case then):Before:
@validation:NotNullAfter:
@assert:NotNullMoreover, the
Assertprefix used for some constraints has been removed (AssertTruetoTrue). -
ApplicationTester::getDisplay()andCommandTester::getDisplay()method now return the command exit code
PR8 to PR9
-
Symfony\Bundle\FrameworkBundle\Util\Filesystemhas been moved toSymfony\Component\HttpKernel\Util\Filesystem -
The
Executeconstraint has been renamed toCallback -
The HTTP exceptions classes signatures have changed:
Before:
throw new NotFoundHttpException('Not Found', $message, 0, $e);After:
throw new NotFoundHttpException($message, $e); -
The RequestMatcher class does not add
^and$anymore to regexp.You need to update your security configuration accordingly for instance:
Before:
pattern: /_profiler.* pattern: /loginAfter:
pattern: ^/_profiler pattern: ^/login$ -
Global templates under
app/moved to a new location (old directory did not work anyway):Before:
app/views/base.html.twig app/views/AcmeDemoBundle/base.html.twigAfter:
app/Resources/views/base.html.twig app/Resources/AcmeDemo/views/base.html.twig -
Bundle logical names lose their
Bundlesuffix:Controllers:
BlogBundle:Post:show->Blog:Post:showTemplates:
BlogBundle:Post:show.html.twig->Blog:Post:show.html.twigResources:
@BlogBundle/Resources/config/blog.xml->@Blog/Resources/config/blog.xmlDoctrine:
$em->find('BlogBundle:Post', $id)->$em->find('Blog:Post', $id) -
Assetic filters must be now explicitly loaded:
assetic: filters: cssrewrite: ~ yui_css: jar: "/path/to/yuicompressor.jar" my_filter: resource: "%kernel.root_dir%/config/my_filter.xml" foo: bar