Skip to content

Commit 04a043b

Browse files
committed
Merge branch '3.4' into 4.2
* 3.4: Use a configuration-block directive move the namespace before the use statements be consistent ´with the following code example wrap code example with class added use statement and filepath to be consistent remove blank line after filepath in php code examples fix use statement try to make the code examples less noisy
2 parents c831443 + bacdc6f commit 04a043b

File tree

12 files changed

+44
-35
lines changed

12 files changed

+44
-35
lines changed

components/console/changing_default_command.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ name to the ``setDefaultCommand()`` method::
3131
Executing the application and changing the default command::
3232

3333
// application.php
34-
3534
use Acme\Console\Command\HelloWorldCommand;
3635
use Symfony\Component\Console\Application;
3736

components/serializer.rst

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -245,23 +245,32 @@ The definition of serialization can be specified using annotations, XML
245245
or YAML. The :class:`Symfony\\Component\\Serializer\\Mapping\\Factory\\ClassMetadataFactory`
246246
that will be used by the normalizer must be aware of the format to use.
247247

248-
Initialize the :class:`Symfony\\Component\\Serializer\\Mapping\\Factory\\ClassMetadataFactory`
249-
like the following::
248+
The following code shows how to initialize the :class:`Symfony\\Component\\Serializer\\Mapping\\Factory\\ClassMetadataFactory`
249+
for each format:
250250

251-
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
252-
// For annotations
253-
use Doctrine\Common\Annotations\AnnotationReader;
254-
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
255-
// For XML
256-
// use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
257-
// For YAML
258-
// use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
251+
.. configuration-block::
259252

260-
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
261-
// For XML
262-
// $classMetadataFactory = new ClassMetadataFactory(new XmlFileLoader('/path/to/your/definition.xml'));
263-
// For YAML
264-
// $classMetadataFactory = new ClassMetadataFactory(new YamlFileLoader('/path/to/your/definition.yaml'));
253+
.. code-block:: php-annotations
254+
255+
use Doctrine\Common\Annotations\AnnotationReader;
256+
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
257+
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
258+
259+
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
260+
261+
.. code-block:: yaml
262+
263+
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
264+
use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
265+
266+
$classMetadataFactory = new ClassMetadataFactory(new YamlFileLoader('/path/to/your/definition.yaml'));
267+
268+
.. code-block:: xml
269+
270+
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
271+
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
272+
273+
$classMetadataFactory = new ClassMetadataFactory(new XmlFileLoader('/path/to/your/definition.xml'));
265274
266275
.. _component-serializer-attributes-groups-annotations:
267276

@@ -966,10 +975,10 @@ Here, we set it to 2 for the ``$child`` property:
966975

967976
.. code-block:: php-annotations
968977
969-
use Symfony\Component\Serializer\Annotation\MaxDepth;
970-
971978
namespace Acme;
972979
980+
use Symfony\Component\Serializer\Annotation\MaxDepth;
981+
973982
class MyObj
974983
{
975984
/**
@@ -1233,13 +1242,13 @@ When using the component standalone, an implementation of :class:`Symfony\\Compo
12331242
(usually an instance of :class:`Symfony\\Component\\PropertyInfo\\PropertyInfoExtractor`) must be passed as the 4th
12341243
parameter of the ``ObjectNormalizer``::
12351244

1245+
namespace Acme;
1246+
12361247
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
12371248
use Symfony\Component\Serializer\Serializer;
12381249
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
12391250
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
12401251

1241-
namespace Acme;
1242-
12431252
class ObjectOuter
12441253
{
12451254
private $inner;

components/yaml.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ First, install the Console component:
394394
Create a console application with ``lint:yaml`` as its only command::
395395

396396
// lint.php
397-
398397
use Symfony\Component\Console\Application;
399398
use Symfony\Component\Yaml\Command\LintCommand;
400399

configuration/micro_kernel_trait.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ Finally, you need a front controller to boot and run the application. Create a
282282
``public/index.php``::
283283

284284
// public/index.php
285-
286285
use App\Kernel;
287286
use Doctrine\Common\Annotations\AnnotationRegistry;
288287
use Symfony\Component\HttpFoundation\Request;

doctrine/lifecycle_callbacks.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ callbacks. This is not necessary if you're using YAML or XML for your mapping.
1515

1616
.. code-block:: php-annotations
1717
18+
// src/Entity/Product.php
19+
use Doctrine\ORM\Mapping as ORM;
20+
1821
/**
1922
* @ORM\Entity()
2023
* @ORM\HasLifecycleCallbacks()
@@ -33,6 +36,7 @@ the current date, only when the entity is first persisted (i.e. inserted):
3336
.. code-block:: php-annotations
3437
3538
// src/Entity/Product.php
39+
use Doctrine\ORM\Mapping as ORM;
3640
3741
/**
3842
* @ORM\PrePersist

doctrine/pdo_session_storage.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ a second array argument to ``PdoSessionHandler``:
150150
.. code-block:: php
151151
152152
// config/services.php
153-
154153
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
155154
// ...
156155

doctrine/resolve_target_entity.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ brevity) to explain how to set up and use the ``ResolveTargetEntityListener``.
4040
A Customer entity::
4141

4242
// src/Entity/Customer.php
43-
4443
namespace App\Entity;
4544

4645
use Doctrine\ORM\Mapping as ORM;
@@ -60,10 +59,9 @@ A Customer entity::
6059
An Invoice entity::
6160

6261
// src/Acme/InvoiceBundle/Entity/Invoice.php
63-
6462
namespace Acme\InvoiceBundle\Entity;
6563

66-
use Doctrine\ORM\Mapping AS ORM;
64+
use Doctrine\ORM\Mapping as ORM;
6765
use Acme\InvoiceBundle\Model\InvoiceSubjectInterface;
6866

6967
/**
@@ -84,7 +82,6 @@ An Invoice entity::
8482
An InvoiceSubjectInterface::
8583

8684
// src/Acme/InvoiceBundle/Model/InvoiceSubjectInterface.php
87-
8885
namespace Acme\InvoiceBundle\Model;
8986

9087
/**

form/dynamic_form_modification.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,16 @@ service into the form type so you can get the current user object::
236236
use Symfony\Component\Security\Core\Security;
237237
// ...
238238

239-
private $security;
240-
241-
public function __construct(Security $security)
239+
class FriendMessageFormType extends AbstractType
242240
{
243-
$this->security = $security;
241+
private $security;
242+
243+
public function __construct(Security $security)
244+
{
245+
$this->security = $security;
246+
}
247+
248+
// ....
244249
}
245250

246251
Customizing the Form Type
@@ -250,7 +255,6 @@ Now that you have all the basics in place you can use the features of the
250255
security helper to fill in the listener logic::
251256

252257
// src/Form/Type/FriendMessageFormType.php
253-
254258
use App\Entity\User;
255259
use Doctrine\ORM\EntityRepository;
256260
use Symfony\Bridge\Doctrine\Form\Type\EntityType;

form/form_collections.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ you will learn about next!).
515515

516516
// src/Entity/Task.php
517517

518+
// ...
518519
public function addTag(Tag $tag)
519520
{
520521
// for a many-to-many association:
@@ -648,7 +649,6 @@ the relationship between the removed ``Tag`` and ``Task`` object.
648649
is handling the "update" of your Task::
649650

650651
// src/Controller/TaskController.php
651-
652652
use App\Entity\Task;
653653
use Doctrine\Common\Collections\ArrayCollection;
654654

form/form_dependencies.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ Suppose you need to access the :ref:`EntityManager <doctrine-entity-manager>` ob
7777
so that you can make a query. First, add this as an argument to your form class::
7878

7979
// src/Form/TaskType.php
80-
8180
use Doctrine\ORM\EntityManagerInterface;
8281
// ...
8382

service_container/factories.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ Configuration of the service container then looks like this:
132132
// config/services.php
133133
use App\Email\NewsletterManager;
134134
use App\Email\NewsletterManagerFactory;
135+
use Symfony\Component\DependencyInjection\Reference;
135136
// ...
136137
137138
$container->register(NewsletterManagerFactory::class);

workflow/usage.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ like this:
117117
.. code-block:: php
118118
119119
// config/packages/workflow.php
120-
121120
$container->loadFromExtension('framework', [
122121
// ...
123122
'workflows' => [

0 commit comments

Comments
 (0)