- ClassLoader
- Config
- Console
- DependencyInjection
- DoctrineBridge
- DomCrawler
- EventDispatcher
- Form
- FrameworkBundle
- HttpFoundation
- HttpKernel
- Locale
- Monolog Bridge
- Process
- PropertyAccess
- Routing
- Security
- SecurityBundle
- Serializer
- Swiftmailer Bridge
- Translator
- Twig Bridge
- TwigBundle
- Validator
- WebProfiler
- Yaml
-
The
UniversalClassLoaderclass has been removed in favor ofClassLoader. The only difference is that some method names are different:Old name New name registerNamespaces()addPrefixes()registerPrefixes()addPrefixes()registerNamespace()addPrefix()registerPrefix()addPrefix()getNamespaces()getPrefixes()getNamespaceFallbacks()getFallbackDirs()getPrefixFallbacks()getFallbackDirs() -
The
DebugUniversalClassLoaderclass has been removed in favor ofDebugClassLoader. The difference is that the constructor now takes a loader to wrap.
-
\Symfony\Component\Config\Resource\ResourceInterface::isFresh()has been removed. Also, cache validation through this method (which was still supported in 2.8 for BC) does no longer work because the\Symfony\Component\Config\Resource\BCResourceInterfaceCheckerhelper class has been removed as well. -
The
__toString()method of the\Symfony\Component\Config\ConfigCacheclass was removed in favor of the newgetPath()method.
-
The
dialoghelper has been removed in favor of thequestionhelper. -
The methods
isQuiet,isVerbose,isVeryVerboseandisDebugwere added toSymfony\Component\Console\Output\OutputInterface. -
ProgressHelperhas been removed in favor ofProgressBar.Before:
$h = new ProgressHelper(); $h->start($output, 10); for ($i = 1; $i < 5; $i++) { usleep(200000); $h->advance(); } $h->finish();
After:
$bar = new ProgressBar($output, 10); $bar->start(); for ($i = 1; $i < 5; $i++) { usleep(200000); $bar->advance(); }
-
TableHelperhas been removed in favor ofTable.Before:
$table = $app->getHelperSet()->get('table'); $table ->setHeaders(array('ISBN', 'Title', 'Author')) ->setRows(array( array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'), array('9971-5-0210-0', 'A Tale of Two Cities', 'Charles Dickens'), array('960-425-059-0', 'The Lord of the Rings', 'J. R. R. Tolkien'), array('80-902734-1-6', 'And Then There Were None', 'Agatha Christie'), )) ; $table->render($output);
After:
use Symfony\Component\Console\Helper\Table; $table = new Table($output); $table ->setHeaders(array('ISBN', 'Title', 'Author')) ->setRows(array( array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'), array('9971-5-0210-0', 'A Tale of Two Cities', 'Charles Dickens'), array('960-425-059-0', 'The Lord of the Rings', 'J. R. R. Tolkien'), array('80-902734-1-6', 'And Then There Were None', 'Agatha Christie'), )) ; $table->render();
-
Parameters of
renderException()method of theSymfony\Component\Console\Applicationare type hinted. You must add the type hint to your implementations.
-
The method
removewas added toSymfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface. -
The concept of scopes was removed, the removed methods are:
Symfony\Component\DependencyInjection\ContainerBuilder::getScopes()Symfony\Component\DependencyInjection\ContainerBuilder::getScopeChildren()Symfony\Component\DependencyInjection\ContainerInterface::enterScope()Symfony\Component\DependencyInjection\ContainerInterface::leaveScope()Symfony\Component\DependencyInjection\ContainerInterface::addScope()Symfony\Component\DependencyInjection\ContainerInterface::hasScope()Symfony\Component\DependencyInjection\ContainerInterface::isScopeActive()Symfony\Component\DependencyInjection\Definition::setScope()Symfony\Component\DependencyInjection\Definition::getScope()Symfony\Component\DependencyInjection\Reference::isStrict()
Also, the $scope and $strict parameters of Symfony\Component\DependencyInjection\ContainerInterface::set()
and Symfony\Component\DependencyInjection\Reference respectively were removed.
-
A new
sharedflag has been added to the service definition in replacement of theprototypescope.Before:
use Symfony\Component\DependencyInjection\ContainerBuilder; $container = new ContainerBuilder(); $container ->register('foo', 'stdClass') ->setScope(ContainerBuilder::SCOPE_PROTOTYPE) ;
services: foo: class: stdClass scope: prototype
<services> <service id="foo" class="stdClass" scope="prototype" /> </services>
After:
use Symfony\Component\DependencyInjection\ContainerBuilder; $container = new ContainerBuilder(); $container ->register('foo', 'stdClass') ->setShared(false) ;
services: foo: class: stdClass shared: false
<services> <service id="foo" class="stdClass" shared="false" /> </services>
-
Symfony\Component\DependencyInjection\ContainerAwarewas removed, useSymfony\Component\DependencyInjection\ContainerAwareTraitor implementSymfony\Component\DependencyInjection\ContainerAwareInterfacemanually -
The methods
Definition::setFactoryClass(),Definition::setFactoryMethod(), andDefinition::setFactoryService()have been removed in favor ofDefinition::setFactory(). Services defined using YAML or XML use the same syntax as configurators. -
Synchronized services are deprecated and the following methods have been removed:
ContainerBuilder::synchronize(),Definition::isSynchronized(), andDefinition::setSynchronized().
-
The interface of the
Symfony\Component\DomCrawler\Crawlerchanged. It does no longer implement\Iteratorbut\IteratorAggregate. If you rely on methods of the\Iteratorinterface, call thegetIteratormethod of the\IteratorAggregateinterface before. No changes are required in a\Traversable-aware control structure, such asforeach.Before:
$crawler->current();
After:
$crawler->getIterator()->current();
-
The
propertyoption ofDoctrineTypewas removed in favor of thechoice_labeloption. -
The
loaderoption ofDoctrineTypewas removed. You now have to override thegetLoader()method in your custom type. -
The
Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceListwas removed in favor ofSymfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader. -
Passing a query builder closure to
ORMQueryBuilderLoaderis not supported anymore. You should pass resolved query builders only.Consequently, the arguments
$managerand$classofORMQueryBuilderLoaderhave been removed as well.Note that the
query_builderoption ofDoctrineTypedoes support closures, but the closure is now resolved in the type instead of in the loader. -
Using the entity provider with a Doctrine repository implementing
UserProviderInterfaceis not supported anymore. You should make the repository implementUserLoaderInterfaceinstead.
- The method
getListenerPriority($eventName, $listener)has been added to theEventDispatcherInterface. - The interface
Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcherInterfaceextendsSymfony\Component\EventDispatcher\EventDispatcherInterface.
-
The
getBlockPrefix()method was added to theFormTypeInterfacein replacement of thegetName()method which has been removed. -
The
configureOptions()method was added to theFormTypeInterfacein replacement of thesetDefaultOptions()method which has been removed. -
The
getBlockPrefix()method was added to theResolvedFormTypeInterfacein replacement of thegetName()method which has been removed. -
The option
optionsof theCollectionTypehas been removed in favor of theentry_optionsoption. -
The
cascade_validationoption was removed. Use theconstraintsoption together with theValidconstraint instead. -
Type names were removed. Instead of referencing types by name, you must reference them by their fully-qualified class name (FQCN) instead:
Before:
$form = $this->createFormBuilder() ->add('name', 'text') ->add('age', 'integer') ->getForm();
After:
use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\Extension\Core\Type\TextType; $form = $this->createFormBuilder() ->add('name', TextType::class) ->add('age', IntegerType::class) ->getForm();
If you want to customize the block prefix of a type in Twig, you must now implement
FormTypeInterface::getBlockPrefix():Before:
class UserProfileType extends AbstractType { public function getName() { return 'profile'; } }
After:
class UserProfileType extends AbstractType { public function getBlockPrefix() { return 'profile'; } }
If you don't customize
getBlockPrefix(), it defaults to the class name without "Type" suffix in underscore notation (here: "user_profile").Type extension must return the fully-qualified class name of the extended type from
FormTypeExtensionInterface::getExtendedType()now.Before:
class MyTypeExtension extends AbstractTypeExtension { public function getExtendedType() { return 'form'; } }
After:
use Symfony\Component\Form\Extension\Core\Type\FormType; class MyTypeExtension extends AbstractTypeExtension { public function getExtendedType() { return FormType::class; } }
-
The
FormTypeInterface::getName()method was removed. -
Returning type instances from
FormTypeInterface::getParent()is not supported anymore. Return the fully-qualified class name of the parent type class instead.Before:
class MyType { public function getParent() { return new ParentType(); } }
After:
class MyType { public function getParent() { return ParentType::class; } }
-
The option
typeof theCollectionTypehas been removed in favor of theentry_typeoption. The value for theentry_typeoption must be the fully-qualified class name (FQCN). -
Passing type instances to
Form::add(),FormBuilder::add()and theFormFactory::create*()methods is not supported anymore. Pass the fully-qualified class name of the type instead.Before:
$form = $this->createForm(new MyType());
After:
$form = $this->createForm(MyType::class);
-
Passing custom data to forms now needs to be done through the options resolver.
In the controller:
Before:
$form = $this->createForm(new MyType($variable), $entity, array( 'action' => $this->generateUrl('action_route'), 'method' => 'PUT', ));
After:
$form = $this->createForm(MyType::class, $entity, array( 'action' => $this->generateUrl('action_route'), 'method' => 'PUT', 'custom_value' => $variable, ));
In the form type:
Before:
class MyType extends AbstractType { private $value; public function __construct($variableValue) { $this->value = $value; } // ... }
After:
public function buildForm(FormBuilderInterface $builder, array $options) { $value = $options['custom_value']; // ... } public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'custom_value' => null, )); }
-
The alias option of the
form.type_extensiontag was removed in favor of theextended_type/extended-typeoption.Before:
<service id="app.type_extension" class="Vendor\Form\Extension\MyTypeExtension"> <tag name="form.type_extension" alias="text" /> </service>
After:
<service id="app.type_extension" class="Vendor\Form\Extension\MyTypeExtension"> <tag name="form.type_extension" extended-type="Symfony\Component\Form\Extension\Core\Type\TextType" /> </service>
-
The
max_lengthoption was removed. Use theattroption instead by setting it to anarraywith amaxlengthkey. -
The
ChoiceToBooleanArrayTransformer,ChoicesToBooleanArrayTransformer,FixRadioInputListener, andFixCheckboxInputListenerclasses were removed. -
The
choice_listoption ofChoiceTypewas removed. -
The option "precision" was renamed to "scale".
Before:
use Symfony\Component\Form\Extension\Core\Type\NumberType; $builder->add('length', NumberType::class, array( 'precision' => 3, ));
After:
use Symfony\Component\Form\Extension\Core\Type\NumberType; $builder->add('length', NumberType::class, array( 'scale' => 3, ));
-
The option "
virtual" was renamed to "inherit_data".Before:
use Symfony\Component\Form\Extension\Core\Type\FormType; $builder->add('address', FormType::class, array( 'virtual' => true, ));
After:
use Symfony\Component\Form\Extension\Core\Type\FormType; $builder->add('address', FormType::class, array( 'inherit_data' => true, ));
-
The method
AbstractType::setDefaultOptions(OptionsResolverInterface $resolver)andAbstractTypeExtension::setDefaultOptions(OptionsResolverInterface $resolver)have been renamed. You should useAbstractType::configureOptions(OptionsResolver $resolver)andAbstractTypeExtension::configureOptions(OptionsResolver $resolver)instead. -
The methods
Form::bind()andForm::isBound()were removed. You should useForm::submit()andForm::isSubmitted()instead.Before:
$form->bind(array(...));
After:
$form->submit(array(...));
-
Passing a
Symfony\Component\HttpFoundation\Requestinstance, as was supported byFormInterface::bind(), is not possible withFormInterface::submit()anymore. You should useFormInterface::handleRequest()instead.Before:
if ('POST' === $request->getMethod()) { $form->bind($request); if ($form->isValid()) { // ... } }
After:
$form->handleRequest($request); if ($form->isValid()) { // ... }
If you want to test whether the form was submitted separately, you can use the method
isSubmitted():$form->handleRequest($request); if ($form->isSubmitted()) { // ... if ($form->isValid()) { // ... } }
-
The events
PRE_BIND,BINDandPOST_BINDwere renamed toPRE_SUBMIT,SUBMITandPOST_SUBMIT.Before:
$builder->addEventListener(FormEvents::PRE_BIND, function (FormEvent $event) { // ... });
After:
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { // ... });
-
The class
VirtualFormAwareIteratorwas renamed toInheritDataAwareIterator.Before:
use Symfony\Component\Form\Util\VirtualFormAwareIterator; $iterator = new VirtualFormAwareIterator($forms);
After:
use Symfony\Component\Form\Util\InheritDataAwareIterator; $iterator = new InheritDataAwareIterator($forms);
-
The
TypeTestCaseclass was moved from theSymfony\Component\Form\Tests\Extension\Core\Typenamespace to theSymfony\Component\Form\Testnamespace.Before:
use Symfony\Component\Form\Tests\Extension\Core\Type\TypeTestCase class MyTypeTest extends TypeTestCase { // ... }
After:
use Symfony\Component\Form\Test\TypeTestCase; class MyTypeTest extends TypeTestCase { // ... }
-
The option "options" of the CollectionType has been renamed to "entry_options".
-
The option "type" of the CollectionType has been renamed to "entry_type". As a value for the option you must provide the fully-qualified class name (FQCN) now as well.
-
The
FormIntegrationTestCaseandFormPerformanceTestCaseclasses were moved form theSymfony\Component\Form\Testsnamespace to theSymfony\Component\Form\Testnamespace. -
The constants
ROUND_HALFEVEN,ROUND_HALFUPandROUND_HALFDOWNin classNumberToLocalizedStringTransformerwere renamed toROUND_HALF_EVEN,ROUND_HALF_UPandROUND_HALF_DOWN. -
The
Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterfacewas removed in favor ofSymfony\Component\Form\ChoiceList\ChoiceListInterface. -
Symfony\Component\Form\Extension\Core\View\ChoiceViewwas removed in favor ofSymfony\Component\Form\ChoiceList\View\ChoiceView. -
The interface
Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterfaceand all of its implementations were removed. Use the new interfaceSymfony\Component\Security\Csrf\CsrfTokenManagerInterfaceinstead. -
The options "
csrf_provider" and "intention" were renamed to "csrf_token_generator" and "csrf_token_id". -
The method
Form::getErrorsAsString()was removed. UseForm::getErrors()instead with the argument$deepset to true and$flattenset to false and cast the returned iterator to a string (if not done implicitly by PHP).Before:
echo $form->getErrorsAsString();
After:
echo $form->getErrors(true, false);
-
The
Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListclass has been removed in favor ofSymfony\Component\Form\ChoiceList\ArrayChoiceList. -
The
Symfony\Component\Form\Extension\Core\ChoiceList\LazyChoiceListclass has been removed in favor ofSymfony\Component\Form\ChoiceList\LazyChoiceList. -
The
Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceListclass has been removed in favor ofSymfony\Component\Form\ChoiceList\ArrayChoiceList. -
The
Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceListclass has been removed in favor ofSymfony\Component\Form\ChoiceList\ArrayChoiceList. -
The
TimezoneType::getTimezones()method was removed. You should not use this method. -
The
Symfony\Component\Form\ChoiceList\ArrayKeyChoiceListclass has been removed in favor ofSymfony\Component\Form\ChoiceList\ArrayChoiceList.
-
The
config:debug,container:debug,router:debug,translation:debugandyaml:lintcommands have been deprecated since Symfony 2.7 and will be removed in Symfony 3.0. Use thedebug:config,debug:container,debug:router,debug:translationandlint:yamlcommands instead. -
The base
Controllerclass is now abstract. -
The visibility of all methods of the base
Controllerclass has been changed frompublictoprotected. -
The
getRequestmethod of the baseControllerclass has been deprecated since Symfony 2.4 and must be therefore removed in 3.0. The only reliable way to get theRequestobject is to inject it in the action method.Before:
namespace Acme\FooBundle\Controller; class DemoController { public function showAction() { $request = $this->getRequest(); // ... } }
After:
namespace Acme\FooBundle\Controller; use Symfony\Component\HttpFoundation\Request; class DemoController { public function showAction(Request $request) { // ... } }
-
In Symfony 2.7 a small BC break was introduced with the new choices_as_values option. In order to have the choice values populated to the html value attribute you had to define the choice_value option. This is now not any more needed.
Before:
$form->add('status', 'choice', array( 'choices' => array( 'Enabled' => Status::ENABLED, 'Disabled' => Status::DISABLED, 'Ignored' => Status::IGNORED, ), // choices_as_values defaults to true in Symfony 3.0 // and setting it to anything else is deprecated as of 3.0 'choices_as_values' => true, // important if you rely on your option value attribute (e.g. for JavaScript) // this will keep the same functionality as before 'choice_value' => function ($choice) { return $choice; }, ));
After:
$form->add('status', ChoiceType::class, array( 'choices' => array( 'Enabled' => Status::ENABLED, 'Disabled' => Status::DISABLED, 'Ignored' => Status::IGNORED, ) ));
-
The
requestservice was removed. You must inject therequest_stackservice instead. -
The
enctypemethod of theformhelper was removed. You should use the new methodstartinstead.Before:
<form method="post" action="http://example.com" <?php echo $view['form']->enctype($form) ?>> ... </form>
After:
<?php echo $view['form']->start($form) ?> ... <?php echo $view['form']->end($form) ?>
The method and action of the form default to "POST" and the current document. If you want to change these values, you can set them explicitly in the controller.
Alternative 1:
$form = $this->createForm('my_form', $formData, array( 'method' => 'PUT', 'action' => $this->generateUrl('target_route'), ));
Alternative 2:
$form = $this->createFormBuilder($formData) // ... ->setMethod('PUT') ->setAction($this->generateUrl('target_route')) ->getForm();
It is also possible to override the method and the action in the template:
<?php echo $view['form']->start($form, array('method' => 'GET', 'action' => 'http://example.com')) ?> ... <?php echo $view['form']->end($form) ?>
-
The
RouterApacheDumperCommandwas removed. -
The
createEsimethod ofSymfony\Bundle\FrameworkBundle\HttpCache\HttpCachewas removed. UsecreateSurrogateinstead. -
The
templating.helper.routerservice was moved totemplating_php.xml. You have to ensure that the PHP templating engine is enabled to be able to use it:framework: templating: engines: ['php']
-
The
form.csrf_providerservice is removed as it implements an adapter for the new token manager to the deprecatedSymfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterfaceinterface. Thesecurity.csrf.token_managershould be used instead. -
The
validator.mapping.cache.apcservice has been removed in favor of thevalidator.mapping.cache.doctrine.apcone. -
The ability to pass
apcas theframework.validation.cacheconfiguration key value has been removed. Usevalidator.mapping.cache.doctrine.apcinstead:Before:
framework: validation: cache: apc
After:
framework: validation: cache: validator.mapping.cache.doctrine.apc
-
The
Symfony\Component\HttpKernel\Log\LoggerInterfacehas been removed in favor ofPsr\Log\LoggerInterface. The only difference is that some method names are different:Old name New name emerg()emergency()crit()critical()err()error()warn()warning()The previous method renames also happened to the following classes:
Symfony\Bridge\Monolog\LoggerSymfony\Component\HttpKernel\Log\NullLogger
-
The
Symfony\Component\HttpKernel\Kernel::init()method has been removed. -
The following classes have been renamed as they have been moved to the Debug component:
Old name New name Symfony\Component\HttpKernel\Debug\ErrorHandlerSymfony\Component\Debug\ErrorHandlerSymfony\Component\HttpKernel\Debug\ExceptionHandlerSymfony\Component\Debug\ExceptionHandlerSymfony\Component\HttpKernel\Exception\FatalErrorExceptionSymfony\Component\Debug\Exception\FatalErrorExceptionSymfony\Component\HttpKernel\Exception\FlattenExceptionSymfony\Component\Debug\Exception\FlattenException -
The
Symfony\Component\HttpKernel\EventListener\ExceptionListenernow passes the Request format as the_formatargument instead offormat. -
The
Symfony\Component\HttpKernel\DependencyInjection\RegisterListenersPasshas been renamed toSymfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPassand moved to the EventDispatcher component.
-
The Locale component was removed and replaced by the Intl component. Instead of the methods in
Symfony\Component\Locale\Locale, you should use these equivalent methods inSymfony\Component\Intl\Intlnow:Old way New way Locale::getDisplayCountries()Intl::getRegionBundle()->getCountryNames()Locale::getCountries()array_keys(Intl::getRegionBundle()->getCountryNames())Locale::getDisplayLanguages()Intl::getLanguageBundle()->getLanguageNames()Locale::getLanguages()array_keys(Intl::getLanguageBundle()->getLanguageNames())Locale::getDisplayLocales()Intl::getLocaleBundle()->getLocaleNames()Locale::getLocales()array_keys(Intl::getLocaleBundle()->getLocaleNames())
-
Renamed
PropertyAccess::getPropertyAccessortocreatePropertyAccessor.Before:
use Symfony\Component\PropertyAccess\PropertyAccess; $accessor = PropertyAccess::getPropertyAccessor();
After:
use Symfony\Component\PropertyAccess\PropertyAccess; $accessor = PropertyAccess::createPropertyAccessor();
-
Some route settings have been renamed:
- The
patternsetting has been removed in favor ofpath - The
_schemeand_methodrequirements have been moved to theschemesandmethodssettings
Before:
article_edit: pattern: /article/{id} requirements: { '_method': 'POST|PUT', '_scheme': 'https', 'id': '\d+' }
<route id="article_edit" pattern="/article/{id}"> <requirement key="_method">POST|PUT</requirement> <requirement key="_scheme">https</requirement> <requirement key="id">\d+</requirement> </route>
$route = new Route(); $route->setPattern('/article/{id}'); $route->setRequirement('_method', 'POST|PUT'); $route->setRequirement('_scheme', 'https');
After:
article_edit: path: /article/{id} methods: [POST, PUT] schemes: https requirements: { 'id': '\d+' }
<route id="article_edit" path="/article/{id}" methods="POST PUT" schemes="https"> <requirement key="id">\d+</requirement> </route>
$route = new Route(); $route->setPath('/article/{id}'); $route->setMethods(array('POST', 'PUT')); $route->setSchemes('https');
- The
-
The
ApacheMatcherDumperandApacheUrlMatcherwere removed since the performance gains were minimal and it's hard to replicate the behaviour of PHP implementation. -
The
getMatcherDumperInstance()andgetGeneratorDumperInstance()methods in theSymfony\Component\Routing\Routerhave been changed frompublictoprotected. -
Use the constants defined in the UrlGeneratorInterface for the $referenceType argument of the UrlGeneratorInterface::generate method.
Before:
// url generated in controller $this->generateUrl('blog_show', array('slug' => 'my-blog-post'), true); // url generated in @router service $router->generate('blog_show', array('slug' => 'my-blog-post'), true);
After:
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; // url generated in controller $this->generateUrl('blog_show', array('slug' => 'my-blog-post'), UrlGeneratorInterface::ABSOLUTE_URL); // url generated in @router service $router->generate('blog_show', array('slug' => 'my-blog-post'), UrlGeneratorInterface::ABSOLUTE_URL);
-
The
vote()method from theVoterInterfacewas changed to now accept arbitrary types and not only objects. You can rely on the new abstractVoterclass introduced in 2.8 to ease integrating your own voters. -
The
AbstractVoterclass was removed in favor of the newVoterclass. -
The
Resources/directory was moved toCore/Resources/ -
The
keysettings ofanonymous,remember_meandhttp_digestare renamed tosecret.Before:
security: # ... firewalls: default: # ... anonymous: { key: "%secret%" } remember_me: key: "%secret%" http_digest: key: "%secret%"
<!-- ... --> <config> <!-- ... --> <firewall> <!-- ... --> <anonymous key="%secret%"/> <remember-me key="%secret%"/> <http-digest key="%secret%"/> </firewall> </config>
// ... $container->loadFromExtension('security', array( // ... 'firewalls' => array( // ... 'anonymous' => array('key' => '%secret%'), 'remember_me' => array('key' => '%secret%'), 'http_digest' => array('key' => '%secret%'), ), ));
After:
security: # ... firewalls: default: # ... anonymous: { secret: "%secret%" } remember_me: secret: "%secret%" http_digest: secret: "%secret%"
<!-- ... --> <config> <!-- ... --> <firewall> <!-- ... --> <anonymous secret="%secret%"/> <remember-me secret="%secret%"/> <http-digest secret="%secret%"/> </firewall> </config>
// ... $container->loadFromExtension('security', array( // ... 'firewalls' => array( // ... 'anonymous' => array('secret' => '%secret%'), 'remember_me' => array('secret' => '%secret%'), 'http_digest' => array('secret' => '%secret%'), ), ));
-
The
AbstractVoterclass was removed. Instead, extend the newVoterclass, introduced in 2.8, and move your voting logic to the to thesupports($attribute, $subject)andvoteOnAttribute($attribute, $object, TokenInterface $token)methods. -
The
vote()method from theVoterInterfacewas changed to now accept arbitrary types, and not only objects. -
The
supportsClassandsupportsAttributemethods were removed from theVoterInterfaceinterface.Before:
class MyVoter extends AbstractVoter { protected function getSupportedAttributes() { return array('CREATE', 'EDIT'); } protected function getSupportedClasses() { return array('AppBundle\Entity\Post'); } // ... }
After:
use Symfony\Component\Security\Core\Authorization\Voter\Voter; class MyVoter extends Voter { protected function supports($attribute, $object) { return $object instanceof Post && in_array($attribute, array('CREATE', 'EDIT')); } protected function voteOnAttribute($attribute, $object, TokenInterface $token) { // Return true or false } }
-
The
AbstractVoter::isGranted()method has been replaced byVoter::voteOnAttribute().Before:
class MyVoter extends AbstractVoter { protected function isGranted($attribute, $object, $user = null) { return 'EDIT' === $attribute && $user === $object->getAuthor(); } // ... }
After:
class MyVoter extends Voter { protected function voteOnAttribute($attribute, $object, TokenInterface $token) { return 'EDIT' === $attribute && $token->getUser() === $object->getAuthor(); } // ... }
-
The
supportsAttribute()andsupportsClass()methods of theAuthenticatedVoter,ExpressionVoter, andRoleVoterclasses have been removed. -
The
intentionoption was renamed tocsrf_token_idfor all the authentication listeners. -
The
csrf_provideroption was renamed tocsrf_token_generatorfor all the authentication listeners.
-
The
intentionfirewall listener setting was renamed tocsrf_token_id. -
The
csrf_providerfirewall listener setting was renamed tocsrf_token_generator.
-
The
setCamelizedAttributes()method of theSymfony\Component\Serializer\Normalizer\GetSetMethodNormalizerandSymfony\Component\Serializer\Normalizer\PropertyNormalizerclasses was removed. -
The
Symfony\Component\Serializer\Exception\Exceptioninterface was removed in favor of the newSymfony\Component\Serializer\Exception\ExceptionInterface.
-
The
Translator::setFallbackLocale()method has been removed in favor ofTranslator::setFallbackLocales(). -
The visibility of the
localeproperty has been changed from protected to private. Rely ongetLocaleandsetLocaleinstead.Before:
class CustomTranslator extends Translator { public function fooMethod() { // get locale $locale = $this->locale; // update locale $this->locale = $locale; } }
After:
class CustomTranslator extends Translator { public function fooMethod() { // get locale $locale = $this->getLocale(); // update locale $this->setLocale($locale); } }
-
The method
FileDumper::format()was removed. You should useFileDumper::formatCatalogue()instead.Before:
class CustomDumper extends FileDumper { protected function format(MessageCatalogue $messages, $domain) { ... } }
After:
class CustomDumper extends FileDumper { public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array()) { ... } }
-
The
getMessages()method of theSymfony\Component\Translation\Translatorclass was removed. You should use thegetCatalogue()method of theSymfony\Component\Translation\TranslatorBagInterface.
-
The
twig:lintcommand has been deprecated since Symfony 2.7 and will be removed in Symfony 3.0. Use thelint:twigcommand instead. -
The
rendertag is deprecated in favor of therenderfunction. -
The
form_enctypehelper was removed. You should use the newform_startfunction instead.Before:
<form method="post" action="http://example.com" {{ form_enctype(form) }}> ... </form>
After:
{{ form_start(form) }} ... {{ form_end(form) }}The method and action of the form default to "POST" and the current document. If you want to change these values, you can set them explicitly in the controller.
Alternative 1:
$form = $this->createForm('my_form', $formData, array( 'method' => 'PUT', 'action' => $this->generateUrl('target_route'), ));
Alternative 2:
$form = $this->createFormBuilder($formData) // ... ->setMethod('PUT') ->setAction($this->generateUrl('target_route')) ->getForm();
It is also possible to override the method and the action in the template:
{{ form_start(form, {'method': 'GET', 'action': 'http://example.com'}) }} ... {{ form_end(form) }}
-
The
Symfony\Bundle\TwigBundle\TwigDefaultEscapingStrategywas removed in favor ofTwig_FileExtensionEscapingStrategy. -
The
twig:debugcommand has been deprecated since Symfony 2.7 and will be removed in Symfony 3.0. Use thedebug:twigcommand instead.
-
The PHP7-incompatible constraints (
Null,True,False) and their related validators (NullValidator,TrueValidator,FalseValidator) have been removed in favor of theirIs-prefixed equivalent. -
The class
Symfony\Component\Validator\Mapping\Cache\ApcCachehas been removed in favor ofSymfony\Component\Validator\Mapping\Cache\DoctrineCache.Before:
use Symfony\Component\Validator\Mapping\Cache\ApcCache; $cache = new ApcCache('symfony.validator');
After:
use Symfony\Component\Validator\Mapping\Cache\DoctrineCache; use Doctrine\Common\Cache\ApcCache; $apcCache = new ApcCache(); $apcCache->setNamespace('symfony.validator'); $cache = new DoctrineCache($apcCache);
-
The constraints
OptionalandRequiredwere moved to theSymfony\Component\Validator\Constraints\namespace. You should adapt the path wherever you used them.Before:
use Symfony\Component\Validator\Constraints as Assert; /** * @Assert\Collection({ * "foo" = @Assert\Collection\Required(), * "bar" = @Assert\Collection\Optional(), * }) */ private $property;
After:
use Symfony\Component\Validator\Constraints as Assert; /** * @Assert\Collection({ * "foo" = @Assert\Required(), * "bar" = @Assert\Optional(), * }) */ private $property;
-
The option "
methods" of theCallbackconstraint was removed. You should use the option "callback" instead. If you have multiple callbacks, add multiple callback constraints instead.Before (YAML):
constraints: - Callback: [firstCallback, secondCallback]
After (YAML):
constraints: - Callback: firstCallback - Callback: secondCallback
When using annotations, you can now put the
Callbackconstraint directly on the method that should be executed.Before (Annotations):
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\ExecutionContextInterface; /** * @Assert\Callback({"callback"}) */ class MyClass { public function callback(ExecutionContextInterface $context) { // ... } }
After (Annotations):
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\ExecutionContextInterface; class MyClass { /** * @Assert\Callback */ public function callback(ExecutionContextInterface $context) { // ... } }
-
The interface
ValidatorInterfacewas replaced by the more powerful interfaceValidator\ValidatorInterface. The signature of thevalidate()method is slightly different in that interface and accepts a value, zero or more constraints and validation group. It replaces bothvalidate()andvalidateValue()in the previous interface.Before:
$validator->validate($object, 'Strict'); $validator->validateValue($value, new NotNull());
After:
$validator->validate($object, null, 'Strict'); $validator->validate($value, new NotNull());
Apart from this change, the new methods
startContext()andinContext()were added. The first of them allows to run multiple validations in the same context and aggregate their violations:$violations = $validator->startContext() ->atPath('firstName')->validate($firstName, new NotNull()) ->atPath('age')->validate($age, new Type('integer')) ->getViolations();
The second allows to run validation in an existing context. This is especially useful when calling the validator from within constraint validators:
$validator->inContext($context)->validate($object);
Instead of a
Validator, the validator builder now returns aValidator\RecursiveValidatorinstead. -
The interface
ValidationVisitorInterfaceand its implementationValidationVisitorwere removed. The implementation of the visitor pattern was flawed. Fixing that implementation would have drastically slowed down the validator execution, so the visitor was removed completely instead.Along with the visitor, the method
accept()was removed fromMetadataInterface. -
The interface
MetadataInterfacewas moved to theMappingnamespace.Before:
use Symfony\Component\Validator\MetadataInterface;
After:
use Symfony\Component\Validator\Mapping\MetadataInterface;
The methods
getCascadingStrategy()andgetTraversalStrategy()were added to the interface. The first method should return a bit mask of the constants in classCascadingStrategy. The second should return a bit mask of the constants inTraversalStrategy.Example:
use Symfony\Component\Validator\Mapping\TraversalStrategy; public function getTraversalStrategy() { return TraversalStrategy::TRAVERSE; }
-
The interface
PropertyMetadataInterfacewas moved to theMappingnamespace.Before:
use Symfony\Component\Validator\PropertyMetadataInterface;
After:
use Symfony\Component\Validator\Mapping\PropertyMetadataInterface;
-
The interface
PropertyMetadataContainerInterfacewas moved to theMappingnamespace and renamed toClassMetadataInterface.Before:
use Symfony\Component\Validator\PropertyMetadataContainerInterface;
After:
use Symfony\Component\Validator\Mapping\ClassMetadataInterface;
The interface now contains four additional methods:
getConstrainedProperties()hasGroupSequence()getGroupSequence()isGroupSequenceProvider()
See the inline documentation of these methods for more information.
-
The interface
ClassBasedInterfacewas removed. You should useMapping\ClassMetadataInterfaceinstead:Before:
use Symfony\Component\Validator\ClassBasedInterface; class MyClassMetadata implements ClassBasedInterface { // ... }
After:
use Symfony\Component\Validator\Mapping\ClassMetadataInterface; class MyClassMetadata implements ClassMetadataInterface { // ... }
-
The class
ElementMetadatawas renamed toGenericMetadata.Before:
use Symfony\Component\Validator\Mapping\ElementMetadata; class MyMetadata extends ElementMetadata { }
After:
use Symfony\Component\Validator\Mapping\GenericMetadata; class MyMetadata extends GenericMetadata { }
-
The interface
ExecutionContextInterfaceand its implementationExecutionContextwere moved to theContextnamespace.Before:
use Symfony\Component\Validator\ExecutionContextInterface;
After:
use Symfony\Component\Validator\Context\ExecutionContextInterface;
The interface now contains the following additional methods:
getValidator()getObject()setNode()setGroup()markGroupAsValidated()isGroupValidated()markConstraintAsValidated()isConstraintValidated()
See the inline documentation of these methods for more information.
The method
addViolationAt()was removed. You should usebuildViolation()instead.Before:
$context->addViolationAt('property', 'The value {{ value }} is invalid.', array( '{{ value }}' => $invalidValue, ));
After:
$context->buildViolation('The value {{ value }} is invalid.') ->atPath('property') ->setParameter('{{ value }}', $invalidValue) ->addViolation();
The methods
validate()andvalidateValue()were removed. You should usegetValidator()together withinContext()instead.Before:
$context->validate($object);
After:
$context->getValidator() ->inContext($context) ->validate($object);
The parameters
$invalidValue,$pluraland$codewere removed fromaddViolation(). You should usebuildViolation()instead. See above for an example.The method
getMetadataFactory()was removed. You can usegetValidator()instead and use the methodsgetMetadataFor()orhasMetadataFor()on the validator instance.Before:
$metadata = $context->getMetadataFactory()->getMetadataFor($myClass);
After:
$metadata = $context->getValidator()->getMetadataFor($myClass);
-
The interface
GlobalExecutionContextInterfacewas removed. Most of the information provided by that interface can be queried fromContext\ExecutionContextInterfaceinstead. -
The interface
MetadataFactoryInterfacewas moved to theMapping\Factorynamespace along with its implementationsBlackholeMetadataFactoryandClassMetadataFactory. These classes were furthermore renamed toBlackHoleMetadataFactoryandLazyLoadingMetadataFactory.Before:
use Symfony\Component\Validator\Mapping\ClassMetadataFactory; $factory = new ClassMetadataFactory($loader);
After:
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory; $factory = new LazyLoadingMetadataFactory($loader);
-
The option
$deepwas removed from the constraintValid. When traversing arrays, nested arrays are always traversed (same behavior as before). When traversing nested objects, their traversal strategy is used. -
The method
ValidatorBuilder::setPropertyAccessor()was removed. The validator now functions without a property accessor. -
The methods
getMessageParameters()andgetMessagePluralization()inConstraintViolationwere renamed togetParameters()andgetPlural().Before:
$parameters = $violation->getMessageParameters(); $plural = $violation->getMessagePluralization();
After:
$parameters = $violation->getParameters(); $plural = $violation->getPlural();
-
The class
Symfony\Component\Validator\DefaultTranslatorwas removed. You should useSymfony\Component\Translation\IdentityTranslatorinstead.Before:
$translator = new \Symfony\Component\Validator\DefaultTranslator();
After:
$translator = new \Symfony\Component\Translation\IdentityTranslator(); $translator->setLocale('en');
-
Using a colon in an unquoted mapping value leads to a
ParseException. -
Starting an unquoted string with
@,`,|, or>leads to aParseException. -
When surrounding strings with double-quotes, you must now escape
\characters. Not escaping those characters (when surrounded by double-quotes) leads to aParseException.Before:
class: "Foo\Var"
After:
class: "Foo\\Var"
-
The ability to pass file names to
Yaml::parse()has been removed.Before:
Yaml::parse($fileName);
After:
Yaml::parse(file_get_contents($fileName));
-
The
profiler:importandprofiler:exportcommands have been removed. -
All the profiler storages different than
FileProfilerStoragehave been removed. The removed classes are:Symfony\Component\HttpKernel\Profiler\BaseMemcacheProfilerStorageSymfony\Component\HttpKernel\Profiler\MemcachedProfilerStorageSymfony\Component\HttpKernel\Profiler\MemcacheProfilerStorageSymfony\Component\HttpKernel\Profiler\MongoDbProfilerStorageSymfony\Component\HttpKernel\Profiler\MysqlProfilerStorageSymfony\Component\HttpKernel\Profiler\PdoProfilerStorageSymfony\Component\HttpKernel\Profiler\RedisProfilerStorageSymfony\Component\HttpKernel\Profiler\SqliteProfilerStorage
Process::setStdin()andProcess::getStdin()have been removed. UseProcess::setInput()andProcess::getInput()that works the same way.Process::setInput()andProcessBuilder::setInput()do not accept non-scalar types.
Symfony\Bridge\Monolog\Logger::emerg()was removed. Useemergency()which is PSR-3 compatible.Symfony\Bridge\Monolog\Logger::crit()was removed. Usecritical()which is PSR-3 compatible.Symfony\Bridge\Monolog\Logger::err()was removed. Useerror()which is PSR-3 compatible.Symfony\Bridge\Monolog\Logger::warn()was removed. Usewarning()which is PSR-3 compatible.
Symfony\Bridge\Swiftmailer\DataCollector\MessageDataCollectorwas removed. Use theSymfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollectorclass instead.
-
The precedence of parameters returned from
Request::get()changed from "GET, PATH, BODY" to "PATH, GET, BODY" -
Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterfaceno longer implements theIteratorAggregateinterface. Use theall()method instead of iterating over the flash bag. -
Removed the feature that allowed finding deep items in
ParameterBag::get(). This may affect you when getting parameters from theRequestclass:Before:
$request->query->get('foo[bar]', null, true);
After:
$request->query->get('foo')['bar'];
Symfony\Bridge\Monolog\Logger::emerg()was removed. Useemergency()which is PSR-3 compatible.Symfony\Bridge\Monolog\Logger::crit()was removed. Usecritical()which is PSR-3 compatible.Symfony\Bridge\Monolog\Logger::err()was removed. Useerror()which is PSR-3 compatible.Symfony\Bridge\Monolog\Logger::warn()was removed. Usewarning()which is PSR-3 compatible.