From 99d467045614d0952875eff0b7e8bc298a4fddca Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Wed, 24 Apr 2019 12:45:34 +0200 Subject: [PATCH] ordered use statements for php code examples --- components/ldap.rst | 2 +- components/mercure.rst | 2 +- components/messenger.rst | 8 ++++---- components/serializer.rst | 10 +++++----- components/var_dumper.rst | 2 +- doctrine/event_listeners_subscribers.rst | 3 +-- form/form_themes.rst | 2 +- mercure.rst | 2 +- messenger.rst | 4 ++-- quick_tour/flex_recipes.rst | 2 +- quick_tour/the_architecture.rst | 4 ++-- reference/configuration/swiftmailer.rst | 3 ++- reference/constraints/Choice.rst | 4 +--- reference/constraints/DivisibleBy.rst | 2 +- reference/constraints/Url.rst | 2 +- reference/dic_tags.rst | 3 +-- security/form_login_setup.rst | 3 ++- security/user_provider.rst | 4 ++-- 18 files changed, 30 insertions(+), 32 deletions(-) diff --git a/components/ldap.rst b/components/ldap.rst index 51dc263b976..153d8e0896b 100644 --- a/components/ldap.rst +++ b/components/ldap.rst @@ -152,8 +152,8 @@ ______________ Use the entry manager's :method:`Symfony\\Component\\Ldap\\Adapter\\ExtLdap\\EntryManager::applyOperations` method to update multiple attributes at once:: - use Symfony\Component\Ldap\Ldap; use Symfony\Component\Ldap\Entry; + use Symfony\Component\Ldap\Ldap; // ... $entry = new Entry('cn=Fabien Potencier,dc=symfony,dc=com', [ diff --git a/components/mercure.rst b/components/mercure.rst index fbe87b758eb..95e8beaf820 100644 --- a/components/mercure.rst +++ b/components/mercure.rst @@ -31,9 +31,9 @@ The following example shows the component in action:: define('HUB_URL', 'https://demo.mercure.rocks/hub'); define('JWT', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXJjdXJlIjp7InN1YnNjcmliZSI6WyJmb28iLCJiYXIiXSwicHVibGlzaCI6WyJmb28iXX19.LRLvirgONK13JgacQ_VbcjySbVhkSmHy3IznH3tA9PM'); + use Symfony\Component\Mercure\Jwt\StaticJwtProvide; use Symfony\Component\Mercure\Publisher; use Symfony\Component\Mercure\Update; - use Symfony\Component\Mercure\Jwt\StaticJwtProvide; $publisher = new Publisher(HUB_URL, new StaticJwtProvide(JWT)); // Serialize the update, and dispatch it to the hub, that will broadcast it to the clients diff --git a/components/messenger.rst b/components/messenger.rst index d1da1e2ff31..89597e2ab4a 100644 --- a/components/messenger.rst +++ b/components/messenger.rst @@ -82,8 +82,8 @@ are configured for you: Example:: use App\Message\MyMessage; - use Symfony\Component\Messenger\MessageBus; use Symfony\Component\Messenger\Handler\HandlersLocator; + use Symfony\Component\Messenger\MessageBus; use Symfony\Component\Messenger\Middleware\HandleMessageMiddleware; $bus = new MessageBus([ @@ -155,9 +155,9 @@ Instead of dealing directly with the messages in the middleware you receive the Hence you can inspect the envelope content and its stamps, or add any:: use App\Message\Stamp\AnotherStamp; - use Symfony\Component\Messenger\Stamp\ReceivedStamp; use Symfony\Component\Messenger\Middleware\MiddlewareInterface; use Symfony\Component\Messenger\Middleware\StackInterface; + use Symfony\Component\Messenger\Stamp\ReceivedStamp; class MyOwnMiddleware implements MiddlewareInterface { @@ -210,8 +210,8 @@ First, create your sender:: namespace App\MessageSender; use App\Message\ImportantAction; - use Symfony\Component\Messenger\Transport\Sender\SenderInterface; use Symfony\Component\Messenger\Envelope; + use Symfony\Component\Messenger\Transport\Sender\SenderInterface; class ImportantActionToEmailSender implements SenderInterface { @@ -264,9 +264,9 @@ First, create your receiver:: namespace App\MessageReceiver; use App\Message\NewOrder; + use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface; use Symfony\Component\Serializer\SerializerInterface; - use Symfony\Component\Messenger\Envelope; class NewOrdersFromCsvFileReceiver implements ReceiverInterface { diff --git a/components/serializer.rst b/components/serializer.rst index 849259ba462..24ce0153522 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -731,9 +731,9 @@ for encoding (array to format) and You can add new encoders to a Serializer instance by using its second constructor argument:: - use Symfony\Component\Serializer\Serializer; - use Symfony\Component\Serializer\Encoder\XmlEncoder; use Symfony\Component\Serializer\Encoder\JsonEncoder; + use Symfony\Component\Serializer\Encoder\XmlEncoder; + use Symfony\Component\Serializer\Serializer; $encoders = [new XmlEncoder(), new JsonEncoder()]; $serializer = new Serializer([], $encoders); @@ -1045,11 +1045,11 @@ maximum depth is reached. This is especially useful when serializing entities having unique identifiers:: use Doctrine\Common\Annotations\AnnotationReader; - use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\Annotation\MaxDepth; use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory; use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; + use Symfony\Component\Serializer\Serializer; class Foo { @@ -1211,8 +1211,8 @@ If the class constructor defines arguments, as usually happens with arguments are missing. In those cases, use the ``default_constructor_arguments`` context option:: - use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; + use Symfony\Component\Serializer\Serializer; class MyObj { @@ -1331,8 +1331,8 @@ this is already set up and you only need to provide the configuration. Otherwise // ... use Symfony\Component\Serializer\Encoder\JsonEncoder; - use Symfony\Component\Serializer\Mapping\ClassDiscriminatorMapping; use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata; + use Symfony\Component\Serializer\Mapping\ClassDiscriminatorMapping; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\Serializer\Serializer; diff --git a/components/var_dumper.rst b/components/var_dumper.rst index d369e52f37d..7ec12a9aa66 100644 --- a/components/var_dumper.rst +++ b/components/var_dumper.rst @@ -152,13 +152,13 @@ Outside a Symfony application, use the :class:`Symfony\\Component\\VarDumper\\Du require __DIR__.'/vendor/autoload.php'; - use Symfony\Component\VarDumper\VarDumper; use Symfony\Component\VarDumper\Cloner\VarCloner; use Symfony\Component\VarDumper\Dumper\CliDumper; use Symfony\Component\VarDumper\Dumper\ContextProvider\CliContextProvider; use Symfony\Component\VarDumper\Dumper\ContextProvider\SourceContextProvider; use Symfony\Component\VarDumper\Dumper\HtmlDumper; use Symfony\Component\VarDumper\Dumper\ServerDumper; + use Symfony\Component\VarDumper\VarDumper; $cloner = new VarCloner(); $fallbackDumper = \in_array(\PHP_SAPI, ['cli', 'phpdbg']) ? new CliDumper() : new HtmlDumper(); diff --git a/doctrine/event_listeners_subscribers.rst b/doctrine/event_listeners_subscribers.rst index 5aed174806f..322b2310d42 100644 --- a/doctrine/event_listeners_subscribers.rst +++ b/doctrine/event_listeners_subscribers.rst @@ -140,11 +140,10 @@ interface and have an event method for each event it subscribes to:: // src/EventListener/SearchIndexerSubscriber.php namespace App\EventListener; - use AppBundle\Entity\Product; + use App\Entity\Product; use Doctrine\Common\EventSubscriber; // for Doctrine < 2.4: use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\Common\Persistence\Event\LifecycleEventArgs; - use App\Entity\Product; use Doctrine\ORM\Events; class SearchIndexerSubscriber implements EventSubscriber diff --git a/form/form_themes.rst b/form/form_themes.rst index a24d656b7d4..3e65d87593c 100644 --- a/form/form_themes.rst +++ b/form/form_themes.rst @@ -260,8 +260,8 @@ based on your form type name (e.g. ``ProductType`` equates to ``product``). If you're not sure what your form name is, look at the HTML code rendered for your form. You can also define this value explicitly with the ``block_name`` option:: - use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\Type\TextType; + use Symfony\Component\Form\FormBuilderInterface; public function buildForm(FormBuilderInterface $builder, array $options) { diff --git a/mercure.rst b/mercure.rst index 34d6ea6231c..577f70859a4 100644 --- a/mercure.rst +++ b/mercure.rst @@ -249,8 +249,8 @@ it will be handled automatically:: namespace App\Controller; use Symfony\Component\HttpFoundation\Response; - use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Mercure\Update; + use Symfony\Component\Messenger\MessageBusInterface; class PublishController { diff --git a/messenger.rst b/messenger.rst index 2c68d05305c..bdc596d2cff 100644 --- a/messenger.rst +++ b/messenger.rst @@ -694,10 +694,10 @@ Create your Transport Factory You need to give FrameworkBundle the opportunity to create your transport from a DSN. You will need a transport factory:: - use Symfony\Component\Messenger\Transport\TransportFactoryInterface; - use Symfony\Component\Messenger\Transport\TransportInterface; use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface; use Symfony\Component\Messenger\Transport\Sender\SenderInterface; + use Symfony\Component\Messenger\Transport\TransportFactoryInterface; + use Symfony\Component\Messenger\Transport\TransportInterface; class YourTransportFactory implements TransportFactoryInterface { diff --git a/quick_tour/flex_recipes.rst b/quick_tour/flex_recipes.rst index c3abf17cb27..287fa17cea6 100644 --- a/quick_tour/flex_recipes.rst +++ b/quick_tour/flex_recipes.rst @@ -156,8 +156,8 @@ Are you building an API? You can already return JSON easily from any controller: // src/Controller/DefaultController.php namespace App\Controller; - use Symfony\Component\Routing\Annotation\Route; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; + use Symfony\Component\Routing\Annotation\Route; class DefaultController extends AbstractController { diff --git a/quick_tour/the_architecture.rst b/quick_tour/the_architecture.rst index c7216a3148c..19d77648f7d 100644 --- a/quick_tour/the_architecture.rst +++ b/quick_tour/the_architecture.rst @@ -25,8 +25,8 @@ use the logger in a controller, add a new argument type-hinted with ``LoggerInte namespace App\Controller; use Psr\Log\LoggerInterface; - use Symfony\Component\Routing\Annotation\Route; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; + use Symfony\Component\Routing\Annotation\Route; class DefaultController extends AbstractController { @@ -110,8 +110,8 @@ Great! You can use this immediately in your controller:: use App\GreetingGenerator; use Psr\Log\LoggerInterface; - use Symfony\Component\Routing\Annotation\Route; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; + use Symfony\Component\Routing\Annotation\Route; class DefaultController extends AbstractController { diff --git a/reference/configuration/swiftmailer.rst b/reference/configuration/swiftmailer.rst index 7ed83e9133c..d53935b8d59 100644 --- a/reference/configuration/swiftmailer.rst +++ b/reference/configuration/swiftmailer.rst @@ -380,8 +380,9 @@ alternatives based on the :ref:`service binding ` feature: // config/services.php use App\Some\Service; - use Symfony\Component\DependencyInjection\Reference; use Psr\Log\LoggerInterface; + use Symfony\Component\DependencyInjection\Reference; + $container->register(Service::class) ->setPublic(true) diff --git a/reference/constraints/Choice.rst b/reference/constraints/Choice.rst index efb85b7334d..2eb4679b797 100644 --- a/reference/constraints/Choice.rst +++ b/reference/constraints/Choice.rst @@ -259,13 +259,11 @@ you can pass the class name and the method as an array. namespace App\Entity; use App\Entity\Genre; - use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Constraints as Assert; + use Symfony\Component\Validator\Mapping\ClassMetadata; class Author { - protected $genre; - public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('genre', new Assert\Choice([ diff --git a/reference/constraints/DivisibleBy.rst b/reference/constraints/DivisibleBy.rst index f0bf60ccf14..43f9e41e73d 100644 --- a/reference/constraints/DivisibleBy.rst +++ b/reference/constraints/DivisibleBy.rst @@ -85,8 +85,8 @@ The following constraints ensure that: // src/Entity/Item.php namespace App\Entity; - use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Constraints as Assert; + use Symfony\Component\Validator\Mapping\ClassMetadata; class Item { diff --git a/reference/constraints/Url.rst b/reference/constraints/Url.rst index c58838b5161..8ed8312fdfa 100644 --- a/reference/constraints/Url.rst +++ b/reference/constraints/Url.rst @@ -146,8 +146,8 @@ option to the value of any of the ``CHECK_DNS_TYPE_*`` constants in the // src/Entity/Author.php namespace App\Entity; - use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Constraints as Assert; + use Symfony\Component\Validator\Mapping\ClassMetadata; class Author { diff --git a/reference/dic_tags.rst b/reference/dic_tags.rst index 1aca88bb444..9ac12b3629e 100644 --- a/reference/dic_tags.rst +++ b/reference/dic_tags.rst @@ -1082,8 +1082,8 @@ the service is auto-registered and auto-tagged. But, you can also register it ma .. code-block:: php - use App\Twig\AppExtension; use App\Twig\AnotherExtension; + use App\Twig\AppExtension; $container ->register(AppExtension::class) @@ -1224,7 +1224,6 @@ the service is auto-registered and auto-tagged. But, you can also register it ma .. code-block:: php use App\Twig\AppExtension; - use App\Twig\AnotherExtension; $container ->register(AppExtension::class) diff --git a/security/form_login_setup.rst b/security/form_login_setup.rst index 4125f46fc36..9844646257b 100644 --- a/security/form_login_setup.rst +++ b/security/form_login_setup.rst @@ -168,12 +168,13 @@ a traditional HTML form that submits to ``/login``: use App\Entity\User; use Doctrine\ORM\EntityManagerInterface; - use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException; + use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; + use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException; use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException; use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\User\UserInterface; diff --git a/security/user_provider.rst b/security/user_provider.rst index a6df9e76a4f..e4628a7ec31 100644 --- a/security/user_provider.rst +++ b/security/user_provider.rst @@ -128,8 +128,8 @@ interface only requires one method: ``loadUserByUsername($username)``:: // src/Repository/UserRepository.php namespace App\Repository; - use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface; use Doctrine\ORM\EntityRepository; + use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface; class UserRepository extends EntityRepository implements UserLoaderInterface { @@ -480,8 +480,8 @@ and want to inject in your ``LoginFormAuthenticator`` a user provider of type // src/Security/LoginFormAuthenticator.php namespace App\Security; - use Symfony\Component\Security\Guard\Authenticator\AbstractFormLoginAuthenticator; use Symfony\Component\Security\Core\User\InMemoryUserProvider; + use Symfony\Component\Security\Guard\Authenticator\AbstractFormLoginAuthenticator; class LoginFormAuthenticator extends AbstractFormLoginAuthenticator {