Skip to content

ordered use statements for php code examples #11478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/ldap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand Down
2 changes: 1 addition & 1 deletion components/mercure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions components/messenger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down
10 changes: 5 additions & 5 deletions components/serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion components/var_dumper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions doctrine/event_listeners_subscribers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion form/form_themes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion mercure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions messenger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion quick_tour/flex_recipes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions quick_tour/the_architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion reference/configuration/swiftmailer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,9 @@ alternatives based on the :ref:`service binding <services-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)
Expand Down
4 changes: 1 addition & 3 deletions reference/constraints/Choice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
2 changes: 1 addition & 1 deletion reference/constraints/DivisibleBy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion reference/constraints/Url.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
3 changes: 1 addition & 2 deletions reference/dic_tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion security/form_login_setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions security/user_provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down