From 9e5cd17b075e9cdc659ace8acac065c78f0c2d4c Mon Sep 17 00:00:00 2001 From: Wouter J Date: Mon, 30 Oct 2017 22:28:00 +0100 Subject: [PATCH 1/3] Lots of automated migrations to Symfony Flex structure --- bundles.rst | 4 +- bundles/extension.rst | 8 +- bundles/override.rst | 2 +- bundles/remove.rst | 8 +- components/dependency_injection.rst | 2 +- components/http_foundation.rst | 2 +- components/routing.rst | 28 ++-- .../front_controllers_and_kernel.rst | 6 +- console.rst | 18 +- console/command_in_controller.rst | 8 +- console/commands_as_services.rst | 12 +- console/hide_commands.rst | 4 +- console/lazy_commands.rst | 2 +- console/request_context.rst | 2 +- console/style.rst | 14 +- controller.rst | 32 ++-- controller/argument_value_resolver.rst | 18 +- controller/error_pages.rst | 12 +- controller/service.rst | 10 +- controller/soap_web_service.rst | 12 +- controller/upload_file.rst | 56 +++---- deployment.rst | 2 +- deployment/azure-website.rst | 26 +-- deployment/heroku.rst | 18 +- deployment/platformsh.rst | 4 +- deployment/proxies.rst | 4 +- doctrine.rst | 22 +-- doctrine/associations.rst | 28 ++-- doctrine/custom_dql_functions.rst | 30 ++-- doctrine/dbal.rst | 12 +- doctrine/event_listeners_subscribers.rst | 36 ++-- doctrine/lifecycle_callbacks.rst | 10 +- doctrine/mapping_model_classes.rst | 2 +- doctrine/registration_form.rst | 34 ++-- doctrine/repository.rst | 26 +-- doctrine/resolve_target_entity.rst | 10 +- doctrine/reverse_engineering.rst | 8 +- email.rst | 4 +- email/testing.rst | 2 +- event_dispatcher.rst | 22 +-- event_dispatcher/before_after_filters.rst | 14 +- event_dispatcher/method_behavior.rst | 14 +- form/action_method.rst | 12 +- form/create_custom_field_type.rst | 20 +-- form/create_form_type_extension.rst | 22 +-- form/csrf_protection.rst | 2 +- form/data_based_validation.rst | 6 +- form/data_transformers.rst | 40 ++--- form/dynamic_form_modification.rst | 50 +++--- form/embedded.rst | 14 +- form/events.rst | 10 +- form/form_collections.rst | 64 +++---- form/form_customization.rst | 14 +- form/form_dependencies.rst | 22 +-- form/form_themes.rst | 12 +- form/inherit_data_option.rst | 28 ++-- form/rendering.rst | 4 +- form/type_guesser.rst | 14 +- form/unit_testing.rst | 18 +- form/use_empty_data.rst | 4 +- form/validation_group_service_resolver.rst | 10 +- forms.rst | 44 ++--- frontend.rst | 2 +- frontend/custom_version_strategy.rst | 18 +- http_cache.rst | 12 +- http_cache/esi.rst | 10 +- http_cache/validation.rst | 14 +- introduction/from_flat_php_to_symfony2.rst | 26 +-- logging/formatter.rst | 2 +- logging/processors.rst | 18 +- profiler/data_collector.rst | 14 +- profiler/matchers.rst | 12 +- quick_tour/the_architecture.rst | 14 +- quick_tour/the_big_picture.rst | 24 +-- quick_tour/the_controller.rst | 30 ++-- quick_tour/the_view.rst | 16 +- reference/dic_tags.rst | 112 ++++++------- routing.rst | 32 ++-- routing/custom_route_loader.rst | 26 +-- routing/external_resources.rst | 8 +- routing/extra_information.rst | 2 +- routing/hostname_pattern.rst | 20 +-- routing/optional_placeholders.rst | 12 +- routing/redirect_in_config.rst | 4 +- routing/redirect_trailing_slash.rst | 8 +- routing/requirements.rst | 16 +- routing/scheme.rst | 6 +- routing/service_container_parameters.rst | 4 +- security.rst | 4 +- security/access_denied_handler.rst | 10 +- security/acl.rst | 8 +- security/api_key_authentication.rst | 36 ++-- security/csrf_in_login_form.rst | 4 +- security/custom_authentication_provider.rst | 44 ++--- security/custom_password_authenticator.rst | 14 +- security/custom_provider.rst | 30 ++-- security/entity_provider.rst | 18 +- security/form_login.rst | 12 +- security/form_login_setup.rst | 14 +- security/guard_authentication.rst | 20 +-- security/impersonating_user.rst | 6 +- security/json_login_setup.rst | 4 +- security/ldap.rst | 2 +- security/multiple_guard_authenticators.rst | 28 ++-- security/multiple_user_providers.rst | 6 +- security/password_encoding.rst | 2 +- security/remember_me.rst | 4 +- security/securing_services.rst | 8 +- security/user_checkers.rst | 14 +- security/voters.rst | 16 +- service_container.rst | 154 ++++++++--------- service_container/3.3-di-changes.rst | 158 +++++++++--------- service_container/alias_private.rst | 28 ++-- service_container/autowiring.rst | 100 +++++------ service_container/calls.rst | 10 +- service_container/compiler_passes.rst | 4 +- service_container/configurators.rst | 56 +++---- service_container/debug.rst | 4 +- service_container/definitions.rst | 12 +- service_container/expression_language.rst | 26 +-- service_container/factories.rst | 56 +++---- service_container/import.rst | 4 +- service_container/injection_types.rst | 20 +-- service_container/lazy_services.rst | 6 +- service_container/optional_dependencies.rst | 12 +- service_container/parameters.rst | 6 +- service_container/parent_services.rst | 70 ++++---- service_container/request.rst | 4 +- service_container/service_decoration.rst | 28 ++-- service_container/service_locators.rst | 24 +-- service_container/shared.rst | 10 +- service_container/tags.rst | 62 +++---- session/locale_sticky_session.rst | 18 +- session/proxy_examples.rst | 18 +- setup/built_in_web_server.rst | 4 +- setup/file_permissions.rst | 2 +- setup/flex.rst | 4 +- setup/new_project_svn.rst | 2 +- setup/web_server_configuration.rst | 32 ++-- templating.rst | 46 ++--- templating/PHP.rst | 26 +-- templating/debug.rst | 6 +- templating/embedding_controllers.rst | 12 +- templating/global_variables.rst | 6 +- templating/inheritance.rst | 6 +- templating/syntax.rst | 2 +- templating/twig_extension.rst | 6 +- testing.rst | 12 +- testing/database.rst | 12 +- testing/doctrine.rst | 4 +- testing/http_authentication.rst | 2 +- translation/locale.rst | 2 +- validation.rst | 72 ++++---- validation/custom_constraint.rst | 42 ++--- validation/groups.rst | 16 +- validation/sequence_provider.rst | 52 +++--- validation/severity.rst | 16 +- validation/translations.rst | 16 +- workflow/state-machines.rst | 6 +- workflow/usage.rst | 10 +- 160 files changed, 1530 insertions(+), 1540 deletions(-) diff --git a/bundles.rst b/bundles.rst index d4d692c724d..7391ffe9d25 100644 --- a/bundles.rst +++ b/bundles.rst @@ -151,14 +151,14 @@ of the most common elements of a bundle: necessary). ``Resources/config/`` - Houses configuration, including routing configuration (e.g. ``routing.yml``). + Houses configuration, including routing configuration (e.g. ``routes.yaml``). ``Resources/views/`` Holds templates organized by controller name (e.g. ``Random/index.html.twig``). ``Resources/public/`` Contains web assets (images, stylesheets, etc) and is copied or symbolically - linked into the project ``web/`` directory via the ``assets:install`` console + linked into the project ``public/`` directory via the ``assets:install`` console command. ``Tests/`` diff --git a/bundles/extension.rst b/bundles/extension.rst index 407831e6710..eee9ff05c10 100644 --- a/bundles/extension.rst +++ b/bundles/extension.rst @@ -116,7 +116,7 @@ Other available loaders are the ``YamlFileLoader``, ``PhpFileLoader`` and .. caution:: If you removed the default file with service definitions (i.e. - ``app/config/services.yml``), make sure to also remove it from the + ``app/config/services.yaml``), make sure to also remove it from the ``imports`` key in ``app/config/config.yml``. Using Configuration to Change the Services @@ -146,8 +146,8 @@ work in the same way, but the second one is for classes that contain PHP annotations). Define the classes to compile as an array of their fully qualified class names:: - use AppBundle\Manager\UserManager; - use AppBundle\Utils\Slugger; + use App\Manager\UserManager; + use App\Utils\Slugger; // ... public function load(array $configs, ContainerBuilder $container) @@ -163,7 +163,7 @@ class names:: // add here only classes that contain PHP annotations $this->addAnnotatedClassesToCompile(array( - 'AppBundle\\Controller\\DefaultController', + 'App\\Controller\\DefaultController', // ... )); } diff --git a/bundles/override.rst b/bundles/override.rst index 3c0fb8c7f2d..b1a55bfd174 100644 --- a/bundles/override.rst +++ b/bundles/override.rst @@ -26,7 +26,7 @@ Routing Routing is never automatically imported in Symfony. If you want to include the routes from any bundle, then they must be manually imported from somewhere -in your application (e.g. ``app/config/routing.yml``). +in your application (e.g. ``app/config/routes.yaml``). The easiest way to "override" a bundle's routing is to never import it at all. Instead of importing a third-party bundle's routing, simply copy diff --git a/bundles/remove.rst b/bundles/remove.rst index 644e8742310..525b3c7787a 100644 --- a/bundles/remove.rst +++ b/bundles/remove.rst @@ -42,8 +42,8 @@ that refers to the bundle. ~~~~~~~~~~~~~~~~~~~~~~~~~ *Some* bundles require you to import routing configuration. Check for references -to the bundle in ``app/config/routing.yml`` and ``app/config/routing_dev.yml``. -If you find any references, remove them completely. +to the bundle in the routing configuration (inside ``config/routes/``). If you +find any references, remove them completely. 2.2 Remove Bundle Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -74,8 +74,8 @@ directory, and any parent directories that are now empty (e.g. ``src/Acme/``). 3.1 Remove Bundle Assets ~~~~~~~~~~~~~~~~~~~~~~~~ -Remove the assets of the bundle in the web/ directory (e.g. -``web/bundles/acmedemo`` for the AcmeDemoBundle). +Remove the assets of the bundle in the public/ directory (e.g. +``public/bundles/acmedemo`` for the AcmeDemoBundle). 4. Remove Integration in other Bundles -------------------------------------- diff --git a/components/dependency_injection.rst b/components/dependency_injection.rst index 5a340a9413d..93d55fe44c7 100644 --- a/components/dependency_injection.rst +++ b/components/dependency_injection.rst @@ -210,7 +210,7 @@ Loading a YAML config file:: $container = new ContainerBuilder(); $loader = new YamlFileLoader($container, new FileLocator(__DIR__)); - $loader->load('services.yml'); + $loader->load('services.yaml'); .. note:: diff --git a/components/http_foundation.rst b/components/http_foundation.rst index 87b340cdc40..88f7b336b58 100644 --- a/components/http_foundation.rst +++ b/components/http_foundation.rst @@ -285,7 +285,7 @@ represents an HTTP message. But when moving from a legacy system, adding methods or changing some default behavior might help. In that case, register a PHP callable that is able to create an instance of your ``Request`` class:: - use AppBundle\Http\SpecialRequest; + use App\Http\SpecialRequest; use Symfony\Component\HttpFoundation\Request; Request::setFactory(function ( diff --git a/components/routing.rst b/components/routing.rst index ca52b33f814..03a2ed62c17 100644 --- a/components/routing.rst +++ b/components/routing.rst @@ -364,8 +364,7 @@ routes with UTF-8 characters: .. code-block:: php-annotations - // src/AppBundle/Controller/DefaultController.php - namespace AppBundle\Controller; + namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\Routing\Annotation\Route; @@ -375,23 +374,21 @@ routes with UTF-8 characters: /** * @Route("/category/{name}", name="route1", options={"utf8": true}) */ - public function categoryAction() + public function category() { // ... } .. code-block:: yaml - # app/config/routing.yml route1: path: /category/{name} - defaults: { _controller: 'AppBundle:Default:category' } + defaults: { _controller: 'App\Controller\DefaultController::category' } options: utf8: true .. code-block:: xml - - AppBundle:Default:category + App\Controller\DefaultController::category .. code-block:: php - // app/config/routing.php use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\Route; $collection = new RouteCollection(); $collection->add('route1', new Route('/category/{name}', array( - '_controller' => 'AppBundle:Default:category', + '_controller' => 'App\Controller\DefaultController::category', ), array(), array( @@ -438,8 +434,7 @@ You can also include UTF-8 strings as routing requirements: .. code-block:: php-annotations - // src/AppBundle/Controller/DefaultController.php - namespace AppBundle\Controller; + namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\Routing\Annotation\Route; @@ -454,17 +449,16 @@ You can also include UTF-8 strings as routing requirements: * options={"utf8": true} * ) */ - public function defaultAction() + public function default() { // ... } .. code-block:: yaml - # app/config/routing.yml route2: path: /default/{default} - defaults: { _controller: 'AppBundle:Default:default' } + defaults: { _controller: 'App\Controller\DefaultController::default' } requirements: default: "한국어" options: @@ -472,7 +466,6 @@ You can also include UTF-8 strings as routing requirements: .. code-block:: xml - - AppBundle:Default:default + App\Controller\DefaultController::default 한국어 @@ -488,14 +481,13 @@ You can also include UTF-8 strings as routing requirements: .. code-block:: php - // app/config/routing.php use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\Route; $collection = new RouteCollection(); $collection->add('route2', new Route('/default/{default}', array( - '_controller' => 'AppBundle:Default:default', + '_controller' => 'App\Controller\DefaultController::default', ), array( 'default' => '한국어', diff --git a/configuration/front_controllers_and_kernel.rst b/configuration/front_controllers_and_kernel.rst index 4b361724ca3..951d9edbd17 100644 --- a/configuration/front_controllers_and_kernel.rst +++ b/configuration/front_controllers_and_kernel.rst @@ -30,9 +30,9 @@ The Front Controller The `front controller`_ is a well-known design pattern; it is a section of code that *all* requests served by an application run through. -In the `Symfony Standard Edition`_, this role is taken by the `app.php`_ -and `app_dev.php`_ files in the ``web/`` directory. These are the very -first PHP scripts executed when a request is processed. +In the `Symfony Standard Edition`_, this role is taken by the `index.php`_ file +in the ``public/`` directory. This is the very first PHP script executed when a +request is processed. The main purpose of the front controller is to create an instance of the ``AppKernel`` (more on that in a second), make it handle the request diff --git a/console.rst b/console.rst index 8227269a07c..3b04623cefb 100644 --- a/console.rst +++ b/console.rst @@ -12,14 +12,12 @@ use it to create your own commands. Creating a Command ------------------ -Commands are defined in classes which should be created in the ``Command`` namespace -of your bundle (e.g. ``AppBundle\Command``) and their names should end with the -``Command`` suffix. +Commands are defined in classes extending +:class:`Symfony\\Component\\Console\\Command\\Command`. For example, you may +want a command to create a user:: -For example, you may want a command to create a user:: - - // src/AppBundle/Command/CreateUserCommand.php - namespace AppBundle\Command; + // src/Command/CreateUserCommand.php + namespace App\Command; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -74,7 +72,7 @@ terminal: .. note:: - If you're using the :ref:`default services.yml configuration `, + If you're using the :ref:`default services.yaml configuration `, your command classes are automatically registered as services. You can also manually register your command as a service by configuring the service @@ -229,9 +227,9 @@ class. It uses special input and output classes to ease testing without a real console:: // tests/AppBundle/Command/CreateUserCommandTest.php - namespace Tests\AppBundle\Command; + namespace Tests\App\Command; - use AppBundle\Command\CreateUserCommand; + use App\Command\CreateUserCommand; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Console\Tester\CommandTester; diff --git a/console/command_in_controller.rst b/console/command_in_controller.rst index 26e39fee70f..cc62d38ae1f 100644 --- a/console/command_in_controller.rst +++ b/console/command_in_controller.rst @@ -24,8 +24,8 @@ Imagine you want to send spooled Swift Mailer messages by :doc:`using the swiftmailer:spool:send command `. Run this command from inside your controller via:: - // src/AppBundle/Controller/SpoolController.php - namespace AppBundle\Controller; + // src/Controller/SpoolController.php + namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Controller\Controller; @@ -76,8 +76,8 @@ First, require the package: Now, use it in your controller:: - // src/AppBundle/Controller/SpoolController.php - namespace AppBundle\Controller; + // src/Controller/SpoolController.php + namespace App\Controller; use SensioLabs\AnsiConverter\AnsiToHtmlConverter; use Symfony\Component\Console\Output\BufferedOutput; diff --git a/console/commands_as_services.rst b/console/commands_as_services.rst index a5533ef3b82..a5e01ddb3da 100644 --- a/console/commands_as_services.rst +++ b/console/commands_as_services.rst @@ -4,7 +4,7 @@ How to Define Commands as Services ================================== -If you're using the :ref:`default services.yml configuration `, +If you're using the :ref:`default services.yaml configuration `, your command classes are already registered as services. Great! This is the recommended setup. @@ -26,7 +26,7 @@ using normal :ref:`dependency injection `. For example, suppose you want to log something from within your command:: - namespace AppBundle\Command; + namespace App\Command; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Command\Command; @@ -59,7 +59,7 @@ For example, suppose you want to log something from within your command:: } } -If you're using the :ref:`default services.yml configuration `, +If you're using the :ref:`default services.yaml configuration `, the command class will automatically be registered as a service and passed the ``$logger`` argument (thanks to autowiring). In other words, *just* by creating this class, everything works! You can call the ``app:sunshine`` command and start logging. @@ -96,7 +96,7 @@ Or set the ``command`` attribute on the ``console.command`` tag in your service services: - AppBundle\Command\SunshineCommand: + App\Command\SunshineCommand: tags: - { name: 'console.command', command: 'app:sunshine' } # ... @@ -110,7 +110,7 @@ Or set the ``command`` attribute on the ``console.command`` tag in your service - + @@ -119,7 +119,7 @@ Or set the ``command`` attribute on the ``console.command`` tag in your service .. code-block:: php - use AppBundle\Command\SunshineCommand; + use App\Command\SunshineCommand; //... diff --git a/console/hide_commands.rst b/console/hide_commands.rst index d7c9b011e94..827f93a0a4a 100644 --- a/console/hide_commands.rst +++ b/console/hide_commands.rst @@ -11,8 +11,8 @@ executed through scheduled tasks, etc. In those cases, you can define the command as **hidden** by setting the ``setHidden()`` method to ``true`` in the command configuration:: - // src/AppBundle/Command/LegacyCommand.php - namespace AppBundle\Command; + // src/Command/LegacyCommand.php + namespace App\Command; use Symfony\Component\Console\Command\Command; diff --git a/console/lazy_commands.rst b/console/lazy_commands.rst index 844bdcd0a1b..6f1a102910f 100644 --- a/console/lazy_commands.rst +++ b/console/lazy_commands.rst @@ -16,7 +16,7 @@ The traditional way of adding commands to your application is to use In order to lazy-load commands, you need to register an intermediate loader which will be responsible for returning ``Command`` instances:: - use AppBundle\Command\HeavyCommand; + use App\Command\HeavyCommand; use Symfony\Component\Console\Application; use Symfony\Component\Console\CommandLoader\FactoryCommmandLoader; diff --git a/console/request_context.rst b/console/request_context.rst index b0983d270ed..11125b58255 100644 --- a/console/request_context.rst +++ b/console/request_context.rst @@ -65,7 +65,7 @@ Configuring the Request Context per Command To change it only in one command you can simply fetch the Request Context from the ``router`` service and override its settings:: - // src/AppBundle/Command/DemoCommand.php + // src/Command/DemoCommand.php // ... class DemoCommand extends ContainerAwareCommand diff --git a/console/style.rst b/console/style.rst index db4af516969..a73523ea646 100644 --- a/console/style.rst +++ b/console/style.rst @@ -10,8 +10,8 @@ questions to the user involves a lot of repetitive code. Consider for example the code used to display the title of the following command:: - // src/AppBundle/Command/GreetCommand.php - namespace AppBundle\Command; + // src/Command/GreetCommand.php + namespace App\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputInterface; @@ -50,8 +50,8 @@ class and pass the ``$input`` and ``$output`` variables as its arguments. Then, you can start using any of its helpers, such as ``title()``, which displays the title of the command:: - // src/AppBundle/Command/GreetCommand.php - namespace AppBundle\Command; + // src/Command/GreetCommand.php + namespace App\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Style\SymfonyStyle; @@ -339,7 +339,7 @@ If you don't like the design of the commands that use the Symfony Style, you can define your own set of console styles. Just create a class that implements the :class:`Symfony\\Component\\Console\\Style\\StyleInterface`:: - namespace AppBundle\Console; + namespace App\Console; use Symfony\Component\Console\Style\StyleInterface; @@ -352,9 +352,9 @@ Then, instantiate this custom class instead of the default ``SymfonyStyle`` in your commands. Thanks to the ``StyleInterface`` you won't need to change the code of your commands to change their appearance:: - namespace AppBundle\Console; + namespace App\Console; - use AppBundle\Console\CustomStyle; + use App\Console\CustomStyle; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; diff --git a/controller.rst b/controller.rst index 680c3e47452..a7433d55455 100644 --- a/controller.rst +++ b/controller.rst @@ -13,8 +13,8 @@ else you can dream up. The controller executes whatever arbitrary logic See how simple this is by looking at a Symfony controller in action. This renders a page that prints a lucky (random) number:: - // src/AppBundle/Controller/LuckyController.php - namespace AppBundle\Controller; + // src/Controller/LuckyController.php + namespace App\Controller; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; @@ -55,8 +55,8 @@ While a controller can be any PHP callable (a function, method on an object, or a ``Closure``), a controller is usually a method inside a controller class:: - // src/AppBundle/Controller/LuckyController.php - namespace AppBundle\Controller; + // src/Controller/LuckyController.php + namespace App\Controller; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; @@ -129,8 +129,8 @@ classes. You can extend either to get access to a number of `helper methods`_. Add the ``use`` statement atop the ``Controller`` class and then modify ``LuckyController`` to extend it:: - // src/AppBundle/Controller/LuckyController.php - namespace AppBundle\Controller; + // src/Controller/LuckyController.php + namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; @@ -221,13 +221,13 @@ If you're serving HTML, you'll want to render a template. The ``render()`` method renders a template **and** puts that content into a ``Response`` object for you:: - // renders app/Resources/views/lucky/number.html.twig + // renders templates/lucky/number.html.twig return $this->render('lucky/number.html.twig', array('name' => $name)); Templates can also live in deeper sub-directories. Just try to avoid creating unnecessarily deep structures:: - // renders app/Resources/views/lottery/lucky/number.html.twig + // renders templates/lottery/lucky/number.html.twig return $this->render('lottery/lucky/number.html.twig', array( 'name' => $name, )); @@ -282,12 +282,12 @@ controller's service config: .. code-block:: yaml - # app/config/services.yml + # app/config/services.yaml services: # ... # explicitly configure the service - AppBundle\Controller\LuckyController: + App\Controller\LuckyController: public: true tags: # add multiple tags to control multiple args @@ -310,7 +310,7 @@ controller's service config: - + register(LuckyController::class) ->setPublic(true) @@ -354,7 +354,7 @@ For more information about services, see the :doc:`/service_container` article. is :ref:`autoconfigured ` and extends either :class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller` or :class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController`. If - you use the :ref:`services.yml configuration from the Symfony Standard Edition `, + you use the :ref:`services.yaml configuration from the Symfony Standard Edition `, then your controllers are already registered as services and autoconfigured. If you're not using the default configuration, you can tag your service manually @@ -424,7 +424,7 @@ Symfony will automatically return a 500 HTTP response code. throw new \Exception('Something went wrong!'); In every case, an error page is shown to the end user and a full debug -error page is shown to the developer (i.e. when you're using the ``app_dev.php`` +error page is shown to the developer (i.e. when you're using the ``index.php`` front controller - see :ref:`page-creation-environments`). You'll want to customize the error page your user sees. To do that, see @@ -536,7 +536,7 @@ read any flash messages from the session using ``app.flashes()``: .. code-block:: html+twig - {# app/Resources/views/base.html.twig #} + {# templates/base.html.twig #} {# you can read and display just one flash message type... #} {% for message in app.flashes('notice') %} @@ -556,7 +556,7 @@ read any flash messages from the session using ``app.flashes()``: .. code-block:: html+php - + // you can read and display just one flash message type... getFlashBag()->get('notice') as $message): ?> diff --git a/controller/argument_value_resolver.rst b/controller/argument_value_resolver.rst index 2772626e91f..6af5f9c320c 100644 --- a/controller/argument_value_resolver.rst +++ b/controller/argument_value_resolver.rst @@ -58,9 +58,9 @@ definition. In the next example, you'll create a value resolver to inject the ``User`` object from the security system. Given you write the following controller:: - namespace AppBundle\Controller; + namespace App\Controller; - use AppBundle\Entity\User; + use App\Entity\User; use Symfony\Component\HttpFoundation\Response; class UserController @@ -92,10 +92,10 @@ Now that you know what to do, you can implement this interface. To get the current ``User``, you need the current security token. This token can be retrieved from the token storage:: - // src/AppBundle/ArgumentResolver/UserValueResolver.php - namespace AppBundle\ArgumentResolver; + // src/ArgumentResolver/UserValueResolver.php + namespace App\ArgumentResolver; - use AppBundle\Entity\User; + use App\Entity\User; use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; @@ -148,14 +148,14 @@ and adding a priority. .. code-block:: yaml - # app/config/services.yml + # app/config/services.yaml services: _defaults: # ... be sure autowiring is enabled autowire: true # ... - AppBundle\ArgumentResolver\UserValueResolver: + App\ArgumentResolver\UserValueResolver: tags: - { name: controller.argument_value_resolver, priority: 50 } @@ -172,7 +172,7 @@ and adding a priority. - + @@ -182,7 +182,7 @@ and adding a priority. .. code-block:: php // app/config/services.php - use AppBundle\ArgumentResolver\UserValueResolver; + use App\ArgumentResolver\UserValueResolver; $container->autowire(UserValueResolver::class) ->addTag('controller.argument_value_resolver', array('priority' => 50)); diff --git a/controller/error_pages.rst b/controller/error_pages.rst index 30271a46de7..413380a40aa 100644 --- a/controller/error_pages.rst +++ b/controller/error_pages.rst @@ -185,8 +185,8 @@ With this route added, you can use URLs like .. code-block:: text - http://localhost/app_dev.php/_error/{statusCode} - http://localhost/app_dev.php/_error/{statusCode}.{format} + http://localhost/index.php/_error/{statusCode} + http://localhost/index.php/_error/{statusCode}.{format} to preview the *error* page for a given status code as HTML or for a given status code and format. @@ -268,14 +268,14 @@ In that case, you might want to override one or both of the ``showAction()`` and .. code-block:: yaml - # app/config/services.yml + # app/config/services.yaml services: _defaults: # ... be sure autowiring is enabled autowire: true # ... - AppBundle\Controller\CustomExceptionController: + App\Controller\CustomExceptionController: public: true arguments: $debug: '%kernel.debug%' @@ -294,7 +294,7 @@ In that case, you might want to override one or both of the ``showAction()`` and - + %kernel.debug% @@ -304,7 +304,7 @@ In that case, you might want to override one or both of the ``showAction()`` and .. code-block:: php // app/config/services.php - use AppBundle\Controller\CustomExceptionController; + use App\Controller\CustomExceptionController; $container->autowire(CustomExceptionController::class) ->setArgument('$debug', '%kernel.debug%'); diff --git a/controller/service.rst b/controller/service.rst index 38b54f93735..0cfd6660611 100644 --- a/controller/service.rst +++ b/controller/service.rst @@ -5,7 +5,7 @@ How to Define Controllers as Services ===================================== In Symfony, a controller does *not* need to be registered as a service. But if you're -using the :ref:`default services.yml configuration `, +using the :ref:`default services.yaml configuration `, your controllers *are* already registered as services. This means you can use dependency injection like any other normal service. @@ -26,7 +26,7 @@ syntax: .. code-block:: php-annotations - // src/AppBundle/Controller/HelloController.php + // src/Controller/HelloController.php // You need to use Sensio's annotation to specify a service id use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; @@ -44,7 +44,7 @@ syntax: .. code-block:: yaml - # app/config/routing.yml + # config/routes.yaml hello: path: /hello defaults: { _controller: app.hello_controller:indexAction } @@ -100,8 +100,8 @@ template and return a Response. But, you can also do this directly: In a controller that's defined as a service, you can instead inject the ``templating`` service and use it directly:: - // src/AppBundle/Controller/HelloController.php - namespace AppBundle\Controller; + // src/Controller/HelloController.php + namespace App\Controller; use Symfony\Component\HttpFoundation\Response; diff --git a/controller/soap_web_service.rst b/controller/soap_web_service.rst index 5661646a7c5..d3375bcd37e 100644 --- a/controller/soap_web_service.rst +++ b/controller/soap_web_service.rst @@ -24,8 +24,8 @@ which represents the functionality that you'll expose in your SOAP service. In this case, the SOAP service will allow the client to call a method called ``hello``, which happens to send an email:: - // src/AppBundle/Service/HelloService.php - namespace AppBundle\Service; + // src/Service/HelloService.php + namespace App\Service; class HelloService { @@ -57,12 +57,12 @@ Finally, below is an example of a controller that is capable of handling a SOAP request. Because ``indexAction()`` is accessible via ``/soap``, the WSDL document can be retrieved via ``/soap?wsdl``:: - namespace AppBundle\Controller; + namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; - use AppBundle\Service\HelloService; + use App\Service\HelloService; class HelloServiceController extends Controller { @@ -99,7 +99,7 @@ Below is an example calling the service using a `NuSOAP`_ client. This example assumes that the ``indexAction()`` in the controller above is accessible via the route ``/soap``:: - $client = new \Soapclient('http://example.com/app.php/soap?wsdl'); + $client = new \Soapclient('http://example.com/index.php/soap?wsdl'); $result = $client->call('hello', array('name' => 'Scott')); @@ -160,7 +160,7 @@ An example WSDL is below. - + diff --git a/controller/upload_file.rst b/controller/upload_file.rst index b3d7be292e9..1b5370e38db 100644 --- a/controller/upload_file.rst +++ b/controller/upload_file.rst @@ -15,8 +15,8 @@ Imagine that you have a ``Product`` entity in your application and you want to add a PDF brochure for each product. To do so, add a new property called ``brochure`` in the ``Product`` entity:: - // src/AppBundle/Entity/Product.php - namespace AppBundle\Entity; + // src/Entity/Product.php + namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; @@ -51,10 +51,10 @@ or ``blob`` because it just stores the PDF file name instead of the file content Then, add a new ``brochure`` field to the form that manages the ``Product`` entity:: - // src/AppBundle/Form/ProductType.php - namespace AppBundle\Form; + // src/Form/ProductType.php + namespace App\Form; - use AppBundle\Entity\Product; + use App\Entity\Product; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -87,7 +87,7 @@ to :doc:`customize form rendering `): .. code-block:: html+twig - {# app/Resources/views/product/new.html.twig #} + {# templates/product/new.html.twig #}

Adding a new product

{{ form_start(form) }} @@ -98,7 +98,7 @@ to :doc:`customize form rendering `): .. code-block:: html+php - +

Adding a new product

start($form) ?> @@ -107,14 +107,14 @@ to :doc:`customize form rendering `): Finally, you need to update the code of the controller that handles the form:: - // src/AppBundle/Controller/ProductController.php - namespace AppBundle\ProductController; + // src/Controller/ProductController.php + namespace App\ProductController; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; - use AppBundle\Entity\Product; - use AppBundle\Form\ProductType; + use App\Entity\Product; + use App\Form\ProductType; class ProductController extends Controller { @@ -165,7 +165,7 @@ controller to specify the directory in which the brochures should be stored: # ... parameters: - brochures_directory: '%kernel.project_dir%/web/uploads/brochures' + brochures_directory: '%kernel.project_dir%/public/uploads/brochures' There are some important things to consider in the code of the above controller: @@ -221,8 +221,8 @@ Creating an Uploader Service To avoid logic in controllers, making them big, you can extract the upload logic to a separate service:: - // src/AppBundle/Service/FileUploader.php - namespace AppBundle\Service; + // src/Service/FileUploader.php + namespace App\Service; use Symfony\Component\HttpFoundation\File\UploadedFile; @@ -256,11 +256,11 @@ Then, define a service for this class: .. code-block:: yaml - # app/config/services.yml + # app/config/services.yaml services: # ... - AppBundle\Service\FileUploader: + App\Service\FileUploader: arguments: $targetDir: '%brochures_directory%' @@ -274,7 +274,7 @@ Then, define a service for this class: http://symfony.com/schema/dic/services/services-1.0.xsd"> - + %brochures_directory% @@ -282,16 +282,16 @@ Then, define a service for this class: .. code-block:: php // app/config/services.php - use AppBundle\Service\FileUploader; + use App\Service\FileUploader; $container->autowire(FileUploader::class) ->setArgument('$targetDir', '%brochures_directory%'); Now you're ready to use this service in the controller:: - // src/AppBundle/Controller/ProductController.php + // src/Controller/ProductController.php use Symfony\Component\HttpFoundation\Request; - use AppBundle\Service\FileUploader; + use App\Service\FileUploader; // ... public function newAction(Request $request, FileUploader $fileUploader) @@ -317,14 +317,14 @@ If you are using Doctrine to store the Product entity, you can create a :doc:`Doctrine listener ` to automatically upload the file when persisting the entity:: - // src/AppBundle/EventListener/BrochureUploadListener.php - namespace AppBundle\EventListener; + // src/EventListener/BrochureUploadListener.php + namespace App\EventListener; use Symfony\Component\HttpFoundation\File\UploadedFile; use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\ORM\Event\PreUpdateEventArgs; - use AppBundle\Entity\Product; - use AppBundle\Service\FileUploader; + use App\Entity\Product; + use App\Service\FileUploader; class BrochureUploadListener { @@ -372,14 +372,14 @@ Now, register this class as a Doctrine listener: .. code-block:: yaml - # app/config/services.yml + # app/config/services.yaml services: _defaults: # ... be sure autowiring is enabled autowire: true # ... - AppBundle\EventListener\BrochureUploadListener: + App\EventListener\BrochureUploadListener: tags: - { name: doctrine.event_listener, event: prePersist } - { name: doctrine.event_listener, event: preUpdate } @@ -397,7 +397,7 @@ Now, register this class as a Doctrine listener: - + @@ -406,7 +406,7 @@ Now, register this class as a Doctrine listener: .. code-block:: php // app/config/services.php - use AppBundle\EventListener\BrochureUploaderListener; + use App\EventListener\BrochureUploaderListener; $container->autowire(BrochureUploaderListener::class) ->addTag('doctrine.event_listener', array( diff --git a/deployment.rst b/deployment.rst index cda57c0d189..1ff67c815c3 100644 --- a/deployment.rst +++ b/deployment.rst @@ -30,7 +30,7 @@ A deployment may also include other tasks, such as: repository; * Creating a temporary staging area to build your updated setup "offline"; * Running any tests available to ensure code and/or server stability; -* Removal of any unnecessary files from the ``web/`` directory to keep your +* Removal of any unnecessary files from the ``public/`` directory to keep your production environment clean; * Clearing of external cache systems (like `Memcached`_ or `Redis`_). diff --git a/deployment/azure-website.rst b/deployment/azure-website.rst index 4c408bedda6..fe28ed9e791 100644 --- a/deployment/azure-website.rst +++ b/deployment/azure-website.rst @@ -263,9 +263,9 @@ directory with at least the following contents: /vendor/ /bin/ /composer.phar - /web/app_dev.php - /web/bundles/ - /web/config.php + /public/index.php + /public/bundles/ + /public/config.php The ``.gitignore`` file asks Git not to track any of the files and directories that match these patterns. This means these files won't be deployed to the Azure @@ -294,7 +294,7 @@ below: The code of the Symfony application has now been deployed to the Azure Website which you can browse from the file explorer of the Kudu application. You should -see the ``app/``, ``src/`` and ``web/`` directories under your ``site/wwwroot`` +see the ``app/``, ``src/`` and ``public/`` directories under your ``site/wwwroot`` directory on the Azure Website filesystem. Configure the Symfony Application @@ -377,12 +377,12 @@ This command builds the tables and indexes for your MySQL database. If your Symfony application is more complex than a basic Symfony Standard Edition, you may have additional commands to execute for setup (see :doc:`/deployment`). -Make sure that your application is running by browsing the ``app.php`` front +Make sure that your application is running by browsing the ``index.php`` front controller with your web browser and the following URL: .. code-block:: terminal - http://.azurewebsites.net/web/app.php + http://.azurewebsites.net/public/index.php If Symfony is correctly installed, you should see the front page of your Symfony application showing. @@ -412,7 +412,7 @@ application, configure it with the following content: - + @@ -420,13 +420,13 @@ application, configure it with the following content: - + - + @@ -434,14 +434,14 @@ application, configure it with the following content: As you can see, the latest rule ``RewriteRequestsToPublic`` is responsible for -rewriting any URLs to the ``web/app.php`` front controller which allows you to -skip the ``web/`` folder in the URL. The first rule called ``BlockAccessToPublic`` -matches all URL patterns that contain the ``web/`` folder and serves a +rewriting any URLs to the ``public/index.php`` front controller which allows you to +skip the ``public/`` folder in the URL. The first rule called ``BlockAccessToPublic`` +matches all URL patterns that contain the ``public/`` folder and serves a ``403 Forbidden`` HTTP response instead. This example is based on Benjamin Eberlei's sample you can find on GitHub in the `SymfonyAzureEdition`_ bundle. Deploy this file under the ``site/wwwroot`` directory of the Azure Website and -browse to your application without the ``web/app.php`` segment in the URL. +browse to your application without the ``public/index.php`` segment in the URL. Conclusion ---------- diff --git a/deployment/heroku.rst b/deployment/heroku.rst index 1fe7748e35a..d34024af5f3 100644 --- a/deployment/heroku.rst +++ b/deployment/heroku.rst @@ -86,7 +86,7 @@ below: By default, Heroku will launch an Apache web server together with PHP to serve applications. However, a special circumstance apply to Symfony applications: -the document root is in the ``web/`` directory and not in the root directory +the document root is in the ``public/`` directory and not in the root directory of the application. Create a new file called ``Procfile`` (without any extension) at the root @@ -94,7 +94,7 @@ directory of the application and add just the following content: .. code-block:: text - web: vendor/bin/heroku-php-apache2 web/ + web: vendor/bin/heroku-php-apache2 public/ .. note:: @@ -104,14 +104,14 @@ directory of the application and add just the following content: .. code-block:: text - web: vendor/bin/heroku-php-nginx -C nginx_app.conf web/ + web: vendor/bin/heroku-php-nginx -C nginx_app.conf public/ If you prefer working on the command console, execute the following commands to create the ``Procfile`` file and to add it to the repository: .. code-block:: terminal - $ echo "web: vendor/bin/heroku-php-apache2 web/" > Procfile + $ echo "web: vendor/bin/heroku-php-apache2 public/" > Procfile $ git add . $ git commit -m "Procfile for Apache and PHP" [master 35075db] Procfile for Apache and PHP @@ -199,9 +199,9 @@ Then, deploy your application executing this command: Creating the "app/config/parameters.yml" file Clearing the cache for the dev environment with debug true Installing assets using the hard copy option - Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework - Installing assets for Acme\DemoBundle into web/bundles/acmedemo - Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution + Installing assets for Symfony\Bundle\FrameworkBundle into public/bundles/framework + Installing assets for Acme\DemoBundle into public/bundles/acmedemo + Installing assets for Sensio\Bundle\DistributionBundle into public/bundles/sensiodistribution -----> Building runtime environment... @@ -241,7 +241,7 @@ Custom Compile Steps If you wish to execute additional custom commands during a build, you can leverage Heroku's `custom compile steps`_. Imagine you want to remove the ``dev`` front controller from your production environment on Heroku in order to avoid a potential vulnerability. -Adding a command to remove ``web/app_dev.php`` to Composer's `post-install-commands`_ would +Adding a command to remove ``public/index.php`` to Composer's `post-install-commands`_ would work, but it also removes the controller in your local development environment on each ``composer install`` or ``composer update`` respectively. Instead, you can add a `custom Composer command`_ named ``compile`` (this key name is a Heroku convention) to the @@ -253,7 +253,7 @@ process: { "scripts": { "compile": [ - "rm web/app_dev.php" + "rm public/index.php" ] } } diff --git a/deployment/platformsh.rst b/deployment/platformsh.rst index f498f057c07..6d9d622a714 100644 --- a/deployment/platformsh.rst +++ b/deployment/platformsh.rst @@ -54,7 +54,7 @@ Platform.sh how to deploy your application (read more about # The public directory of the app, relative to its root. document_root: '/web' # The front-controller script to send non-static requests to. - passthru: '/app.php' + passthru: '/index.php' # The size of the persistent disk of the application (in MB). disk: 2048 @@ -68,7 +68,7 @@ Platform.sh how to deploy your application (read more about # The hooks that will be performed when the package is deployed. hooks: build: | - rm web/app_dev.php + rm public/index.php bin/console --env=prod assetic:dump --no-debug deploy: | bin/console --env=prod cache:clear diff --git a/deployment/proxies.rst b/deployment/proxies.rst index 25a8026108c..436b6f23f10 100644 --- a/deployment/proxies.rst +++ b/deployment/proxies.rst @@ -26,7 +26,7 @@ and what headers your reverse proxy uses to send information: .. code-block:: php - // web/app.php + // public/index.php // ... $request = Request::createFromGlobals(); @@ -65,7 +65,7 @@ In this case, you'll need to - *very carefully* - trust *all* proxies. .. code-block:: php - // web/app.php + // public/index.php // ... Request::setTrustedProxies( diff --git a/doctrine.rst b/doctrine.rst index 67b29c0da4e..040ff0d36ec 100644 --- a/doctrine.rst +++ b/doctrine.rst @@ -249,8 +249,8 @@ Without even thinking about Doctrine or databases, you already know that you need a ``Product`` object to represent those products. Create this class inside the ``Entity`` directory of your AppBundle:: - // src/AppBundle/Entity/Product.php - namespace AppBundle\Entity; + // src/Entity/Product.php + namespace App\Entity; class Product { @@ -303,8 +303,8 @@ directly inside the ``Product`` class via DocBlock annotations: .. code-block:: php-annotations - // src/AppBundle/Entity/Product.php - namespace AppBundle\Entity; + // src/Entity/Product.php + namespace App\Entity; use Doctrine\ORM\Mapping as ORM; @@ -339,8 +339,8 @@ directly inside the ``Product`` class via DocBlock annotations: .. code-block:: yaml - # src/AppBundle/Resources/config/doctrine/Product.orm.yml - AppBundle\Entity\Product: + # src/Resources/config/doctrine/Product.orm.yml + App\Entity\Product: type: entity table: product id: @@ -359,14 +359,14 @@ directly inside the ``Product`` class via DocBlock annotations: .. code-block:: xml - + - + @@ -495,10 +495,10 @@ a controller, this is pretty easy. Add the following method to the ``DefaultController`` of the bundle:: - // src/AppBundle/Controller/DefaultController.php + // src/Controller/DefaultController.php // ... - use AppBundle\Entity\Product; + use App\Entity\Product; use Symfony\Component\HttpFoundation\Response; use Doctrine\ORM\EntityManagerInterface; @@ -680,7 +680,7 @@ Updating an Object Once you've fetched an object from Doctrine, updating it is easy. Suppose you have a route that maps a product id to an update action in a controller:: - use AppBundle\Entity\Product; + use App\Entity\Product; // ... public function updateAction($productId) diff --git a/doctrine/associations.rst b/doctrine/associations.rst index 94dd37f0356..517eacf2735 100644 --- a/doctrine/associations.rst +++ b/doctrine/associations.rst @@ -42,7 +42,7 @@ property on the ``Product`` class, annotated as follows: .. code-block:: php-annotations - // src/AppBundle/Entity/Product.php + // src/Entity/Product.php // ... class Product @@ -58,8 +58,8 @@ property on the ``Product`` class, annotated as follows: .. code-block:: yaml - # src/AppBundle/Resources/config/doctrine/Product.orm.yml - AppBundle\Entity\Product: + # src/Resources/config/doctrine/Product.orm.yml + App\Entity\Product: type: entity # ... manyToOne: @@ -72,14 +72,14 @@ property on the ``Product`` class, annotated as follows: .. code-block:: xml - + - + + - + getEntityManager() diff --git a/doctrine/custom_dql_functions.rst b/doctrine/custom_dql_functions.rst index bc9687c065a..e19c9a26eb6 100644 --- a/doctrine/custom_dql_functions.rst +++ b/doctrine/custom_dql_functions.rst @@ -19,12 +19,12 @@ In Symfony, you can register your custom DQL functions as follows: # ... dql: string_functions: - test_string: AppBundle\DQL\StringFunction - second_string: AppBundle\DQL\SecondStringFunction + test_string: App\DQL\StringFunction + second_string: App\DQL\SecondStringFunction numeric_functions: - test_numeric: AppBundle\DQL\NumericFunction + test_numeric: App\DQL\NumericFunction datetime_functions: - test_datetime: AppBundle\DQL\DatetimeFunction + test_datetime: App\DQL\DatetimeFunction .. code-block:: xml @@ -41,10 +41,10 @@ In Symfony, you can register your custom DQL functions as follows: - AppBundle\DQL\StringFunction - AppBundle\DQL\SecondStringFunction - AppBundle\DQL\NumericFunction - AppBundle\DQL\DatetimeFunction + App\DQL\StringFunction + App\DQL\SecondStringFunction + App\DQL\NumericFunction + App\DQL\DatetimeFunction @@ -53,10 +53,10 @@ In Symfony, you can register your custom DQL functions as follows: .. code-block:: php // app/config/config.php - use AppBundle\DQL\StringFunction; - use AppBundle\DQL\SecondStringFunction; - use AppBundle\DQL\NumericFunction; - use AppBundle\DQL\DatetimeFunction; + use App\DQL\StringFunction; + use App\DQL\SecondStringFunction; + use App\DQL\NumericFunction; + use App\DQL\DatetimeFunction; $container->loadFromExtension('doctrine', array( 'orm' => array( @@ -95,7 +95,7 @@ In Symfony, you can register your custom DQL functions as follows: # Place your functions here dql: datetime_functions: - test_datetime: AppBundle\DQL\DatetimeFunction + test_datetime: App\DQL\DatetimeFunction .. code-block:: xml @@ -117,7 +117,7 @@ In Symfony, you can register your custom DQL functions as follows: - AppBundle\DQL\DatetimeFunction + App\DQL\DatetimeFunction @@ -128,7 +128,7 @@ In Symfony, you can register your custom DQL functions as follows: .. code-block:: php // app/config/config.php - use AppBundle\DQL\DatetimeFunction; + use App\DQL\DatetimeFunction; $container->loadFromExtension('doctrine', array( 'doctrine' => array( diff --git a/doctrine/dbal.rst b/doctrine/dbal.rst index 299446ad541..63829c74674 100644 --- a/doctrine/dbal.rst +++ b/doctrine/dbal.rst @@ -110,8 +110,8 @@ mapping types, read Doctrine's `Custom Mapping Types`_ section of their document doctrine: dbal: types: - custom_first: AppBundle\Type\CustomFirst - custom_second: AppBundle\Type\CustomSecond + custom_first: App\Type\CustomFirst + custom_second: App\Type\CustomSecond .. code-block:: xml @@ -126,8 +126,8 @@ mapping types, read Doctrine's `Custom Mapping Types`_ section of their document - - + + @@ -135,8 +135,8 @@ mapping types, read Doctrine's `Custom Mapping Types`_ section of their document .. code-block:: php // app/config/config.php - use AppBundle\Type\CustomFirst; - use AppBundle\Type\CustomSecond; + use App\Type\CustomFirst; + use App\Type\CustomSecond; $container->loadFromExtension('doctrine', array( 'dbal' => array( diff --git a/doctrine/event_listeners_subscribers.rst b/doctrine/event_listeners_subscribers.rst index e69c7b2d80c..48c3d8a33a3 100644 --- a/doctrine/event_listeners_subscribers.rst +++ b/doctrine/event_listeners_subscribers.rst @@ -35,13 +35,13 @@ managers that use this connection. services: # ... - AppBundle\EventListener\SearchIndexer: + App\EventListener\SearchIndexer: tags: - { name: doctrine.event_listener, event: postPersist } - AppBundle\EventListener\SearchIndexer2: + App\EventListener\SearchIndexer2: tags: - { name: doctrine.event_listener, event: postPersist, connection: default } - AppBundle\EventListener\SearchIndexerSubscriber: + App\EventListener\SearchIndexerSubscriber: tags: - { name: doctrine.event_subscriber, connection: default } @@ -53,13 +53,13 @@ managers that use this connection. - + - + - + @@ -67,9 +67,9 @@ managers that use this connection. .. code-block:: php - use AppBundle\EventListener\SearchIndexer; - use AppBundle\EventListener\SearchIndexer2; - use AppBundle\EventListener\SearchIndexerSubscriber; + use App\EventListener\SearchIndexer; + use App\EventListener\SearchIndexer2; + use App\EventListener\SearchIndexerSubscriber; $container->autowire(SearchIndexer::class) ->addTag('doctrine.event_listener', array('event' => 'postPersist')) @@ -91,11 +91,11 @@ In the previous example, a ``SearchIndexer`` service was configured as a Doctrin listener on the event ``postPersist``. The class behind that service must have a ``postPersist()`` method, which will be called when the event is dispatched:: - // src/AppBundle/EventListener/SearchIndexer.php - namespace AppBundle\EventListener; + // src/EventListener/SearchIndexer.php + namespace App\EventListener; use Doctrine\ORM\Event\LifecycleEventArgs; - use AppBundle\Entity\Product; + use App\Entity\Product; class SearchIndexer { @@ -135,13 +135,13 @@ Creating the Subscriber Class A Doctrine event subscriber must implement the ``Doctrine\Common\EventSubscriber`` interface and have an event method for each event it subscribes to:: - // src/AppBundle/EventListener/SearchIndexerSubscriber.php - namespace AppBundle\EventListener; + // src/EventListener/SearchIndexerSubscriber.php + namespace App\EventListener; use Doctrine\Common\EventSubscriber; // for Doctrine < 2.4: use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\Common\Persistence\Event\LifecycleEventArgs; - use AppBundle\Entity\Product; + use App\Entity\Product; class SearchIndexerSubscriber implements EventSubscriber { @@ -207,7 +207,7 @@ to the tag like so: services: my.listener: - class: AppBundle\EventListener\SearchIndexer + class: App\EventListener\SearchIndexer tags: - { name: doctrine.event_listener, event: postPersist, lazy: true } @@ -218,7 +218,7 @@ to the tag like so: xmlns:doctrine="http://symfony.com/schema/dic/doctrine"> - + @@ -226,7 +226,7 @@ to the tag like so: .. code-block:: php - use AppBundle\EventListener\SearchIndexer; + use App\EventListener\SearchIndexer; $container ->register('my.listener', SearchIndexer::class) diff --git a/doctrine/lifecycle_callbacks.rst b/doctrine/lifecycle_callbacks.rst index a6535a9c749..6f7bf14a6e4 100644 --- a/doctrine/lifecycle_callbacks.rst +++ b/doctrine/lifecycle_callbacks.rst @@ -32,7 +32,7 @@ the current date, only when the entity is first persisted (i.e. inserted): .. code-block:: php-annotations - // src/AppBundle/Entity/Product.php + // src/Entity/Product.php /** * @ORM\PrePersist @@ -44,8 +44,8 @@ the current date, only when the entity is first persisted (i.e. inserted): .. code-block:: yaml - # src/AppBundle/Resources/config/doctrine/Product.orm.yml - AppBundle\Entity\Product: + # src/Resources/config/doctrine/Product.orm.yml + App\Entity\Product: type: entity # ... lifecycleCallbacks: @@ -53,14 +53,14 @@ the current date, only when the entity is first persisted (i.e. inserted): .. code-block:: xml - + - + diff --git a/doctrine/mapping_model_classes.rst b/doctrine/mapping_model_classes.rst index 8052b51dbe0..134912d2dea 100644 --- a/doctrine/mapping_model_classes.rst +++ b/doctrine/mapping_model_classes.rst @@ -117,7 +117,7 @@ Annotations, XML, Yaml, PHP and StaticPHP. The arguments are: use Doctrine\Common\Persistence\Mapping\Driver\DefaultFileLocator; use Doctrine\ORM\Mapping\Driver\XmlDriver; - use AppBundle\Model; + use App\Model; // ... private function buildMappingCompilerPass() diff --git a/doctrine/registration_form.rst b/doctrine/registration_form.rst index 9320e456b96..5e44f9d2833 100644 --- a/doctrine/registration_form.rst +++ b/doctrine/registration_form.rst @@ -39,8 +39,8 @@ Your ``User`` entity will probably at least have the following fields: With some validation added, your class may look something like this:: - // src/AppBundle/Entity/User.php - namespace AppBundle\Entity; + // src/Entity/User.php + namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; @@ -167,10 +167,10 @@ Create a Form for the Entity Next, create the form for the ``User`` entity:: - // src/AppBundle/Form/UserType.php - namespace AppBundle\Form; + // src/Form/UserType.php + namespace App\Form; - use AppBundle\Entity\User; + use App\Entity\User; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -217,11 +217,11 @@ Next, you need a controller to handle the form rendering and submission. If the form is submitted, the controller performs the validation and saves the data into the database:: - // src/AppBundle/Controller/RegistrationController.php - namespace AppBundle\Controller; + // src/Controller/RegistrationController.php + namespace App\Controller; - use AppBundle\Form\UserType; - use AppBundle\Entity\User; + use App\Form\UserType; + use App\Entity\User; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; @@ -274,7 +274,7 @@ encoder in the security configuration: # app/config/security.yml security: encoders: - AppBundle\Entity\User: bcrypt + App\Entity\User: bcrypt .. code-block:: xml @@ -286,14 +286,14 @@ encoder in the security configuration: xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - bcrypt + bcrypt .. code-block:: php // app/config/security.php - use AppBundle\Entity\User; + use App\Entity\User; $container->loadFromExtension('security', array( 'encoders' => array( @@ -313,7 +313,7 @@ the :ref:`user password encoding ` article. .. code-block:: yaml - # app/config/routing.yml + # config/routes.yaml user_registration: path: /register defaults: { _controller: AppBundle:Registration:register } @@ -350,7 +350,7 @@ Next, create the template: .. code-block:: html+twig - {# app/Resources/views/registration/register.html.twig #} + {# templates/registration/register.html.twig #} {{ form_start(form) }} {{ form_row(form.username) }} @@ -363,7 +363,7 @@ Next, create the template: .. code-block:: html+php - + start($form) ?> row($form['username']) ?> @@ -398,7 +398,7 @@ If you want your users to login via email and you don't need a username, then yo can remove it from your ``User`` entity entirely. Instead, make ``getUsername()`` return the ``email`` property:: - // src/AppBundle/Entity/User.php + // src/Entity/User.php // ... class User implements UserInterface @@ -428,7 +428,7 @@ that you'll never need. To do this, add a ``termsAccepted`` field to your form, but set its :ref:`mapped ` option to ``false``:: - // src/AppBundle/Form/UserType.php + // src/Form/UserType.php // ... use Symfony\Component\Validator\Constraints\IsTrue; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; diff --git a/doctrine/repository.rst b/doctrine/repository.rst index e89a24361e1..d92d0885c62 100644 --- a/doctrine/repository.rst +++ b/doctrine/repository.rst @@ -15,13 +15,13 @@ To do this, add the repository class name to your entity's mapping definition: .. code-block:: php-annotations - // src/AppBundle/Entity/Product.php - namespace AppBundle\Entity; + // src/Entity/Product.php + namespace App\Entity; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass="AppBundle\Repository\ProductRepository") + * @ORM\Entity(repositoryClass="App\Repository\ProductRepository") */ class Product { @@ -30,15 +30,15 @@ To do this, add the repository class name to your entity's mapping definition: .. code-block:: yaml - # src/AppBundle/Resources/config/doctrine/Product.orm.yml - AppBundle\Entity\Product: + # src/Resources/config/doctrine/Product.orm.yml + App\Entity\Product: type: entity - repositoryClass: AppBundle\Repository\ProductRepository + repositoryClass: App\Repository\ProductRepository # ... .. code-block:: xml - + + name="App\Entity\Product" + repository-class="App\Repository\ProductRepository"> -Then, create an empty ``AppBundle\Repository\ProductRepository`` class extending +Then, create an empty ``App\Repository\ProductRepository`` class extending from ``Doctrine\ORM\EntityRepository``. Next, add a new method - ``findAllOrderedByName()`` - to the newly-generated @@ -62,8 +62,8 @@ entities, ordered alphabetically by name. .. code-block:: php - // src/AppBundle/Repository/ProductRepository.php - namespace AppBundle\Repository; + // src/Repository/ProductRepository.php + namespace App\Repository; use Doctrine\ORM\EntityRepository; @@ -86,7 +86,7 @@ entities, ordered alphabetically by name. You can use this new method just like the default finder methods of the repository:: - use AppBundle\Entity\Product; + use App\Entity\Product; // ... public function listAction() diff --git a/doctrine/resolve_target_entity.rst b/doctrine/resolve_target_entity.rst index 9c5901b354d..4bf4aba7566 100644 --- a/doctrine/resolve_target_entity.rst +++ b/doctrine/resolve_target_entity.rst @@ -39,9 +39,9 @@ brevity) to explain how to set up and use the ``ResolveTargetEntityListener``. A Customer entity:: - // src/AppBundle/Entity/Customer.php + // src/Entity/Customer.php - namespace AppBundle\Entity; + namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use Acme\CustomerBundle\Entity\Customer as BaseCustomer; @@ -118,7 +118,7 @@ about the replacement: orm: # ... resolve_target_entities: - Acme\InvoiceBundle\Model\InvoiceSubjectInterface: AppBundle\Entity\Customer + Acme\InvoiceBundle\Model\InvoiceSubjectInterface: App\Entity\Customer .. code-block:: xml @@ -135,7 +135,7 @@ about the replacement: - AppBundle\Entity\Customer + App\Entity\Customer @@ -144,7 +144,7 @@ about the replacement: // app/config/config.php use Acme\InvoiceBundle\Model\InvoiceSubjectInterface; - use AppBundle\Entity\Customer; + use App\Entity\Customer; $container->loadFromExtension('doctrine', array( 'orm' => array( diff --git a/doctrine/reverse_engineering.rst b/doctrine/reverse_engineering.rst index 1e82856bd48..c5263ce915b 100644 --- a/doctrine/reverse_engineering.rst +++ b/doctrine/reverse_engineering.rst @@ -60,7 +60,7 @@ table fields. $ php bin/console doctrine:mapping:import --force AppBundle xml This command line tool asks Doctrine to introspect the database and generate -the XML metadata files under the ``src/AppBundle/Resources/config/doctrine`` +the XML metadata files under the ``src/Resources/config/doctrine`` folder of your bundle. This generates two files: ``BlogPost.orm.xml`` and ``BlogComment.orm.xml``. @@ -75,7 +75,7 @@ The generated ``BlogPost.orm.xml`` metadata file looks as follows: - + @@ -101,8 +101,8 @@ entity classes by executing the following command. For example, the newly created ``BlogComment`` entity class looks as follow:: - // src/AppBundle/Entity/BlogComment.php - namespace AppBundle\Entity; + // src/Entity/BlogComment.php + namespace App\Entity; use Doctrine\ORM\Mapping as ORM; diff --git a/email.rst b/email.rst index 4ed365c673c..c03ad166a56 100644 --- a/email.rst +++ b/email.rst @@ -108,7 +108,7 @@ an email is pretty straightforward:: ->setTo('recipient@example.com') ->setBody( $this->renderView( - // app/Resources/views/Emails/registration.html.twig + // templates/Emails/registration.html.twig 'Emails/registration.html.twig', array('name' => $name) ), @@ -140,7 +140,7 @@ template might look something like this: .. code-block:: html+jinja - {# app/Resources/views/Emails/registration.html.twig #} + {# templates/Emails/registration.html.twig #}

You did it! You registered!

Hi {{ name }}! You're successfully registered. diff --git a/email/testing.rst b/email/testing.rst index 2403cfdde8e..acd4b7f66c8 100644 --- a/email/testing.rst +++ b/email/testing.rst @@ -29,7 +29,7 @@ In your functional test, use the ``swiftmailer`` collector on the profiler to get information about the messages sent on the previous request:: // tests/AppBundle/Controller/MailControllerTest.php - namespace Tests\AppBundle\Controller; + namespace Tests\App\Controller; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; diff --git a/event_dispatcher.rst b/event_dispatcher.rst index b21f34f1a54..f76fa6f8f09 100644 --- a/event_dispatcher.rst +++ b/event_dispatcher.rst @@ -23,8 +23,8 @@ Creating an Event Listener The most common way to listen to an event is to register an **event listener**:: - // src/AppBundle/EventListener/ExceptionListener.php - namespace AppBundle\EventListener; + // src/EventListener/ExceptionListener.php + namespace App\EventListener; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpFoundation\Response; @@ -75,9 +75,9 @@ using a special "tag": .. code-block:: yaml - # app/config/services.yml + # app/config/services.yaml services: - AppBundle\EventListener\ExceptionListener: + App\EventListener\ExceptionListener: tags: - { name: kernel.event_listener, event: kernel.exception } @@ -92,7 +92,7 @@ using a special "tag": + class="App\EventListener\ExceptionListener"> @@ -102,7 +102,7 @@ using a special "tag": .. code-block:: php // app/config/services.php - use AppBundle\EventListener\ExceptionListener; + use App\EventListener\ExceptionListener; $container ->register('app.exception_listener', ExceptionListener::class) @@ -141,8 +141,8 @@ about event subscribers, read :doc:`/components/event_dispatcher`. The following example shows an event subscriber that defines several methods which listen to the same ``kernel.exception`` event:: - // src/AppBundle/EventSubscriber/ExceptionSubscriber.php - namespace AppBundle\EventSubscriber; + // src/EventSubscriber/ExceptionSubscriber.php + namespace App\EventSubscriber; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; @@ -178,7 +178,7 @@ listen to the same ``kernel.exception`` event:: } } -That's it! Your ``services.yml`` file should already be setup to load services from +That's it! Your ``services.yaml`` file should already be setup to load services from the ``EventSubscriber`` directory. Symfony takes care of the rest. .. _ref-event-subscriber-configuration: @@ -198,8 +198,8 @@ sub-requests - typically by :doc:`/templating/embedding_controllers`). For the c Symfony events, you might need to check to see if the event is for a "master" request or a "sub request":: - // src/AppBundle/EventListener/RequestListener.php - namespace AppBundle\EventListener; + // src/EventListener/RequestListener.php + namespace App\EventListener; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\HttpKernel; diff --git a/event_dispatcher/before_after_filters.rst b/event_dispatcher/before_after_filters.rst index 6e38cfe4846..bb1d7f2f755 100644 --- a/event_dispatcher/before_after_filters.rst +++ b/event_dispatcher/before_after_filters.rst @@ -81,7 +81,7 @@ some way to identify if the controller that matches the request needs token vali A clean and easy way is to create an empty interface and make the controllers implement it:: - namespace AppBundle\Controller; + namespace App\Controller; interface TokenAuthenticatedController { @@ -90,9 +90,9 @@ implement it:: A controller that implements this interface simply looks like this:: - namespace AppBundle\Controller; + namespace App\Controller; - use AppBundle\Controller\TokenAuthenticatedController; + use App\Controller\TokenAuthenticatedController; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class FooController extends Controller implements TokenAuthenticatedController @@ -111,10 +111,10 @@ Next, you'll need to create an event listener, which will hold the logic that you want to be executed before your controllers. If you're not familiar with event listeners, you can learn more about them at :doc:`/event_dispatcher`:: - // src/AppBundle/EventSubscriber/TokenSubscriber.php - namespace AppBundle\EventSubscriber; + // src/EventSubscriber/TokenSubscriber.php + namespace App\EventSubscriber; - use AppBundle\Controller\TokenAuthenticatedController; + use App\Controller\TokenAuthenticatedController; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Event\FilterControllerEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -158,7 +158,7 @@ event listeners, you can learn more about them at :doc:`/event_dispatcher`:: } } -That's it! Your ``services.yml`` file should already be setup to load services from +That's it! Your ``services.yaml`` file should already be setup to load services from the ``EventSubscriber`` directory. Symfony takes care of the rest. Your ``TokenSubscriber`` ``onKernelController()`` method will be executed on each request. If the controller that is about to be executed implements ``TokenAuthenticatedController``, diff --git a/event_dispatcher/method_behavior.rst b/event_dispatcher/method_behavior.rst index 274f8f1983b..0577989350e 100644 --- a/event_dispatcher/method_behavior.rst +++ b/event_dispatcher/method_behavior.rst @@ -41,8 +41,8 @@ executed, and ``mailer.post_send`` after the method is executed. Each uses a custom Event class to communicate information to the listeners of the two events. For example, ``BeforeSendMailEvent`` might look like this:: - // src/AppBundle/Event/BeforeSendMailEvent.php - namespace AppBundle\Event; + // src/Event/BeforeSendMailEvent.php + namespace App\Event; use Symfony\Component\EventDispatcher\Event; @@ -80,8 +80,8 @@ events. For example, ``BeforeSendMailEvent`` might look like this:: And the ``AfterSendMailEvent`` even like this:: - // src/AppBundle/Event/AfterSendMailEvent.php - namespace AppBundle\Event; + // src/Event/AfterSendMailEvent.php + namespace App\Event; use Symfony\Component\EventDispatcher\Event; @@ -111,11 +111,11 @@ that information (e.g. ``setMessage()``). Now, you can create an event subscriber to hook into this event. For example, you could listen to the ``mailer.post_send`` event and change the method's return value:: - // src/AppBundle/EventSubscriber/MailPostSendSubscriber.php - namespace AppBundle\EventSubscriber; + // src/EventSubscriber/MailPostSendSubscriber.php + namespace App\EventSubscriber; use Symfony\Component\EventDispatcher\EventSubscriberInterface; - use AppBundle\Event\AfterSendMailEvent; + use App\Event\AfterSendMailEvent; class MailPostSendSubscriber implements EventSubscriberInterface { diff --git a/form/action_method.rst b/form/action_method.rst index 5178a917887..bb99ab052e9 100644 --- a/form/action_method.rst +++ b/form/action_method.rst @@ -16,7 +16,7 @@ form, you can use ``setAction()`` and ``setMethod()``: .. code-block:: php-symfony // AppBundle/Controller/DefaultController.php - namespace AppBundle\Controller; + namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\Form\Extension\Core\Type\DateType; @@ -76,10 +76,10 @@ options: .. code-block:: php-symfony // AppBundle/Controller/DefaultController.php - namespace AppBundle\Controller; + namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; - use AppBundle\Form\TaskType; + use App\Form\TaskType; class DefaultController extends Controller { @@ -99,7 +99,7 @@ options: .. code-block:: php-standalone use Symfony\Component\Form\Forms; - use AppBundle\Form\TaskType; + use App\Form\TaskType; $formFactoryBuilder = Forms::createFormFactoryBuilder(); @@ -119,12 +119,12 @@ to the ``form()`` or the ``form_start()`` helper functions: .. code-block:: html+twig - {# app/Resources/views/default/new.html.twig #} + {# templates/default/new.html.twig #} {{ form_start(form, {'action': path('target_route'), 'method': 'GET'}) }} .. code-block:: html+php - + start($form, array( // The path() method was introduced in Symfony 2.8. Prior to 2.8, // you had to use generate(). diff --git a/form/create_custom_field_type.rst b/form/create_custom_field_type.rst index 7860ef75f3c..40c223f8267 100644 --- a/form/create_custom_field_type.rst +++ b/form/create_custom_field_type.rst @@ -19,8 +19,8 @@ will be called ``ShippingType`` and the file will be stored in the default locat for form fields, which is ``\Form\Type``. Make sure the field extends :class:`Symfony\\Component\\Form\\AbstractType`:: - // src/AppBundle/Form/Type/ShippingType.php - namespace AppBundle\Form\Type; + // src/Form/Type/ShippingType.php + namespace App\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -120,7 +120,7 @@ link for details), create a ``shipping_widget`` block to handle this: .. code-block:: html+twig - {# app/Resources/views/form/fields.html.twig #} + {# templates/form/fields.html.twig #} {% block shipping_widget %} {% spaceless %} {% if expanded %} @@ -141,7 +141,7 @@ link for details), create a ``shipping_widget`` block to handle this: .. code-block:: html+php - +
    block($form, 'widget_container_attributes') ?>> @@ -251,12 +251,12 @@ Using the Field Type You can now use your custom field type immediately, simply by creating a new instance of the type in one of your forms:: - // src/AppBundle/Form/Type/OrderType.php - namespace AppBundle\Form\Type; + // src/Form/Type/OrderType.php + namespace App\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; - use AppBundle\Form\Type\ShippingType; + use App\Form\Type\ShippingType; class OrderType extends AbstractType { @@ -281,8 +281,8 @@ Accessing Services and Config If you need to access :doc:`services ` from your form class, add a ``__construct()`` method like normal:: - // src/AppBundle/Form/Type/ShippingType.php - namespace AppBundle\Form\Type; + // src/Form/Type/ShippingType.php + namespace App\Form\Type; // ... use Doctrine\ORM\EntityManagerInterface; @@ -299,7 +299,7 @@ add a ``__construct()`` method like normal:: // use $this->em down anywhere you want ... } -If you're using the default ``services.yml`` configuration (i.e. services from the +If you're using the default ``services.yaml`` configuration (i.e. services from the ``Form/`` are loaded and ``autoconfigure`` is enabled), this will already work! See :ref:`service-container-creating-service` for more details. diff --git a/form/create_form_type_extension.rst b/form/create_form_type_extension.rst index 0e730ad126e..d2ef0bea408 100644 --- a/form/create_form_type_extension.rst +++ b/form/create_form_type_extension.rst @@ -24,8 +24,8 @@ Defining the Form Type Extension First, create the form type extension class:: - // src/AppBundle/Form/Extension/ImageTypeExtension.php - namespace AppBundle\Form\Extension; + // src/Form/Extension/ImageTypeExtension.php + namespace App\Form\Extension; use Symfony\Component\Form\AbstractTypeExtension; use Symfony\Component\Form\Extension\Core\Type\FileType; @@ -74,7 +74,7 @@ your class as a service and using the ``form.type_extension`` tag: services: # ... - AppBundle\Form\Extension\ImageTypeExtension: + App\Form\Extension\ImageTypeExtension: tags: - { name: form.type_extension, extended_type: Symfony\Component\Form\Extension\Core\Type\FileType } @@ -87,7 +87,7 @@ your class as a service and using the ``form.type_extension`` tag: http://symfony.com/schema/dic/services/services-1.0.xsd"> - + @@ -95,7 +95,7 @@ your class as a service and using the ``form.type_extension`` tag: .. code-block:: php - use AppBundle\Form\Extension\ImageTypeExtension; + use App\Form\Extension\ImageTypeExtension; use Symfony\Component\Form\Extension\Core\Type\FileType; $container->autowire(ImageTypeExtension::class) @@ -134,8 +134,8 @@ you use an approach similar to the one described in you have a Media model with a path property, corresponding to the image path in the database:: - // src/AppBundle/Entity/Media.php - namespace AppBundle\Entity; + // src/Entity/Media.php + namespace App\Entity; use Symfony\Component\Validator\Constraints as Assert; @@ -167,8 +167,8 @@ the ``FileType::class`` form type: For example:: - // src/AppBundle/Form/Extension/ImageTypeExtension.php - namespace AppBundle\Form\Extension; + // src/Form/Extension/ImageTypeExtension.php + namespace App\Form\Extension; use Symfony\Component\Form\AbstractTypeExtension; use Symfony\Component\Form\FormView; @@ -256,8 +256,8 @@ From now on, when adding a field of type ``FileType::class`` to your form, you c specify an ``image_property`` option that will be used to display an image next to the file field. For example:: - // src/AppBundle/Form/Type/MediaType.php - namespace AppBundle\Form\Type; + // src/Form/Type/MediaType.php + namespace App\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; diff --git a/form/csrf_protection.rst b/form/csrf_protection.rst index 266555579c0..f06b7cf3947 100644 --- a/form/csrf_protection.rst +++ b/form/csrf_protection.rst @@ -31,7 +31,7 @@ that all un-rendered fields are output. The CSRF token can be customized on a form-by-form basis. For example:: // ... - use AppBundle\Entity\Task; + use App\Entity\Task; use Symfony\Component\OptionsResolver\OptionsResolver; class TaskType extends AbstractType diff --git a/form/data_based_validation.rst b/form/data_based_validation.rst index 3e31be7cd67..c8a74bb99f3 100644 --- a/form/data_based_validation.rst +++ b/form/data_based_validation.rst @@ -8,7 +8,7 @@ If you need some advanced logic to determine the validation groups (e.g. based on submitted data), you can set the ``validation_groups`` option to an array callback:: - use AppBundle\Entity\Client; + use App\Entity\Client; use Symfony\Component\OptionsResolver\OptionsResolver; // ... @@ -27,7 +27,7 @@ This will call the static method ``determineValidationGroups()`` on the The Form object is passed as an argument to that method (see next example). You can also define whole logic inline by using a ``Closure``:: - use AppBundle\Entity\Client; + use App\Entity\Client; use Symfony\Component\Form\FormInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -51,7 +51,7 @@ Using the ``validation_groups`` option overrides the default validation group which is being used. If you want to validate the default constraints of the entity as well you have to adjust the option as follows:: - use AppBundle\Entity\Client; + use App\Entity\Client; use Symfony\Component\Form\FormInterface; use Symfony\Component\OptionsResolver\OptionsResolver; diff --git a/form/data_transformers.rst b/form/data_transformers.rst index 08390909d9c..248001d7697 100644 --- a/form/data_transformers.rst +++ b/form/data_transformers.rst @@ -23,10 +23,10 @@ Simple Example: Transforming String Tags from User Input to an Array Suppose you have a Task form with a tags ``text`` type:: - // src/AppBundle/Form/Type/TaskType.php - namespace AppBundle\Form\Type; + // src/Form/Type/TaskType.php + namespace App\Form\Type; - use AppBundle\Entity\Task; + use App\Entity\Task; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Form\Extension\Core\Type\TextType; @@ -56,8 +56,8 @@ This is a *perfect* time to attach a custom data transformer to the ``tags`` field. The easiest way to do this is with the :class:`Symfony\\Component\\Form\\CallbackTransformer` class:: - // src/AppBundle/Form/Type/TaskType.php - namespace AppBundle\Form\Type; + // src/Form/Type/TaskType.php + namespace App\Form\Type; use Symfony\Component\Form\CallbackTransformer; use Symfony\Component\Form\FormBuilderInterface; @@ -120,10 +120,10 @@ issue number. Start by setting up the text field like normal:: - // src/AppBundle/Form/Type/TaskType.php - namespace AppBundle\Form\Type; + // src/Form/Type/TaskType.php + namespace App\Form\Type; - use AppBundle\Entity\Task; + use App\Entity\Task; use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\Form\Extension\Core\Type\TextType; @@ -161,10 +161,10 @@ complex, creating a new transformer class will keep the ``TaskType`` form class Create an ``IssueToNumberTransformer`` class: it will be responsible for converting to and from the issue number and the ``Issue`` object:: - // src/AppBundle/Form/DataTransformer/IssueToNumberTransformer.php - namespace AppBundle\Form\DataTransformer; + // src/Form/DataTransformer/IssueToNumberTransformer.php + namespace App\Form\DataTransformer; - use AppBundle\Entity\Issue; + use App\Entity\Issue; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Form\DataTransformerInterface; use Symfony\Component\Form\Exception\TransformationFailedException; @@ -250,10 +250,10 @@ Next, you need to use the ``IssueToNumberTransformer`` object inside if ``TaskTy and add it to the ``issue`` field. No problem! Just add a ``__construct()`` method and type-hint the new class:: - // src/AppBundle/Form/Type/TaskType.php - namespace AppBundle\Form\Type; + // src/Form/Type/TaskType.php + namespace App\Form\Type; - use AppBundle\Form\DataTransformer\IssueToNumberTransformer; + use App\Form\DataTransformer\IssueToNumberTransformer; use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\Form\Extension\Core\Type\TextType; @@ -332,10 +332,10 @@ that does this automatically. First, create the custom field type class:: - // src/AppBundle/Form/IssueSelectorType.php - namespace AppBundle\Form; + // src/Form/IssueSelectorType.php + namespace App\Form; - use AppBundle\Form\DataTransformer\IssueToNumberTransformer; + use App\Form\DataTransformer\IssueToNumberTransformer; use Doctrine\Common\Persistence\ObjectManager; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; @@ -374,10 +374,10 @@ have the data transformer *and* a nice default value for the ``invalid_message`` As long as you're using :ref:`autowire ` and :ref:`autoconfigure `, you can start using the form immediately:: - // src/AppBundle/Form/Type/TaskType.php - namespace AppBundle\Form\Type; + // src/Form/Type/TaskType.php + namespace App\Form\Type; - use AppBundle\Form\DataTransformer\IssueToNumberTransformer; + use App\Form\DataTransformer\IssueToNumberTransformer; use Symfony\Component\Form\Extension\Core\Type\TextareaType; // ... diff --git a/form/dynamic_form_modification.rst b/form/dynamic_form_modification.rst index d4e216c1175..bb64ef3a938 100644 --- a/form/dynamic_form_modification.rst +++ b/form/dynamic_form_modification.rst @@ -35,10 +35,10 @@ Customizing your Form Based on the Underlying Data Before starting with dynamic form generation, remember what a bare form class looks like:: - // src/AppBundle/Form/Type/ProductType.php - namespace AppBundle\Form\Type; + // src/Form/Type/ProductType.php + namespace App\Form\Type; - use AppBundle\Entity\Product; + use App\Entity\Product; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -83,8 +83,8 @@ Adding an Event Listener to a Form Class So, instead of directly adding that ``name`` widget, the responsibility of creating that particular field is delegated to an event listener:: - // src/AppBundle/Form/Type/ProductType.php - namespace AppBundle\Form\Type; + // src/Form/Type/ProductType.php + namespace App\Form\Type; // ... use Symfony\Component\Form\FormEvent; @@ -142,8 +142,8 @@ For better reusability or if there is some heavy logic in your event listener, you can also move the logic for creating the ``name`` field to an :ref:`event subscriber `:: - // src/AppBundle/Form/EventListener/AddNameFieldSubscriber.php - namespace AppBundle\Form\EventListener; + // src/Form/EventListener/AddNameFieldSubscriber.php + namespace App\Form\EventListener; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; @@ -172,11 +172,11 @@ you can also move the logic for creating the ``name`` field to an Great! Now use that in your form class:: - // src/AppBundle/Form/Type/ProductType.php - namespace AppBundle\Form\Type; + // src/Form/Type/ProductType.php + namespace App\Form\Type; // ... - use AppBundle\Form\EventListener\AddNameFieldSubscriber; + use App\Form\EventListener\AddNameFieldSubscriber; class ProductType extends AbstractType { @@ -206,8 +206,8 @@ Creating the Form Type Using an event listener, your form might look like this:: - // src/AppBundle/Form/Type/FriendMessageFormType.php - namespace AppBundle\Form\Type; + // src/Form/Type/FriendMessageFormType.php + namespace App\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; @@ -260,9 +260,9 @@ Customizing the Form Type Now that you have all the basics in place you can take advantage of the ``TokenStorageInterface`` and fill in the listener logic:: - // src/AppBundle/Form/Type/FriendMessageFormType.php + // src/Form/Type/FriendMessageFormType.php - use AppBundle\Entity\User; + use App\Entity\User; use Doctrine\ORM\EntityRepository; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\Extension\Core\Type\TextType; @@ -376,8 +376,8 @@ will need the correct options in order for validation to pass. The meetup is passed as an entity field to the form. So we can access each sport like this:: - // src/AppBundle/Form/Type/SportMeetupType.php - namespace AppBundle\Form\Type; + // src/Form/Type/SportMeetupType.php + namespace App\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; @@ -442,13 +442,13 @@ new field automatically and map it to the submitted client data. The type would now look like:: - // src/AppBundle/Form/Type/SportMeetupType.php - namespace AppBundle\Form\Type; + // src/Form/Type/SportMeetupType.php + namespace App\Form\Type; // ... use Symfony\Component\Form\FormInterface; use Symfony\Bridge\Doctrine\Form\Type\EntityType; - use AppBundle\Entity\Sport; + use App\Entity\Sport; class SportMeetupType extends AbstractType { @@ -507,13 +507,13 @@ One piece that is still missing is the client-side updating of your form after the sport is selected. This should be handled by making an AJAX call back to your application. Assume that you have a sport meetup creation controller:: - // src/AppBundle/Controller/MeetupController.php - namespace AppBundle\Controller; + // src/Controller/MeetupController.php + namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; - use AppBundle\Entity\SportMeetup; - use AppBundle\Form\Type\SportMeetupType; + use App\Entity\SportMeetup; + use App\Form\Type\SportMeetupType; // ... class MeetupController extends Controller @@ -543,7 +543,7 @@ field according to the current selection in the ``sport`` field: .. code-block:: html+twig - {# app/Resources/views/meetup/create.html.twig #} + {# templates/meetup/create.html.twig #} {{ form_start(form) }} {{ form_row(form.sport) }} {#