diff --git a/UPGRADE-2.1.md b/UPGRADE-2.1.md index ecb2a18af809a..ebf556b4a1171 100644 --- a/UPGRADE-2.1.md +++ b/UPGRADE-2.1.md @@ -40,7 +40,7 @@ Before: - ``` + ```yml framework: session: default_locale: fr @@ -48,7 +48,7 @@ After: - ``` + ```yml framework: default_locale: fr ``` @@ -77,7 +77,7 @@ registering a listener that looks like the following if the parameter which handles the locale value in the request is `_locale`: - ``` + ```php namespace XXX; use Symfony\Component\HttpKernel\Event\GetResponseEvent; @@ -138,7 +138,7 @@ Before: - ``` + ```php class User implements UserInterface { // ... @@ -149,7 +149,7 @@ After: - ``` + ```php class User implements UserInterface, EquatableInterface { // ... @@ -165,13 +165,13 @@ Before: - ``` yaml + ```yaml security: factories: - "%kernel.root_dir%/../src/Acme/DemoBundle/Resources/config/security_factories.yml" ``` - ``` yaml + ```yaml # src/Acme/DemoBundle/Resources/config/security_factories.yml services: security.authentication.factory.custom: @@ -182,7 +182,7 @@ After: - ``` + ```php namespace Acme\DemoBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -212,7 +212,7 @@ Before: - ``` yaml + ```yaml security: providers: my_chain_provider: @@ -225,7 +225,7 @@ After: - ``` yaml + ```yaml security: providers: my_chain_provider: @@ -245,14 +245,14 @@ Before: - ``` + ```php use Symfony\Bundle\SecurityBundle\Validator\Constraint\UserPassword; use Symfony\Bundle\SecurityBundle\Validator\Constraint as SecurityAssert; ``` After: - ``` + ```php use Symfony\Component\Security\Core\Validator\Constraint\UserPassword; use Symfony\Component\Security\Core\Validator\Constraint as SecurityAssert; ``` @@ -270,7 +270,7 @@ Before: - ``` + ```php use Symfony\Component\Form\FormBuilder; public function buildForm(FormBuilder $builder, array $options) @@ -278,7 +278,7 @@ After: - ``` + ```php use Symfony\Component\Form\FormBuilderInterface; public function buildForm(FormBuilderInterface $builder, array $options) @@ -301,7 +301,7 @@ Before: - ``` + ```php public function getParent(array $options) { return 'field'; @@ -310,7 +310,7 @@ After: - ``` + ```php public function getParent() { return 'form'; @@ -333,7 +333,7 @@ Before: - ``` + ```php public function getParent(array $options) { return $options['expanded'] ? 'form' : 'field'; @@ -342,7 +342,7 @@ After: - ``` + ```php use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Symfony\Component\OptionsResolver\Options; @@ -374,7 +374,7 @@ Form mapped to an instance of `Person`: - ``` + ```php use Symfony\Component\OptionsResolver\OptionsResolverInterface; public function setDefaultOptions(OptionsResolverInterface $resolver) @@ -399,7 +399,7 @@ Before: - ``` + ```php $builder->add('name', 'text', array( 'property_path' => 'address.street', )); @@ -407,7 +407,7 @@ After (if the address object is an array): - ``` + ```php $builder->add('name', 'text', array( 'property_path' => 'address[street]', )); @@ -427,7 +427,7 @@ underscores wherever you specify a value for the field's "prototype_name" option. - ``` + ```php $builder->add('tags', 'collection', array('prototype_name' => '__proto__')); // results in the name "__proto__" in the template @@ -455,7 +455,7 @@ Before: - ``` + ```twig {% block url_widget %} {% spaceless %} {% set type = type|default('url') %} @@ -466,7 +466,7 @@ After: - ``` + ```twig {% block url_widget %} {% spaceless %} {% set type = type|default('url') %} @@ -482,7 +482,7 @@ Before: - ``` + ```twig {% block form_errors %} {% spaceless %} ... form code ... @@ -498,7 +498,7 @@ After: - ``` + ```twig {% block form_errors %} {% spaceless %} {% if compound %} @@ -532,7 +532,7 @@ Before: - ``` + ```twig {% for choice, label in choices %} {% if _form_is_choice_group(label) %} @@ -550,7 +550,7 @@ After: - ``` + ```twig {% for label, choice in choices %} {% if choice is iterable %} @@ -571,7 +571,7 @@ accommodate those cases when the `label` option has not been explicitly set. - ``` + ```twig {% block form_label %} {% if label is empty %} {% set label = name|humanize %} @@ -588,7 +588,7 @@ Before: - ``` + ```twig {% block _author_tags_0_label %} {# ... #} {% endblock %} @@ -600,7 +600,7 @@ After: - ``` + ```twig {% block _author_tags_entry_label %} {# ... #} {% endblock %} @@ -612,13 +612,13 @@ Before: - ``` + ```php renderBlock('widget_attributes') ?> ``` After: - ``` + ```php block($form, 'widget_attributes') ?> ``` @@ -631,13 +631,13 @@ Before: - ``` + ```php $form = $factory->createNamed('text', 'firstName'); ``` After: - ``` + ```php $form = $factory->createNamed('firstName', 'text'); ``` @@ -648,7 +648,7 @@ Before: - ``` + ```php class MyChoiceList extends ArrayChoiceList { protected function load() @@ -664,7 +664,7 @@ After: - ``` + ```php class MyChoiceList extends SimpleChoiceList { public function __construct() @@ -680,7 +680,7 @@ accessed for the first time -- you can extend `LazyChoiceList` instead and load the choices by overriding `loadChoiceList()`. - ``` + ```php class MyChoiceList extends LazyChoiceList { protected function loadChoiceList() @@ -705,13 +705,13 @@ Before: - ``` + ```twig {{ form_label(form.name, 'Your Name', { 'attr': {'class': 'foo'} }) }} ``` After: - ``` + ```twig {{ form_label(form.name, 'Your Name', { 'label_attr': {'class': 'foo'} }) }} ``` @@ -751,7 +751,7 @@ Before: - ``` + ```php public function getDefaultOptions(array $options) { return array( @@ -769,7 +769,7 @@ After: - ``` + ```php public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( @@ -786,7 +786,7 @@ Before: - ``` + ```php public function getDefaultOptions(array $options) { $defaultOptions = array(); @@ -801,7 +801,7 @@ After: - ``` + ```php public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( @@ -832,13 +832,13 @@ Before: - ``` + ```php $builder->appendClientTransformer(new MyTransformer()); ``` After: - ``` + ```php $builder->addViewTransformer(new MyTransformer()); ``` @@ -857,7 +857,7 @@ Before: - ``` + ```php $builder->addListener(FormEvents::BIND_CLIENT_DATA, function (FilterDataEvent $event) { // ... }); @@ -865,7 +865,7 @@ After: - ``` + ```php $builder->addListener(FormEvents::PRE_BIND, function (FormEvent $event) { // ... }); @@ -886,7 +886,7 @@ Before: - ``` + ```php public function guessMinLength($class, $property) { if (/* condition */) { @@ -897,7 +897,7 @@ After: - ``` + ```php public function guessPattern($class, $property) { if (/* condition */) { @@ -914,7 +914,7 @@ Before: - ``` + ```php $builder->add('termsAccepted', 'checkbox', array( 'property_path' => false, )); @@ -922,7 +922,7 @@ After: - ``` + ```php $builder->add('termsAccepted', 'checkbox', array( 'mapped' => false, )); @@ -944,13 +944,13 @@ Before: - ``` + ```php $form->getErrorBubbling() ``` After: - ``` + ```php $form->getConfig()->getErrorBubbling(); ``` @@ -962,13 +962,13 @@ Before: - ``` + ```php if ($form->hasChildren()) { ``` After: - ``` + ```php if (count($form) > 0) { ``` @@ -976,13 +976,13 @@ Before: - ``` + ```php $form->bindRequest($request); ``` After: - ``` + ```php $form->bind($request); ``` @@ -992,7 +992,7 @@ Before: - ``` + ```php $builder->add('name', 'text', array( 'validation_constraint' => new NotBlank(), )); @@ -1000,7 +1000,7 @@ After: - ``` + ```php $builder->add('name', 'text', array( 'constraints' => new NotBlank(), )); @@ -1008,7 +1008,7 @@ Unlike previously, you can also pass a list of constraints now: - ``` + ```php $builder->add('name', 'text', array( 'constraints' => array( new NotBlank(), @@ -1021,7 +1021,7 @@ to the validated group! So if you validate a form in group "Custom" and previously did: - ``` + ```php $builder->add('name', 'text', array( 'validation_constraint' => new NotBlank(), )); @@ -1029,7 +1029,7 @@ Then you need to add the constraint to the group "Custom" now: - ``` + ```php $builder->add('name', 'text', array( 'constraints' => new NotBlank(array('groups' => 'Custom')), )); @@ -1041,7 +1041,7 @@ Before: - ``` + ```php $builder->add('scheduledFor', 'date', array( 'data_timezone' => 'UTC', 'user_timezone' => 'America/New_York', @@ -1050,7 +1050,7 @@ After: - ``` + ```php $builder->add('scheduledFor', 'date', array( 'model_timezone' => 'UTC', 'view_timezone' => 'America/New_York', @@ -1063,13 +1063,13 @@ Before: - ``` + ```php $this->get('form.factory')->addType(new MyFormType()); ``` After: - ``` + ```php $registry = $this->get('form.registry'); $registry->addType($registry->resolveType(new MyFormType())); @@ -1098,14 +1098,14 @@ Before: - ``` + ```php $view->set('help', 'A text longer than six characters'); $view->set('error_class', 'max_length_error'); ``` After: - ``` + ```php $view->vars = array_replace($view->vars, array( 'help' => 'A text longer than six characters', 'error_class' => 'max_length_error', @@ -1114,25 +1114,25 @@ Before: - ``` + ```php echo $view->get('error_class'); ``` After: - ``` + ```php echo $view->vars['error_class']; ``` Before: - ``` + ```php if ($view->hasChildren()) { ... ``` After: - ``` + ```php if (count($view->children)) { ... ``` @@ -1147,7 +1147,7 @@ Before: - ``` + ```php public function isValid($value, Constraint $constraint) { // ... @@ -1163,7 +1163,7 @@ After: - ``` + ```php public function isValid($value, Constraint $constraint) { // ... @@ -1185,7 +1185,7 @@ Before: - ``` + ```php public function isPropertyValid(ExecutionContext $context) { // ... @@ -1197,7 +1197,7 @@ After: - ``` + ```php public function isPropertyValid(ExecutionContext $context) { // ... @@ -1216,7 +1216,7 @@ Before: - ``` + ```php public function isValid($value, Constraint $constraint) { // ... @@ -1232,7 +1232,7 @@ After: - ``` + ```php public function validate($value, Constraint $constraint) { // ... @@ -1259,14 +1259,14 @@ Before: - ``` + ```php /** @Assert\Valid */ private $recursiveCollection; ``` After: - ``` + ```php /** @Assert\Valid(deep = true) */ private $recursiveCollection; ``` @@ -1276,28 +1276,28 @@ Before: - ``` + ```php /** @Assert\Size(min = 2, max = 16) */ private $numberOfCpus; ``` After: - ``` + ```php /** @Assert\Range(min = 2, max = 16) */ private $numberOfCpus; ``` Before: - ``` + ```php /** @Assert\Min(2) */ private $numberOfCpus; ``` After: - ``` + ```php /** @Assert\Range(min = 2) */ private $numberOfCpus; ``` @@ -1307,14 +1307,14 @@ Before: - ``` + ```php /** @Assert\MinLength(8) */ private $password; ``` After: - ``` + ```php /** @Assert\Length(min = 8) */ private $password; ``` @@ -1325,14 +1325,14 @@ Before: - ``` + ```php $validator = ValidatorFactory::buildDefault(array('path/to/mapping.xml')) ->getValidator(); ``` After: - ``` + ```php $validator = Validation::createValidatorBuilder() ->addXmlMapping('path/to/mapping.xml') ->getValidator(); @@ -1349,7 +1349,7 @@ Before: - ``` + ```twig {% if app.session.hasFlash('notice') %}
{{ app.session.getFlash('notice') }} @@ -1358,7 +1358,7 @@ ``` After: - ``` + ```twig {% for flashMessage in app.session.flashbag.get('notice') %}
{{ flashMessage }} @@ -1368,7 +1368,7 @@ You can process all flash messages in a single loop with: - ``` + ```twig {% for type, flashMessages in app.session.flashbag.all() %} {% for flashMessage in flashMessages %}
@@ -1391,7 +1391,7 @@ * The `item` element is now converted to an array when deserializing XML. - ``` xml + ```xml <![CDATA[title1]]><![CDATA[title2]]> @@ -1433,7 +1433,7 @@ Before: - ``` + ```yaml framework: session: lifetime: 3600 @@ -1445,7 +1445,7 @@ After: - ``` + ```yaml framework: session: cookie_lifetime: 3600 @@ -1457,7 +1457,7 @@ Added `handler_id`, defaults to `session.handler.native_file`. - ``` + ```yaml framework: session: storage_id: session.storage.native @@ -1466,7 +1466,7 @@ Added `handler_id`, defaults to `session.handler.native_file`. To use mock session storage use the following. `handler_id` is irrelevant in this context. - ``` + ```yaml framework: session: storage_id: session.storage.mock_file diff --git a/UPGRADE-2.2.md b/UPGRADE-2.2.md index 24d8b0f86b62d..75baca3a6228b 100644 --- a/UPGRADE-2.2.md +++ b/UPGRADE-2.2.md @@ -7,13 +7,13 @@ Before: - ``` + ```twig {% render 'BlogBundle:Post:list' with { 'limit': 2 }, { 'alt': 'BlogBundle:Post:error' } %} ``` After: - ``` + ```twig {% render controller('BlogBundle:Post:list', { 'limit': 2 }), { 'alt': 'BlogBundle:Post:error' } %} {# Or: #} {{ render(controller('BlogBundle:Post:list', { 'limit': 2 }), { 'alt': 'BlogBundle:Post:error'}) }} @@ -29,7 +29,7 @@ Before: - ``` + ```twig {% render 'BlogBundle:Post:list' with { 'limit': 2 }, {'standalone': true} %} {% render 'BlogBundle:Post:list' with { 'limit': 2 }, {'standalone': false} %} {% render 'BlogBundle:Post:list' with { 'limit': 2 }, {'standalone': 'js'} %} @@ -37,7 +37,7 @@ After: - ``` + ```twig {{ render(controller('BlogBundle:Post:list', { 'limit': 2 }), { 'strategy': 'esi'}) }} {{ render(controller('BlogBundle:Post:list', { 'limit': 2 }), { 'strategy': 'inline'}) }} {{ render(controller('BlogBundle:Post:list', { 'limit': 2 }), { 'strategy': 'hinclude'}) }} @@ -65,7 +65,7 @@ You should now use the `AcceptHeader` class which give you fluent methods to parse request accept-* headers. Some examples: - ``` + ```php $accept = AcceptHeader::fromString($request->headers->get('Accept')); if ($accept->has('text/html') { $item = $accept->get('html'); @@ -95,7 +95,7 @@ Before: - ``` + ```twig {{ error.messagePluralization is null ? error.messageTemplate|trans(error.messageParameters, 'validators') @@ -105,7 +105,7 @@ After: - ``` + ```twig {{ error.message }} ``` @@ -117,7 +117,7 @@ Before: - ``` + ```php use Symfony\Component\Form\Extensions\Core\DataMapper\PropertyPathMapper; class CustomMapper extends PropertyPathMapper @@ -133,7 +133,7 @@ After: - ``` + ```php use Symfony\Component\Form\Extensions\Core\DataMapper\PropertyPathMapper; class CustomMapper extends PropertyPathMapper @@ -163,7 +163,7 @@ Before: - ``` + ```php use Symfony\Component\Form\Util\PropertyPath; use Symfony\Component\Form\Util\PropertyPathBuilder; use Symfony\Component\Form\Util\PropertyPathInterface; @@ -176,7 +176,7 @@ After: - ``` + ```php use Symfony\Component\PropertyAccess\PropertyPath; use Symfony\Component\PropertyAccess\PropertyPathBuilder; use Symfony\Component\PropertyAccess\PropertyPathInterface; @@ -192,7 +192,7 @@ Before: - ``` + ```php use Symfony\Component\Form\Util\FormUtil; $singular = FormUtil::singularify($plural); @@ -200,7 +200,7 @@ After: - ``` + ```php use Symfony\Component\PropertyAccess\StringUtil; $singular = StringUtil::singularify($plural); @@ -211,7 +211,7 @@ Before: - ``` + ```php use Symfony\Component\Form\Util\PropertyPath; $propertyPath = new PropertyPath('some.path'); @@ -222,7 +222,7 @@ After (alternative 1): - ``` + ```php use Symfony\Component\PropertyAccess\PropertyAccess; $propertyAccessor = PropertyAccess::getPropertyAccessor(); @@ -233,7 +233,7 @@ After (alternative 2): - ``` + ```php use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyPath; @@ -253,7 +253,7 @@ Before: - ``` + ```php $rootCollection = new RouteCollection(); $subCollection = new RouteCollection(); $rootCollection->addCollection($subCollection); @@ -262,7 +262,7 @@ After: - ``` + ```php $rootCollection = new RouteCollection(); $subCollection = new RouteCollection(); $subCollection->add('foo', new Route('/foo')); @@ -272,7 +272,7 @@ Also one must call `addCollection` from the bottom to the top hierarchy. So the correct sequence is the following (and not the reverse): - ``` + ```php $childCollection->addCollection($grandchildCollection); $rootCollection->addCollection($childCollection); ``` @@ -298,7 +298,7 @@ use-case instead. Before: `$parentCollection->addCollection($collection, '/prefix', array(...), array(...))` After: - ``` + ```php $collection->addPrefix('/prefix', array(...), array(...)); $parentCollection->addCollection($collection); ``` @@ -312,7 +312,7 @@ Before: - ``` + ```php use Symfony\Component\Validator\ExecutionContext; public function validateCustomLogic(ExecutionContext $context) @@ -320,7 +320,7 @@ After: - ``` + ```php use Symfony\Component\Validator\ExecutionContextInterface; public function validateCustomLogic(ExecutionContextInterface $context) @@ -331,7 +331,7 @@ Before: - ``` + ```php use Symfony\Component\Validator\ConstraintValidatorInterface; use Symfony\Component\Validator\ExecutionContext; @@ -346,7 +346,7 @@ After: - ``` + ```php use Symfony\Component\Validator\ConstraintValidatorInterface; use Symfony\Component\Validator\ExecutionContextInterface; @@ -391,7 +391,7 @@ Before: - ``` + ```php use Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface; class MyMetadataFactory implements ClassMetadataFactoryInterface @@ -405,7 +405,7 @@ After: - ``` + ```php use Symfony\Component\Validator\MetadataFactoryInterface; use Symfony\Component\Validator\Exception\NoSuchMetadataException; @@ -432,14 +432,14 @@ Before: - ``` + ```php $metadataFactory = $validator->getMetadataFactory(); $metadata = $metadataFactory->getClassMetadata('Vendor\MyClass'); ``` After: - ``` + ```php $metadataFactory = $validator->getMetadataFactory(); $metadata = $metadataFactory->getMetadataFor('Vendor\MyClass'); ``` @@ -451,7 +451,7 @@ Before: - ``` + ```php use Symfony\Component\Validator\ExecutionContext; public function validateCustomLogic(ExecutionContext $context) @@ -471,7 +471,7 @@ After: - ``` + ```php use Symfony\Component\Validator\ExecutionContextInterface; public function validateCustomLogic(ExecutionContextInterface $context) @@ -488,7 +488,7 @@ Before: - ``` + ```php use Symfony\Component\Validator\ExecutionContext; public function validateCustomLogic(ExecutionContext $context) @@ -501,7 +501,7 @@ After: - ``` + ```php use Symfony\Component\Validator\ExecutionContextInterface; public function validateCustomLogic(ExecutionContextInterface $context) @@ -519,7 +519,7 @@ Before: - ``` + ```php use Symfony\Component\Validator\ExecutionContext; public function validateCustomLogic(ExecutionContext $context) @@ -534,7 +534,7 @@ After: - ``` + ```php use Symfony\Component\Validator\ExecutionContextInterface; public function validateCustomLogic(ExecutionContextInterface $context) @@ -553,20 +553,20 @@ Before: - ``` + ```php render('BlogBundle:Post:list', array('limit' => 2), array('alt' => 'BlogBundle:Post:error')) ?> ``` After: - ``` + ```php render($view['router']->generate('post_list', array('limit' => 2)), array('alt' => 'BlogBundle:Post:error')) ?> ``` where `post_list` is the route name for the `BlogBundle:Post:list` controller, or if you don't want to create a route: - ``` + ```php render(new ControllerReference('BlogBundle:Post:list', array('limit' => 2)), array('alt' => 'BlogBundle:Post:error')) ?> ``` @@ -577,7 +577,7 @@ Before: - ``` + ```yaml # app/config/config.yml framework: trust_proxy_headers: false @@ -585,7 +585,7 @@ After: - ``` + ```yaml # app/config/config.yml framework: trusted_proxies: ['127.0.0.1', '10.0.0.1'] # a list of proxy IPs you trust @@ -598,13 +598,13 @@ Before: - ``` + ```php use Symfony\Component\Security\Core\Validator\Constraint\UserPassword; ``` After: (note the `s` at the end of `Constraint`) - ``` + ```php use Symfony\Component\Security\Core\Validator\Constraints\UserPassword; ``` @@ -612,7 +612,7 @@ ``service`` option that allows to specify a custom validator service name in order to validate the current logged-in user's password. - ``` + ```php use Symfony\Component\Security\Core\Validator\Constraints\UserPassword; $constraint = new UserPassword(array( @@ -628,14 +628,14 @@ Before: - ``` + ```php use Symfony\Component\Security\Core\Validator\Constraint\UserPassword; use Symfony\Component\Security\Core\Validator\Constraint\UserPasswordValidator; ``` After: - ``` + ```php use Symfony\Component\Security\Core\Validator\Constraints\UserPassword; use Symfony\Component\Security\Core\Validator\Constraints\UserPasswordValidator; ``` diff --git a/UPGRADE-2.3.md b/UPGRADE-2.3.md index f03a76f7b60e1..8a3eda8f022fe 100644 --- a/UPGRADE-2.3.md +++ b/UPGRADE-2.3.md @@ -15,7 +15,7 @@ Form Before: - ``` + ```php // equivalent notations for validating in group "Default" "validation_groups" => null "validation_groups" => "Default" @@ -27,7 +27,7 @@ Form After: - ``` + ```php // equivalent notations for validating in group "Default" "validation_groups" => null "validation_groups" => "Default" @@ -41,7 +41,7 @@ Form Before: - ``` + ```php use Symfony\Component\Form\DataMapperInterface; class MyDataMapper @@ -60,7 +60,7 @@ Form After: - ``` + ```php use Symfony\Component\Form\DataMapperInterface; class MyDataMapper @@ -84,7 +84,7 @@ Form Before: - ``` + ```php use Symfony\Component\Form\Util\VirtualFormAwareIterator; public function mapFormsToData(array $forms, $data) @@ -101,7 +101,7 @@ Form After: - ``` + ```php public function mapFormsToData($forms, $data) { foreach ($forms as $form) { @@ -121,7 +121,7 @@ Form Before: - ``` + ```php $form = $factory->create('form'); $form->add($factory->createNamed('field', 'text')); ``` @@ -135,7 +135,7 @@ Form After (Alternative 1): - ``` + ```php $form = $factory->create('form'); $form->add($factory->createNamed('field', 'text', array(), array( 'auto_initialize' => false, @@ -147,7 +147,7 @@ Form After (Alternative 2): - ``` + ```php $builder = $factory->createBuilder('form'); $builder->add($factory->createBuilder('field', 'text')); $form = $builder->getForm(); @@ -157,14 +157,14 @@ Form After (Alternative 3): - ``` + ```php $form = $factory->create('form'); $form->add('field', 'text'); ``` After (Alternative 4): - ``` + ```php $builder = $factory->createBuilder('form'); $builder->add('field', 'text'); $form = $builder->getForm(); @@ -180,7 +180,7 @@ Form Before: - ``` + ```php $builder->add('field', 'text', array( 'data' => $defaultData ?: null, )); @@ -188,7 +188,7 @@ Form After: - ``` + ```php $options = array(); if ($defaultData) { $options['data'] = $defaultData; @@ -203,7 +203,7 @@ PropertyAccess even if a non-public match was found. This means that the property "author" in the following class will now correctly be found: - ``` + ```php class Article { public $author; @@ -224,7 +224,7 @@ PropertyAccess Before: - ``` + ```php use Symfony\Component\PropertyAccess\Exception\PropertyAccessDeniedException; use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException; @@ -239,7 +239,7 @@ PropertyAccess After: - ``` + ```php use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException; try { @@ -257,7 +257,7 @@ DomCrawler Before: - ``` + ```php $data = $crawler->each(function ($node, $i) { return $node->nodeValue; }); @@ -265,7 +265,7 @@ DomCrawler After: - ``` + ```php $data = $crawler->each(function ($crawler, $i) { return $crawler->text(); }); @@ -280,13 +280,13 @@ Console Before: - ``` + ```php if (OutputInterface::VERBOSITY_VERBOSE === $output->getVerbosity()) { ... } ``` After: - ``` + ```php if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { ... } ``` diff --git a/UPGRADE-2.5.md b/UPGRADE-2.5.md index be656cd36a3d0..a5e18d1777c1d 100644 --- a/UPGRADE-2.5.md +++ b/UPGRADE-2.5.md @@ -17,13 +17,13 @@ Form Before: - ``` + ```php $errors = array_map($callback, $form->getErrors()); ``` After: - ``` + ```php $errors = array_map($callback, iterator_to_array($form->getErrors())); ``` @@ -33,27 +33,27 @@ Form Before: - ``` + ```php public function getErrors() { ``` After: - ``` + ```php public function getErrors($deep = false, $flatten = true) { ``` Before: - ``` + ```twig {% if form.vars.errors %} ``` After: - ``` + ```twig {% if form.vars.errors|length %} ``` @@ -114,7 +114,7 @@ Validator Strict email validation has to be explicitly activated in the configuration file by adding - ``` + ```yaml framework: //... validation: @@ -125,7 +125,7 @@ Validator Also you have to add to your composer.json: - ``` + ```json "egulias/email-validator": "~1.2" ``` @@ -137,14 +137,14 @@ Validator Before: - ``` + ```php $sequence = $metadata->getGroupSequence(); $result = array_map($callback, $sequence); ``` After: - ``` + ```php $sequence = iterator_to_array($metadata->getGroupSequence()); $result = array_map($callback, $sequence); ``` @@ -155,7 +155,7 @@ Validator Before: - ``` + ```php public function setGroupSequence(array $groups) { // ... @@ -164,7 +164,7 @@ Validator After: - ``` + ```php public function setGroupSequence($groupSequence) { // ... @@ -180,7 +180,7 @@ Validator You can choose the desired API via the new "api" entry in app/config/config.yml: - ``` + ```yaml framework: validation: enabled: true @@ -190,7 +190,7 @@ Validator When running PHP 5.3.9 or higher, Symfony will then use an implementation that supports both the old API and the new one: - ``` + ```yaml framework: validation: enabled: true @@ -200,7 +200,7 @@ Validator When running PHP lower than 5.3.9, that compatibility layer is not supported. On those versions, the old implementation will be used instead: - ``` + ```yaml framework: validation: enabled: true @@ -211,7 +211,7 @@ Validator also set the API to 2.5. In that case, the backwards compatibility layer will not be activated: - ``` + ```yaml framework: validation: enabled: true @@ -221,7 +221,7 @@ Validator When using the validator outside of the Symfony full-stack framework, the desired API can be selected using `setApiVersion()` on the validator builder: - ``` + ```php // Previous implementation $validator = Validation::createValidatorBuilder() ->setApiVersion(Validation::API_VERSION_2_4) @@ -247,7 +247,7 @@ Yaml Component Example: - ``` + ```yaml parentElement: firstChild: foo secondChild: 123 diff --git a/UPGRADE-3.0.md b/UPGRADE-3.0.md index 38156e47f675a..bc0a3728c8909 100644 --- a/UPGRADE-3.0.md +++ b/UPGRADE-3.0.md @@ -29,7 +29,7 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php $h = new ProgressHelper(); $h->start($output, 10); for ($i = 1; $i < 5; $i++) { @@ -41,7 +41,7 @@ UPGRADE FROM 2.x to 3.0 After: - ``` + ```php $bar = new ProgressBar($output, 10); $bar->start(); for ($i = 1; $i < 5; $i++) { @@ -54,7 +54,7 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php $table = $app->getHelperSet()->get('table'); $table ->setHeaders(array('ISBN', 'Title', 'Author')) @@ -70,7 +70,7 @@ UPGRADE FROM 2.x to 3.0 After: - ``` + ```php use Symfony\Component\Console\Helper\Table; $table = new Table($output); @@ -98,13 +98,13 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php $form->bind(array(...)); ``` After: - ``` + ```php $form->submit(array(...)); ``` @@ -115,7 +115,7 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php if ('POST' === $request->getMethod()) { $form->bind($request); @@ -127,7 +127,7 @@ UPGRADE FROM 2.x to 3.0 After: - ``` + ```php $form->handleRequest($request); if ($form->isValid()) { @@ -138,7 +138,7 @@ UPGRADE FROM 2.x to 3.0 If you want to test whether the form was submitted separately, you can use the method `isSubmitted()`: - ``` + ```php $form->handleRequest($request); if ($form->isSubmitted()) { @@ -155,7 +155,7 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php $builder->addEventListener(FormEvents::PRE_BIND, function (FormEvent $event) { // ... }); @@ -163,7 +163,7 @@ UPGRADE FROM 2.x to 3.0 After: - ``` + ```php $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { // ... }); @@ -173,7 +173,7 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php $builder->add('address', 'form', array( 'virtual' => true, )); @@ -181,7 +181,7 @@ UPGRADE FROM 2.x to 3.0 After: - ``` + ```php $builder->add('address', 'form', array( 'inherit_data' => true, )); @@ -191,7 +191,7 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php use Symfony\Component\Form\Util\VirtualFormAwareIterator; $iterator = new VirtualFormAwareIterator($forms); @@ -199,7 +199,7 @@ UPGRADE FROM 2.x to 3.0 After: - ``` + ```php use Symfony\Component\Form\Util\InheritDataAwareIterator; $iterator = new InheritDataAwareIterator($forms); @@ -209,7 +209,7 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php use Symfony\Component\Form\Tests\Extension\Core\Type\TypeTestCase class MyTypeTest extends TypeTestCase @@ -220,7 +220,7 @@ UPGRADE FROM 2.x to 3.0 After: - ``` + ```php use Symfony\Component\Form\Test\TypeTestCase; class MyTypeTest extends TypeTestCase @@ -254,13 +254,13 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php echo $form->getErrorsAsString(); ``` After: - ``` + ```php echo $form->getErrors(true, false); ``` @@ -273,7 +273,7 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php namespace Acme\FooBundle\Controller; class DemoController @@ -288,7 +288,7 @@ UPGRADE FROM 2.x to 3.0 After: - ``` + ```php namespace Acme\FooBundle\Controller; use Symfony\Component\HttpFoundation\Request; @@ -310,7 +310,7 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php
enctype($form) ?>> ...
@@ -318,7 +318,7 @@ UPGRADE FROM 2.x to 3.0 After: - ``` + ```php start($form) ?> ... end($form) ?> @@ -330,7 +330,7 @@ UPGRADE FROM 2.x to 3.0 Alternative 1: - ``` + ```php $form = $this->createForm('my_form', $formData, array( 'method' => 'PUT', 'action' => $this->generateUrl('target_route'), @@ -339,7 +339,7 @@ UPGRADE FROM 2.x to 3.0 Alternative 2: - ``` + ```php $form = $this->createFormBuilder($formData) // ... ->setMethod('PUT') @@ -349,7 +349,7 @@ UPGRADE FROM 2.x to 3.0 It is also possible to override the method and the action in the template: - ``` + ```php start($form, array('method' => 'GET', 'action' => 'http://example.com')) ?> ... end($form) ?> @@ -408,7 +408,7 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php use Symfony\Component\PropertyAccess\PropertyAccess; $accessor = PropertyAccess::getPropertyAccessor(); @@ -416,7 +416,7 @@ UPGRADE FROM 2.x to 3.0 After: - ``` + ```php use Symfony\Component\PropertyAccess\PropertyAccess; $accessor = PropertyAccess::createPropertyAccessor(); @@ -431,17 +431,21 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```yaml article_edit: pattern: /article/{id} requirements: { '_method': 'POST|PUT', '_scheme': 'https', 'id': '\d+' } + ``` + ```xml POST|PUT https \d+ + ``` + ```php $route = new Route(); $route->setPattern('/article/{id}'); $route->setRequirement('_method', 'POST|PUT'); @@ -450,17 +454,21 @@ UPGRADE FROM 2.x to 3.0 After: - ``` + ```yaml article_edit: path: /article/{id} methods: [POST, PUT] schemes: https requirements: { 'id': '\d+' } + ``` + ```xml \d+ + ``` + ```php $route = new Route(); $route->setPath('/article/{id}'); $route->setMethods(array('POST', 'PUT')); @@ -489,7 +497,7 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```twig
...
@@ -497,7 +505,7 @@ UPGRADE FROM 2.x to 3.0 After: - ``` + ```twig {{ form_start(form) }} ... {{ form_end(form) }} @@ -509,7 +517,7 @@ UPGRADE FROM 2.x to 3.0 Alternative 1: - ``` + ```php $form = $this->createForm('my_form', $formData, array( 'method' => 'PUT', 'action' => $this->generateUrl('target_route'), @@ -518,7 +526,7 @@ UPGRADE FROM 2.x to 3.0 Alternative 2: - ``` + ```php $form = $this->createFormBuilder($formData) // ... ->setMethod('PUT') @@ -528,7 +536,7 @@ UPGRADE FROM 2.x to 3.0 It is also possible to override the method and the action in the template: - ``` + ```twig {{ form_start(form, {'method': 'GET', 'action': 'http://example.com'}) }} ... {{ form_end(form) }} @@ -541,7 +549,7 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php use Symfony\Component\Validator\Mapping\Cache\ApcCache; $cache = new ApcCache('symfony.validator'); @@ -549,7 +557,7 @@ UPGRADE FROM 2.x to 3.0 After: - ``` + ```php use Symfony\Component\Validator\Mapping\Cache\DoctrineCache; use Doctrine\Common\Cache\ApcCache; @@ -565,7 +573,7 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php use Symfony\Component\Validator\Constraints as Assert; /** @@ -579,7 +587,7 @@ UPGRADE FROM 2.x to 3.0 After: - ``` + ```php use Symfony\Component\Validator\Constraints as Assert; /** @@ -597,14 +605,14 @@ UPGRADE FROM 2.x to 3.0 Before (YAML): - ``` + ```yaml constraints: - Callback: [firstCallback, secondCallback] ``` After (YAML): - ``` + ```yaml constraints: - Callback: firstCallback - Callback: secondCallback @@ -615,7 +623,7 @@ UPGRADE FROM 2.x to 3.0 Before (Annotations): - ``` + ```php use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\ExecutionContextInterface; @@ -633,7 +641,7 @@ UPGRADE FROM 2.x to 3.0 After (Annotations): - ``` + ```php use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\ExecutionContextInterface; @@ -657,7 +665,7 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php $validator->validate($object, 'Strict'); $validator->validateValue($value, new NotNull()); @@ -665,7 +673,7 @@ UPGRADE FROM 2.x to 3.0 After: - ``` + ```php $validator->validate($object, null, 'Strict'); $validator->validate($value, new NotNull()); @@ -675,7 +683,7 @@ UPGRADE FROM 2.x to 3.0 were added. The first of them allows to run multiple validations in the same context and aggregate their violations: - ``` + ```php $violations = $validator->startContext() ->atPath('firstName')->validate($firstName, new NotNull()) ->atPath('age')->validate($age, new Type('integer')) @@ -686,7 +694,7 @@ UPGRADE FROM 2.x to 3.0 especially useful when calling the validator from within constraint validators: - ``` + ```php $validator->inContext($context)->validate($object); ``` @@ -705,13 +713,13 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php use Symfony\Component\Validator\MetadataInterface; ``` After: - ``` + ```php use Symfony\Component\Validator\Mapping\MetadataInterface; ``` @@ -722,7 +730,7 @@ UPGRADE FROM 2.x to 3.0 Example: - ``` + ```php use Symfony\Component\Validator\Mapping\TraversalStrategy; public function getTraversalStrategy() @@ -736,13 +744,13 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php use Symfony\Component\Validator\PropertyMetadataInterface; ``` After: - ``` + ```php use Symfony\Component\Validator\Mapping\PropertyMetadataInterface; ``` @@ -751,13 +759,13 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php use Symfony\Component\Validator\PropertyMetadataContainerInterface; ``` After: - ``` + ```php use Symfony\Component\Validator\Mapping\ClassMetadataInterface; ``` @@ -775,7 +783,7 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php use Symfony\Component\Validator\ClassBasedInterface; class MyClassMetadata implements ClassBasedInterface @@ -786,7 +794,7 @@ UPGRADE FROM 2.x to 3.0 After: - ``` + ```php use Symfony\Component\Validator\Mapping\ClassMetadataInterface; class MyClassMetadata implements ClassMetadataInterface @@ -799,7 +807,7 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php use Symfony\Component\Validator\Mapping\ElementMetadata; class MyMetadata extends ElementMetadata @@ -809,7 +817,7 @@ UPGRADE FROM 2.x to 3.0 After: - ``` + ```php use Symfony\Component\Validator\Mapping\GenericMetadata; class MyMetadata extends GenericMetadata @@ -822,13 +830,13 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php use Symfony\Component\Validator\ExecutionContextInterface; ``` After: - ``` + ```php use Symfony\Component\Validator\Context\ExecutionContextInterface; ``` @@ -850,7 +858,7 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php $context->addViolationAt('property', 'The value {{ value }} is invalid.', array( '{{ value }}' => $invalidValue, )); @@ -858,7 +866,7 @@ UPGRADE FROM 2.x to 3.0 After: - ``` + ```php $context->buildViolation('The value {{ value }} is invalid.') ->atPath('property') ->setParameter('{{ value }}', $invalidValue) @@ -870,13 +878,13 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php $context->validate($object); ``` After: - ``` + ```php $context->getValidator() ->inContext($context) ->validate($object); @@ -892,13 +900,13 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php $metadata = $context->getMetadataFactory()->getMetadataFor($myClass); ``` After: - ``` + ```php $metadata = $context->getValidator()->getMetadataFor($myClass); ``` @@ -913,7 +921,7 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php use Symfony\Component\Validator\Mapping\ClassMetadataFactory; $factory = new ClassMetadataFactory($loader); @@ -921,7 +929,7 @@ UPGRADE FROM 2.x to 3.0 After: - ``` + ```php use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory; $factory = new LazyLoadingMetadataFactory($loader); @@ -939,14 +947,14 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php $parameters = $violation->getMessageParameters(); $plural = $violation->getMessagePluralization(); ``` After: - ``` + ```php $parameters = $violation->getParameters(); $plural = $violation->getPlural(); ``` @@ -957,13 +965,13 @@ UPGRADE FROM 2.x to 3.0 Before: - ``` + ```php Yaml::parse($fileName); ``` After: - ``` + ```php Yaml::parse(file_get_contents($fileName)); ### Process