diff --git a/controller/argument_value_resolver.rst b/controller/argument_value_resolver.rst index da209a731df..90763c591c0 100644 --- a/controller/argument_value_resolver.rst +++ b/controller/argument_value_resolver.rst @@ -76,6 +76,7 @@ In the next example, you'll create a value resolver to inject the object that represents the current user whenever a controller method type-hints an argument with the ``User`` class:: + // src/Controller/UserController.php namespace App\Controller; use App\Entity\User; diff --git a/controller/error_pages.rst b/controller/error_pages.rst index 613a245ef8d..f3c8256e453 100644 --- a/controller/error_pages.rst +++ b/controller/error_pages.rst @@ -208,7 +208,7 @@ JSON/XML/CSV/YAML encoders. When your application throws an exception, Symfony can output it in one of those formats. If you want to change the output contents, create a new Normalizer that supports the ``FlattenException`` input:: - # src/App/Serializer/MyCustomProblemNormalizer.php + # src/Serializer/MyCustomProblemNormalizer.php namespace App\Serializer; use Symfony\Component\ErrorHandler\Exception\FlattenException; diff --git a/controller/service.rst b/controller/service.rst index 18ee56ee707..ca2f09b5d70 100644 --- a/controller/service.rst +++ b/controller/service.rst @@ -26,6 +26,8 @@ a service like: ``App\Controller\HelloController::index``: .. code-block:: php-annotations // src/Controller/HelloController.php + namespace App\Controller; + use Symfony\Component\Routing\Annotation\Route; class HelloController @@ -87,6 +89,8 @@ which is a common practice when following the `ADR pattern`_ .. code-block:: php-annotations // src/Controller/Hello.php + namespace App\Controller; + use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; diff --git a/controller/soap_web_service.rst b/controller/soap_web_service.rst index 8d1f7ae1f0a..37c72316878 100644 --- a/controller/soap_web_service.rst +++ b/controller/soap_web_service.rst @@ -57,6 +57,7 @@ Finally, below is an example of a controller that is capable of handling a SOAP request. Because ``index()`` is accessible via ``/soap``, the WSDL document can be retrieved via ``/soap?wsdl``:: + // src/Controller/HelloServiceController.php namespace App\Controller; use App\Service\HelloService; diff --git a/controller/upload_file.rst b/controller/upload_file.rst index a50368e9f93..dad80ee957d 100644 --- a/controller/upload_file.rst +++ b/controller/upload_file.rst @@ -327,6 +327,8 @@ Then, define a service for this class: Now you're ready to use this service in the controller:: // src/Controller/ProductController.php + namespace App\Controller; + use App\Service\FileUploader; use Symfony\Component\HttpFoundation\Request; diff --git a/deployment/fortrabbit.rst b/deployment/fortrabbit.rst index f13bf4f0ad4..d2aedab9598 100644 --- a/deployment/fortrabbit.rst +++ b/deployment/fortrabbit.rst @@ -9,4 +9,4 @@ Deploying to fortrabbit For details on deploying to fortrabbit, see their official documentation: `Install Symfony`_ -.. _`Install Symfony`: https://help.fortrabbit.com/install-symfony-3-uni +.. _`Install Symfony`: https://help.fortrabbit.com/install-symfony-5-uni diff --git a/doctrine/associations.rst b/doctrine/associations.rst index 017f5903391..8bdddab536b 100644 --- a/doctrine/associations.rst +++ b/doctrine/associations.rst @@ -548,6 +548,7 @@ What about *removing* a ``Product`` from a ``Category``? The ``make:entity`` com also generated a ``removeProduct()`` method:: // src/Entity/Category.php + namespace App\Entity; // ... class Category diff --git a/doctrine/dbal.rst b/doctrine/dbal.rst index 8487ffdce91..3d451fb4af6 100644 --- a/doctrine/dbal.rst +++ b/doctrine/dbal.rst @@ -44,6 +44,9 @@ if you *don't* want to use the Doctrine ORM. You can then access the Doctrine DBAL connection by autowiring the ``Connection`` object:: + // src/Controller/UserController.php + namespace App\Controller; + use Doctrine\DBAL\Driver\Connection; class UserController extends AbstractController diff --git a/doctrine/events.rst b/doctrine/events.rst index 9b44b35cba1..1ce0bfa8ac0 100644 --- a/doctrine/events.rst +++ b/doctrine/events.rst @@ -56,6 +56,8 @@ define a callback for the ``prePersist`` Doctrine event: .. code-block:: php-annotations // src/Entity/Product.php + namespace App\Entity; + use Doctrine\ORM\Mapping as ORM; // When using annotations, don't forget to add @ORM\HasLifecycleCallbacks() diff --git a/doctrine/multiple_entity_managers.rst b/doctrine/multiple_entity_managers.rst index 132dbaac4ba..faffc480877 100644 --- a/doctrine/multiple_entity_managers.rst +++ b/doctrine/multiple_entity_managers.rst @@ -230,6 +230,9 @@ When working with multiple entity managers to generate migrations: If you *do* omit the entity manager's name when asking for it, the default entity manager (i.e. ``default``) is returned:: + // src/Controller/UserController.php + namespace App\Controller; + // ... use Doctrine\ORM\EntityManagerInterface; @@ -256,6 +259,9 @@ entity manager to persist and fetch its entities. The same applies to repository calls:: + // src/Controller/UserController.php + namespace App\Controller; + use AcmeStoreBundle\Entity\Customer; use AcmeStoreBundle\Entity\Product; // ... diff --git a/doctrine/resolve_target_entity.rst b/doctrine/resolve_target_entity.rst index a60dfe3e604..36038fd9f3c 100644 --- a/doctrine/resolve_target_entity.rst +++ b/doctrine/resolve_target_entity.rst @@ -42,8 +42,8 @@ A Customer entity:: // src/Entity/Customer.php namespace App\Entity; - use Acme\CustomerBundle\Entity\Customer as BaseCustomer; - use Acme\InvoiceBundle\Model\InvoiceSubjectInterface; + use App\Entity\CustomerInterface as BaseCustomer; + use App\Model\InvoiceSubjectInterface; use Doctrine\ORM\Mapping as ORM; /** @@ -58,10 +58,10 @@ A Customer entity:: An Invoice entity:: - // src/Acme/InvoiceBundle/Entity/Invoice.php - namespace Acme\InvoiceBundle\Entity; + // src/Entity/Invoice.php + namespace App\Entity; - use Acme\InvoiceBundle\Model\InvoiceSubjectInterface; + use App\Model\InvoiceSubjectInterface; use Doctrine\ORM\Mapping as ORM; /** @@ -73,7 +73,7 @@ An Invoice entity:: class Invoice { /** - * @ORM\ManyToOne(targetEntity="Acme\InvoiceBundle\Model\InvoiceSubjectInterface") + * @ORM\ManyToOne(targetEntity="App\Model\InvoiceSubjectInterface") * @var InvoiceSubjectInterface */ protected $subject; @@ -81,8 +81,8 @@ An Invoice entity:: An InvoiceSubjectInterface:: - // src/Acme/InvoiceBundle/Model/InvoiceSubjectInterface.php - namespace Acme\InvoiceBundle\Model; + // src/Model/InvoiceSubjectInterface.php + namespace App\Model; /** * An interface that the invoice Subject object should implement. @@ -115,7 +115,7 @@ about the replacement: orm: # ... resolve_target_entities: - Acme\InvoiceBundle\Model\InvoiceSubjectInterface: App\Entity\Customer + App\Model\InvoiceSubjectInterface: App\Entity\Customer .. code-block:: xml @@ -132,7 +132,7 @@ about the replacement: - App\Entity\Customer + App\Entity\Customer @@ -140,8 +140,8 @@ about the replacement: .. code-block:: php // config/packages/doctrine.php - use Acme\InvoiceBundle\Model\InvoiceSubjectInterface; use App\Entity\Customer; + use App\Model\InvoiceSubjectInterface; $container->loadFromExtension('doctrine', [ 'orm' => [ diff --git a/form/create_custom_field_type.rst b/form/create_custom_field_type.rst index b17add4b3d7..58e265fd2ad 100644 --- a/form/create_custom_field_type.rst +++ b/form/create_custom_field_type.rst @@ -287,6 +287,8 @@ to define, validate and process their values:: Now you can configure these options when using the form type:: // src/Form/Type/OrderType.php + namespace App\Form\Type; + // ... class OrderType extends AbstractType @@ -310,6 +312,8 @@ Now you can configure these options when using the form type:: The last step is to use these options when building the form:: // src/Form/Type/PostalAddressType.php + namespace App\Form\Type; + // ... class PostalAddressType extends AbstractType @@ -453,6 +457,8 @@ defined by the form or be completely independent:: // src/Form/Type/PostalAddressType.php + namespace App\Form\Type; + use Doctrine\ORM\EntityManagerInterface; // ... diff --git a/form/create_form_type_extension.rst b/form/create_form_type_extension.rst index fb1cd2e02b2..59b1c06e9fe 100644 --- a/form/create_form_type_extension.rst +++ b/form/create_form_type_extension.rst @@ -251,6 +251,8 @@ may not be applied to it. Another option is to return multiple form types in the ``getExtendedTypes()`` method to extend all of them:: + // src/Form/Extension/DateTimeExtension.php + namespace App\Form\Extension; // ... use Symfony\Component\Form\Extension\Core\Type\DateTimeType; use Symfony\Component\Form\Extension\Core\Type\DateType; diff --git a/form/dynamic_form_modification.rst b/form/dynamic_form_modification.rst index f2b37cb07c5..69339480248 100644 --- a/form/dynamic_form_modification.rst +++ b/form/dynamic_form_modification.rst @@ -255,6 +255,8 @@ Now that you have all the basics in place you can use the features of the security helper to fill in the listener logic:: // src/Form/Type/FriendMessageFormType.php + namespace App\Form\Type; + use App\Entity\User; use Doctrine\ORM\EntityRepository; use Symfony\Bridge\Doctrine\Form\Type\EntityType; diff --git a/form/inherit_data_option.rst b/form/inherit_data_option.rst index 113e66d6381..3321ab2153a 100644 --- a/form/inherit_data_option.rst +++ b/form/inherit_data_option.rst @@ -126,6 +126,8 @@ access the properties of the ``Customer`` instance instead. Convenient, eh? Finally, make this work by adding the location form to your two original forms:: // src/Form/Type/CompanyType.php + namespace App\Form\Type; + use App\Entity\Company; // ... @@ -141,6 +143,8 @@ Finally, make this work by adding the location form to your two original forms:: .. code-block:: php // src/Form/Type/CustomerType.php + namespace App\Form\Type; + use App\Entity\Customer; // ... diff --git a/form/type_guesser.rst b/form/type_guesser.rst index b842e12a9ad..f990aad4115 100644 --- a/form/type_guesser.rst +++ b/form/type_guesser.rst @@ -82,6 +82,7 @@ The ``TypeGuess`` constructor requires three options: With this knowledge, you can implement the ``guessType()`` method of the ``PHPDocTypeGuesser``:: + // src/Form/TypeGuesser/PHPDocTypeGuesser.php namespace App\Form\TypeGuesser; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; @@ -221,7 +222,7 @@ and tag it with ``form.type_guesser``: :method:`Symfony\\Component\\Form\\FormFactoryBuilder::addTypeGuessers` of the ``FormFactoryBuilder`` to register new type guessers:: - use Acme\Form\PHPDocTypeGuesser; + use App\Form\TypeGuesser\PHPDocTypeGuesser; use Symfony\Component\Form\Forms; $formFactory = Forms::createFormFactoryBuilder() diff --git a/form/use_empty_data.rst b/form/use_empty_data.rst index c186396f8e4..6a567286094 100644 --- a/form/use_empty_data.rst +++ b/form/use_empty_data.rst @@ -44,6 +44,7 @@ that takes arguments. Remember, the default ``data_class`` option calls that constructor with no arguments:: // src/Form/Type/BlogType.php + namespace App\Form\Type; // ... use App\Entity\Blog; diff --git a/http_cache/esi.rst b/http_cache/esi.rst index 31b4c354e37..621f604ea95 100644 --- a/http_cache/esi.rst +++ b/http_cache/esi.rst @@ -98,7 +98,8 @@ ticker at the bottom of the content. With ESI, you can cache the news ticker independently of the rest of the page:: // src/Controller/DefaultController.php - + namespace App\Controller; + // ... class DefaultController extends AbstractController { diff --git a/http_cache/ssi.rst b/http_cache/ssi.rst index 7397c7b0a5e..94bab702db4 100644 --- a/http_cache/ssi.rst +++ b/http_cache/ssi.rst @@ -85,7 +85,8 @@ to cache a static GDPR content block. With SSI, you can add some expiration on this block and keep the page private:: // src/Controller/ProfileController.php - + namespace App\Controller; + // ... class ProfileController extends AbstractController { diff --git a/logging/monolog_console.rst b/logging/monolog_console.rst index 9eb8b28b062..5c0263c5349 100644 --- a/logging/monolog_console.rst +++ b/logging/monolog_console.rst @@ -35,6 +35,9 @@ the current log level and the console verbosity. The example above could then be rewritten as:: + // src/Command/YourCommand.php + namespace App\Command; + use Psr\Log\LoggerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; diff --git a/logging/processors.rst b/logging/processors.rst index f2b889461ec..9f46326ddaa 100644 --- a/logging/processors.rst +++ b/logging/processors.rst @@ -16,6 +16,7 @@ Sometimes it is hard to tell which entries in the log belong to which session and/or request. The following example will add a unique token for each request using a processor:: + // src/Logger/SessionRequestProcessor.php namespace App\Logger; use Symfony\Component\HttpFoundation\Session\SessionInterface; diff --git a/messenger/dispatch_after_current_bus.rst b/messenger/dispatch_after_current_bus.rst index c2b85c2aaad..e382f49eed3 100644 --- a/messenger/dispatch_after_current_bus.rst +++ b/messenger/dispatch_after_current_bus.rst @@ -44,6 +44,7 @@ are dispatched by a handler once that handler has fully finished. This can be by using the ``DispatchAfterCurrentBusMiddleware`` and adding a ``DispatchAfterCurrentBusStamp`` stamp to :ref:`the message Envelope `:: + // src/Messenger/CommandHandler/RegisterUserHandler.php namespace App\Messenger\CommandHandler; use App\Entity\User; @@ -85,6 +86,7 @@ using the ``DispatchAfterCurrentBusMiddleware`` and adding a .. code-block:: php + // src/Messenger/EventSubscriber/WhenUserRegisteredThenSendWelcomeEmail.php namespace App\Messenger\EventSubscriber; use App\Entity\User; diff --git a/reference/configuration/kernel.rst b/reference/configuration/kernel.rst index 5852927e7ad..6b0ac4279ad 100644 --- a/reference/configuration/kernel.rst +++ b/reference/configuration/kernel.rst @@ -33,6 +33,8 @@ To change this value, override the ``getCharset()`` method and return another charset:: // src/Kernel.php + namespace App; + use Symfony\Component\HttpKernel\Kernel as BaseKernel; // ... @@ -89,6 +91,8 @@ override the :method:`Symfony\\Component\\HttpKernel\\Kernel::getProjectDir` method to return the right project directory:: // src/Kernel.php + namespace App; + use Symfony\Component\HttpKernel\Kernel as BaseKernel; // ...