2013-01-15 07:06:36 +00:00
UPGRADE FROM 2.x to 3.0
=======================
2013-02-08 13:02:12 +00:00
### ClassLoader
2013-03-20 17:09:46 +00:00
* The `UniversalClassLoader` class has been removed in favor of
`ClassLoader` . The only difference is that some method names are different:
2013-02-08 13:02:12 +00:00
2014-11-18 08:38:51 +00:00
| Old name | New name
| -------- | ---
| `registerNamespaces()` | `addPrefixes()`
| `registerPrefixes()` | `addPrefixes()`
2016-01-12 11:47:35 +00:00
| `registerNamespace()` | `addPrefix()`
2015-12-08 11:43:15 +00:00
| `registerPrefix()` | `addPrefix()`
2014-11-18 08:38:51 +00:00
| `getNamespaces()` | `getPrefixes()`
| `getNamespaceFallbacks()` | `getFallbackDirs()`
| `getPrefixFallbacks()` | `getFallbackDirs()`
2013-02-08 13:02:12 +00:00
* The `DebugUniversalClassLoader` class has been removed in favor of
`DebugClassLoader` . The difference is that the constructor now takes a
loader to wrap.
2016-01-16 18:39:57 +00:00
### Config
* `\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\BCResourceInterfaceChecker` helper class
has been removed as well.
2016-01-16 18:17:20 +00:00
* The `__toString()` method of the `\Symfony\Component\Config\ConfigCache` class
was removed in favor of the new `getPath()` method.
2013-02-08 13:02:12 +00:00
2014-02-07 16:08:27 +00:00
### Console
2013-12-13 13:43:58 +00:00
* The `dialog` helper has been removed in favor of the `question` helper.
2014-02-07 16:08:27 +00:00
* The methods `isQuiet` , `isVerbose` , `isVeryVerbose` and `isDebug` were added
2014-02-24 15:17:08 +00:00
to `Symfony\Component\Console\Output\OutputInterface` .
2014-02-07 16:08:27 +00:00
2014-03-01 04:11:27 +00:00
* `ProgressHelper` has been removed in favor of `ProgressBar` .
Before:
2014-11-18 08:38:51 +00:00
```php
2014-03-01 04:11:27 +00:00
$h = new ProgressHelper();
$h->start($output, 10);
for ($i = 1; $i < 5 ; $ i + + ) {
usleep(200000);
$h->advance();
}
$h->finish();
```
After:
2014-11-18 08:38:51 +00:00
```php
2014-03-01 04:11:27 +00:00
$bar = new ProgressBar($output, 10);
$bar->start();
for ($i = 1; $i < 5 ; $ i + + ) {
usleep(200000);
$bar->advance();
}
```
2014-03-03 10:06:26 +00:00
* `TableHelper` has been removed in favor of `Table` .
Before:
2014-11-18 08:38:51 +00:00
```php
2014-03-03 10:06:26 +00:00
$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:
2014-11-18 08:38:51 +00:00
```php
2014-03-03 10:06:26 +00:00
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();
```
2014-11-18 08:38:51 +00:00
### DependencyInjection
2016-01-16 18:39:57 +00:00
* 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 `shared` flag has been added to the service definition
in replacement of the `prototype` scope.
Before:
```php
use Symfony\Component\DependencyInjection\ContainerBuilder;
$container = new ContainerBuilder();
$container
->register('foo', 'stdClass')
->setScope(ContainerBuilder::SCOPE_PROTOTYPE)
;
```
```yml
services:
foo:
class: stdClass
scope: prototype
```
```xml
< services >
< service id = "foo" class = "stdClass" scope = "prototype" / >
< / services >
```
After:
```php
use Symfony\Component\DependencyInjection\ContainerBuilder;
$container = new ContainerBuilder();
$container
->register('foo', 'stdClass')
->setShared(false)
;
```
```yml
services:
foo:
class: stdClass
shared: false
```
```xml
< services >
< service id = "foo" class = "stdClass" shared = "false" / >
< / services >
```
* `Symfony\Component\DependencyInjection\ContainerAware` was removed, use
`Symfony\Component\DependencyInjection\ContainerAwareTrait` or implement
`Symfony\Component\DependencyInjection\ContainerAwareInterface` manually
2014-11-18 08:38:51 +00:00
* The methods `Definition::setFactoryClass()` ,
`Definition::setFactoryMethod()` , and `Definition::setFactoryService()` have
been removed in favor of `Definition::setFactory()` . Services defined using
YAML or XML use the same syntax as configurators.
2015-01-06 16:17:37 +00:00
* Synchronized services are deprecated and the following methods have been
removed: `ContainerBuilder::synchronize()` , `Definition::isSynchronized()` ,
and `Definition::setSynchronized()` .
2016-01-16 18:17:20 +00:00
### DoctrineBridge
* The `property` option of `DoctrineType` was removed in favor of the `choice_label` option.
* The `loader` option of `DoctrineType` was removed. You now have to override the `getLoader()`
method in your custom type.
* The `Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList` was removed in favor
of `Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader` .
* Passing a query builder closure to `ORMQueryBuilderLoader` is not supported anymore.
You should pass resolved query builders only.
Consequently, the arguments `$manager` and `$class` of `ORMQueryBuilderLoader`
have been removed as well.
Note that the `query_builder` option of `DoctrineType` *does* support
closures, but the closure is now resolved in the type instead of in the
loader.
2013-12-28 19:36:11 +00:00
### EventDispatcher
* The interface `Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcherInterface`
extends `Symfony\Component\EventDispatcher\EventDispatcherInterface` .
2013-04-17 17:47:21 +01:00
### Form
2016-01-16 18:39:57 +00:00
* The option `options` of the `CollectionType` has been removed in favor
of the `entry_options` option.
* The `cascade_validation` option was removed. Use the `constraints` option
together with the `Valid` constraint instead.
* Type names were removed. Instead of referencing types by name, you must
reference them by their fully-qualified class name (FQCN) instead:
Before:
```php
$form = $this->createFormBuilder()
->add('name', 'text')
->add('age', 'integer')
->getForm();
```
After:
```php
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:
```php
class UserProfileType extends AbstractType
{
public function getName()
{
return 'profile';
}
}
```
After:
```php
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:
```php
class MyTypeExtension extends AbstractTypeExtension
{
public function getExtendedType()
{
return 'form';
}
}
```
After:
```php
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:
```php
class MyType
{
public function getParent()
{
return new ParentType();
}
}
```
After:
```php
class MyType
{
public function getParent()
{
return ParentType::class;
}
}
```
* The option `type` of the `CollectionType` has been removed in favor of
the `entry_type` option. The value for the `entry_type` option must be
the fully-qualified class name (FQCN).
* Passing type instances to `Form::add()` , `FormBuilder::add()` and the
`FormFactory::create*()` methods is not supported anymore. Pass the
fully-qualified class name of the type instead.
Before:
```php
$form = $this->createForm(new MyType());
```
After:
```php
$form = $this->createForm(MyType::class);
```
2016-10-11 16:48:30 +01:00
* Passing custom data to forms now needs to be done
through the options resolver.
In the controller:
Before:
```php
$form = $this->createForm(new MyType($variable), $entity, array(
'action' => $this->generateUrl('action_route'),
'method' => 'PUT',
));
```
After:
```php
$form = $this->createForm(MyType::class, $entity, array(
'action' => $this->generateUrl('action_route'),
'method' => 'PUT',
'custom_value' => $variable,
));
```
In the form type:
Before:
```php
class MyType extends AbstractType
{
private $value;
public function __construct($variableValue)
{
$this->value = $value;
}
// ...
}
```
After:
```php
public function buildForm(FormBuilderInterface $builder, array $options)
{
$value = $options['custom_value'];
// ...
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'custom_value' => null,
));
}
```
2016-01-16 18:39:57 +00:00
* The alias option of the `form.type_extension` tag was removed in favor of
the `extended_type` /`extended-type` option.
Before:
```xml
< service id = "app.type_extension" class = "Vendor \Form \Extension \MyTypeExtension" >
< tag name = "form.type_extension" alias = "text" / >
< / service >
```
After:
```xml
< 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 >
```
2016-05-13 15:45:14 +01:00
* The `max_length` option was removed. Use the `attr` option instead by setting it to
an `array` with a `maxlength` key.
* The `ChoiceToBooleanArrayTransformer` , `ChoicesToBooleanArrayTransformer` ,
2016-05-24 11:00:02 +01:00
`FixRadioInputListener` , and `FixCheckboxInputListener` classes were removed.
2016-01-16 18:17:20 +00:00
* The `choice_list` option of `ChoiceType` was removed.
2015-02-17 13:21:59 +00:00
* The option "precision" was renamed to "scale".
Before:
```php
2016-01-16 18:39:57 +00:00
use Symfony\Component\Form\Extension\Core\Type\NumberType;
$builder->add('length', NumberType::class, array(
2015-02-17 13:21:59 +00:00
'precision' => 3,
));
```
After:
```php
2016-01-16 18:39:57 +00:00
use Symfony\Component\Form\Extension\Core\Type\NumberType;
$builder->add('length', NumberType::class, array(
2015-02-17 13:21:59 +00:00
'scale' => 3,
));
```
2015-11-11 09:55:11 +00:00
* The option "`virtual`" was renamed to "`inherit_data`".
Before:
```php
2016-01-16 18:39:57 +00:00
use Symfony\Component\Form\Extension\Core\Type\FormType;
$builder->add('address', FormType::class, array(
2015-11-11 09:55:11 +00:00
'virtual' => true,
));
```
After:
```php
2016-01-16 18:39:57 +00:00
use Symfony\Component\Form\Extension\Core\Type\FormType;
$builder->add('address', FormType::class, array(
2015-11-11 09:55:11 +00:00
'inherit_data' => true,
));
```
2014-12-08 07:03:20 +00:00
* The method `AbstractType::setDefaultOptions(OptionsResolverInterface $resolver)` and
`AbstractTypeExtension::setDefaultOptions(OptionsResolverInterface $resolver)` have been
renamed. You should use `AbstractType::configureOptions(OptionsResolver $resolver)` and
`AbstractTypeExtension::configureOptions(OptionsResolver $resolver)` instead.
2013-04-20 16:32:55 +01:00
* The methods `Form::bind()` and `Form::isBound()` were removed. You should
use `Form::submit()` and `Form::isSubmitted()` instead.
Before:
2014-09-26 11:51:50 +01:00
```php
2013-04-20 16:32:55 +01:00
$form->bind(array(...));
```
After:
2014-09-26 11:51:50 +01:00
```php
2013-04-20 16:32:55 +01:00
$form->submit(array(...));
```
* Passing a `Symfony\Component\HttpFoundation\Request` instance, as was
supported by `FormInterface::bind()` , is not possible with
`FormInterface::submit()` anymore. You should use `FormInterface::handleRequest()`
instead.
2013-04-17 17:47:21 +01:00
Before:
2014-09-26 11:51:50 +01:00
```php
2013-04-17 17:47:21 +01:00
if ('POST' === $request->getMethod()) {
$form->bind($request);
if ($form->isValid()) {
// ...
}
}
```
After:
2014-09-26 11:51:50 +01:00
```php
2013-04-20 16:32:55 +01:00
$form->handleRequest($request);
2013-04-20 14:56:42 +01:00
if ($form->isValid()) {
2013-04-17 17:47:21 +01:00
// ...
}
```
If you want to test whether the form was submitted separately, you can use
2013-04-20 16:32:55 +01:00
the method `isSubmitted()` :
2013-04-17 17:47:21 +01:00
2014-09-26 11:51:50 +01:00
```php
2013-04-20 16:32:55 +01:00
$form->handleRequest($request);
2013-04-20 14:56:42 +01:00
2013-04-20 16:32:55 +01:00
if ($form->isSubmitted()) {
2013-04-17 17:47:21 +01:00
// ...
if ($form->isValid()) {
// ...
}
}
```
2014-11-18 08:38:51 +00:00
* The events `PRE_BIND` , `BIND` and `POST_BIND` were renamed to `PRE_SUBMIT` , `SUBMIT`
and `POST_SUBMIT` .
2013-04-20 16:32:55 +01:00
Before:
2014-09-26 11:51:50 +01:00
```php
2013-04-20 16:32:55 +01:00
$builder->addEventListener(FormEvents::PRE_BIND, function (FormEvent $event) {
// ...
});
```
After:
2014-09-26 11:51:50 +01:00
```php
2013-04-20 16:32:55 +01:00
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
// ...
});
```
2014-11-18 08:38:51 +00:00
* The class `VirtualFormAwareIterator` was renamed to `InheritDataAwareIterator` .
2013-01-04 15:34:38 +00:00
Before:
2014-09-26 11:51:50 +01:00
```php
2013-01-04 15:34:38 +00:00
use Symfony\Component\Form\Util\VirtualFormAwareIterator;
$iterator = new VirtualFormAwareIterator($forms);
```
After:
2014-09-26 11:51:50 +01:00
```php
2013-01-04 15:34:38 +00:00
use Symfony\Component\Form\Util\InheritDataAwareIterator;
$iterator = new InheritDataAwareIterator($forms);
```
2013-04-28 10:04:40 +01:00
* The `TypeTestCase` class was moved from the `Symfony\Component\Form\Tests\Extension\Core\Type` namespace to the `Symfony\Component\Form\Test` namespace.
2013-09-10 13:28:39 +01:00
2013-04-28 10:04:40 +01:00
Before:
2014-09-26 11:51:50 +01:00
```php
2013-04-28 10:04:40 +01:00
use Symfony\Component\Form\Tests\Extension\Core\Type\TypeTestCase
class MyTypeTest extends TypeTestCase
{
// ...
}
```
After:
2014-09-26 11:51:50 +01:00
```php
2013-04-28 10:04:40 +01:00
use Symfony\Component\Form\Test\TypeTestCase;
class MyTypeTest extends TypeTestCase
{
// ...
}
```
2016-01-16 18:39:57 +00:00
2015-11-25 09:54:34 +00:00
* The option "options" of the CollectionType has been renamed to "entry_options".
* The option "type" of the CollectionType has been renamed to "entry_type".
2016-01-16 18:39:57 +00:00
As a value for the option you must provide the fully-qualified class name (FQCN)
now as well.
2013-04-28 10:04:40 +01:00
2013-08-23 22:58:13 +01:00
* The `FormIntegrationTestCase` and `FormPerformanceTestCase` classes were moved form the `Symfony\Component\Form\Tests` namespace to the `Symfony\Component\Form\Test` namespace.
2013-04-28 10:04:40 +01:00
2013-08-01 14:31:18 +01:00
* The constants `ROUND_HALFEVEN` , `ROUND_HALFUP` and `ROUND_HALFDOWN` in class
`NumberToLocalizedStringTransformer` were renamed to `ROUND_HALF_EVEN` ,
`ROUND_HALF_UP` and `ROUND_HALF_DOWN` .
2016-01-16 18:17:20 +00:00
* The `Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface` was
removed in favor of `Symfony\Component\Form\ChoiceList\ChoiceListInterface` .
* `Symfony\Component\Form\Extension\Core\View\ChoiceView` was removed in favor of
`Symfony\Component\Form\ChoiceList\View\ChoiceView` .
2013-09-10 13:28:39 +01:00
2013-09-27 08:37:01 +01:00
* The interface `Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface`
and all of its implementations were removed. Use the new interface
2013-10-04 14:25:38 +01:00
`Symfony\Component\Security\Csrf\CsrfTokenManagerInterface` instead.
2013-09-27 08:37:01 +01:00
2014-11-20 13:22:25 +00:00
* The options "`csrf_provider`" and "`intention`" were renamed to "`csrf_token_generator`"
2014-11-18 08:38:51 +00:00
and "`csrf_token_id`".
2013-09-27 08:37:01 +01:00
2013-12-31 16:24:28 +00:00
* The method `Form::getErrorsAsString()` was removed. Use `Form::getErrors()`
2014-01-10 12:53:52 +00:00
instead with the argument `$deep` set to true and `$flatten` set to false
and cast the returned iterator to a string (if not done implicitly by PHP).
2013-12-31 16:24:28 +00:00
Before:
2014-11-18 08:38:51 +00:00
```php
2013-12-31 16:24:28 +00:00
echo $form->getErrorsAsString();
```
After:
2014-11-18 08:38:51 +00:00
```php
2014-01-10 12:53:52 +00:00
echo $form->getErrors(true, false);
2013-12-31 16:24:28 +00:00
```
2015-07-24 20:28:02 +01:00
2015-10-05 09:42:37 +01:00
* The `Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList` class has been removed in
favor of `Symfony\Component\Form\ChoiceList\ArrayChoiceList` .
2015-07-24 20:28:02 +01:00
2015-10-05 09:42:37 +01:00
* The `Symfony\Component\Form\Extension\Core\ChoiceList\LazyChoiceList` class has been removed in
favor of `Symfony\Component\Form\ChoiceList\LazyChoiceList` .
2015-07-24 20:28:02 +01:00
2015-10-05 09:42:37 +01:00
* The `Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList` class has been removed in
favor of `Symfony\Component\Form\ChoiceList\ArrayChoiceList` .
* The `Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList` class has been removed in
favor of `Symfony\Component\Form\ChoiceList\ArrayChoiceList` .
2016-01-16 18:39:57 +00:00
* The `TimezoneType::getTimezones()` method was removed. You should not use
2015-11-26 17:08:26 +00:00
this method.
2013-12-31 16:24:28 +00:00
2015-11-26 17:36:46 +00:00
* The `Symfony\Component\Form\ChoiceList\ArrayKeyChoiceList` class has been removed in
favor of `Symfony\Component\Form\ChoiceList\ArrayChoiceList` .
2013-04-17 17:47:21 +01:00
### FrameworkBundle
2015-05-20 19:01:48 +01:00
* The `config:debug` , `container:debug` , `router:debug` , `translation:debug`
and `yaml:lint` commands have been deprecated since Symfony 2.7 and will
be removed in Symfony 3.0. Use the `debug:config` , `debug:container` ,
`debug:router` , `debug:translation` and `lint:yaml` commands instead.
2013-11-20 15:09:21 +00:00
* The `getRequest` method of the base `Controller` class has been deprecated
since Symfony 2.4 and must be therefore removed in 3.0. The only reliable
way to get the `Request` object is to inject it in the action method.
Before:
2014-11-18 08:38:51 +00:00
```php
2013-11-20 15:09:21 +00:00
namespace Acme\FooBundle\Controller;
class DemoController
{
public function showAction()
{
$request = $this->getRequest();
// ...
}
}
```
After:
2014-11-18 08:38:51 +00:00
```php
2013-11-20 15:09:21 +00:00
namespace Acme\FooBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
class DemoController
{
public function showAction(Request $request)
{
// ...
}
}
```
2016-01-16 18:39:57 +00:00
2015-12-05 09:49:38 +00:00
* 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.
2016-01-16 18:39:57 +00:00
2015-12-05 09:49:38 +00:00
Before:
```php
$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;
},
));
```
2016-01-16 18:39:57 +00:00
2015-12-05 09:49:38 +00:00
After:
2016-01-16 18:39:57 +00:00
2015-12-05 09:49:38 +00:00
```php
$form->add('status', ChoiceType::class, array(
'choices' => array(
'Enabled' => Status::ENABLED,
'Disabled' => Status::DISABLED,
'Ignored' => Status::IGNORED,
)
));
2016-01-16 18:39:57 +00:00
```
2013-11-20 15:09:21 +00:00
2013-10-09 07:28:55 +01:00
* The `request` service was removed. You must inject the `request_stack`
service instead.
2013-04-17 17:47:21 +01:00
* The `enctype` method of the `form` helper was removed. You should use the
new method `start` instead.
Before:
2014-09-26 11:51:50 +01:00
```php
2013-04-17 17:47:21 +01:00
< form method = "post" action = "http://example.com" < ? php echo $ view [ ' form ' ] - > enctype($form) ?>>
...
< / form >
```
After:
2014-09-26 11:51:50 +01:00
```php
2013-04-17 17:47:21 +01:00
<?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:
2014-09-26 11:51:50 +01:00
```php
2013-04-17 17:47:21 +01:00
$form = $this->createForm('my_form', $formData, array(
'method' => 'PUT',
'action' => $this->generateUrl('target_route'),
));
```
Alternative 2:
2014-09-26 11:51:50 +01:00
```php
2013-04-17 17:47:21 +01:00
$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:
2014-09-26 11:51:50 +01:00
```php
2013-04-17 17:47:21 +01:00
<?php echo $view['form']->start($form, array('method' => 'GET', 'action' => 'http://example.com')) ?>
...
<?php echo $view['form']->end($form) ?>
```
2014-01-08 22:03:56 +00:00
* The `RouterApacheDumperCommand` was removed.
2015-05-30 21:40:00 +01:00
* The `templating.helper.router` service was moved to `templating_php.xml` . You
have to ensure that the PHP templating engine is enabled to be able to use it:
```yaml
framework:
templating:
engines: ['php']
```
2015-06-07 11:05:37 +01:00
* The `form.csrf_provider` service is removed as it implements an adapter for
the new token manager to the deprecated
`Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface`
interface.
The `security.csrf.token_manager` should be used instead.
2015-12-03 13:16:45 +00:00
* The `validator.mapping.cache.apc` service has been removed in favor of the `validator.mapping.cache.doctrine.apc` one.
2016-03-08 15:36:29 +00:00
2015-12-03 13:16:45 +00:00
* The ability to pass `apc` as the `framework.validation.cache` configuration key value has been removed.
Use `validator.mapping.cache.doctrine.apc` instead:
Before:
```yaml
framework:
validation:
cache: apc
```
After:
```yaml
framework:
validation:
cache: validator.mapping.cache.doctrine.apc
```
2013-01-16 22:09:43 +00:00
### HttpKernel
* The `Symfony\Component\HttpKernel\Log\LoggerInterface` has been removed in
favor of `Psr\Log\LoggerInterface` . The only difference is that some method
names are different:
2014-11-18 08:38:51 +00:00
| Old name | New name
| -------- | ---
| `emerg()` | `emergency()`
| `crit()` | `critical()`
| `err()` | `error()`
| `warn()` | `warning()`
2013-01-16 22:09:43 +00:00
The previous method renames also happened to the following classes:
2013-01-17 14:01:21 +00:00
* `Symfony\Bridge\Monolog\Logger`
* `Symfony\Component\HttpKernel\Log\NullLogger`
2013-01-16 22:09:43 +00:00
2013-03-20 17:09:46 +00:00
* 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:
2014-11-18 08:38:51 +00:00
| Old name | New name
| -------- | ---
| `Symfony\Component\HttpKernel\Debug\ErrorHandler` | `Symfony\Component\Debug\ErrorHandler`
| `Symfony\Component\HttpKernel\Debug\ExceptionHandler` | `Symfony\Component\Debug\ExceptionHandler`
| `Symfony\Component\HttpKernel\Exception\FatalErrorException` | `Symfony\Component\Debug\Exception\FatalErrorException`
| `Symfony\Component\HttpKernel\Exception\FlattenException` | `Symfony\Component\Debug\Exception\FlattenException`
2013-03-20 17:09:46 +00:00
2013-08-22 04:08:01 +01:00
* The `Symfony\Component\HttpKernel\EventListener\ExceptionListener` now
passes the Request format as the `_format` argument instead of `format` .
2013-12-16 17:44:05 +00:00
* The `Symfony\Component\HttpKernel\DependencyInjection\RegisterListenersPass` has been renamed to
`Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass` and moved to the EventDispatcher component.
2013-04-28 10:04:40 +01:00
### Locale
2013-04-12 16:49:02 +01:00
2013-04-28 10:04:40 +01:00
* 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 in `Symfony\Component\Intl\Intl` now:
2013-09-10 13:28:39 +01:00
2014-11-18 08:38:51 +00:00
| 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())`
2013-04-19 13:16:57 +01:00
2013-04-25 17:28:27 +01:00
### PropertyAccess
* Renamed `PropertyAccess::getPropertyAccessor` to `createPropertyAccessor` .
Before:
2014-09-26 11:51:50 +01:00
```php
2013-04-25 17:28:27 +01:00
use Symfony\Component\PropertyAccess\PropertyAccess;
$accessor = PropertyAccess::getPropertyAccessor();
```
After:
2014-09-26 11:51:50 +01:00
```php
2013-04-25 17:28:27 +01:00
use Symfony\Component\PropertyAccess\PropertyAccess;
$accessor = PropertyAccess::createPropertyAccessor();
```
2013-01-15 07:06:36 +00:00
### Routing
* Some route settings have been renamed:
2016-01-16 18:17:20 +00:00
* The `pattern` setting has been removed in favor of `path`
2013-01-17 14:01:21 +00:00
* The `_scheme` and `_method` requirements have been moved to the `schemes` and `methods` settings
2013-01-15 07:06:36 +00:00
Before:
2014-09-26 11:51:50 +01:00
```yaml
2013-01-15 07:06:36 +00:00
article_edit:
pattern: /article/{id}
requirements: { '_method': 'POST|PUT', '_scheme': 'https', 'id': '\d+' }
2014-09-26 11:51:50 +01:00
```
2013-01-15 07:06:36 +00:00
2014-09-26 11:51:50 +01:00
```xml
2013-01-15 07:06:36 +00:00
< route id = "article_edit" pattern = "/article/{id}" >
< requirement key = "_method" > POST|PUT< / requirement >
< requirement key = "_scheme" > https< / requirement >
< requirement key = "id" > \d+</ requirement >
< / route >
2014-09-26 11:51:50 +01:00
```
2013-01-15 07:06:36 +00:00
2014-09-26 11:51:50 +01:00
```php
2013-01-15 07:06:36 +00:00
$route = new Route();
$route->setPattern('/article/{id}');
$route->setRequirement('_method', 'POST|PUT');
$route->setRequirement('_scheme', 'https');
```
After:
2014-09-26 11:51:50 +01:00
```yaml
2013-01-15 07:06:36 +00:00
article_edit:
path: /article/{id}
methods: [POST, PUT]
schemes: https
requirements: { 'id': '\d+' }
2014-09-26 11:51:50 +01:00
```
2013-01-15 07:06:36 +00:00
2014-09-26 11:51:50 +01:00
```xml
2013-01-15 18:31:20 +00:00
< route id = "article_edit" path = "/article/{id}" methods = "POST PUT" schemes = "https" >
2013-01-15 07:06:36 +00:00
< requirement key = "id" > \d+</ requirement >
< / route >
2014-09-26 11:51:50 +01:00
```
2013-01-15 07:06:36 +00:00
2014-09-26 11:51:50 +01:00
```php
2013-01-15 07:06:36 +00:00
$route = new Route();
$route->setPath('/article/{id}');
$route->setMethods(array('POST', 'PUT'));
$route->setSchemes('https');
```
2013-01-17 14:01:21 +00:00
2014-01-08 22:03:56 +00:00
* The `ApacheMatcherDumper` and `ApacheUrlMatcher` were removed since
the performance gains were minimal and it's hard to replicate the behaviour
of PHP implementation.
2016-01-16 18:17:20 +00:00
* The `getMatcherDumperInstance()` and `getGeneratorDumperInstance()` methods in the
`Symfony\Component\Routing\Router` have been changed from `public` to `protected` .
2016-06-17 09:10:27 +01:00
* Use the constants defined in the UrlGeneratorInterface for the $referenceType argument of the UrlGeneratorInterface::generate method.
Before:
```php
// 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:
```php
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);
```
2013-09-18 08:24:07 +01:00
### Security
* The `Resources/` directory was moved to `Core/Resources/`
2015-11-07 17:29:53 +00:00
* The `key` settings of `anonymous` , `remember_me` and `http_digest` are
renamed to `secret` .
2015-06-29 12:59:59 +01:00
Before:
```yaml
security:
# ...
firewalls:
default:
# ...
anonymous: { key: "%secret%" }
remember_me:
key: "%secret%"
2015-11-07 17:29:53 +00:00
http_digest:
key: "%secret%"
2015-06-29 12:59:59 +01:00
```
```xml
<!-- ... -->
< config >
<!-- ... -->
< firewall >
<!-- ... -->
< anonymous key = "%secret%" / >
< remember-me key = "%secret%" / >
2015-11-07 17:29:53 +00:00
< http-digest key = "%secret%" / >
2015-06-29 12:59:59 +01:00
< / firewall >
< / config >
```
```php
// ...
$container->loadFromExtension('security', array(
// ...
'firewalls' => array(
// ...
'anonymous' => array('key' => '%secret%'),
'remember_me' => array('key' => '%secret%'),
2015-11-07 17:29:53 +00:00
'http_digest' => array('key' => '%secret%'),
2015-06-29 12:59:59 +01:00
),
));
```
After:
```yaml
security:
# ...
firewalls:
default:
# ...
anonymous: { secret: "%secret%" }
remember_me:
secret: "%secret%"
2015-11-07 17:29:53 +00:00
http_digest:
secret: "%secret%"
2015-06-29 12:59:59 +01:00
```
```xml
<!-- ... -->
< config >
<!-- ... -->
< firewall >
<!-- ... -->
< anonymous secret = "%secret%" / >
< remember-me secret = "%secret%" / >
2015-11-07 17:29:53 +00:00
< http-digest secret = "%secret%" / >
2015-06-29 12:59:59 +01:00
< / firewall >
< / config >
```
```php
// ...
$container->loadFromExtension('security', array(
// ...
'firewalls' => array(
// ...
'anonymous' => array('secret' => '%secret%'),
'remember_me' => array('secret' => '%secret%'),
2015-11-07 17:29:53 +00:00
'http_digest' => array('secret' => '%secret%'),
2015-06-29 12:59:59 +01:00
),
));
```
2016-01-23 22:43:00 +00:00
* The `AbstractVoter` class was removed. Instead, extend the new `Voter` class,
introduced in 2.8, and move your voting logic to the to the `supports($attribute, $subject)`
and `voteOnAttribute($attribute, $object, TokenInterface $token)` methods.
* The `vote()` method from the `VoterInterface` was changed to now accept arbitrary
types, and not only objects.
* The `supportsClass` and `supportsAttribute` methods were
removed from the `VoterInterface` interface.
2015-06-30 13:43:35 +01:00
Before:
```php
class MyVoter extends AbstractVoter
{
protected function getSupportedAttributes()
{
return array('CREATE', 'EDIT');
}
protected function getSupportedClasses()
{
return array('AppBundle\Entity\Post');
}
// ...
}
```
After:
```php
2016-01-23 22:43:00 +00:00
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
2016-03-08 15:36:29 +00:00
2016-01-23 22:43:00 +00:00
class MyVoter extends Voter
2015-06-30 13:43:35 +01:00
{
2015-10-04 10:03:28 +01:00
protected function supports($attribute, $object)
2015-06-30 13:43:35 +01:00
{
2015-10-04 10:03:28 +01:00
return $object instanceof Post & & in_array($attribute, array('CREATE', 'EDIT'));
2015-06-30 13:43:35 +01:00
}
2016-01-23 22:43:00 +00:00
protected function voteOnAttribute($attribute, $object, TokenInterface $token)
{
// Return true or false
}
2015-06-30 13:43:35 +01:00
}
```
2016-05-31 20:30:07 +01:00
* The `AbstractVoter::isGranted()` method has been replaced by `Voter::voteOnAttribute()` .
Before:
```php
class MyVoter extends AbstractVoter
{
protected function isGranted($attribute, $object, $user = null)
{
return 'EDIT' === $attribute & & $user === $object->getAuthor();
}
// ...
}
```
After:
```php
class MyVoter extends Voter
{
protected function voteOnAttribute($attribute, $object, TokenInterface $token)
{
return 'EDIT' === $attribute & & $token->getUser() === $object->getAuthor();
}
// ...
}
```
* The `supportsAttribute()` and `supportsClass()` methods of the `AuthenticatedVoter` , `ExpressionVoter` ,
and `RoleVoter` classes have been removed.
2016-01-16 16:20:11 +00:00
* The `intention` option was renamed to `csrf_token_id` for all the authentication listeners.
* The `csrf_provider` option was renamed to `csrf_token_generator` for all the authentication listeners.
### SecurityBundle
* The `intention` firewall listener setting was renamed to `csrf_token_id` .
* The `csrf_provider` firewall listener setting was renamed to `csrf_token_generator` .
2016-01-16 18:17:20 +00:00
### Serializer
* The `setCamelizedAttributes()` method of the
`Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer` and
`Symfony\Component\Serializer\Normalizer\PropertyNormalizer` classes
was removed.
* The `Symfony\Component\Serializer\Exception\Exception` interface was removed
in favor of the new `Symfony\Component\Serializer\Exception\ExceptionInterface` .
2013-02-17 17:30:02 +00:00
### Translator
* The `Translator::setFallbackLocale()` method has been removed in favor of
`Translator::setFallbackLocales()` .
2016-01-16 18:39:57 +00:00
* The `getMessages()` method of the `Symfony\Component\Translation\Translator`
class was removed. You should use the `getCatalogue()` method of the
`Symfony\Component\Translation\TranslatorBagInterface` .
2013-01-28 17:29:00 +00:00
### Twig Bridge
2015-05-20 19:01:48 +01:00
* The `twig:lint` command has been deprecated since Symfony 2.7 and will be
removed in Symfony 3.0. Use the `lint:twig` command instead.
2013-01-28 17:29:00 +00:00
* The `render` tag is deprecated in favor of the `render` function.
2013-04-17 17:47:21 +01:00
* The `form_enctype` helper was removed. You should use the new `form_start`
function instead.
Before:
2014-09-26 11:51:50 +01:00
```php
2013-04-17 17:47:21 +01:00
< form method = "post" action = "http://example.com" { { form_enctype ( form ) } } >
...
< / form >
```
After:
2014-09-26 11:51:50 +01:00
```jinja
2013-04-17 17:47:21 +01:00
{{ 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:
2014-09-26 11:51:50 +01:00
```php
2013-04-17 17:47:21 +01:00
$form = $this->createForm('my_form', $formData, array(
'method' => 'PUT',
'action' => $this->generateUrl('target_route'),
));
```
Alternative 2:
2014-09-26 11:51:50 +01:00
```php
2013-04-17 17:47:21 +01:00
$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:
2014-09-26 11:51:50 +01:00
```jinja
2013-04-17 17:47:21 +01:00
{{ form_start(form, {'method': 'GET', 'action': 'http://example.com'}) }}
...
{{ form_end(form) }}
```
2015-05-20 19:01:48 +01:00
### TwigBundle
2016-01-16 18:17:20 +00:00
* The `Symfony\Bundle\TwigBundle\TwigDefaultEscapingStrategy` was removed
in favor of `Twig_FileExtensionEscapingStrategy` .
2015-05-20 19:01:48 +01:00
* The `twig:debug` command has been deprecated since Symfony 2.7 and will be
removed in Symfony 3.0. Use the `debug:twig` command instead.
2013-04-17 17:02:12 +01:00
### Validator
2016-01-16 18:17:20 +00:00
* The PHP7-incompatible constraints (`Null`, `True` , `False` ) and their related
validators (`NullValidator`, `TrueValidator` , `FalseValidator` ) have been
removed in favor of their `Is` -prefixed equivalent.
2013-12-29 20:44:38 +00:00
* The class `Symfony\Component\Validator\Mapping\Cache\ApcCache` has been removed in favor
of `Symfony\Component\Validator\Mapping\Cache\DoctrineCache` .
Before:
2014-11-18 08:38:51 +00:00
```php
2013-12-29 20:44:38 +00:00
use Symfony\Component\Validator\Mapping\Cache\ApcCache;
$cache = new ApcCache('symfony.validator');
```
After:
2014-11-18 08:38:51 +00:00
```php
2013-12-29 20:44:38 +00:00
use Symfony\Component\Validator\Mapping\Cache\DoctrineCache;
use Doctrine\Common\Cache\ApcCache;
$apcCache = new ApcCache();
$apcCache->setNamespace('symfony.validator');
$cache = new DoctrineCache($apcCache);
```
2013-04-17 17:02:12 +01:00
* The constraints `Optional` and `Required` were moved to the
`Symfony\Component\Validator\Constraints\` namespace. You should adapt
the path wherever you used them.
Before:
2014-09-26 11:51:50 +01:00
```php
2013-04-17 17:02:12 +01:00
use Symfony\Component\Validator\Constraints as Assert;
/**
* @Assert \Collection({
* "foo" = @Assert \Collection\Required(),
* "bar" = @Assert \Collection\Optional(),
* })
*/
private $property;
```
After:
2014-09-26 11:51:50 +01:00
```php
2013-04-17 17:02:12 +01:00
use Symfony\Component\Validator\Constraints as Assert;
/**
* @Assert \Collection({
* "foo" = @Assert \Required(),
* "bar" = @Assert \Optional(),
* })
*/
private $property;
```
2013-04-28 10:04:40 +01:00
2014-11-18 08:38:51 +00:00
* The option "`methods`" of the `Callback` constraint was removed. You should
use the option "`callback`" instead. If you have multiple callbacks, add
2013-09-26 10:03:13 +01:00
multiple callback constraints instead.
Before (YAML):
2014-11-18 08:38:51 +00:00
```yaml
2013-09-26 10:03:13 +01:00
constraints:
- Callback: [firstCallback, secondCallback]
```
After (YAML):
2014-11-18 08:38:51 +00:00
```yaml
2013-09-26 10:03:13 +01:00
constraints:
- Callback: firstCallback
- Callback: secondCallback
```
2014-11-18 08:38:51 +00:00
When using annotations, you can now put the `Callback` constraint directly on
2013-09-26 10:03:13 +01:00
the method that should be executed.
Before (Annotations):
2014-11-18 08:38:51 +00:00
```php
2013-09-26 10:03:13 +01:00
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\ExecutionContextInterface;
/**
* @Assert \Callback({"callback"})
*/
class MyClass
{
public function callback(ExecutionContextInterface $context)
{
// ...
}
}
```
After (Annotations):
2014-11-18 08:38:51 +00:00
```php
2013-09-26 10:03:13 +01:00
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\ExecutionContextInterface;
class MyClass
{
/**
* @Assert \Callback
*/
public function callback(ExecutionContextInterface $context)
{
// ...
}
}
```
2014-03-30 19:03:32 +01:00
* The interface `ValidatorInterface` was replaced by the more powerful
interface `Validator\ValidatorInterface` . The signature of the `validate()`
method is slightly different in that interface and accepts a value, zero
or more constraints and validation group. It replaces both
`validate()` and `validateValue()` in the previous interface.
Before:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
$validator->validate($object, 'Strict');
$validator->validateValue($value, new NotNull());
```
After:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
$validator->validate($object, null, 'Strict');
$validator->validate($value, new NotNull());
```
Apart from this change, the new methods `startContext()` and `inContext()`
were added. The first of them allows to run multiple validations in the
same context and aggregate their violations:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
$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:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
$validator->inContext($context)->validate($object);
```
Instead of a `Validator` , the validator builder now returns a
`Validator\RecursiveValidator` instead.
* The interface `ValidationVisitorInterface` and its implementation
`ValidationVisitor` were 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 from
`MetadataInterface` .
* The interface `MetadataInterface` was moved to the `Mapping` namespace.
Before:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
use Symfony\Component\Validator\MetadataInterface;
```
After:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
use Symfony\Component\Validator\Mapping\MetadataInterface;
```
The methods `getCascadingStrategy()` and `getTraversalStrategy()` were
added to the interface. The first method should return a bit mask of the
constants in class `CascadingStrategy` . The second should return a bit
mask of the constants in `TraversalStrategy` .
Example:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
use Symfony\Component\Validator\Mapping\TraversalStrategy;
public function getTraversalStrategy()
{
return TraversalStrategy::TRAVERSE;
}
```
* The interface `PropertyMetadataInterface` was moved to the `Mapping`
namespace.
Before:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
use Symfony\Component\Validator\PropertyMetadataInterface;
```
After:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
use Symfony\Component\Validator\Mapping\PropertyMetadataInterface;
```
* The interface `PropertyMetadataContainerInterface` was moved to the `Mapping`
namespace and renamed to `ClassMetadataInterface` .
Before:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
use Symfony\Component\Validator\PropertyMetadataContainerInterface;
```
After:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
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 `ClassBasedInterface` was removed. You should use
`Mapping\ClassMetadataInterface` instead:
Before:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
use Symfony\Component\Validator\ClassBasedInterface;
class MyClassMetadata implements ClassBasedInterface
{
// ...
}
```
After:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
use Symfony\Component\Validator\Mapping\ClassMetadataInterface;
class MyClassMetadata implements ClassMetadataInterface
{
// ...
}
```
* The class `ElementMetadata` was renamed to `GenericMetadata` .
Before:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
use Symfony\Component\Validator\Mapping\ElementMetadata;
class MyMetadata extends ElementMetadata
{
}
```
After:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
use Symfony\Component\Validator\Mapping\GenericMetadata;
class MyMetadata extends GenericMetadata
{
}
```
* The interface `ExecutionContextInterface` and its implementation
`ExecutionContext` were moved to the `Context` namespace.
Before:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
use Symfony\Component\Validator\ExecutionContextInterface;
```
After:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
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 use `buildViolation()`
instead.
Before:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
$context->addViolationAt('property', 'The value {{ value }} is invalid.', array(
'{{ value }}' => $invalidValue,
));
```
After:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
$context->buildViolation('The value {{ value }} is invalid.')
->atPath('property')
->setParameter('{{ value }}', $invalidValue)
->addViolation();
```
The methods `validate()` and `validateValue()` were removed. You should use
`getValidator()` together with `inContext()` instead.
Before:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
$context->validate($object);
```
After:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
$context->getValidator()
->inContext($context)
->validate($object);
```
The parameters `$invalidValue` , `$plural` and `$code` were removed from
`addViolation()` . You should use `buildViolation()` instead. See above for
an example.
The method `getMetadataFactory()` was removed. You can use `getValidator()`
instead and use the methods `getMetadataFor()` or `hasMetadataFor()` on the
validator instance.
Before:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
$metadata = $context->getMetadataFactory()->getMetadataFor($myClass);
```
After:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
$metadata = $context->getValidator()->getMetadataFor($myClass);
```
* The interface `GlobalExecutionContextInterface` was removed. Most of the
information provided by that interface can be queried from
`Context\ExecutionContextInterface` instead.
* The interface `MetadataFactoryInterface` was moved to the `Mapping\Factory`
namespace along with its implementations `BlackholeMetadataFactory` and
`ClassMetadataFactory` . These classes were furthermore renamed to
`BlackHoleMetadataFactory` and `LazyLoadingMetadataFactory` .
Before:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
use Symfony\Component\Validator\Mapping\ClassMetadataFactory;
$factory = new ClassMetadataFactory($loader);
```
After:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
$factory = new LazyLoadingMetadataFactory($loader);
```
* The option `$deep` was removed from the constraint `Valid` . 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()` and `getMessagePluralization()` in
`ConstraintViolation` were renamed to `getParameters()` and `getPlural()` .
Before:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
$parameters = $violation->getMessageParameters();
$plural = $violation->getMessagePluralization();
```
After:
2014-11-18 08:38:51 +00:00
```php
2014-03-30 19:03:32 +01:00
$parameters = $violation->getParameters();
$plural = $violation->getPlural();
```
2015-01-04 17:59:57 +00:00
* The class `Symfony\Component\Validator\DefaultTranslator` was removed. You
should use `Symfony\Component\Translation\IdentityTranslator` instead.
Before:
```php
$translator = new \Symfony\Component\Validator\DefaultTranslator();
```
After:
```php
$translator = new \Symfony\Component\Translation\IdentityTranslator();
$translator->setLocale('en');
```
2013-04-28 10:04:40 +01:00
### Yaml
2015-11-24 20:31:58 +00:00
* Using a colon in an unquoted mapping value leads to a `ParseException` .
* Starting an unquoted string with `@` , `` ` ``, ` |`, or `>` leads to a `ParseException` .
2015-11-25 12:40:04 +00:00
* When surrounding strings with double-quotes, you must now escape `\` characters. Not
escaping those characters (when surrounded by double-quotes) leads to a `ParseException` .
Before:
```yml
class: "Foo\Var"
```
After:
```yml
class: "Foo\\Var"
```
2015-11-24 20:31:58 +00:00
2013-04-28 10:04:40 +01:00
* The ability to pass file names to `Yaml::parse()` has been removed.
Before:
2014-09-26 11:51:50 +01:00
```php
2013-04-28 10:04:40 +01:00
Yaml::parse($fileName);
```
After:
2014-09-26 11:51:50 +01:00
```php
2013-04-28 10:04:40 +01:00
Yaml::parse(file_get_contents($fileName));
2014-10-12 17:43:03 +01:00
```
2014-05-17 19:36:38 +01:00
2016-01-16 18:39:57 +00:00
### WebProfiler
2016-05-19 20:50:23 +01:00
* The `profiler:import` and `profiler:export` commands have been removed.
2016-01-16 18:39:57 +00:00
* All the profiler storages different than `FileProfilerStorage` have been
removed. The removed classes are:
- `Symfony\Component\HttpKernel\Profiler\BaseMemcacheProfilerStorage`
- `Symfony\Component\HttpKernel\Profiler\MemcachedProfilerStorage`
- `Symfony\Component\HttpKernel\Profiler\MemcacheProfilerStorage`
- `Symfony\Component\HttpKernel\Profiler\MongoDbProfilerStorage`
- `Symfony\Component\HttpKernel\Profiler\MysqlProfilerStorage`
- `Symfony\Component\HttpKernel\Profiler\PdoProfilerStorage`
- `Symfony\Component\HttpKernel\Profiler\RedisProfilerStorage`
- `Symfony\Component\HttpKernel\Profiler\SqliteProfilerStorage`
2014-05-17 19:36:38 +01:00
### Process
2014-11-18 08:38:51 +00:00
* `Process::setStdin()` and `Process::getStdin()` have been removed. Use
`Process::setInput()` and `Process::getInput()` that works the same way.
* `Process::setInput()` and `ProcessBuilder::setInput()` do not accept non-scalar types.
2016-03-08 15:36:29 +00:00
### HttpFoundation
* Removed the feature that allowed finding deep items in `ParameterBag::get()` .
This may affect you when getting parameters from the `Request` class:
Before:
```php
$request->query->get('foo[bar]', null, true);
```
After:
```php
$request->query->get('foo')[bar];
```