diff --git a/best_practices/business-logic.rst b/best_practices/business-logic.rst index 913d7a69ab1..5fe7760a3a5 100644 --- a/best_practices/business-logic.rst +++ b/best_practices/business-logic.rst @@ -21,6 +21,8 @@ Inside here, you can create whatever directories you want to organize things: │ └─ AppBundle/ │ └─ Utils/ │ └─ MyClass.php + ├─ tests/ + ├─ var/ ├─ vendor/ └─ web/ @@ -40,6 +42,8 @@ and put things there: │ │ └─ Utils/ │ │ └─ MyClass.php │ └─ AppBundle/ + ├─ tests/ + ├─ var/ ├─ vendor/ └─ web/ @@ -318,7 +322,7 @@ command: .. code-block:: bash - $ php app/console doctrine:fixtures:load + $ php bin/console doctrine:fixtures:load Careful, database will be purged. Do you want to continue Y/N ? Y > purging database diff --git a/best_practices/creating-the-project.rst b/best_practices/creating-the-project.rst index 7e658fdae59..2d6c819e0ce 100644 --- a/best_practices/creating-the-project.rst +++ b/best_practices/creating-the-project.rst @@ -27,7 +27,6 @@ to create files and execute the following commands: .. code-block:: bash - # Linux, Mac OS X $ cd projects/ $ symfony new blog @@ -63,13 +62,18 @@ number of files and directories generated automatically: blog/ ├─ app/ - │ ├─ console - │ ├─ cache/ │ ├─ config/ - │ ├─ logs/ │ └─ Resources/ + ├─ bin + │ └─ console ├─ src/ │ └─ AppBundle/ + ├─ var/ + │ ├─ cache/ + │ ├─ logs/ + │ └─ sessions/ + ├─ tests/ + │ └─ AppBundle/ ├─ vendor/ └─ web/ @@ -77,13 +81,16 @@ This file and directory hierarchy is the convention proposed by Symfony to structure your applications. The recommended purpose of each directory is the following: -* ``app/cache/``, stores all the cache files generated by the application; * ``app/config/``, stores all the configuration defined for any environment; -* ``app/logs/``, stores all the log files generated by the application; * ``app/Resources/``, stores all the templates and the translation files for the application; * ``src/AppBundle/``, stores the Symfony specific code (controllers and routes), your domain code (e.g. Doctrine classes) and all your business logic; +* ``var/cache/``, stores all the cache files generated by the application; +* ``var/logs/``, stores all the log files generated by the application; +* ``var/sessions/``, stores all the session files generated by the application; +* ``tests/AppBundle/``, stores the automatic tests (e.g. Unit tests) of the + application. * ``vendor/``, this is the directory where Composer installs the application's dependencies and you should never modify any of its contents; * ``web/``, stores all the front controller files and all the web assets, such @@ -128,13 +135,18 @@ that follows these best practices: blog/ ├─ app/ - │ ├─ console - │ ├─ cache/ │ ├─ config/ - │ ├─ logs/ │ └─ Resources/ + ├─ bin/ + │ └─ console ├─ src/ │ └─ AppBundle/ + ├─ tests/ + │ └─ AppBundle/ + ├─ var/ + │ ├─ cache/ + │ ├─ logs/ + └─ sessions/ ├─ vendor/ └─ web/ ├─ app.php @@ -147,7 +159,7 @@ that follows these best practices: .. code-block:: bash - $ php app/console generate:bundle --namespace=AppBundle --dir=src --format=annotation --no-interaction + $ php bin/console generate:bundle --namespace=AppBundle --dir=src --format=annotation --no-interaction Extending the Directory Structure --------------------------------- @@ -157,27 +169,6 @@ structure of Symfony, you can :doc:`override the location of the main directories `: ``cache/``, ``logs/`` and ``web/``. -In addition, Symfony3 will use a slightly different directory structure when -it's released: - -.. code-block:: text - - blog-symfony3/ - ├─ app/ - │ ├─ config/ - │ └─ Resources/ - ├─ bin/ - │ └─ console - ├─ src/ - ├─ var/ - │ ├─ cache/ - │ └─ logs/ - ├─ vendor/ - └─ web/ - -The changes are pretty superficial, but for now, we recommend that you use -the Symfony directory structure. - .. _`Composer`: https://getcomposer.org/ .. _`Get Started`: https://getcomposer.org/doc/00-intro.md .. _`Composer download page`: https://getcomposer.org/download/ diff --git a/best_practices/introduction.rst b/best_practices/introduction.rst index 2c5661c6671..dad135249e6 100644 --- a/best_practices/introduction.rst +++ b/best_practices/introduction.rst @@ -76,12 +76,8 @@ installer and then execute this command to download the demo application: .. code-block:: bash - # Linux and Mac OS X $ symfony demo - # Windows - c:\> php symfony demo - **The demo application is a simple blog engine**, because that will allow us to focus on the Symfony concepts and features without getting buried in difficult implementation details. Instead of developing the application step by step in diff --git a/best_practices/tests.rst b/best_practices/tests.rst index 758c7b567ce..16aa6d16a35 100644 --- a/best_practices/tests.rst +++ b/best_practices/tests.rst @@ -30,8 +30,8 @@ A functional test can be as easy as this: .. code-block:: php - // src/AppBundle/Tests/ApplicationAvailabilityFunctionalTest.php - namespace AppBundle\Tests; + // tests/AppBundle/ApplicationAvailabilityFunctionalTest.php + namespace Tests\AppBundle; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; diff --git a/book/bundles.rst b/book/bundles.rst index ff09cc6fc3e..db7994795c2 100644 --- a/book/bundles.rst +++ b/book/bundles.rst @@ -107,6 +107,7 @@ Now that you've created the bundle, enable it via the ``AppKernel`` class:: { $bundles = array( // ... + // register your bundle new Acme\TestBundle\AcmeTestBundle(), ); @@ -122,7 +123,7 @@ generating a basic bundle skeleton: .. code-block:: bash - $ php app/console generate:bundle --namespace=Acme/TestBundle + $ php bin/console generate:bundle --namespace=Acme/TestBundle The bundle skeleton generates a basic controller, template and routing resource that can be customized. You'll learn more about Symfony's command-line diff --git a/book/configuration.rst b/book/configuration.rst index 2574096f4d6..360e6a8c449 100644 --- a/book/configuration.rst +++ b/book/configuration.rst @@ -122,13 +122,13 @@ FrameworkBundle configuration: .. code-block:: bash - $ app/console config:dump-reference FrameworkBundle + $ php bin/console config:dump-reference FrameworkBundle The extension alias (configuration key) can also be used: .. code-block:: bash - $ app/console config:dump-reference framework + $ php bin/console config:dump-reference framework .. note:: @@ -177,7 +177,7 @@ cached files and allow them to rebuild: .. code-block:: bash - $ php app/console cache:clear --env=prod --no-debug + $ php bin/console cache:clear --env=prod --no-debug .. note:: diff --git a/book/controller.rst b/book/controller.rst index 13a19afb334..ca8010416f9 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -534,7 +534,7 @@ console command: .. code-block:: bash - $ php app/console debug:container + $ php bin/console debug:container .. versionadded:: 2.6 Prior to Symfony 2.6, this command was called ``container:debug``. diff --git a/book/doctrine.rst b/book/doctrine.rst index 67aca7f3865..2e2037df5c2 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -116,7 +116,7 @@ for you: .. code-block:: bash - $ php app/console doctrine:database:create + $ php bin/console doctrine:database:create .. sidebar:: Setting up the Database to be UTF8 @@ -128,8 +128,8 @@ for you: .. code-block:: bash - $ php app/console doctrine:database:drop --force - $ php app/console doctrine:database:create + $ php bin/console doctrine:database:drop --force + $ php bin/console doctrine:database:create There's no way to configure these defaults inside Doctrine, as it tries to be as agnostic as possible in terms of environment configuration. One way to solve @@ -227,7 +227,7 @@ just a simple PHP class. .. code-block:: bash - $ php app/console doctrine:generate:entity + $ php bin/console doctrine:generate:entity .. index:: single: Doctrine; Adding mapping metadata @@ -392,7 +392,7 @@ a regular PHP class, you need to create getter and setter methods (e.g. ``getNam .. code-block:: bash - $ php app/console doctrine:generate:entities AppBundle/Entity/Product + $ php bin/console doctrine:generate:entities AppBundle/Entity/Product This command makes sure that all the getters and setters are generated for the ``Product`` class. This is a safe command - you can run it over and @@ -434,10 +434,10 @@ mapping information) of a bundle or an entire namespace: .. code-block:: bash # generates all entities in the AppBundle - $ php app/console doctrine:generate:entities AppBundle + $ php bin/console doctrine:generate:entities AppBundle # generates all entities of bundles in the Acme namespace - $ php app/console doctrine:generate:entities Acme + $ php bin/console doctrine:generate:entities Acme .. note:: @@ -459,7 +459,7 @@ in your application. To do this, run: .. code-block:: bash - $ php app/console doctrine:schema:update --force + $ php bin/console doctrine:schema:update --force .. tip:: @@ -852,7 +852,7 @@ used earlier to generate the missing getter and setter methods: .. code-block:: bash - $ php app/console doctrine:generate:entities AppBundle + $ php bin/console doctrine:generate:entities AppBundle Next, add a new method - ``findAllOrderedByName()`` - to the newly generated repository class. This method will query for all the ``Product`` entities, @@ -906,7 +906,7 @@ you can let Doctrine create the class for you. .. code-block:: bash - $ php app/console doctrine:generate:entity --no-interaction \ + $ php bin/console doctrine:generate:entity --no-interaction \ --entity="AppBundle:Category" \ --fields="name:string(255)" @@ -1063,7 +1063,7 @@ methods for you: .. code-block:: bash - $ php app/console doctrine:generate:entities AppBundle + $ php bin/console doctrine:generate:entities AppBundle Ignore the Doctrine metadata for a moment. You now have two classes - ``Category`` and ``Product`` with a natural one-to-many relationship. The ``Category`` @@ -1092,7 +1092,7 @@ table, and ``product.category_id`` column, and new foreign key: .. code-block:: bash - $ php app/console doctrine:schema:update --force + $ php bin/console doctrine:schema:update --force .. note:: diff --git a/book/forms.rst b/book/forms.rst index 2aab3af5d7e..4aeaa2231fd 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -95,8 +95,6 @@ from inside a controller:: $form = $this->createFormBuilder($task) ->add('task', TextType::class) - // If you use PHP 5.3 or 5.4 you must use - // ->add('task', 'Symfony\Component\Form\Extension\Core\Type\TextType') ->add('dueDate', DateType::class) ->add('save', SubmitType::class, array('label' => 'Create Task')) ->getForm(); diff --git a/book/http_cache.rst b/book/http_cache.rst index e01baff8c6d..8faf197fcf9 100644 --- a/book/http_cache.rst +++ b/book/http_cache.rst @@ -145,12 +145,9 @@ To enable caching, modify the code of a front controller to use the caching kernel:: // web/app.php - require_once __DIR__.'/../app/bootstrap.php.cache'; - require_once __DIR__.'/../app/AppKernel.php'; - require_once __DIR__.'/../app/AppCache.php'; - use Symfony\Component\HttpFoundation\Request; + // ... $kernel = new AppKernel('prod', false); $kernel->loadClassCache(); // wrap the default AppKernel with the AppCache one diff --git a/book/installation.rst b/book/installation.rst index aee59fdbaf7..5e6a97b75a1 100644 --- a/book/installation.rst +++ b/book/installation.rst @@ -97,16 +97,16 @@ optional second argument of the ``new`` command: .. code-block:: bash # use the most recent version in any Symfony branch - $ symfony new my_project_name 2.6 $ symfony new my_project_name 2.8 + $ symfony new my_project_name 3.1 # use a specific Symfony version - $ symfony new my_project_name 2.7.3 $ symfony new my_project_name 2.8.1 + $ symfony new my_project_name 3.0.2 # use a beta or RC version (useful for testing new Symfony versions) - $ symfony new my_project 2.8.0-BETA1 - $ symfony new my_project 2.7.0-RC1 + $ symfony new my_project 3.0.0-BETA1 + $ symfony new my_project 3.1.0-RC1 The installer also supports a special version called ``lts`` which installs the most recent :ref:`Symfony LTS version ` available: @@ -152,7 +152,7 @@ version as the second argument of the ``create-project`` command: .. code-block:: bash - $ composer create-project symfony/framework-standard-edition my_project_name "2.8.*" + $ composer create-project symfony/framework-standard-edition my_project_name "3.1.*" .. tip:: @@ -170,7 +170,7 @@ browsing the project directory and executing this command: .. code-block:: bash $ cd my_project_name/ - $ php app/console server:run + $ php bin/console server:run Then, open your browser and access the ``http://localhost:8000/`` URL to see the Welcome Page of Symfony: @@ -201,7 +201,7 @@ server with the ``server:stop`` command: .. code-block:: bash - $ php app/console server:stop + $ php bin/console server:stop Checking Symfony Application Configuration and Setup ---------------------------------------------------- @@ -220,8 +220,8 @@ If there are any issues, correct them now before moving on. .. sidebar:: Setting up Permissions - One common issue when installing Symfony is that the ``app/cache`` and - ``app/logs`` directories must be writable both by the web server and the + One common issue when installing Symfony is that the ``var/cache`` and + ``var/logs`` directories must be writable both by the web server and the command line user. On a UNIX system, if your web server user is different from your command line user, you can try one of the following solutions. @@ -242,12 +242,12 @@ If there are any issues, correct them now before moving on. .. code-block:: bash - $ rm -rf app/cache/* - $ rm -rf app/logs/* + $ rm -rf var/cache/* + $ rm -rf var/logs/* $ HTTPDUSER=`ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1` - $ sudo chmod +a "$HTTPDUSER allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs - $ sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs + $ sudo chmod +a "$HTTPDUSER allow delete,write,append,file_inherit,directory_inherit" var/cache var/logs + $ sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" var/cache var/logs **3. Using ACL on a system that does not support chmod +a** @@ -261,8 +261,8 @@ If there are any issues, correct them now before moving on. .. code-block:: bash $ HTTPDUSER=`ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1` - $ sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs - $ sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs + $ sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX var/cache var/logs + $ sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX var/cache var/logs If this doesn't work, try adding ``-n`` option. @@ -271,7 +271,7 @@ If there are any issues, correct them now before moving on. If none of the previous methods work for you, change the umask so that the cache and log directories will be group-writable or world-writable (depending if the web server user and the command line user are in the same group or not). - To achieve this, put the following line at the beginning of the ``app/console``, + To achieve this, put the following line at the beginning of the ``bin/console``, ``web/app.php`` and ``web/app_dev.php`` files:: umask(0002); // This will let the permissions be 0775 @@ -312,7 +312,7 @@ several minutes to complete. .. code-block:: bash - $ php app/console security:check + $ php bin/console security:check A good security practice is to execute this command regularly to be able to update or replace compromised dependencies as soon as possible. @@ -337,7 +337,7 @@ of the Symfony Installer anywhere in your system: c:\projects\> php symfony demo Once downloaded, enter into the ``symfony_demo/`` directory and run the PHP's -built-in web server executing the ``php app/console server:run`` command. Access +built-in web server executing the ``php bin/console server:run`` command. Access to the ``http://localhost:8000`` URL in your browser to start using the Symfony Demo application. diff --git a/book/page_creation.rst b/book/page_creation.rst index 4a762d61478..40fc1117d68 100644 --- a/book/page_creation.rst +++ b/book/page_creation.rst @@ -101,8 +101,8 @@ Suppose you want to create a JSON endpoint that returns the lucky number. Just add a second method to ``LuckyController``:: // src/AppBundle/Controller/LuckyController.php - // ... + // ... class LuckyController { // ... @@ -131,8 +131,8 @@ Try this out in your browser: You can even shorten this with the handy :class:`Symfony\\Component\\HttpFoundation\\JsonResponse`:: // src/AppBundle/Controller/LuckyController.php - // ... + // ... // --> don't forget this new use statement use Symfony\Component\HttpFoundation\JsonResponse; @@ -167,8 +167,8 @@ at the end: .. code-block:: php-annotations // src/AppBundle/Controller/LuckyController.php - // ... + // ... class LuckyController { /** @@ -273,8 +273,8 @@ to use Twig - or many other tools in Symfony - is to extend Symfony's base :class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller` class:: // src/AppBundle/Controller/LuckyController.php - // ... + // ... // --> add this new use statement use Symfony\Bundle\FrameworkBundle\Controller\Controller; @@ -295,8 +295,8 @@ Twig templates, another that can log messages and many more. To render a Twig template, use a service called ``templating``:: // src/AppBundle/Controller/LuckyController.php - // ... + // ... class LuckyController extends Controller { /** @@ -328,8 +328,8 @@ But this can get even easier! By extending the ``Controller`` class, you also get a lot of shortcut methods, like ``render()``:: // src/AppBundle/Controller/LuckyController.php - // ... + // ... /** * @Route("/lucky/number/{count}") */ @@ -433,30 +433,41 @@ worked inside the two most important directories: else). As you get more advanced, you'll learn what can be done inside each of these. -The ``app/`` directory also holds a few other things, like the cache directory -``app/cache/``, the logs directory ``app/logs/`` and ``app/AppKernel.php``, -which you'll use to enable new bundles (and one of a *very* short list of +The ``app/`` directory also holds some other things, like ``app/AppKernel.php``, +which you'll use to enable new bundles (this is one of a *very* short list of PHP files in ``app/``). The ``src/`` directory has just one directory - ``src/AppBundle`` - and everything lives inside of it. A bundle is like a "plugin" and you can `find open source bundles`_ and install them into your project. But even -*your* code lives in a bundle - typically ``AppBundle`` (though there's -nothing special about ``AppBundle``). To find out more about bundles and +*your* code lives in a bundle - typically *AppBundle* (though there's +nothing special about AppBundle). To find out more about bundles and why you might create multiple bundles (hint: sharing code between projects), see the :doc:`Bundles ` chapter. So what about the other directories in the project? -``vendor/`` - Vendor (i.e. third-party) libraries and bundles are downloaded here by - the `Composer`_ package manager. - ``web/`` This is the document root for the project and contains any publicly accessible files, like CSS, images and the Symfony front controllers that execute the app (``app_dev.php`` and ``app.php``). +``tests/`` + The automatic tests (e.g. Unit tests) of your application live here. + +``bin/`` + The "binary" files live here. The most important one is the ``console`` + file which is used to execute Symfony commands via the console. + +``var/`` + This is where automatically created files are stored, like cache files + (``var/cache/``) and logs (``var/logs/``). + +``vendor/`` + Third-party libraries, packages and bundles are downloaded here by + the `Composer`_ package manager. You should never edit something in this + directory. + .. seealso:: Symfony is flexible. If you need to, you can easily override the default @@ -474,8 +485,8 @@ is ``app/config/config.yml``: .. code-block:: yaml # app/config/config.yml - # ... + # ... framework: secret: '%secret%' router: @@ -543,11 +554,11 @@ by changing one option in this configuration file. To find out how, see the :doc:`Configuration Reference ` section. Or, to get a big example dump of all of the valid configuration under a key, -use the handy ``app/console`` command: +use the handy ``bin/console`` command: .. code-block:: bash - $ app/console config:dump-reference framework + $ php bin/console config:dump-reference framework There's a lot more power behind Symfony's configuration system, including environments, imports and parameters. To learn all of it, see the diff --git a/book/performance.rst b/book/performance.rst index c73ed68c1ee..c60554015b8 100644 --- a/book/performance.rst +++ b/book/performance.rst @@ -75,16 +75,18 @@ If you're using the Standard Distribution, this code should already be available as comments in this file:: // app.php - // ... - - $loader = require_once __DIR__.'/../app/bootstrap.php.cache'; - // Use APC for autoloading to improve performance - // Change 'sf2' by the prefix you want in order - // to prevent key conflict with another application + // ... + $loader = require __DIR__.'/../app/autoload.php'; + include_once __DIR__.'/../var/bootstrap.php.cache'; + // Enable APC for autoloading to improve performance. + // You should change the ApcClassLoader first argument to a unique prefix + // in order to prevent cache key conflicts with other applications + // also using APC. /* - $loader = new ApcClassLoader('sf2', $loader); - $loader->register(true); + $apcLoader = new Symfony\Component\ClassLoader\ApcClassLoader(sha1(__FILE__), $loader); + $loader->unregister(); + $apcLoader->register(true); */ // ... @@ -119,7 +121,7 @@ If you're using the Symfony Standard Edition, then you're probably already using the bootstrap file. To be sure, open your front controller (usually ``app.php``) and check to make sure that the following line exists:: - require_once __DIR__.'/../app/bootstrap.php.cache'; + include_once __DIR__.'/../var/bootstrap.php.cache'; Note that there are two disadvantages when using a bootstrap file: diff --git a/book/routing.rst b/book/routing.rst index 39d32735434..aaeeea2a627 100644 --- a/book/routing.rst +++ b/book/routing.rst @@ -1401,7 +1401,7 @@ the command by running the following from the root of your project. .. code-block:: bash - $ php app/console debug:router + $ php bin/console debug:router .. versionadded:: 2.6 Prior to Symfony 2.6, this command was called ``router:debug``. @@ -1423,14 +1423,14 @@ the route name after the command: .. code-block:: bash - $ php app/console debug:router article_show + $ php bin/console debug:router article_show Likewise, if you want to test whether a URL matches a given route, you can use the ``router:match`` console command: .. code-block:: bash - $ php app/console router:match /blog/my-latest-post + $ php bin/console router:match /blog/my-latest-post This command will print which route the URL matches. diff --git a/book/security.rst b/book/security.rst index f7ebdccb824..668830e468b 100644 --- a/book/security.rst +++ b/book/security.rst @@ -510,14 +510,12 @@ else, you'll want to encode their passwords. The best algorithm to use is // ... )); -.. include:: /cookbook/security/_ircmaxwell_password-compat.rst.inc - Of course, your users' passwords now need to be encoded with this exact algorithm. For hardcoded users, since 2.7 you can use the built-in command : .. code-block:: bash - $ php app/console security:encode-password + $ php bin/console security:encode-password It will give you something like this: @@ -1368,7 +1366,7 @@ security vulnerability in your installed dependencies: .. code-block:: bash - $ php app/console security:check + $ php bin/console security:check A good security practice is to execute this command regularly to be able to update or replace compromised dependencies as soon as possible. Internally, diff --git a/book/service_container.rst b/book/service_container.rst index 4616b216056..f8c670c0978 100644 --- a/book/service_container.rst +++ b/book/service_container.rst @@ -884,20 +884,6 @@ Now, just inject the ``request_stack``, which behaves like any normal service: array(new Reference('request_stack')) )); -.. sidebar:: Why not Inject the ``request`` Service? - - Almost all Symfony2 built-in services behave in the same way: a single - instance is created by the container which it returns whenever you get it or - when it is injected into another service. There is one exception in a standard - Symfony2 application: the ``request`` service. - - If you try to inject the ``request`` into a service, you will probably receive - a - :class:`Symfony\\Component\\DependencyInjection\\Exception\\ScopeWideningInjectionException` - exception. That's because the ``request`` can **change** during the life-time - of a container (when a sub-request is created for instance). - - .. tip:: If you define a controller as a service then you can get the ``Request`` @@ -1148,7 +1134,7 @@ console. To show all services and the class for each service, run: .. code-block:: bash - $ php app/console debug:container + $ php bin/console debug:container .. versionadded:: 2.6 Prior to Symfony 2.6, this command was called ``container:debug``. @@ -1157,7 +1143,7 @@ By default, only public services are shown, but you can also view private servic .. code-block:: bash - $ php app/console debug:container --show-private + $ php bin/console debug:container --show-private .. note:: @@ -1171,7 +1157,7 @@ its id: .. code-block:: bash - $ php app/console debug:container app.mailer + $ php bin/console debug:container app.mailer Learn more ---------- @@ -1183,7 +1169,6 @@ Learn more * :doc:`/components/dependency_injection/parentservices` * :doc:`/components/dependency_injection/tags` * :doc:`/cookbook/controller/service` -* :doc:`/cookbook/service_container/scopes` * :doc:`/cookbook/service_container/compiler_passes` * :doc:`/components/dependency_injection/advanced` diff --git a/book/templating.rst b/book/templating.rst index 5b76fe410d4..b9822b9200e 100644 --- a/book/templating.rst +++ b/book/templating.rst @@ -159,7 +159,7 @@ Twig Template Caching Twig is fast. Each Twig template is compiled down to a native PHP class that is rendered at runtime. The compiled classes are located in the -``app/cache/{environment}/twig`` directory (where ``{environment}`` is the +``var/cache/{environment}/twig`` directory (where ``{environment}`` is the environment, such as ``dev`` or ``prod``) and in some cases can be useful while debugging. See :ref:`environments-summary` for more information on environments. @@ -1218,7 +1218,7 @@ should use the ``parent()`` Twig function to include everything from the ``style block of the base template. You can also include assets located in your bundles' ``Resources/public`` folder. -You will need to run the ``php app/console assets:install target [--symlink]`` +You will need to run the ``php bin/console assets:install target [--symlink]`` command, which moves (or symlinks) files into the correct location. (target is by default "web"). @@ -1398,7 +1398,7 @@ to create it). You're now free to customize the template. .. caution:: If you add a template in a new location, you *may* need to clear your - cache (``php app/console cache:clear``), even if you are in debug mode. + cache (``php bin/console cache:clear``), even if you are in debug mode. This logic also applies to base bundle templates. Suppose also that each template in AcmeBlogBundle inherits from a base template called @@ -1648,10 +1648,10 @@ console command: .. code-block:: bash # You can check by filename: - $ php app/console lint:twig app/Resources/views/article/recent_list.html.twig + $ php bin/console lint:twig app/Resources/views/article/recent_list.html.twig # or by directory: - $ php app/console lint:twig app/Resources/views + $ php bin/console lint:twig app/Resources/views .. _template-formats: diff --git a/book/testing.rst b/book/testing.rst index 9dc85d4cba8..4d0a9d3613b 100644 --- a/book/testing.rst +++ b/book/testing.rst @@ -21,18 +21,16 @@ it has its own excellent `documentation`_. to use version 4.2 or higher to test the Symfony core code itself). Each test - whether it's a unit test or a functional test - is a PHP class -that should live in the ``Tests/`` subdirectory of your bundles. If you follow +that should live in the ``tests/`` directory of your application. If you follow this rule, then you can run all of your application's tests with the following command: .. code-block:: bash - # specify the configuration directory on the command line - $ phpunit -c app/ + $ phpunit -The ``-c`` option tells PHPUnit to look in the ``app/`` directory for a configuration -file. If you're curious about the PHPUnit options, check out the ``app/phpunit.xml.dist`` -file. +PHPunit is configured by the ``phpunit.xml.dist`` file in the root of your +Symfony application. .. tip:: @@ -64,11 +62,11 @@ called ``Calculator`` in the ``Util/`` directory of the app bundle:: } } -To test this, create a ``CalculatorTest`` file in the ``Tests/Util`` directory +To test this, create a ``CalculatorTest`` file in the ``tests/AppBundle/Util`` directory of your bundle:: - // src/AppBundle/Tests/Util/CalculatorTest.php - namespace AppBundle\Tests\Util; + // tests/AppBundle/Util/CalculatorTest.php + namespace Tests\AppBundle\Util; use AppBundle\Util\Calculator; @@ -86,30 +84,30 @@ of your bundle:: .. note:: - By convention, the ``Tests/`` sub-directory should replicate the directory - of your bundle for unit tests. So, if you're testing a class in your - bundle's ``Util/`` directory, put the test in the ``Tests/Util/`` + By convention, the ``Tests/AppBundle`` directory should replicate the directory + of your bundle for unit tests. So, if you're testing a class in the + ``AppBundle/Util/`` directory, put the test in the ``tests/AppBundle/Util/`` directory. Just like in your real application - autoloading is automatically enabled -via the ``bootstrap.php.cache`` file (as configured by default in the -``app/phpunit.xml.dist`` file). +via the ``autoload.php`` file (as configured by default in the +``phpunit.xml.dist`` file). Running tests for a given file or directory is also very easy: .. code-block:: bash # run all tests of the application - $ phpunit -c app + $ phpunit # run all tests in the Util directory - $ phpunit -c app src/AppBundle/Tests/Util + $ phpunit tests/AppBundle/Util # run tests for the Calculator class - $ phpunit -c app src/AppBundle/Tests/Util/CalculatorTest.php + $ phpunit tests/AppBundle/Util/CalculatorTest.php # run all tests for the entire Bundle - $ phpunit -c app src/AppBundle/ + $ phpunit tests/AppBundle/ .. index:: single: Tests; Functional tests @@ -130,15 +128,15 @@ tests as far as PHPUnit is concerned, but they have a very specific workflow: Your First Functional Test ~~~~~~~~~~~~~~~~~~~~~~~~~~ -Functional tests are simple PHP files that typically live in the ``Tests/Controller`` -directory of your bundle. If you want to test the pages handled by your +Functional tests are simple PHP files that typically live in the ``tests/AppBundle/Controller`` +directory for your bundle. If you want to test the pages handled by your ``PostController`` class, start by creating a new ``PostControllerTest.php`` file that extends a special ``WebTestCase`` class. As an example, a test could look like this:: - // src/AppBundle/Tests/Controller/PostControllerTest.php - namespace AppBundle\Tests\Controller; + // tests/AppBundle/Controller/PostControllerTest.php + namespace Tests\AppBundle\Controller; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; @@ -802,30 +800,26 @@ PHPUnit Configuration ~~~~~~~~~~~~~~~~~~~~~ Each application has its own PHPUnit configuration, stored in the -``app/phpunit.xml.dist`` file. You can edit this file to change the defaults or -create an ``app/phpunit.xml`` file to set up a configuration for your local -machine only. +``phpunit.xml.dist`` file. You can edit this file to change the defaults or +create an ``phpunit.xml`` file to set up a configuration for your local machine +only. .. tip:: - Store the ``app/phpunit.xml.dist`` file in your code repository and ignore - the ``app/phpunit.xml`` file. + Store the ``phpunit.xml.dist`` file in your code repository and ignore + the ``phpunit.xml`` file. -By default, only the tests from your own custom bundles stored in the standard -directories ``src/*/*Bundle/Tests``, ``src/*/Bundle/*Bundle/Tests``, -``src/*Bundle/Tests`` are run by the ``phpunit`` command, as configured -in the ``app/phpunit.xml.dist`` file: +By default, only the tests stored in ``/tests`` are run via the ``phpunit`` command, +as configured in the ``phpunit.xml.dist`` file: .. code-block:: xml - + - ../src/*/*Bundle/Tests - ../src/*/Bundle/*Bundle/Tests - ../src/*Bundle/Tests + tests @@ -836,7 +830,7 @@ configuration adds tests from a custom ``lib/tests`` directory: .. code-block:: xml - + @@ -853,7 +847,7 @@ section: .. code-block:: xml - + diff --git a/book/translation.rst b/book/translation.rst index 08fcc57d9d7..b9d20077e7d 100644 --- a/book/translation.rst +++ b/book/translation.rst @@ -432,7 +432,7 @@ For more options, see :ref:`component-translator-message-catalogs`. .. code-block:: bash - $ php app/console cache:clear + $ php bin/console cache:clear .. _book-translation-fallback: @@ -860,7 +860,7 @@ To inspect all messages in the ``fr`` locale for the AcmeDemoBundle, run: .. code-block:: bash - $ php app/console debug:translation fr AcmeDemoBundle + $ php bin/console debug:translation fr AcmeDemoBundle You will get this output: @@ -901,15 +901,15 @@ By default all domains are inspected, but it is possible to specify a single dom .. code-block:: bash - $ php app/console debug:translation en AcmeDemoBundle --domain=messages + $ php bin/console debug:translation en AcmeDemoBundle --domain=messages When bundles have a lot of messages, it is useful to display only the unused or only the missing messages, by using the ``--only-unused`` or ``--only-missing`` switches: .. code-block:: bash - $ php app/console debug:translation en AcmeDemoBundle --only-unused - $ php app/console debug:translation en AcmeDemoBundle --only-missing + $ php bin/console debug:translation en AcmeDemoBundle --only-unused + $ php bin/console debug:translation en AcmeDemoBundle --only-missing Summary ------- diff --git a/changelog.rst b/changelog.rst index 42916827635..88182ddac88 100644 --- a/changelog.rst +++ b/changelog.rst @@ -19,6 +19,9 @@ November, 2015 New Documentation ~~~~~~~~~~~~~~~~~ +* `#5917 `_ [3.0][Cookbook] Use the 3.0 directory structure (WouterJ) +* `#5916 `_ [3.0][Best Practices][Quick Tour] Use the 3.0 directory structure (WouterJ) +* `#5913 `_ [3.0][Book] Use the 3.0 directory structure (WouterJ) * `#5907 `_ Updating some places to use the new CustomUserMessageAuthenticationException (weaverryan) * `#5922 `_ Added minimal cookbook article about the shared flag (WouterJ) * `#5908 `_ Voter update (weaverryan) @@ -238,6 +241,7 @@ Minor Documentation Changes * `#5553 `_ Fix all broken links/permanent redirects/removed anchors (WouterJ) * `#5650 `_ [RFR] fixing typo and removing duplicated lines in Config component doc (salahm) * `#5635 `_ Fix minor problems in book/page_creation.rst (fabschurt) +* `#5579 `_ [3.0] Remove mentions of Symfony1 (WouterJ) * `#5647 `_ don't ignore the _exts directory anymore (xabbuh) * `#5587 `_ [2.6] Don't use deprecated features (WouterJ) * `#5637 `_ Add QueryBuilder vs DQL section (bocharsky-bw) @@ -271,6 +275,7 @@ July, 2015 New Documentation ~~~~~~~~~~~~~~~~~ +* `#5374 `_ Remove deprecated parameters (norkunas) * `#5533 `_ Replace Capifony with Capistrano/symfony (mojzis) * `#5543 `_ Add deprecation notice to "choice_list" option of ChoiceType (XitasoChris) * `#5521 `_ [Cookbook][WebServer] #5504 add a tip for the --force option (vincentaubert) @@ -706,6 +711,7 @@ Minor Documentation Changes - `3be0081 `_ #4976 Improved sentence (edsonmedina) - `a444220 `_ #4885 Fix typos (ifdattic) - `482502d `_ #4793 [Contributing] Several tweaks (xelaris) +- `a2395ef `_ #5054 [Changelog] fix changelog syntax (xabbuh) - `6b66f03 `_ #5003 Updated the generic Deployment article (javiereguiluz) - `39a1487 `_ #4999 Fixed semantic error (beni0888) @@ -746,7 +752,6 @@ Minor Documentation Changes - `1726054 `_ #4500 Link to standard edition (harikt) - `91ff6f8 `_ #4329 ensure consistency with the note (greg0ire) - `f4ab4b6 `_ #5002 Revert very bad merge (WouterJ) -- `e747392 `_ Revert "#4977 Unnecessary comma (edsonmedina)" - `e5dbd49 `_ #4977 Unnecessary comma (edsonmedina) - `ed80100 `_ #4977 Unnecessary comma (edsonmedina) - `5d44987 `_ #4991 Fixed typo and tweaked syntax. (cdvrooman) diff --git a/components/dependency_injection/parentservices.rst b/components/dependency_injection/parentservices.rst index 1afcf43b72c..2177f56bf7b 100644 --- a/components/dependency_injection/parentservices.rst +++ b/components/dependency_injection/parentservices.rst @@ -277,8 +277,7 @@ called when the child services are instantiated. .. caution:: - The ``scope``, ``abstract`` and ``tags`` attributes are always taken - from the child service. + The ``abstract`` and ``tags`` attributes are always taken from the child service. The parent service is abstract as it should not be directly retrieved from the container or passed into another service. It exists merely as a "template" diff --git a/components/form/introduction.rst b/components/form/introduction.rst index 36a13fb9d28..a6515aa3aac 100644 --- a/components/form/introduction.rst +++ b/components/form/introduction.rst @@ -398,8 +398,6 @@ is created from the form factory. $form = $formFactory->createBuilder() ->add('task', TextType::class) - // If you use PHP 5.3 or 5.4, you must use - // ->add('task', 'Symfony\Component\Form\Extension\Core\Type\TextType') ->add('dueDate', DateType::class) ->getForm(); @@ -426,8 +424,6 @@ is created from the form factory. $form = $this->createFormBuilder() ->add('task', TextType::class) - // If you use PHP 5.3 or 5.4, you must use - // ->add('task', 'Symfony\Component\Form\Extension\Core\Type\TextType') ->add('dueDate', DateType::class) ->getForm(); @@ -439,8 +435,7 @@ is created from the form factory. As you can see, creating a form is like writing a recipe: you call ``add`` for each new field you want to create. The first argument to ``add`` is the -name of your field, and the second is the fully qualified class name. If you -use PHP 5.5 or above, you can use ``::class`` constant of a form type. The Form +name of your field, and the second is the fully qualified class name. The Form component comes with a lot of :doc:`built-in types `. Now that you've built your form, learn how to :ref:`render ` diff --git a/components/var_dumper/introduction.rst b/components/var_dumper/introduction.rst index 8f11a198c4d..9e97e3ec15d 100644 --- a/components/var_dumper/introduction.rst +++ b/components/var_dumper/introduction.rst @@ -145,11 +145,6 @@ Example:: } } -.. tip:: - - If you still use PHP 5.3, you can extend the - :class:`Symfony\\Component\\VarDumper\\Test\\VarDumperTestClass` instead. - Dump Examples and Output ------------------------ diff --git a/components/yaml/introduction.rst b/components/yaml/introduction.rst index adb0d0956e6..c4104e01e40 100644 --- a/components/yaml/introduction.rst +++ b/components/yaml/introduction.rst @@ -135,16 +135,9 @@ It may also be convenient to use the $yaml = Yaml::parse(file_get_contents('/path/to/file.yml')); -The :method:`Symfony\\Component\\Yaml\\Yaml::parse` static method takes a YAML -string or a file containing YAML. Internally, it calls the -:method:`Symfony\\Component\\Yaml\\Parser::parse` method, but enhances the -error if something goes wrong by adding the filename to the message. - -.. caution:: - - Because it is currently possible to pass a filename to this method, you - must validate the input first. Passing a filename is deprecated in - Symfony 2.2, and will be removed in Symfony 3.0. +The :method:`Symfony\\Component\\Yaml\\Yaml::parse` static method takes a YAML string. +Internally, it constructs a :class:`Symfony\\Component\\Yaml\\Parser` object and calls +the :method:`Symfony\\Component\\Yaml\\Parser::parse` method. .. _components-yaml-dump: diff --git a/contributing/code/patches.rst b/contributing/code/patches.rst index 7d5ef0c3452..b4f0b2ba4fa 100644 --- a/contributing/code/patches.rst +++ b/contributing/code/patches.rst @@ -14,14 +14,14 @@ Before working on Symfony, setup a friendly environment with the following software: * Git; -* PHP version 5.3.9 or above; +* PHP version 5.5.9 or above; * `PHPUnit`_ 4.2 or above. .. caution:: - Before Symfony 2.7, the minimal PHP version was 5.3.3. Please keep - this in mind, if you are working on a bug fix for earlier versions - of Symfony. + Before Symfony 2.7, the minimal PHP version was 5.3.3. Before Symfony 3.0, + minimal version was 5.3.9. Please keep this in mind, if you are working on a + bug fix for earlier versions of Symfony. Configure Git ~~~~~~~~~~~~~ diff --git a/cookbook/assetic/asset_management.rst b/cookbook/assetic/asset_management.rst index e6019418aac..a30a32a9237 100644 --- a/cookbook/assetic/asset_management.rst +++ b/cookbook/assetic/asset_management.rst @@ -583,7 +583,7 @@ each time you deploy), you should run the following command: .. code-block:: bash - $ php app/console assetic:dump --env=prod --no-debug + $ php bin/console assetic:dump --env=prod --no-debug This will physically generate and write each file that you need (e.g. ``/js/abcd123.js``). If you update any of your assets, you'll need to run this again to regenerate @@ -625,7 +625,7 @@ need to dump them manually. To do so, run the following command: .. code-block:: bash - $ php app/console assetic:dump + $ php bin/console assetic:dump This physically writes all of the asset files you need for your ``dev`` environment. The big disadvantage is that you need to run this each time @@ -634,7 +634,7 @@ assets will be regenerated automatically *as they change*: .. code-block:: bash - $ php app/console assetic:watch + $ php bin/console assetic:watch The ``assetic:watch`` command was introduced in AsseticBundle 2.4. In prior versions, you had to use the ``--watch`` option of the ``assetic:dump`` diff --git a/cookbook/bundles/installation.rst b/cookbook/bundles/installation.rst index 1dd7e1f4d83..2b6f222fd57 100644 --- a/cookbook/bundles/installation.rst +++ b/cookbook/bundles/installation.rst @@ -108,14 +108,14 @@ via the ``config:dump-reference`` command: .. code-block:: bash - $ app/console config:dump-reference AsseticBundle + $ bin/console config:dump-reference AsseticBundle Instead of the full bundle name, you can also pass the short name used as the root of the bundle's configuration: .. code-block:: bash - $ app/console config:dump-reference assetic + $ bin/console config:dump-reference assetic The output will look like this: diff --git a/cookbook/configuration/apache_router.rst b/cookbook/configuration/apache_router.rst index a8b4f8a7c33..4e69b18a289 100644 --- a/cookbook/configuration/apache_router.rst +++ b/cookbook/configuration/apache_router.rst @@ -98,7 +98,7 @@ Now generate the mod_rewrite rules: .. code-block:: bash - $ php app/console router:dump-apache -e=prod --no-debug + $ php bin/console router:dump-apache -e=prod --no-debug Which should roughly output the following: @@ -145,7 +145,7 @@ to ``ApacheRequest`` in ``web/app.php``:: // web/app.php - require_once __DIR__.'/../app/bootstrap.php.cache'; + require_once __DIR__.'/../var/bootstrap.php.cache'; require_once __DIR__.'/../app/AppKernel.php'; // require_once __DIR__.'/../app/AppCache.php'; diff --git a/cookbook/configuration/configuration_organization.rst b/cookbook/configuration/configuration_organization.rst index 5473a4c06b1..d3a1fc85b2f 100644 --- a/cookbook/configuration/configuration_organization.rst +++ b/cookbook/configuration/configuration_organization.rst @@ -34,8 +34,9 @@ default Symfony Standard Edition follow this structure: .. code-block:: text - / + your-project/ ├─ app/ + │ ├─ ... │ └─ config/ │ ├─ config.yml │ ├─ config_dev.yml @@ -46,9 +47,7 @@ default Symfony Standard Edition follow this structure: │ ├─ routing.yml │ ├─ routing_dev.yml │ └─ security.yml - ├─ src/ - ├─ vendor/ - └─ web/ + ├─ ... This default structure was chosen for its simplicity — one file per environment. But as any other Symfony feature, you can customize it to better suit your needs. @@ -65,8 +64,9 @@ name as the environment: .. code-block:: text - / + your-project/ ├─ app/ + │ ├─ ... │ └─ config/ │ ├─ common/ │ │ ├─ config.yml @@ -83,9 +83,7 @@ name as the environment: │ ├─ parameters.yml │ ├─ routing.yml │ └─ security.yml - ├─ src/ - ├─ vendor/ - └─ web/ + ├─ ... To make this work, change the code of the :method:`Symfony\\Component\\HttpKernel\\KernelInterface::registerContainerConfiguration` @@ -161,8 +159,9 @@ and several files to define all application services: .. code-block:: text - / + your-project/ ├─ app/ + │ ├─ ... │ └─ config/ │ ├─ bundles/ │ │ ├─ bundle1.yml @@ -182,9 +181,7 @@ and several files to define all application services: │ ├─ backend.yml │ ├─ ... │ └─ security.yml - ├─ src/ - ├─ vendor/ - └─ web/ + ├─ ... Again, change the code of the ``registerContainerConfiguration()`` method to make Symfony aware of the new file organization:: diff --git a/cookbook/configuration/environments.rst b/cookbook/configuration/environments.rst index 0b8b8776b17..faf1ffefe6d 100644 --- a/cookbook/configuration/environments.rst +++ b/cookbook/configuration/environments.rst @@ -221,13 +221,13 @@ behavior: .. code-block:: bash # 'dev' environment and debug enabled - $ php app/console command_name + $ php bin/console command_name # 'prod' environment (debug is always disabled for 'prod') - $ php app/console command_name --env=prod + $ php bin/console command_name --env=prod # 'test' environment and debug disabled - $ php app/console command_name --env=test --no-debug + $ php bin/console command_name --env=test --no-debug In addition to the ``--env`` and ``--debug`` options, the behavior of Symfony commands can also be controlled with environment variables. The Symfony console @@ -342,13 +342,13 @@ Symfony takes advantage of caching in many ways: the application configuration, routing configuration, Twig templates and more are cached to PHP objects stored in files on the filesystem. -By default, these cached files are largely stored in the ``app/cache`` directory. +By default, these cached files are largely stored in the ``var/cache`` directory. However, each environment caches its own set of files: .. code-block:: text - / - ├─ app/ + your-project/ + ├─ var/ │ ├─ cache/ │ │ ├─ dev/ # cache directory for the *dev* environment │ │ └─ prod/ # cache directory for the *prod* environment @@ -357,7 +357,7 @@ However, each environment caches its own set of files: Sometimes, when debugging, it may be helpful to inspect a cached file to understand how something is working. When doing so, remember to look in the directory of the environment you're using (most commonly ``dev`` while -developing and debugging). While it can vary, the ``app/cache/dev`` directory +developing and debugging). While it can vary, the ``var/cache/dev`` directory includes the following: ``appDevDebugProjectContainer.php`` diff --git a/cookbook/configuration/front_controllers_and_kernel.rst b/cookbook/configuration/front_controllers_and_kernel.rst index cab5f41b427..9bfe3be4e46 100644 --- a/cookbook/configuration/front_controllers_and_kernel.rst +++ b/cookbook/configuration/front_controllers_and_kernel.rst @@ -75,7 +75,7 @@ as the default one. access. For example, you don't want to make a debugging environment available to arbitrary users in your production environment. -Technically, the `app/console`_ script used when running Symfony on the command +Technically, the `bin/console`_ script used when running Symfony on the command line is also a front controller, only that is not used for web, but for command line requests. @@ -162,7 +162,7 @@ way of loading your configuration. .. _Symfony Standard Edition: https://github.com/symfony/symfony-standard .. _app.php: https://github.com/symfony/symfony-standard/blob/master/web/app.php .. _app_dev.php: https://github.com/symfony/symfony-standard/blob/master/web/app_dev.php -.. _app/console: https://github.com/symfony/symfony-standard/blob/master/app/console +.. _bin/console: https://github.com/symfony/symfony-standard/blob/master/bin/console .. _AppKernel: https://github.com/symfony/symfony-standard/blob/master/app/AppKernel.php .. _decorate: https://en.wikipedia.org/wiki/Decorator_pattern .. _RewriteRule shipped with the Symfony Standard Edition: https://github.com/symfony/symfony-standard/blob/master/web/.htaccess diff --git a/cookbook/configuration/micro-kernel-trait.rst b/cookbook/configuration/micro-kernel-trait.rst index 79f1d474f6d..7e4563f34bb 100644 --- a/cookbook/configuration/micro-kernel-trait.rst +++ b/cookbook/configuration/micro-kernel-trait.rst @@ -11,12 +11,6 @@ as one file? This is possible thanks to the new you to start with a tiny application, and then add features and structure as you need to. -.. note:: - - The MicroKernelTrait requires PHP 5.4. However, there's nothing special about - this trait. If you're using PHP 5.3, simply copy its methods into *your* kernel - class to get the same functionality. - A Single-File Symfony Application --------------------------------- diff --git a/cookbook/configuration/override_dir_structure.rst b/cookbook/configuration/override_dir_structure.rst index 6029e428b90..f43cb7f1fb8 100644 --- a/cookbook/configuration/override_dir_structure.rst +++ b/cookbook/configuration/override_dir_structure.rst @@ -12,12 +12,18 @@ directory structure is: your-project/ ├─ app/ - │ ├─ cache/ │ ├─ config/ - │ ├─ logs/ + │ └─ ... + ├─ bin/ │ └─ ... ├─ src/ │ └─ ... + ├─ tests/ + │ └─ ... + ├─ var/ + │ ├─ cache/ + │ ├─ logs/ + │ └─ ... ├─ vendor/ │ └─ ... └─ web/ @@ -41,13 +47,13 @@ in the ``AppKernel`` class of you application:: public function getCacheDir() { - return $this->rootDir.'/'.$this->environment.'/cache'; + return dirname(__DIR__).'/var/'.$this->environment.'/cache'; } } -``$this->rootDir`` is the absolute path to the ``app`` directory and ``$this->environment`` -is the current environment (i.e. ``dev``). In this case you have changed -the location of the cache directory to ``app/{environment}/cache``. +In this code, ``$this->environment`` is the current environment (i.e. ``dev``). +In this case you have changed the location of the cache directory to +``var/{environment}/cache``. .. caution:: @@ -74,11 +80,11 @@ method:: public function getLogDir() { - return $this->rootDir.'/'.$this->environment.'/logs'; + return dirname(__DIR__).'/var/'.$this->environment.'/logs'; } } -Here you have changed the location of the directory to ``app/{environment}/logs``. +Here you have changed the location of the directory to ``var/{environment}/logs``. .. _override-web-dir: @@ -86,23 +92,22 @@ Override the ``web`` Directory ------------------------------ If you need to rename or move your ``web`` directory, the only thing you -need to guarantee is that the path to the ``app`` directory is still correct +need to guarantee is that the path to the ``var`` directory is still correct in your ``app.php`` and ``app_dev.php`` front controllers. If you simply renamed the directory, you're fine. But if you moved it in some way, you may need to modify these paths inside those files:: - require_once __DIR__.'/../Symfony/app/bootstrap.php.cache'; - require_once __DIR__.'/../Symfony/app/AppKernel.php'; + require_once __DIR__.'/../path/to/app/autoload.php'; -You also need to change the ``extra.symfony-web-dir`` option in the ``composer.json`` -file: +You also need to change the ``extra.symfony-web-dir`` option in the +``composer.json`` file: -.. code-block:: javascript +.. code-block:: json { - ... + "...": "...", "extra": { - ... + "...": "...", "symfony-web-dir": "my_new_web_dir" } } @@ -154,8 +159,8 @@ file: .. code-block:: bash - $ php app/console cache:clear --env=prod - $ php app/console assetic:dump --env=prod --no-debug + $ php bin/console cache:clear --env=prod + $ php bin/console assetic:dump --env=prod --no-debug Override the ``vendor`` Directory --------------------------------- @@ -179,6 +184,7 @@ The change in the ``composer.json`` will look like this: Then, update the path to the ``autoload.php`` file in ``app/autoload.php``:: // app/autoload.php + // ... $loader = require '/some/dir/vendor/autoload.php'; diff --git a/cookbook/console/console_command.rst b/cookbook/console/console_command.rst index 7b4940623f0..8c88efb3622 100644 --- a/cookbook/console/console_command.rst +++ b/cookbook/console/console_command.rst @@ -68,7 +68,7 @@ This command will now automatically be available to run: .. code-block:: bash - $ php app/console demo:greet Fabien + $ php bin/console demo:greet Fabien .. _cookbook-console-dic: diff --git a/cookbook/console/logging.rst b/cookbook/console/logging.rst index eb6b092c547..9a7bbdc9369 100644 --- a/cookbook/console/logging.rst +++ b/cookbook/console/logging.rst @@ -65,7 +65,7 @@ container and use it to do the logging:: } Depending on the environment in which you run your command (and your logging -setup), you should see the logged entries in ``app/logs/dev.log`` or ``app/logs/prod.log``. +setup), you should see the logged entries in ``var/logs/dev.log`` or ``var/logs/prod.log``. Enabling automatic Exceptions Logging ------------------------------------- diff --git a/cookbook/console/usage.rst b/cookbook/console/usage.rst index 0e2c1e5befd..8bdd134913e 100644 --- a/cookbook/console/usage.rst +++ b/cookbook/console/usage.rst @@ -17,13 +17,13 @@ clear and warm the ``prod`` cache you need to run: .. code-block:: bash - $ php app/console cache:clear --env=prod + $ php bin/console cache:clear --env=prod or the equivalent: .. code-block:: bash - $ php app/console cache:clear -e prod + $ php bin/console cache:clear -e prod In addition to changing the environment, you can also choose to disable debug mode. This can be useful where you want to run commands in the ``dev`` environment @@ -31,4 +31,4 @@ but avoid the performance hit of collecting debug data: .. code-block:: bash - $ php app/console list --no-debug + $ php bin/console list --no-debug diff --git a/cookbook/debugging.rst b/cookbook/debugging.rst index 98fae25bad8..2333bd65665 100644 --- a/cookbook/debugging.rst +++ b/cookbook/debugging.rst @@ -30,22 +30,21 @@ The ``app_dev.php`` front controller reads as follows by default:: // ... - $loader = require_once __DIR__.'/../app/bootstrap.php.cache'; - require_once __DIR__.'/../app/AppKernel.php'; + $loader = require __DIR__.'/../app/autoload.php'; + Debug::enable(); $kernel = new AppKernel('dev', true); $kernel->loadClassCache(); $request = Request::createFromGlobals(); + // ... -To make your debugger happier, disable all PHP class caches by removing the -call to ``loadClassCache()`` and by replacing the require statements like -below:: +To make your debugger happier, disable all PHP class caches by removing (or +commenting) the call to ``loadClassCache()``:: // ... - // $loader = require_once __DIR__.'/../app/bootstrap.php.cache'; $loader = require_once __DIR__.'/../app/autoload.php'; - require_once __DIR__.'/../app/AppKernel.php'; + Debug::enable(); $kernel = new AppKernel('dev', true); // $kernel->loadClassCache(); diff --git a/cookbook/deployment/azure-website.rst b/cookbook/deployment/azure-website.rst index e24ed31409e..54c6175b55f 100644 --- a/cookbook/deployment/azure-website.rst +++ b/cookbook/deployment/azure-website.rst @@ -96,8 +96,8 @@ and how to properly configure PHP for a production environment. Configuring the latest PHP Runtime ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Even though Symfony only requires PHP 5.3.9 to run, it's always recommended -to use the most recent PHP version whenever possible. PHP 5.3 is no longer +Even though Symfony only requires PHP 5.5.9 to run, it's always recommended +to use the most recent PHP version whenever possible. Earlier versions are no longer supported by the PHP core team, but you can update it easily in Azure. To update your PHP version on Azure, go to the **Configure** tab of the control @@ -259,13 +259,13 @@ directory with at least the following contents: .. code-block:: text - /app/bootstrap.php.cache - /app/cache/* + /var/bootstrap.php.cache + /var/cache/* /app/config/parameters.yml - /app/logs/* - !app/cache/.gitkeep - !app/logs/.gitkeep - /app/SymfonyRequirements.php + /var/logs/* + !var/cache/.gitkeep + !var/logs/.gitkeep + /var/SymfonyRequirements.php /build/ /vendor/ /bin/ @@ -388,7 +388,7 @@ MySQL database. .. code-block:: bash - $ php app/console doctrine:schema:update --force + $ php bin/console doctrine:schema:update --force 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 diff --git a/cookbook/deployment/heroku.rst b/cookbook/deployment/heroku.rst index 92feaabe329..0a8279fd161 100644 --- a/cookbook/deployment/heroku.rst +++ b/cookbook/deployment/heroku.rst @@ -275,7 +275,7 @@ This is also very useful to build assets on the production system, e.g. with Ass { "scripts": { "compile": [ - "app/console assetic:dump" + "bin/console assetic:dump" ] } } diff --git a/cookbook/deployment/platformsh.rst b/cookbook/deployment/platformsh.rst index d257c8df4c2..2f0857f5af1 100644 --- a/cookbook/deployment/platformsh.rst +++ b/cookbook/deployment/platformsh.rst @@ -62,16 +62,16 @@ Platform.sh how to deploy your application (read more about # The mounts that will be performed when the package is deployed. mounts: - '/app/cache': 'shared:files/cache' - '/app/logs': 'shared:files/logs' + '/var/cache': 'shared:files/cache' + '/var/logs': 'shared:files/logs' # The hooks that will be performed when the package is deployed. hooks: build: | rm web/app_dev.php - app/console --env=prod assetic:dump --no-debug + bin/console --env=prod assetic:dump --no-debug deploy: | - app/console --env=prod cache:clear + bin/console --env=prod cache:clear For best practices, you should also add a ``.platform`` folder at the root of your Git repository which contains the following files: diff --git a/cookbook/deployment/tools.rst b/cookbook/deployment/tools.rst index c53ed2fa6a5..cf6c3186e1f 100644 --- a/cookbook/deployment/tools.rst +++ b/cookbook/deployment/tools.rst @@ -150,7 +150,7 @@ Make sure you clear (and warm-up) your Symfony cache: .. code-block:: bash - $ php app/console cache:clear --env=prod --no-debug + $ php bin/console cache:clear --env=prod --no-debug E) Dump your Assetic Assets ~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -159,7 +159,7 @@ If you're using Assetic, you'll also want to dump your assets: .. code-block:: bash - $ php app/console assetic:dump --env=prod --no-debug + $ php bin/console assetic:dump --env=prod --no-debug F) Other Things! ~~~~~~~~~~~~~~~~ diff --git a/cookbook/doctrine/console.rst b/cookbook/doctrine/console.rst index 0cfb7befca0..11459a3b2d5 100644 --- a/cookbook/doctrine/console.rst +++ b/cookbook/doctrine/console.rst @@ -11,7 +11,7 @@ command: .. code-block:: bash - $ php app/console list doctrine + $ php bin/console list doctrine A list of available commands will print out. You can find out more information about any of these commands (or any Symfony command) by running the ``help`` @@ -20,7 +20,7 @@ task, run: .. code-block:: bash - $ php app/console help doctrine:database:create + $ php bin/console help doctrine:database:create Some notable or interesting tasks include: @@ -30,7 +30,7 @@ Some notable or interesting tasks include: .. code-block:: bash - $ php app/console doctrine:ensure-production-settings --env=prod + $ php bin/console doctrine:ensure-production-settings --env=prod * ``doctrine:mapping:import`` - allows Doctrine to introspect an existing database and create mapping information. For more information, see diff --git a/cookbook/doctrine/multiple_entity_managers.rst b/cookbook/doctrine/multiple_entity_managers.rst index 7bcb18b2861..aeab0576eff 100644 --- a/cookbook/doctrine/multiple_entity_managers.rst +++ b/cookbook/doctrine/multiple_entity_managers.rst @@ -165,20 +165,20 @@ When working with multiple connections to create your databases: .. code-block:: bash # Play only with "default" connection - $ php app/console doctrine:database:create + $ php bin/console doctrine:database:create # Play only with "customer" connection - $ php app/console doctrine:database:create --connection=customer + $ php bin/console doctrine:database:create --connection=customer When working with multiple entity managers to update your schema: .. code-block:: bash # Play only with "default" mappings - $ php app/console doctrine:schema:update --force + $ php bin/console doctrine:schema:update --force # Play only with "customer" mappings - $ php app/console doctrine:schema:update --force --em=customer + $ php bin/console doctrine:schema:update --force --em=customer If you *do* omit the entity manager's name when asking for it, the default entity manager (i.e. ``default``) is returned:: diff --git a/cookbook/doctrine/registration_form.rst b/cookbook/doctrine/registration_form.rst index 7ef2850278d..6f1341e4bb5 100644 --- a/cookbook/doctrine/registration_form.rst +++ b/cookbook/doctrine/registration_form.rst @@ -326,7 +326,7 @@ database schema using this command: .. code-block:: bash - $ php app/console doctrine:schema:update --force + $ php bin/console doctrine:schema:update --force That's it! Head to ``/register`` to try things out! diff --git a/cookbook/doctrine/reverse_engineering.rst b/cookbook/doctrine/reverse_engineering.rst index dd50a6be9c2..efa393a0beb 100644 --- a/cookbook/doctrine/reverse_engineering.rst +++ b/cookbook/doctrine/reverse_engineering.rst @@ -59,7 +59,7 @@ table fields. .. code-block:: bash - $ php app/console doctrine:mapping:import --force AcmeBlogBundle xml + $ php bin/console doctrine:mapping:import --force AcmeBlogBundle xml This command line tool asks Doctrine to introspect the database and generate the XML metadata files under the ``src/Acme/BlogBundle/Resources/config/doctrine`` @@ -92,8 +92,8 @@ entity classes by executing the following two commands. .. code-block:: bash - $ php app/console doctrine:mapping:convert annotation ./src - $ php app/console doctrine:generate:entities AcmeBlogBundle + $ php bin/console doctrine:mapping:convert annotation ./src + $ php bin/console doctrine:generate:entities AcmeBlogBundle The first command generates entity classes with annotation mappings. But if you want to use YAML or XML mapping instead of annotations, you should diff --git a/cookbook/email/spool.rst b/cookbook/email/spool.rst index 244098df9b3..592892f9f5b 100644 --- a/cookbook/email/spool.rst +++ b/cookbook/email/spool.rst @@ -117,19 +117,19 @@ There is a console command to send the messages in the spool: .. code-block:: bash - $ php app/console swiftmailer:spool:send --env=prod + $ php bin/console swiftmailer:spool:send --env=prod It has an option to limit the number of messages to be sent: .. code-block:: bash - $ php app/console swiftmailer:spool:send --message-limit=10 --env=prod + $ php bin/console swiftmailer:spool:send --message-limit=10 --env=prod You can also set the time limit in seconds: .. code-block:: bash - $ php app/console swiftmailer:spool:send --time-limit=10 --env=prod + $ php bin/console swiftmailer:spool:send --time-limit=10 --env=prod Of course you will not want to run this manually in reality. Instead, the console command should be triggered by a cron job or scheduled task and run diff --git a/cookbook/email/testing.rst b/cookbook/email/testing.rst index 270f7506895..6ab1e522e7e 100644 --- a/cookbook/email/testing.rst +++ b/cookbook/email/testing.rst @@ -33,7 +33,9 @@ Start with an easy controller action that sends an email:: In your functional test, use the ``swiftmailer`` collector on the profiler to get information about the messages sent on the previous request:: - // src/AppBundle/Tests/Controller/MailControllerTest.php + // tests/AppBundle/Controller/MailControllerTest.php + namespace Tests\AppBundle\Controller; + use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class MailControllerTest extends WebTestCase diff --git a/cookbook/event_dispatcher/before_after_filters.rst b/cookbook/event_dispatcher/before_after_filters.rst index 2ae36f8a0de..fff97e4b04b 100644 --- a/cookbook/event_dispatcher/before_after_filters.rst +++ b/cookbook/event_dispatcher/before_after_filters.rst @@ -8,10 +8,10 @@ It is quite common in web application development to need some logic to be executed just before or just after your controller actions acting as filters or hooks. -In symfony1, this was achieved with the preExecute and postExecute methods. -Most major frameworks have similar methods but there is no such thing in Symfony. -The good news is that there is a much better way to interfere with the -Request -> Response process using the :doc:`EventDispatcher component `. +Some web frameworks define methods like ``preExecute()`` and ``postExecute()``, +but there is no such thing in Symfony. The good news is that there is a much +better way to interfere with the Request -> Response process using the +:doc:`EventDispatcher component `. Token Validation Example ------------------------ diff --git a/cookbook/event_dispatcher/event_listener.rst b/cookbook/event_dispatcher/event_listener.rst index 19ceebf755f..ecdcada660b 100644 --- a/cookbook/event_dispatcher/event_listener.rst +++ b/cookbook/event_dispatcher/event_listener.rst @@ -274,11 +274,11 @@ using the console. To show all events and their listeners, run: .. code-block:: bash - $ php app/console debug:event-dispatcher + $ php bin/console debug:event-dispatcher You can get registered listeners for a particular event by specifying its name: .. code-block:: bash - $ php app/console debug:event-dispatcher kernel.exception + $ php bin/console debug:event-dispatcher kernel.exception diff --git a/cookbook/form/unit_testing.rst b/cookbook/form/unit_testing.rst index 2ffcc4b5d4d..c45a0e40e3a 100644 --- a/cookbook/form/unit_testing.rst +++ b/cookbook/form/unit_testing.rst @@ -36,8 +36,8 @@ The Basics The simplest ``TypeTestCase`` implementation looks like the following:: - // src/AppBundle/Tests/Form/Type/TestedTypeTest.php - namespace AppBundle\Tests\Form\Type; + // tests/AppBundle/Form/Type/TestedTypeTest.php + namespace Tests\AppBundle\Form\Type; use AppBundle\Form\Type\TestedType; use AppBundle\Model\TestObject; @@ -117,15 +117,18 @@ might look like this:: // src/AppBundle/Form/Type/TestedType.php - // ... the buildForm method - $builder->add('app_test_child_type'); + // ... + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder->add('app_test_child_type'); + } To create your form correctly, you need to make the type available to the form factory in your test. The easiest way is to register it manually before creating the parent form using the ``PreloadedExtension`` class:: - // src/AppBundle/Tests/Form/Type/TestedTypeTests.php - namespace AppBundle\Tests\Form\Type; + // tests/AppBundle/Form/Type/TestedTypeTests.php + namespace Tests\AppBundle\Form\Type; use AppBundle\Form\Type\TestedType; use AppBundle\Model\TestObject; @@ -170,8 +173,8 @@ depends on other extensions. The :method:`Symfony\\Component\\Form\\Test\\TypeTestCase::getExtensions` allows you to return a list of extensions to register:: - // src/AppBundle/Tests/Form/Type/TestedTypeTests.php - namespace AppBundle\Tests\Form\Type; + // tests/AppBundle/Form/Type/TestedTypeTests.php + namespace Tests\AppBundle\Form\Type; use AppBundle\Form\Type\TestedType; use AppBundle\Model\TestObject; @@ -202,8 +205,8 @@ Testing against Different Sets of Data If you are not familiar yet with PHPUnit's `data providers`_, this might be a good opportunity to use them:: - // src/AppBundle/Tests/Form/Type/TestedTypeTests.php - namespace AppBundle\Tests\Form\Type; + // tests/AppBundle/Form/Type/TestedTypeTests.php + namespace Tests\AppBundle\Form\Type; use AppBundle\Form\Type\TestedType; use AppBundle\Model\TestObject; @@ -211,7 +214,6 @@ a good opportunity to use them:: class TestedTypeTest extends TypeTestCase { - /** * @dataProvider getValidTestData */ diff --git a/cookbook/index.rst b/cookbook/index.rst index bdf414d6177..ba0f13c6fc1 100644 --- a/cookbook/index.rst +++ b/cookbook/index.rst @@ -29,7 +29,6 @@ The Cookbook service_container/index session/index psr7 - symfony1 templating/index testing/index upgrade/index diff --git a/cookbook/logging/monolog.rst b/cookbook/logging/monolog.rst index 2b95c990731..ae3b6eeb2e6 100644 --- a/cookbook/logging/monolog.rst +++ b/cookbook/logging/monolog.rst @@ -39,8 +39,8 @@ to write the logs (the handlers can be shared). the logger will log to. The basic handler is the ``StreamHandler`` which writes logs in a stream -(by default in the ``app/logs/prod.log`` in the prod environment and -``app/logs/dev.log`` in the dev environment). +(by default in the ``var/logs/prod.log`` in the prod environment and +``var/logs/dev.log`` in the dev environment). Monolog comes also with a powerful built-in handler for the logging in prod environment: ``FingersCrossedHandler``. It allows you to store the diff --git a/cookbook/map.rst.inc b/cookbook/map.rst.inc index 73587ee5d47..b175020f713 100644 --- a/cookbook/map.rst.inc +++ b/cookbook/map.rst.inc @@ -194,7 +194,6 @@ * :doc:`/cookbook/service_container/index` * :doc:`/cookbook/service_container/shared` - * :doc:`/cookbook/service_container/scopes` * :doc:`/cookbook/service_container/compiler_passes` * (Event Dispatcher) :doc:`/cookbook/event_dispatcher/event_listener` @@ -214,10 +213,6 @@ * :doc:`/cookbook/psr7` -* **symfony1** - - * :doc:`/cookbook/symfony1` - * :doc:`/cookbook/templating/index` * :doc:`/cookbook/templating/global_variables` diff --git a/cookbook/profiler/profiling_data.rst b/cookbook/profiler/profiling_data.rst index 761dae943e6..bb87bbf8cd7 100644 --- a/cookbook/profiler/profiling_data.rst +++ b/cookbook/profiler/profiling_data.rst @@ -53,10 +53,10 @@ one where the information was generated, use the ``profiler:export`` and .. code-block:: bash # on the production machine - $ php app/console profiler:export > profile.data + $ php bin/console profiler:export > profile.data # on the development machine - $ php app/console profiler:import /path/to/profile.data + $ php bin/console profiler:import /path/to/profile.data # you can also pipe from the STDIN - $ cat /path/to/profile.data | php app/console profiler:import + $ cat /path/to/profile.data | php bin/console profiler:import diff --git a/cookbook/security/_ircmaxwell_password-compat.rst.inc b/cookbook/security/_ircmaxwell_password-compat.rst.inc deleted file mode 100644 index 3f96c454488..00000000000 --- a/cookbook/security/_ircmaxwell_password-compat.rst.inc +++ /dev/null @@ -1,13 +0,0 @@ -.. caution:: - - If you're using PHP 5.4 or lower, you'll need to install the ``ircmaxell/password-compat`` - library via Composer in order to be able to use the ``bcrypt`` encoder: - - .. code-block:: json - - { - "require": { - ... - "ircmaxell/password-compat": "~1.0.3" - } - } diff --git a/cookbook/security/acl.rst b/cookbook/security/acl.rst index b881393d91b..df3b936b3f0 100644 --- a/cookbook/security/acl.rst +++ b/cookbook/security/acl.rst @@ -96,7 +96,7 @@ Fortunately, there is a task for this. Simply run the following command: .. code-block:: bash - $ php app/console init:acl + $ php bin/console init:acl Getting Started --------------- diff --git a/cookbook/security/entity_provider.rst b/cookbook/security/entity_provider.rst index 0f4fe3c28d2..5b435ecf799 100644 --- a/cookbook/security/entity_provider.rst +++ b/cookbook/security/entity_provider.rst @@ -145,13 +145,13 @@ by running: .. code-block:: bash - $ php app/console doctrine:generate:entities AppBundle/Entity/User + $ php bin/console doctrine:generate:entities AppBundle/Entity/User Next, make sure to :ref:`create the database table `: .. code-block:: bash - $ php app/console doctrine:schema:update --force + $ php bin/console doctrine:schema:update --force What's this UserInterface? ~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -291,8 +291,6 @@ name ``our_db_provider`` isn't important: it just needs to match the value of the ``provider`` key under your firewall. Or, if you don't set the ``provider`` key under your firewall, the first "user provider" is automatically used. -.. include:: /cookbook/security/_ircmaxwell_password-compat.rst.inc - Creating your First User ~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/cookbook/service_container/index.rst b/cookbook/service_container/index.rst index f0166e75fd8..4c341ae4c1d 100644 --- a/cookbook/service_container/index.rst +++ b/cookbook/service_container/index.rst @@ -5,5 +5,4 @@ Service Container :maxdepth: 2 shared - scopes compiler_passes diff --git a/cookbook/service_container/scopes.rst b/cookbook/service_container/scopes.rst deleted file mode 100644 index adcf54beaeb..00000000000 --- a/cookbook/service_container/scopes.rst +++ /dev/null @@ -1,249 +0,0 @@ -.. index:: - single: DependencyInjection; Scopes - -How to Work with Scopes -======================= - -.. caution:: - - The "container scopes" concept explained in this article has been deprecated - in Symfony 2.8 and it will be removed in Symfony 3.0. - - Use the ``request_stack`` service (introduced in Symfony 2.4) instead of - the ``request`` service/scope and use the ``shared`` setting (introduced in - Symfony 2.8) instead of the ``prototype`` scope - (:doc:`read more about shared services `). - -This article is all about scopes, a somewhat advanced topic related to the -:doc:`/book/service_container`. If you've ever gotten an error mentioning -"scopes" when creating services, then this article is for you. - -.. note:: - - If you are trying to inject the ``request`` service, the simple solution - is to inject the ``request_stack`` service instead and access the current - Request by calling the - :method:`Symfony\\Component\\HttpFoundation\\RequestStack::getCurrentRequest` - method (see :ref:`book-container-request-stack`). The rest of this entry - talks about scopes in a theoretical and more advanced way. If you're - dealing with scopes for the ``request`` service, simply inject ``request_stack``. - -Understanding Scopes --------------------- - -The scope of a service controls how long an instance of a service is used -by the container. The DependencyInjection component provides two generic -scopes: - -``container`` (the default one): - The same instance is used each time you ask for it from this container. - -``prototype``: - A new instance is created each time you ask for the service. - -The -:class:`Symfony\\Component\\HttpKernel\\DependencyInjection\\ContainerAwareHttpKernel` -also defines a third scope: ``request``. This scope is tied to the request, -meaning a new instance is created for each subrequest and is unavailable -outside the request (for instance in the CLI). - -An Example: Client Scope -~~~~~~~~~~~~~~~~~~~~~~~~ - -Other than the ``request`` service (which has a simple solution, see the -above note), no services in the default Symfony container belong to any -scope other than ``container`` and ``prototype``. But for the purposes of -this article, imagine there is another scope ``client`` and a service ``client_configuration`` -that belongs to it. This is not a common situation, but the idea is that -you may enter and exit multiple ``client`` scopes during a request, and each -has its own ``client_configuration`` service. - -Scopes add a constraint on the dependencies of a service: a service cannot -depend on services from a narrower scope. For example, if you create a generic -``my_foo`` service, but try to inject the ``client_configuration`` service, -you will receive a -:class:`Symfony\\Component\\DependencyInjection\\Exception\\ScopeWideningInjectionException` -when compiling the container. Read the sidebar below for more details. - -.. sidebar:: Scopes and Dependencies - - Imagine you've configured a ``my_mailer`` service. You haven't configured - the scope of the service, so it defaults to ``container``. In other words, - every time you ask the container for the ``my_mailer`` service, you get - the same object back. This is usually how you want your services to work. - - Imagine, however, that you need the ``client_configuration`` service - in your ``my_mailer`` service, maybe because you're reading some details - from it, such as what the "sender" address should be. You add it as a - constructor argument. There are several reasons why this presents a problem: - - * When requesting ``my_mailer``, an instance of ``my_mailer`` (called - *MailerA* here) is created and the ``client_configuration`` service ( - called *ConfigurationA* here) is passed to it. Life is good! - - * Your application now needs to do something with another client, and - you've designed your application in such a way that you handle this - by entering a new ``client_configuration`` scope and setting a new - ``client_configuration`` service into the container. Call this - *ConfigurationB*. - - * Somewhere in your application, you once again ask for the ``my_mailer`` - service. Since your service is in the ``container`` scope, the same - instance (*MailerA*) is just re-used. But here's the problem: the - *MailerA* instance still contains the old *ConfigurationA* object, which - is now **not** the correct configuration object to have (*ConfigurationB* - is now the current ``client_configuration`` service). This is subtle, - but the mis-match could cause major problems, which is why it's not - allowed. - - So, that's the reason *why* scopes exist, and how they can cause - problems. Keep reading to find out the common solutions. - -.. note:: - - A service can of course depend on a service from a wider scope without - any issue. - -Using a Service from a Narrower Scope -------------------------------------- - -There are two solutions to the scope problem: - -* A) Put your service in the same scope as the dependency (or a narrower one). If - you depend on the ``client_configuration`` service, this means putting your - new service in the ``client`` scope (see :ref:`changing-service-scope`); - -* B) Pass the entire container to your service and retrieve your dependency from - the container each time you need it to be sure you have the right instance - -- your service can live in the default ``container`` scope (see - :ref:`passing-container`). - -Each scenario is detailed in the following sections. - -.. _using-synchronized-service: - -.. note:: - - Prior to Symfony 2.7, there was another alternative based on ``synchronized`` - services. However, these kind of services have been deprecated starting from - Symfony 2.7. - -.. _changing-service-scope: - -A) Changing the Scope of your Service -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Changing the scope of a service should be done in its definition. This example -assumes that the ``Mailer`` class has a ``__construct`` function whose first -argument is the ``ClientConfiguration`` object: - -.. configuration-block:: - - .. code-block:: yaml - - # app/config/services.yml - services: - my_mailer: - class: AppBundle\Mail\Mailer - scope: client - arguments: ['@client_configuration'] - - .. code-block:: xml - - - - - - - - - .. code-block:: php - - // app/config/services.php - use Symfony\Component\DependencyInjection\Definition; - - $definition = $container->setDefinition( - 'my_mailer', - new Definition( - 'AppBundle\Mail\Mailer', - array(new Reference('client_configuration'), - )) - )->setScope('client'); - -.. _passing-container: - -B) Passing the Container as a Dependency of your Service -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Setting the scope to a narrower one is not always possible (for instance, a -twig extension must be in the ``container`` scope as the Twig environment -needs it as a dependency). In these cases, you can pass the entire container -into your service:: - - // src/AppBundle/Mail/Mailer.php - namespace AppBundle\Mail; - - use Symfony\Component\DependencyInjection\ContainerInterface; - - class Mailer - { - protected $container; - - public function __construct(ContainerInterface $container) - { - $this->container = $container; - } - - public function sendEmail() - { - $request = $this->container->get('client_configuration'); - // ... do something using the client configuration here - } - } - -.. caution:: - - Take care not to store the client configuration in a property of the object - for a future call of the service as it would cause the same issue described - in the first section (except that Symfony cannot detect that you are - wrong). - -The service configuration for this class would look something like this: - -.. configuration-block:: - - .. code-block:: yaml - - # app/config/services.yml - services: - my_mailer: - class: AppBundle\Mail\Mailer - arguments: ['@service_container'] - # scope: container can be omitted as it is the default - - .. code-block:: xml - - - - - - - - - .. code-block:: php - - // app/config/services.php - use Symfony\Component\DependencyInjection\Definition; - use Symfony\Component\DependencyInjection\Reference; - - $container->setDefinition('my_mailer', new Definition( - 'AppBundle\Mail\Mailer', - array(new Reference('service_container')) - )); - -.. note:: - - Injecting the whole container into a service is generally not a good - idea (only inject what you need). diff --git a/cookbook/symfony1.rst b/cookbook/symfony1.rst deleted file mode 100644 index f30e18e623f..00000000000 --- a/cookbook/symfony1.rst +++ /dev/null @@ -1,369 +0,0 @@ -.. index:: - single: symfony1 - -How Symfony2 Differs from Symfony1 -================================== - -The Symfony2 Framework embodies a significant evolution when compared with -the first version of the framework. Fortunately, with the MVC architecture -at its core, the skills used to master a symfony1 project continue to be -very relevant when developing in Symfony2. Sure, ``app.yml`` is gone, but -routing, controllers and templates all remain. - -This chapter walks through the differences between symfony1 and Symfony2. -As you'll see, many tasks are tackled in a slightly different way. You'll -come to appreciate these minor differences as they promote stable, predictable, -testable and decoupled code in your Symfony2 applications. - -So, sit back and relax as you travel from "then" to "now". - -Directory Structure -------------------- - -When looking at a Symfony2 project - for example, the `Symfony Standard Edition`_ - -you'll notice a very different directory structure than in symfony1. The -differences, however, are somewhat superficial. - -The ``app/`` Directory -~~~~~~~~~~~~~~~~~~~~~~ - -In symfony1, your project has one or more applications, and each lives inside -the ``apps/`` directory (e.g. ``apps/frontend``). By default in Symfony2, -you have just one application represented by the ``app/`` directory. Like -in symfony1, the ``app/`` directory contains configuration specific to that -application. It also contains application-specific cache, log and template -directories as well as a ``Kernel`` class (``AppKernel``), which is the base -object that represents the application. - -Unlike symfony1, almost no PHP code lives in the ``app/`` directory. This -directory is not meant to house modules or library files as it did in symfony1. -Instead, it's simply the home of configuration and other resources (templates, -translation files). - -The ``src/`` Directory -~~~~~~~~~~~~~~~~~~~~~~ - -Put simply, your actual code goes here. In Symfony2, all actual application-code -lives inside a bundle (roughly equivalent to a symfony1 plugin) and, by default, -each bundle lives inside the ``src`` directory. In that way, the ``src`` -directory is a bit like the ``plugins`` directory in symfony1, but much more -flexible. Additionally, while *your* bundles will live in the ``src/`` directory, -third-party bundles will live somewhere in the ``vendor/`` directory. - -To get a better picture of the ``src/`` directory, first think of the structure -of a symfony1 application. First, part of your code likely lives inside one or -more applications. Most commonly these include modules, but could also include -any other PHP classes you put in your application. You may have also created -a ``schema.yml`` file in the ``config`` directory of your project and built -several model files. Finally, to help with some common functionality, you're -using several third-party plugins that live in the ``plugins/`` directory. -In other words, the code that drives your application lives in many different -places. - -In Symfony2, life is much simpler because *all* Symfony2 code must live in -a bundle. In the pretend symfony1 project, all the code *could* be moved -into one or more plugins (which is a very good practice, in fact). Assuming -that all modules, PHP classes, schema, routing configuration, etc. were moved -into a plugin, the symfony1 ``plugins/`` directory would be very similar -to the Symfony2 ``src/`` directory. - -Put simply again, the ``src/`` directory is where your code, assets, -templates and most anything else specific to your project will live. - -The ``vendor/`` Directory -~~~~~~~~~~~~~~~~~~~~~~~~~ - -The ``vendor/`` directory is basically equivalent to the ``lib/vendor/`` -directory in symfony1, which was the conventional directory for all vendor -libraries and bundles. By default, you'll find the Symfony2 library files in -this directory, along with several other dependent libraries such as Doctrine2, -Twig and Swift Mailer. 3rd party Symfony2 bundles live somewhere in the -``vendor/``. - -The ``web/`` Directory -~~~~~~~~~~~~~~~~~~~~~~ - -Not much has changed in the ``web/`` directory. The most noticeable difference -is the absence of the ``css/``, ``js/`` and ``images/`` directories. This -is intentional. Like with your PHP code, all assets should also live inside -a bundle. With the help of a console command, the ``Resources/public/`` -directory of each bundle is copied or symbolically-linked to the ``web/bundles/`` -directory. This allows you to keep assets organized inside your bundle, but -still make them available to the public. To make sure that all bundles are -available, run the following command: - -.. code-block:: bash - - $ php app/console assets:install web - -.. note:: - - This command is the Symfony2 equivalent to the symfony1 ``plugin:publish-assets`` - command. - -Autoloading ------------ - -One of the advantages of modern frameworks is never needing to worry about -requiring files. By making use of an autoloader, you can refer to any class -in your project and trust that it's available. Autoloading has changed in -Symfony2 to be more universal, faster, and independent of needing to clear -your cache. - -In symfony1, autoloading was done by searching the entire project for the -presence of PHP class files and caching this information in a giant array. -That array told symfony1 exactly which file contained each class. In the -production environment, this caused you to need to clear the cache when classes -were added or moved. - -In Symfony2, a tool named `Composer`_ handles this process. -The idea behind the autoloader is simple: the name of your class (including -the namespace) must match up with the path to the file containing that class. -Take the FrameworkExtraBundle from the Symfony2 Standard Edition as an -example:: - - namespace Sensio\Bundle\FrameworkExtraBundle; - - use Symfony\Component\HttpKernel\Bundle\Bundle; - // ... - - class SensioFrameworkExtraBundle extends Bundle - { - // ... - } - -The file itself lives at -``vendor/sensio/framework-extra-bundle/Sensio/Bundle/FrameworkExtraBundle/SensioFrameworkExtraBundle.php``. -As you can see, the second part of the path follows the namespace of the -class. The first part is equal to the package name of the SensioFrameworkExtraBundle. - -The namespace, ``Sensio\Bundle\FrameworkExtraBundle``, and package name, -``sensio/framework-extra-bundle``, spells out the directory that the file -should live in -(``vendor/sensio/framework-extra-bundle/Sensio/Bundle/FrameworkExtraBundle/``). -Composer can then look for the file at this specific place and load it very -fast. - -If the file did *not* live at this exact location, you'd receive a -``Class "Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle" does not exist.`` -error. In Symfony2, a "class does not exist" error means that the namespace of -the class and physical location do not match. Basically, Symfony2 is looking -in one exact location for that class, but that location doesn't exist (or -contains a different class). In order for a class to be autoloaded, you -**never need to clear your cache** in Symfony2. - -As mentioned before, for the autoloader to work, it needs to know that the -``Sensio`` namespace lives in the ``vendor/sensio/framework-extra-bundle`` -directory and that, for example, the ``Doctrine`` namespace lives in the -``vendor/doctrine/orm/lib/`` directory. This mapping is entirely controlled by -Composer. Each third-party library you load through Composer has its -settings defined and Composer takes care of everything for you. - -For this to work, all third-party libraries used by your project must be -defined in the ``composer.json`` file. - -If you look at the ``HelloController`` from the Symfony Standard Edition you -can see that it lives in the ``Acme\DemoBundle\Controller`` namespace. Yet, the -AcmeDemoBundle is not defined in your ``composer.json`` file. Nonetheless are -the files autoloaded. This is because you can tell Composer to autoload files -from specific directories without defining a dependency: - -.. code-block:: json - - "autoload": { - "psr-0": { "": "src/" } - } - -This means that if a class is not found in the ``vendor`` directory, Composer -will search in the ``src`` directory before throwing a "class does not exist" -exception. Read more about configuring the Composer autoloader in -`the Composer documentation`_. - -Using the Console ------------------ - -In symfony1, the console is in the root directory of your project and is -called ``symfony``: - -.. code-block:: bash - - $ php symfony - -In Symfony2, the console is now in the app sub-directory and is called -``console``: - -.. code-block:: bash - - $ php app/console - -Applications ------------- - -In a symfony1 project, it is common to have several applications: one for the -front-end and one for the back-end for instance. - -In a Symfony2 project, you only need to create one application (a blog -application, an intranet application, ...). Most of the time, if you want to -create a second application, you might instead create another project and -share some bundles between them. - -And if you need to separate the front-end and the back-end features of some -bundles, you can create sub-namespaces for controllers, sub-directories for -templates, different semantic configurations, separate routing configurations, -and so on. - -Of course, there's nothing wrong with having multiple applications in your -project, that's entirely up to you. A second application would mean a new -directory, e.g. ``my_app/``, with the same basic setup as the ``app/`` directory. - -.. tip:: - - Read the definition of a :term:`Project`, an :term:`Application`, and a - :term:`Bundle` in the glossary. - -Bundles and Plugins -------------------- - -In a symfony1 project, a plugin could contain configuration, modules, PHP -libraries, assets and anything else related to your project. In Symfony2, -the idea of a plugin is replaced by the "bundle". A bundle is even more powerful -than a plugin because the core Symfony2 Framework is brought in via a series -of bundles. In Symfony2, bundles are first-class citizens that are so flexible -that even core code itself is a bundle. - -In symfony1, a plugin must be enabled inside the ``ProjectConfiguration`` -class:: - - // config/ProjectConfiguration.class.php - public function setup() - { - // some plugins here - $this->enableAllPluginsExcept(array(...)); - } - -In Symfony2, the bundles are activated inside the application kernel:: - - // app/AppKernel.php - public function registerBundles() - { - $bundles = array( - new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), - new Symfony\Bundle\TwigBundle\TwigBundle(), - ..., - new Acme\DemoBundle\AcmeDemoBundle(), - ); - - return $bundles; - } - -Routing (``routing.yml``) and Configuration (``config.yml``) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -In symfony1, the ``routing.yml`` and ``app.yml`` configuration files were -automatically loaded inside any plugin. In Symfony2, routing and application -configuration inside a bundle must be included manually. For example, to -include a routing resource from a bundle called AcmeDemoBundle, you can -do the following: - -.. configuration-block:: - - .. code-block:: yaml - - # app/config/routing.yml - _hello: - resource: '@AcmeDemoBundle/Resources/config/routing.yml' - - .. code-block:: xml - - - - - - - - - - .. code-block:: php - - // app/config/routing.php - use Symfony\Component\Routing\RouteCollection; - - $collection = new RouteCollection(); - $collection->addCollection($loader->import("@AcmeHelloBundle/Resources/config/routing.php")); - - return $collection; - -This will load the routes found in the ``Resources/config/routing.yml`` file -of the AcmeDemoBundle. The special ``@AcmeDemoBundle`` is a shortcut syntax -that, internally, resolves to the full path to that bundle. - -You can use this same strategy to bring in configuration from a bundle: - -.. configuration-block:: - - .. code-block:: yaml - - # app/config/config.yml - imports: - - { resource: "@AcmeDemoBundle/Resources/config/config.yml" } - - .. code-block:: xml - - - - - - - .. code-block:: php - - // app/config/config.php - $this->import('@AcmeDemoBundle/Resources/config/config.php') - -In Symfony2, configuration is a bit like ``app.yml`` in symfony1, except much -more systematic. With ``app.yml``, you could simply create any keys you wanted. -By default, these entries were meaningless and depended entirely on how you -used them in your application: - -.. code-block:: yaml - - # some app.yml file from symfony1 - all: - email: - from_address: 'foo.bar@example.com' - -In Symfony2, you can also create arbitrary entries under the ``parameters`` -key of your configuration: - -.. configuration-block:: - - .. code-block:: yaml - - parameters: - email.from_address: 'foo.bar@example.com' - - .. code-block:: xml - - - foo.bar@example.com - - - .. code-block:: php - - $container->setParameter('email.from_address', 'foo.bar@example.com'); - -You can now access this from a controller, for example:: - - public function helloAction($name) - { - $fromAddress = $this->container->getParameter('email.from_address'); - } - -In reality, the Symfony2 configuration is much more powerful and is used -primarily to configure objects that you can use. For more information, see -the chapter titled ":doc:`/book/service_container`". - -.. _`Composer`: https://getcomposer.org -.. _`Symfony Standard Edition`: https://github.com/symfony/symfony-standard -.. _`the Composer documentation`: https://getcomposer.org/doc/04-schema.md#autoload diff --git a/cookbook/testing/bootstrap.rst b/cookbook/testing/bootstrap.rst index aecbaff6c94..67ad9db1d8e 100644 --- a/cookbook/testing/bootstrap.rst +++ b/cookbook/testing/bootstrap.rst @@ -17,14 +17,14 @@ First, add the following file:: )); } - require __DIR__.'/bootstrap.php.cache'; + require __DIR__.'/autoload.php'; -Replace the test bootstrap file ``bootstrap.php.cache`` in ``app/phpunit.xml.dist`` +Replace the test bootstrap file ``autoload.php`` in ``phpunit.xml.dist`` with ``tests.bootstrap.php``: .. code-block:: xml - + + diff --git a/cookbook/testing/database.rst b/cookbook/testing/database.rst index 04c8d07ee48..405a329f4e1 100644 --- a/cookbook/testing/database.rst +++ b/cookbook/testing/database.rst @@ -33,6 +33,7 @@ class. Suppose the class you want to test looks like this:: + // src/AppBundle/Salary/SalaryCalculator.php namespace AppBundle\Salary; use Doctrine\Common\Persistence\ObjectManager; @@ -59,14 +60,20 @@ Suppose the class you want to test looks like this:: Since the ``ObjectManager`` gets injected into the class through the constructor, it's easy to pass a mock object within a test:: + // tests/AppBundle/Salary/SalaryCalculatorTest.php + namespace Tests\AppBundle\Salary; + use AppBundle\Salary\SalaryCalculator; + use AppBundle\Entity\Employee; + use Doctrine\ORM\EntityRepository; + use Doctrine\Common\Persistence\ObjectManager; class SalaryCalculatorTest extends \PHPUnit_Framework_TestCase { public function testCalculateTotalSalary() { // First, mock the object to be used in the test - $employee = $this->getMock('\AppBundle\Entity\Employee'); + $employee = $this->getMock(Employee::class); $employee->expects($this->once()) ->method('getSalary') ->will($this->returnValue(1000)); @@ -76,7 +83,7 @@ it's easy to pass a mock object within a test:: // Now, mock the repository so it returns the mock of the employee $employeeRepository = $this - ->getMockBuilder('\Doctrine\ORM\EntityRepository') + ->getMockBuilder(EntityRepository::class) ->disableOriginalConstructor() ->getMock(); $employeeRepository->expects($this->once()) @@ -85,7 +92,7 @@ it's easy to pass a mock object within a test:: // Last, mock the EntityManager to return the mock of the repository $entityManager = $this - ->getMockBuilder('\Doctrine\Common\Persistence\ObjectManager') + ->getMockBuilder(ObjectManager::class) ->disableOriginalConstructor() ->getMock(); $entityManager->expects($this->once()) diff --git a/cookbook/testing/doctrine.rst b/cookbook/testing/doctrine.rst index c263d18c91c..aadbe729113 100644 --- a/cookbook/testing/doctrine.rst +++ b/cookbook/testing/doctrine.rst @@ -20,12 +20,12 @@ If you need to actually execute a query, you will need to boot the kernel to get a valid connection. In this case, you'll extend the ``KernelTestCase``, which makes all of this quite easy:: - // src/AppBundle/Tests/Entity/ProductRepositoryFunctionalTest.php - namespace AppBundle\Tests\Entity; + // tests/AppBundle/Entity/ProductRepositoryTest.php + namespace Tests\AppBundle\Entity; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; - class ProductRepositoryFunctionalTest extends KernelTestCase + class ProductRepositoryTest extends KernelTestCase { /** * @var \Doctrine\ORM\EntityManager @@ -38,10 +38,10 @@ which makes all of this quite easy:: public function setUp() { self::bootKernel(); + $this->em = static::$kernel->getContainer() ->get('doctrine') - ->getManager() - ; + ->getManager(); } public function testSearchByCategoryName() @@ -60,6 +60,7 @@ which makes all of this quite easy:: protected function tearDown() { parent::tearDown(); + $this->em->close(); } } diff --git a/cookbook/testing/profiling.rst b/cookbook/testing/profiling.rst index 1789c69dbc9..d809c4febe2 100644 --- a/cookbook/testing/profiling.rst +++ b/cookbook/testing/profiling.rst @@ -15,9 +15,9 @@ spent in the framework, etc. But before writing assertions, enable the profiler and check that the profiler is indeed available (it is enabled by default in the ``test`` environment):: - class HelloControllerTest extends WebTestCase + class LuckyControllerTest extends WebTestCase { - public function testIndex() + public function testNumberAction() { $client = static::createClient(); @@ -25,7 +25,7 @@ the ``test`` environment):: // (it does nothing if the profiler is not available) $client->enableProfiler(); - $crawler = $client->request('GET', '/hello/Fabien'); + $crawler = $client->request('GET', '/lucky/number'); // ... write some assertions about the Response diff --git a/cookbook/testing/simulating_authentication.rst b/cookbook/testing/simulating_authentication.rst index f2e04acd612..8777a67e2a1 100644 --- a/cookbook/testing/simulating_authentication.rst +++ b/cookbook/testing/simulating_authentication.rst @@ -15,8 +15,8 @@ Another way would be to create a token yourself and store it in a session. While doing this, you have to make sure that an appropriate cookie is sent with a request. The following example demonstrates this technique:: - // src/AppBundle/Tests/Controller/DefaultControllerTest.php - namespace Appbundle\Tests\Controller; + // tests/AppBundle/Controller/DefaultControllerTest.php + namespace Tests\Appbundle\Controller; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\BrowserKit\Cookie; diff --git a/cookbook/validation/custom_constraint.rst b/cookbook/validation/custom_constraint.rst index a248a8494aa..1adf5edf1eb 100644 --- a/cookbook/validation/custom_constraint.rst +++ b/cookbook/validation/custom_constraint.rst @@ -167,7 +167,7 @@ Constraint Validators with Dependencies If your constraint validator has dependencies, such as a database connection, it will need to be configured as a service in the Dependency Injection Container. This service must include the ``validator.constraint_validator`` -tag and an ``alias`` attribute: +tag and may include an ``alias`` attribute: .. configuration-block:: @@ -195,21 +195,14 @@ tag and an ``alias`` attribute: ->register('validator.unique.your_validator_name', 'Fully\Qualified\Validator\Class\Name') ->addTag('validator.constraint_validator', array('alias' => 'alias_name')); -Your constraint class should now use this alias to reference the appropriate -validator:: +As mentioned above, Symfony will automatically look for a class named after +the constraint, with ``Validator`` appended. You can override this in you constraint class:: public function validatedBy() { - return 'alias_name'; + return 'Fully\Qualified\Class\Named\ConstraintValidator'; \\ or 'alias_name' if provided } -As mentioned above, Symfony will automatically look for a class named after -the constraint, with ``Validator`` appended. If your constraint validator -is defined as a service, it's important that you override the -``validatedBy()`` method to return the alias used when defining your service, -otherwise Symfony won't use the constraint validator service, and will -instantiate the class instead, without any dependencies injected. - Class Constraint Validator ~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/cookbook/web_server/built_in.rst b/cookbook/web_server/built_in.rst index dc42eda9cb9..10dceab5b4e 100644 --- a/cookbook/web_server/built_in.rst +++ b/cookbook/web_server/built_in.rst @@ -27,7 +27,7 @@ executing the ``server:start`` command: .. code-block:: bash - $ php app/console server:start + $ php bin/console server:start This starts the web server at ``localhost:8000`` in the background that serves your Symfony application. @@ -37,7 +37,7 @@ can change the socket passing an IP address and a port as a command-line argumen .. code-block:: bash - $ php app/console server:start 192.168.0.1:8080 + $ php bin/console server:start 192.168.0.1:8080 .. note:: @@ -46,7 +46,7 @@ can change the socket passing an IP address and a port as a command-line argumen .. code-block:: bash - $ php app/console server:start --force + $ php bin/console server:start --force .. versionadded:: 2.8 The ``--force`` option was introduced in Symfony 2.8. @@ -58,9 +58,9 @@ can change the socket passing an IP address and a port as a command-line argumen .. code-block:: bash - $ php app/console server:status + $ php bin/console server:status - $ php app/console server:status 192.168.0.1:8080 + $ php bin/console server:status 192.168.0.1:8080 The first command shows if your Symfony application will be server through ``localhost:8000``, the second one does the same for ``192.168.0.1:8080``. @@ -82,7 +82,7 @@ can change the socket passing an IP address and a port as a command-line argumen .. code-block:: bash - $ php app/console server:start 0.0.0.0:8000 + $ php bin/console server:start 0.0.0.0:8000 .. caution:: @@ -101,14 +101,14 @@ script: .. code-block:: bash - $ php app/console server:start --env=test --router=app/config/router_test.php + $ php bin/console server:start --env=test --router=app/config/router_test.php If your application's document root differs from the standard directory layout, you have to pass the correct location using the ``--docroot`` option: .. code-block:: bash - $ php app/console server:start --docroot=public_html + $ php bin/console server:start --docroot=public_html Stopping the Server ------------------- @@ -118,7 +118,7 @@ command: .. code-block:: bash - $ php app/console server:stop + $ php bin/console server:stop Like with the start command, if you omit the socket information, Symfony will stop the web server bound to ``localhost:8000``. Just pass the socket information @@ -126,7 +126,7 @@ when the web server listens to another IP address or to another port: .. code-block:: bash - $ php app/console server:stop 192.168.0.1:8080 + $ php bin/console server:stop 192.168.0.1:8080 .. _`built-in web server`: http://www.php.net/manual/en/features.commandline.webserver.php .. _`php.net`: http://php.net/manual/en/features.commandline.webserver.php#example-411 diff --git a/cookbook/workflow/new_project_svn.rst b/cookbook/workflow/new_project_svn.rst index 8fe7e9eacd9..7cec932445d 100644 --- a/cookbook/workflow/new_project_svn.rst +++ b/cookbook/workflow/new_project_svn.rst @@ -75,17 +75,17 @@ with these steps: .. code-block:: bash $ cd myproject/ - $ svn add --depth=empty app app/cache app/logs app/config web + $ svn add --depth=empty app var/cache var/logs app/config web $ svn propset svn:ignore "vendor" . - $ svn propset svn:ignore "bootstrap*" app/ + $ svn propset svn:ignore "bootstrap*" var/ $ svn propset svn:ignore "parameters.yml" app/config/ - $ svn propset svn:ignore "*" app/cache/ - $ svn propset svn:ignore "*" app/logs/ + $ svn propset svn:ignore "*" var/cache/ + $ svn propset svn:ignore "*" var/logs/ $ svn propset svn:ignore "bundles" web - $ svn ci -m "commit basic Symfony ignore list (vendor, app/bootstrap*, app/config/parameters.yml, app/cache/*, app/logs/*, web/bundles)" + $ svn ci -m "commit basic Symfony ignore list (vendor, var/bootstrap*, app/config/parameters.yml, var/cache/*, var/logs/*, web/bundles)" #. The rest of the files can now be added and committed to the project: diff --git a/create_framework/dependency-injection.rst b/create_framework/dependency-injection.rst index 39eaae4702e..725a8c019e1 100644 --- a/create_framework/dependency-injection.rst +++ b/create_framework/dependency-injection.rst @@ -219,7 +219,7 @@ And the related change in the front controller:: We have obviously barely scratched the surface of what you can do with the container: from class names as parameters, to overriding existing object -definitions, from scope support to dumping a container to a plain PHP class, +definitions, from shared service support to dumping a container to a plain PHP class, and much more. The Symfony dependency injection container is really powerful and is able to manage any kind of PHP class. diff --git a/create_framework/introduction.rst b/create_framework/introduction.rst index 1d1bb864639..31c03ed3c6d 100644 --- a/create_framework/introduction.rst +++ b/create_framework/introduction.rst @@ -69,7 +69,7 @@ Before You Start Reading about how to create a framework is not enough. You will have to follow along and actually type all the examples included in this tutorial. For that, -you need a recent version of PHP (5.3.9 or later is good enough), a web server +you need a recent version of PHP (5.5.9 or later is good enough), a web server (like Apache, NGinx or PHP's built-in web server), a good knowledge of PHP and an understanding of Object Oriented programming. @@ -109,9 +109,8 @@ start with the simplest web application we can think of in PHP:: printf('Hello %s', $input); -If you have PHP 5.4, you can use the PHP built-in server to test this great -application in a browser (``http://localhost:4321/index.php?name=Fabien``). -Otherwise, use your own server (Apache, Nginx, etc.): +You can use the PHP built-in server to test this great application in a browser +(``http://localhost:4321/index.php?name=Fabien``): .. code-block:: bash diff --git a/quick_tour/the_architecture.rst b/quick_tour/the_architecture.rst index 72e312b24c1..546f736f72d 100644 --- a/quick_tour/the_architecture.rst +++ b/quick_tour/the_architecture.rst @@ -15,8 +15,14 @@ but the recommended structure is as follows: ``app/`` The application configuration, templates and translations. +``bin/`` + Executable files (e.g. ``bin/console``). ``src/`` The project's PHP code. +``tests/`` + Automatic tests (e.g. Unit tests). +``var/`` + Generated files (cache, logs, etc.). ``vendor/`` The third-party dependencies. ``web/`` @@ -30,7 +36,7 @@ stylesheets and JavaScript files. It is also where each :term:`front controller` lives, such as the production controller shown here:: // web/app.php - require_once __DIR__.'/../app/bootstrap.php.cache'; + require_once __DIR__.'/../var/bootstrap.php.cache'; require_once __DIR__.'/../app/AppKernel.php'; use Symfony\Component\HttpFoundation\Request; @@ -260,7 +266,7 @@ Symfony applications can contain several configuration files defined in several formats (YAML, XML, PHP, etc.) Instead of parsing and combining all those files for each request, Symfony uses its own cache system. In fact, the application configuration is only parsed for the very first request -and then compiled down to plain PHP code stored in the ``app/cache/`` +and then compiled down to plain PHP code stored in the ``var/cache/`` directory. In the development environment, Symfony is smart enough to update the cache @@ -271,16 +277,16 @@ the ``prod`` environment: .. code-block:: bash - $ php app/console cache:clear --env=prod + $ php bin/console cache:clear --env=prod When developing a web application, things can go wrong in many ways. The -log files in the ``app/logs/`` directory tell you everything about the requests +log files in the ``var/logs/`` directory tell you everything about the requests and help you fix the problem quickly. Using the Command Line Interface -------------------------------- -Each application comes with a command line interface tool (``app/console``) +Each application comes with a command line interface tool (``bin/console``) that helps you maintain your application. It provides commands that boost your productivity by automating tedious and repetitive tasks. @@ -288,13 +294,13 @@ Run it without any arguments to learn more about its capabilities: .. code-block:: bash - $ php app/console + $ php bin/console The ``--help`` option helps you discover the usage of a command: .. code-block:: bash - $ php app/console debug:router --help + $ php bin/console debug:router --help Final Thoughts -------------- diff --git a/reference/configuration/security.rst b/reference/configuration/security.rst index e0689597865..fe340993adf 100644 --- a/reference/configuration/security.rst +++ b/reference/configuration/security.rst @@ -354,11 +354,6 @@ for the hash algorithm. Using the BCrypt Password Encoder --------------------------------- -.. caution:: - - To use this encoder, you either need to use PHP Version 5.5 or install - the `ircmaxell/password-compat`_ library via Composer. - .. configuration-block:: .. code-block:: yaml diff --git a/reference/constraints/Valid.rst b/reference/constraints/Valid.rst index 67ec4bc86a6..e52e9e53bf1 100644 --- a/reference/constraints/Valid.rst +++ b/reference/constraints/Valid.rst @@ -9,7 +9,6 @@ an object and all sub-objects associated with it. | Applies to | :ref:`property or method ` | +----------------+---------------------------------------------------------------------+ | Options | - `traverse`_ | -| | - `deep`_ (deprecated as of 2.5) | | | - `payload`_ | +----------------+---------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Validator\\Constraints\\Valid` | @@ -268,19 +267,4 @@ If this constraint is applied to a property that holds an array of objects, then each object in that array will be validated only if this option is set to ``true``. -deep -~~~~ - -.. caution:: - - The ``deep`` option was deprecated in Symfony 2.5 and will be removed - in Symfony 3.0. When traversing arrays, nested arrays are always traversed. - When traversing nested objects, their traversal strategy is used. - -**type**: ``boolean`` **default**: ``false`` - -If this constraint is applied to a property that holds an array of objects, -then each object in that array will be validated recursively if this option -is set to ``true``. - .. include:: /reference/constraints/_payload-option.rst.inc diff --git a/reference/requirements.rst b/reference/requirements.rst index a0f9e262846..9ff4d99665d 100644 --- a/reference/requirements.rst +++ b/reference/requirements.rst @@ -21,16 +21,11 @@ Below is the list of required and optional requirements. Required -------- -* PHP needs to be a minimum version of PHP 5.3.9 +* PHP needs to be a minimum version of PHP 5.5.9 * JSON needs to be enabled * ctype needs to be enabled * Your ``php.ini`` needs to have the ``date.timezone`` setting -.. caution:: - - Be aware that Symfony has some known limitations when using PHP 5.3.16. - For more information see the `Requirements section of the README`_. - Optional -------- diff --git a/reference/twig_reference.rst b/reference/twig_reference.rst index e19857b8843..b8c0c3db278 100644 --- a/reference/twig_reference.rst +++ b/reference/twig_reference.rst @@ -98,7 +98,7 @@ asset .. code-block:: twig - {{ asset(path, packageName, absolute = false, version = null) }} + {{ asset(path, packageName = null) }} ``path`` **type**: ``string``