summaryrefslogtreecommitdiff
path: root/UPGRADE-2.7.md
blob: 5de67ebede36ce24fb3d661f80741c48078a5024 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
UPGRADE FROM 2.6 to 2.7
=======================

Global
------

 * Deprecation notices -
   `@trigger_error('... is deprecated ...', E_USER_DEPRECATED)` -
   are now triggered when using any deprecated functionality.

   By default these notices are silenced, so they won't appear in the PHP logs of
   your production server. However, these notices are still visible in the web
   debug toolbar, so you can know where your code needs an upgrade.

   In addition, it's strongly recommended to enable the [phpunit-bridge](https://github.com/symfony/phpunit-bridge)
   so that you can deal with deprecation notices in your test suite.

Router
------

 * Route conditions now support container parameters which
   can be injected into condition using `%parameter%` notation.
   Due to the fact that it works by replacing all parameters
   with their corresponding values before passing condition
   expression for compilation there can be BC breaks where you
   could already have used percentage symbols. Single percentage symbol
   usage is not affected in any way. Conflicts may occur where
   you might have used `%` as a modulo operator, here's an example:
   `foo%bar%2` which would be compiled to `$foo % $bar % 2` in 2.6
   but in 2.7 you would get an error if `bar` parameter
   doesn't exist or unexpected result otherwise.

 * The `getMatcherDumperInstance()` and `getGeneratorDumperInstance()` methods in the
   `Symfony\Component\Routing\Router` have been changed from `protected` to `public`.
   If you override these methods in a subclass, you will need to change your 
   methods to `public` as well. Note however that this is a temporary change needed for
   PHP 5.3 compatibility only. It will be reverted in Symfony 3.0.
 
Form
----

 * In form types and extension overriding the "setDefaultOptions" of the
   AbstractType or AbstractExtensionType has been deprecated in favor of
   overriding the new "configureOptions" method.

   The method "setDefaultOptions(OptionsResolverInterface $resolver)" will
   be renamed in Symfony 3.0 to "configureOptions(OptionsResolver $resolver)".

   Before:

   ```php
    use Symfony\Component\OptionsResolver\OptionsResolverInterface;

    class TaskType extends AbstractType
    {
        // ...
        public function setDefaultOptions(OptionsResolverInterface $resolver)
        {
            $resolver->setDefaults(array(
                'data_class' => 'AppBundle\Entity\Task',
            ));
        }
    }
   ```

   After:

   ```php
    use Symfony\Component\OptionsResolver\OptionsResolver;

    class TaskType extends AbstractType
    {
        // ...
        public function configureOptions(OptionsResolver $resolver)
        {
            $resolver->setDefaults(array(
                'data_class' => 'AppBundle\Entity\Task',
            ));
        }
    }
   ```

 * The "choice_list" option of ChoiceType was deprecated. You should use
   "choices_as_values" or "choice_loader" now.

   Before:

   ```php
   $form->add('status', 'choice', array(
       'choice_list' => new ObjectChoiceList(array(
           Status::getInstance(Status::ENABLED),
           Status::getInstance(Status::DISABLED),
           Status::getInstance(Status::IGNORED),
       )),
   ));
   ```

   After:

   ```php
   $form->add('status', 'choice', array(
       'choices' => array(
           Status::getInstance(Status::ENABLED),
           Status::getInstance(Status::DISABLED),
           Status::getInstance(Status::IGNORED),
       ),
       'choices_as_values' => true,
   ));
   ```

 * You should flip the keys and values of the "choices" option in ChoiceType
   and set the "choices_as_values" option to `true`. The default value of that
   option will be switched to `true` in Symfony 3.0.

   Before:

   ```php
   $form->add('status', 'choice', array(
       'choices' => array(
           Status::ENABLED => 'Enabled',
           Status::DISABLED => 'Disabled',
           Status::IGNORED => 'Ignored',
       )),
   ));
   ```

   After:

   ```php
   $form->add('status', 'choice', array(
       'choices' => array(
           'Enabled' => Status::ENABLED,
           'Disabled' => Status::DISABLED,
           'Ignored' => Status::IGNORED,
       ),
       '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;
       },
   ));
   ```

 * `Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface` was
   deprecated and will be removed in Symfony 3.0. You should use
   `Symfony\Component\Form\ChoiceList\ChoiceListInterface` instead.

   Before:

   ```php
   use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;

   public function doSomething(ChoiceListInterface $choiceList)
   {
       // ...
   }
   ```

   After:

   ```php
   use Symfony\Component\Form\ChoiceList\ChoiceListInterface;

   public function doSomething(ChoiceListInterface $choiceList)
   {
       // ...
   }
   ```

 * `Symfony\Component\Form\Extension\Core\View\ChoiceView` was
   deprecated and will be removed in Symfony 3.0. You should use
   `Symfony\Component\Form\ChoiceList\View\ChoiceView` instead.
   The constructor arguments of the new class are in the same order than in the
   deprecated one (this was not true in 2.7.0 but has been fixed in 2.7.1).

 * `Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList` was
   deprecated and will be removed in Symfony 3.0. You should use
   `Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory` instead.

   Before:

   ```php
   use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;

   $choiceList = new ChoiceList(
       array(Status::ENABLED, Status::DISABLED, Status::IGNORED),
       array('Enabled', 'Disabled', 'Ignored'),
       // Preferred choices
       array(Status::ENABLED),
   );
   ```

   After:

   ```php
   use Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory;

   $factory = new DefaultChoiceListFactory();

   $choices = array(Status::ENABLED, Status::DISABLED, Status::IGNORED);
   $labels = array('Enabled', 'Disabled', 'Ignored');

   $choiceList = $factory->createListFromChoices($choices);

   $choiceListView = $factory->createView(
       $choiceList,
       // Preferred choices
       array(Status::ENABLED),
       // Labels
       function ($choice, $key) use ($labels) {
           return $labels[$key];
       }
   );
   ```

 * `Symfony\Component\Form\Extension\Core\ChoiceList\LazyChoiceList` was
   deprecated and will be removed in Symfony 3.0. You should use
   `Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory::createListFromLoader()`
   together with an implementation of
   `Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface` instead.

   Before:

   ```php
   use Symfony\Component\Form\Extension\Core\ChoiceList\LazyChoiceList;

   class MyLazyChoiceList extends LazyChoiceList
   {
       public function loadChoiceList()
       {
           // load $choiceList

           return $choiceList;
       }
   }

   $choiceList = new MyLazyChoiceList();
   ```

   After:

   ```php
   use Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory;
   use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;

   class MyChoiceLoader implements ChoiceLoaderInterface
   {
       // ...
   }

   $factory = new DefaultChoiceListFactory();

   $choiceList = $factory->createListFromLoader(new MyChoiceLoader());
   ```

 * `Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList` was
   deprecated and will be removed in Symfony 3.0. You should use
   `Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory` instead.

   Before:

   ```php
   use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList;

   $choiceList = new ObjectChoiceList(
       array(Status::getInstance(Status::ENABLED), Status::getInstance(Status::DISABLED)),
       // Label property
       'name'
   );
   ```

   After:

   ```php
   use Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory;

   $factory = new DefaultChoiceListFactory();

   $choiceList = $factory->createListFromChoices(array(
       Status::getInstance(Status::ENABLED),
       Status::getInstance(Status::DISABLED),
   ));

   $choiceListView = $factory->createView(
       $choiceList,
       // Preferred choices
       array(),
       // Label property
       'name'
   );
   ```

 * `Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList` was
   deprecated and will be removed in Symfony 3.0. You should use
   `Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory` instead.

   Before:

   ```php
   use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;

   $choiceList = new SimpleChoiceList(array(
       Status::ENABLED => 'Enabled',
       Status::DISABLED => 'Disabled',
   ));
   ```

   After:

   ```php
   use Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory;

   $factory = new DefaultChoiceListFactory();

   $choices = array(Status::ENABLED, Status::DISABLED);
   $labels = array('Enabled', 'Disabled');

   $choiceList = $factory->createListFromChoices($choices);

   $choiceListView = $factory->createView(
       $choiceList,
       // Preferred choices
       array(),
       // Label
       function ($choice, $key) use ($labels) {
           return $labels[$key];
       }
   );
   ```

 * The "property" option of `DoctrineType` was deprecated. You should use the
   new inherited option "choice_label" instead, which has the same effect.

   Before:

   ```php
   $form->add('tags', 'entity', array(
       'class' => 'Acme\Entity\MyTag',
       'property' => 'name',
   ))
   ```

   After:

   ```php
   $form->add('tags', 'entity', array(
       'class' => 'Acme\Entity\MyTag',
       'choice_label' => 'name',
   ))
   ```

 * The "loader" option of `DoctrineType` was deprecated and will be removed in
   Symfony 3.0. You should override the `getLoader()` method instead in a custom
   type.

   Before:

   ```php
   $form->add('tags', 'entity', array(
       'class' => 'Acme\Entity\MyTag',
       'loader' => new MyEntityLoader(),
   ))
   ```

   After:

   ```php
   class MyEntityType extends DoctrineType
   {
       // ...

       public function getLoader()
       {
           return new MyEntityLoader();
       }
   }
   ```

 * `Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList` was
   deprecated and will be removed in Symfony 3.0. You should use
   `Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader` instead.

   Before:

   ```php
   use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;

   $choiceList = new EntityChoiceList($em, 'Acme\Entity\MyEntity');
   ```

   After:

   ```php
   use Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory;

   $factory = new DefaultChoiceListFactory();

   $choices = array(Status::ENABLED, Status::DISABLED);
   $labels = array('Enabled', 'Disabled');

   $choiceLoader = new DoctrineChoiceLoader($factory, $em, 'Acme\Entity\MyEntity');
   $choiceList = $factory->createListFromLoader($choiceLoader);
   ```

 * Passing a query builder closure to `ORMQueryBuilderLoader` was deprecated and
   will not be supported anymore in Symfony 3.0. You should pass resolved query
   builders only.

   Consequently, the arguments `$manager` and `$class` of `ORMQueryBuilderLoader`
   have been deprecated 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.

   Before:

   ```php
   use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;

   $queryBuilder = function () {
       // return QueryBuilder
   };
   $loader = new ORMQueryBuilderLoader($queryBuilder);
   ```

   After:

   ```php
   use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;

   // create $queryBuilder
   $loader = new ORMQueryBuilderLoader($queryBuilder);
   ```

 * The classes `ChoiceToBooleanArrayTransformer`,
   `ChoicesToBooleanArrayTransformer`, `FixRadioInputListener` and
   `FixCheckboxInputListener` were deprecated and will be removed in Symfony 3.0.
   Their functionality is covered by the new classes `RadioListMapper` and
   `CheckboxListMapper`.

 * The ability to translate Doctrine type entries by the translator component
   is now disabled by default and to enable it you must explicitly set the option
   "choice_translation_domain" to true

   Before:

   ```php
   $form->add('products', 'entity', array(
       'class' => 'AppBundle/Entity/Product',
   ));
   ```

   After:

   ```php
   $form->add('products', 'entity', array(
       'class' => 'AppBundle/Entity/Product',
       'choice_translation_domain' => true,
   ));
   ```

 * In the block `choice_widget_options` the `translation_domain` has been replaced
   with the `choice_translation_domain` option.

   Before:

   ```jinja
   {{ choice.label|trans({}, translation_domain) }}
   ```

   After:

   ```jinja
   {{ choice_translation_domain is same as(false) ? choice.label : choice.label|trans({}, choice_translation_domain) }}
   ```

Serializer
----------

 * The `setCamelizedAttributes()` method of the
   `Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer` and
   `Symfony\Component\Serializer\Normalizer\PropertyNormalizer` classes is marked
   as deprecated in favor of the new NameConverter system.

   Before:

   ```php
   $normalizer->setCamelizedAttributes(array('foo_bar', 'bar_foo'));
   ```

   After:

   ```php
   use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
   use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;

   $nameConverter = new CamelCaseToSnakeCaseNameConverter(array('fooBar', 'barFoo'));
   $normalizer = new GetSetMethodNormalizer(null, $nameConverter);
   ```

 * `Symfony\Component\Serializer\Exception\ExceptionInterface` is the new name for the now
   deprecated `Symfony\Component\Serializer\Exception\Exception` interface.

PropertyAccess
--------------

 * `UnexpectedTypeException` now expects three constructor arguments: The invalid property value,
   the `PropertyPathInterface` object and the current index of the property path.

   Before:

   ```php
        use Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException;

        new UnexpectedTypeException($value, $expectedType);
   ```

   After:

   ```php
        use Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException;

        new UnexpectedTypeException($value, $path, $pathIndex);
   ```

Config
------

 * The `__toString()` method of the `\Symfony\Component\Config\ConfigCache` is marked as 
   deprecated in favor of the new `getPath()` method.
   
Validator
---------

 * The PHP7-incompatible constraints (Null, True, False) and related validators
   (NullValidator, TrueValidator, FalseValidator) are marked as deprecated
   in favor of their `Is`-prefixed equivalent.

Console
-------

 * The `Symfony\Component\Console\Input\InputDefinition::getSynopsis()` method
   now has an optional argument (it previously had no arguments). If you override
   this method, you'll need to add this argument so that your signature matches:

   Before:

   ```php
   public function getSynopsis()
   {
       // ...
   }
   ```

   After:

   ```php
   public function getSynopsis($short = false)
   {
       // ...
   }
   ```

TwigBundle
----------

 * The `Symfony\Bundle\TwigBundle\TwigDefaultEscapingStrategy` is deprecated and no longer
   used in favor of `Twig_FileExtensionEscapingStrategy`. This means that CSS files automatically
   use the CSS escape strategy. This can cause different behaviour when outputting reserved
   characters.

   Before:

   ```css
   {# styles.css.twig #}

   {# with brand_color: '#123456' #}
   body {
       background: {{ brand_color }};
   }
   ```

   After:

   ```css
   {# styles.css.twig #}

   {# with brand_color: '#123456' #}
   body {
       background: {{ brand_color|raw }};
   }
   ```

FrameworkBundle
---------------

 * The `templating.helper.assets` service was refactored and now returns an object of type
   `Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper` instead of
   `Symfony\Component\Templating\Helper\CoreAssetsHelper`. You can update your class definition
   or use the `assets.packages` service instead. Using the `assets.packages` service is the recommended 
   way.

   Before:

   ```php
   use Symfony\Component\Templating\Helper\CoreAssetsHelper;

   class DemoService
   {
       private $assetsHelper;

       public function __construct(CoreAssetsHelper $assetsHelper)
       {
           $this->assetsHelper = $assetsHelper;
       }

       public function testMethod()
       {
           return $this->assetsHelper->getUrl('thumbnail.png', null, $this->assetsHelper->getVersion());
       }
   }
   ```

   After:

   ```php
   use Symfony\Component\Asset\Packages;

   class DemoService
   {
       private $assetPackages;

       public function __construct(Packages $assetPackages)
       {
           $this->assetPackages = $assetPackages;
       }

       public function testMethod()
       {
           return $this->assetPackages->getUrl('thumbnail.png').$this->assetPackages->getVersion();
       }
   }
   ```

Security
---------------

 * Injection of the `security.context` service has been reduced to a bare minimum. This means
   that arguments that once hinted `SecurityContext` or `SecurityContextInterface` will have
   to be updated accordingly to either the `TokenStorageInterface` or `AuthorizationCheckerInterface`.
   The following classes now require the `security.token_storage` service instead of the `security.context`,
   please update your extending implementations accordingly.

    * `AbstractAuthenticationListener`
    * `AnonymousAuthenticationListener`
    * `ContextListener`
    * `SimplePreAuthenticationListener`
    * `X509AuthenticationListener`
    * `RemoteUserAuthenticationListener`
    * `BasicAuthenticationListener`
    * `DigestAuthenticationListener`
    * `ExceptionListener`
    * `SwitchUserListener`
    * `AccessListener`
    * `RememberMeListener`

UPGRADE FROM 2.7.1 to 2.7.2
===========================

Form
----

 * In order to fix a few regressions in the new `ChoiceList` implementation,
   a few details had to be changed compared to 2.7.
   
   The legacy `Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface` 
   now does not extend the new `Symfony\Component\Form\ChoiceList\ChoiceListInterface`
   anymore. If you pass an implementation of the old interface in a context
   where the new interface is required, wrap the list into a
   `LegacyChoiceListAdapter`:
   
   Before:
   
   ```php
   use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
   
   function doSomething(ChoiceListInterface $choiceList)
   {
       // ...
   }
   
   doSomething($legacyList);
   ```
   
   After:
   
   ```php
   use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
   use Symfony\Component\Form\ChoiceList\LegacyChoiceListAdapter;
   
   function doSomething(ChoiceListInterface $choiceList)
   {
       // ...
   }
   
   doSomething(new LegacyChoiceListAdapter($legacyList));
   ```
   
   The new `ChoiceListInterface` now has two additional methods
   `getStructuredValues()` and `getOriginalKeys()`. You should add these methods
   if you implement this interface. See their doc blocks and the implementation
   of the core choice lists for inspiration.
   
   The method `ArrayKeyChoiceList::toArrayKey()` was marked as internal. This
   method was never supposed to be used outside the class.
   
   The method `ChoiceListFactoryInterface::createView()` does not accept arrays
   and `Traversable` instances anymore for the `$groupBy` parameter. Pass a
   callable instead.