diff --git a/book/forms.rst b/book/forms.rst index 0d695e71a95..abc29a7ba9c 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -344,17 +344,6 @@ object. .. configuration-block:: - .. code-block:: yaml - - # AppBundle/Resources/config/validation.yml - AppBundle\Entity\Task: - properties: - task: - - NotBlank: ~ - dueDate: - - NotBlank: ~ - - Type: \DateTime - .. code-block:: php-annotations // AppBundle/Entity/Task.php @@ -374,6 +363,17 @@ object. protected $dueDate; } + .. code-block:: yaml + + # AppBundle/Resources/config/validation.yml + AppBundle\Entity\Task: + properties: + task: + - NotBlank: ~ + dueDate: + - NotBlank: ~ + - Type: \DateTime + .. code-block:: xml diff --git a/components/process.rst b/components/process.rst index 631bb5d594a..82e440aef58 100644 --- a/components/process.rst +++ b/components/process.rst @@ -36,7 +36,7 @@ a command in a sub-process:: The component takes care of the subtle differences between the different platforms when executing the command. -The ``getOutput()`` method always return the whole content of the standard +The ``getOutput()`` method always returns the whole content of the standard output of the command and ``getErrorOutput()`` the content of the error output. Alternatively, the :method:`Symfony\\Component\\Process\\Process::getIncrementalOutput` and :method:`Symfony\\Component\\Process\\Process::getIncrementalErrorOutput` diff --git a/cookbook/cache/form_csrf_caching.rst b/cookbook/cache/form_csrf_caching.rst index 74d4c5854e7..281f08f2f5d 100644 --- a/cookbook/cache/form_csrf_caching.rst +++ b/cookbook/cache/form_csrf_caching.rst @@ -22,7 +22,7 @@ validation when submitting the form. In fact, many reverse proxies (like Varnish) will refuse to cache a page with a CSRF token. This is because a cookie is sent in order to preserve -the PHP session open and Varnish's default behaviour is to not cache HTTP +the PHP session open and Varnish's default behavior is to not cache HTTP requests with cookies. How to Cache Most of the Page and still be able to Use CSRF Protection diff --git a/cookbook/cache/varnish.rst b/cookbook/cache/varnish.rst index 41ae548aafa..054269d6393 100644 --- a/cookbook/cache/varnish.rst +++ b/cookbook/cache/varnish.rst @@ -15,25 +15,31 @@ cached content fast and including support for :ref:`Edge Side Includes ` -headers to be used, you need to configure Varnish as a -:doc:`trusted proxy `. +Varnish automatically forwards the IP as ``X-Forwarded-For`` and leaves the +``X-Forwarded-Proto`` header in the request. If you do not configure Varnish as +trusted proxy, Symfony will see all requests as coming through insecure HTTP +connections from the Varnish host instead of the real client. + +Remember to configure :ref:`framework.trusted_proxies ` +in the Symfony configuration so that Varnish is seen as a trusted proxy and the +:ref:`X-Forwarded ` headers are used. .. _varnish-x-forwarded-headers: Routing and X-FORWARDED Headers ------------------------------- -To ensure that the Symfony Router generates URLs correctly with Varnish, -a ``X-Forwarded-Port`` header must be present for Symfony to use the -correct port number. +If the ``X-Forwarded-Port`` header is not set correctly, Symfony will append +the port where the PHP application is running when generating absolute URLs, +e.g. ``http://example.com:8080/my/path``. To ensure that the Symfony router +generates URLs correctly with Varnish, add the correct port number in the +``X-Forwarded-Port`` header. This port depends on your setup. -This port depends on your setup. Lets say that external connections come in -on the default HTTP port 80. For HTTPS connections, there is another proxy -(as Varnish does not do HTTPS itself) on the default HTTPS port 443 that -handles the SSL termination and forwards the requests as HTTP requests to -Varnish with a ``X-Forwarded-Proto`` header. In this case, you need to add -the following configuration snippet: +Suppose that external connections come in on the default HTTP port 80. For HTTPS +connections, there is another proxy (as Varnish does not do HTTPS itself) on the +default HTTPS port 443 that handles the SSL termination and forwards the requests +as HTTP requests to Varnish with a ``X-Forwarded-Proto`` header. In this case, +add the following to your Varnish configuration: .. code-block:: varnish4 @@ -45,31 +51,16 @@ the following configuration snippet: } } -.. note:: - - Remember to configure :ref:`framework.trusted_proxies ` - in the Symfony configuration so that Varnish is seen as a trusted proxy - and the ``X-Forwarded-*`` headers are used. - - Varnish automatically forwards the IP as ``X-Forwarded-For`` and leaves - the ``X-Forwarded-Proto`` header in the request. If you do not configure - Varnish as trusted proxy, Symfony will see all requests as coming through - insecure HTTP connections from the Varnish host instead of the real client. - -If the ``X-Forwarded-Port`` header is not set correctly, Symfony will append -the port where the PHP application is running when generating absolute URLs, -e.g. ``http://example.com:8080/my/path``. - Cookies and Caching ------------------- By default, a sane caching proxy does not cache anything when a request is sent -with :ref:`cookies or a basic authentication header`. +with :ref:`cookies or a basic authentication header `. This is because the content of the page is supposed to depend on the cookie value or authentication header. If you know for sure that the backend never uses sessions or basic -authentication, have varnish remove the corresponding header from requests to +authentication, have Varnish remove the corresponding header from requests to prevent clients from bypassing the cache. In practice, you will need sessions at least for some parts of the site, e.g. when using forms with :ref:`CSRF Protection `. In this situation, make sure to @@ -77,13 +68,13 @@ at least for some parts of the site, e.g. when using forms with and clear the session when it is no longer needed. Alternatively, you can look into :doc:`/cookbook/cache/form_csrf_caching`. -Cookies created in Javascript and used only in the frontend, e.g. when using -Google analytics are nonetheless sent to the server. These cookies are not +Cookies created in JavaScript and used only in the frontend, e.g. when using +Google Analytics, are nonetheless sent to the server. These cookies are not relevant for the backend and should not affect the caching decision. Configure your Varnish cache to `clean the cookies header`_. You want to keep the session cookie, if there is one, and get rid of all other cookies so that pages are cached if there is no active session. Unless you changed the default -configuration of PHP, your session cookie has the name PHPSESSID: +configuration of PHP, your session cookie has the name ``PHPSESSID``: .. code-block:: varnish4 @@ -110,8 +101,8 @@ configuration of PHP, your session cookie has the name PHPSESSID: implemented and explained by the FOSHttpCacheBundle_ under the name `User Context`_. -Ensure Consistent Caching Behaviour ------------------------------------ +Ensure Consistent Caching Behavior +---------------------------------- Varnish uses the cache headers sent by your application to determine how to cache content. However, versions prior to Varnish 4 did not respect @@ -143,7 +134,7 @@ using Varnish 3: Enable Edge Side Includes (ESI) ------------------------------- -As explained in the :ref:`Edge Side Includes section`, +As explained in the :ref:`Edge Side Includes section `, Symfony detects whether it talks to a reverse proxy that understands ESI or not. When you use the Symfony reverse proxy, you don't need to do anything. But to make Varnish instead of Symfony resolve the ESI tags, you need some @@ -168,10 +159,11 @@ application: .. note:: - The ``abc`` part of the header isn't important unless you have multiple "surrogates" - that need to advertise their capabilities. See `Surrogate-Capability Header`_ for details. + The ``abc`` part of the header isn't important unless you have multiple + "surrogates" that need to advertise their capabilities. See + `Surrogate-Capability Header`_ for details. -Then, optimize Varnish so that it only parses the Response contents when there +Then, optimize Varnish so that it only parses the response contents when there is at least one ESI tag by checking the ``Surrogate-Control`` header that Symfony adds automatically: diff --git a/cookbook/configuration/apache_router.rst b/cookbook/configuration/apache_router.rst index f77b3d6e7e9..b1d9d860268 100644 --- a/cookbook/configuration/apache_router.rst +++ b/cookbook/configuration/apache_router.rst @@ -4,8 +4,18 @@ How to Use the Apache Router ============================ -Symfony, while fast out of the box, also provides various ways to increase that speed with a little bit of tweaking. -One of these ways is by letting Apache handle routes directly, rather than using Symfony for this task. +.. caution:: + + **Using the Apache Router is no longer considered a good practice**. + The small increase obtained in the application routing performance is not + worth the hassle of continuously updating the routes configuration. + + The Apache Router will be removed in Symfony 3 and it's highly recommended + to not use it in your applications. + +Symfony, while fast out of the box, also provides various ways to increase that +speed with a little bit of tweaking. One of these ways is by letting Apache +handle routes directly, rather than using Symfony for this task. .. caution:: @@ -68,20 +78,20 @@ To test that it's working, create a very basic route for the AppBundle: # app/config/routing.yml hello: path: /hello/{name} - defaults: { _controller: AppBundle:Demo:hello } + defaults: { _controller: AppBundle:Greet:hello } .. code-block:: xml - AppBundle:Demo:hello + AppBundle:Greet:hello .. code-block:: php // app/config/routing.php $collection->add('hello', new Route('/hello/{name}', array( - '_controller' => 'AppBundle:Demo:hello', + '_controller' => 'AppBundle:Greet:hello', ))); Now generate the mod_rewrite rules: @@ -100,7 +110,7 @@ Which should roughly output the following: # hello RewriteCond %{REQUEST_URI} ^/hello/([^/]+?)$ - RewriteRule .* app.php [QSA,L,E=_ROUTING__route:hello,E=_ROUTING_name:%1,E=_ROUTING__controller:AppBundle\:Demo\:hello] + RewriteRule .* app.php [QSA,L,E=_ROUTING__route:hello,E=_ROUTING_name:%1,E=_ROUTING__controller:AppBundle\:Greet\:hello] You can now rewrite ``web/.htaccess`` to use the new rules, so with this example it should look like this: @@ -116,12 +126,13 @@ it should look like this: # hello RewriteCond %{REQUEST_URI} ^/hello/([^/]+?)$ - RewriteRule .* app.php [QSA,L,E=_ROUTING__route:hello,E=_ROUTING_name:%1,E=_ROUTING__controller:AppBundle\:Demo\:hello] + RewriteRule .* app.php [QSA,L,E=_ROUTING__route:hello,E=_ROUTING_name:%1,E=_ROUTING__controller:AppBundle\:Greet\:hello] .. note:: - The procedure above should be done each time you add/change a route if you want to take full advantage of this setup. + The procedure above should be done each time you add/change a route if you + want to take full advantage of this setup. That's it! You're now all set to use Apache routes. diff --git a/cookbook/configuration/environments.rst b/cookbook/configuration/environments.rst index 751f5971ca1..70800816a38 100644 --- a/cookbook/configuration/environments.rst +++ b/cookbook/configuration/environments.rst @@ -20,7 +20,7 @@ Different Environments, different Configuration Files ----------------------------------------------------- A typical Symfony application begins with three environments: ``dev``, -``prod``, and ``test``. As discussed, each "environment" simply represents +``prod``, and ``test``. As mentioned, each environment simply represents a way to execute the same codebase with different configuration. It should be no surprise then that each environment loads its own individual configuration file. If you're using the YAML configuration format, the following files @@ -55,8 +55,8 @@ multiple environments in an elegant, powerful and transparent way. Of course, in reality, each environment differs only somewhat from others. Generally, all environments will share a large base of common configuration. -Opening the "dev" configuration file, you can see how this is accomplished -easily and transparently: +Opening the ``config_dev.yml`` configuration file, you can see how this is +accomplished easily and transparently: .. configuration-block:: @@ -86,7 +86,8 @@ simply first imports from a central configuration file (``config.yml``). The remainder of the file can then deviate from the default configuration by overriding individual parameters. For example, by default, the ``web_profiler`` toolbar is disabled. However, in the ``dev`` environment, the toolbar is -activated by modifying the default value in the ``dev`` configuration file: +activated by modifying the value of the ``toolbar`` option in the ``config_dev.yml`` +configuration file: .. configuration-block:: @@ -151,9 +152,9 @@ used by each is explicitly set:: // ... -As you can see, the ``prod`` key specifies that this application will run -in the ``prod`` environment. A Symfony application can be executed in any -environment by using this code and changing the environment string. +The ``prod`` key specifies that this application will run in the ``prod`` +environment. A Symfony application can be executed in any environment by using +this code and changing the environment string. .. note:: @@ -325,9 +326,7 @@ The new environment is now accessible via:: certain environments, for debugging purposes, may give too much information about the application or underlying infrastructure. To be sure these environments aren't accessible, the front controller is usually protected from external - IP addresses via the following code at the top of the controller: - - .. code-block:: php + IP addresses via the following code at the top of the controller:: if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) { die('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.'); @@ -361,17 +360,20 @@ the directory of the environment you're using (most commonly ``dev`` while developing and debugging). While it can vary, the ``app/cache/dev`` directory includes the following: -* ``appDevDebugProjectContainer.php`` - the cached "service container" that - represents the cached application configuration; +``appDevDebugProjectContainer.php`` + The cached "service container" that represents the cached application + configuration. -* ``appDevUrlGenerator.php`` - the PHP class generated from the routing - configuration and used when generating URLs; +``appDevUrlGenerator.php`` + The PHP class generated from the routing configuration and used when + generating URLs. -* ``appDevUrlMatcher.php`` - the PHP class used for route matching - look - here to see the compiled regular expression logic used to match incoming - URLs to different routes; +``appDevUrlMatcher.php`` + The PHP class used for route matching - look here to see the compiled regular + expression logic used to match incoming URLs to different routes. -* ``twig/`` - this directory contains all the cached Twig templates. +``twig/`` + This directory contains all the cached Twig templates. .. note:: diff --git a/cookbook/configuration/front_controllers_and_kernel.rst b/cookbook/configuration/front_controllers_and_kernel.rst index 705b6697983..2e569e87764 100644 --- a/cookbook/configuration/front_controllers_and_kernel.rst +++ b/cookbook/configuration/front_controllers_and_kernel.rst @@ -94,12 +94,10 @@ There are two methods declared in the left unimplemented in :class:`Symfony\\Component\\HttpKernel\\Kernel` and thus serve as `template methods`_: -* :method:`Symfony\\Component\\HttpKernel\\KernelInterface::registerBundles`, - which must return an array of all bundles needed to run the - application; - -* :method:`Symfony\\Component\\HttpKernel\\KernelInterface::registerContainerConfiguration`, - which loads the application configuration. +:method:`Symfony\\Component\\HttpKernel\\KernelInterface::registerBundles` + It must return an array of all bundles needed to run the application. +:method:`Symfony\\Component\\HttpKernel\\KernelInterface::registerContainerConfiguration` + It loads the application configuration. To fill these (small) blanks, your application needs to subclass the Kernel and implement these methods. The resulting class is conventionally @@ -124,8 +122,7 @@ controller to make use of the new kernel. it might therefore make sense to add additional sub-directories, for example ``app/admin/AdminKernel.php`` and ``app/api/ApiKernel.php``. All that matters is that your front - controller is able to create an instance of the appropriate - kernel. + controller is able to create an instance of the appropriate kernel. Having different ``AppKernels`` might be useful to enable different front controllers (on potentially different servers) to run parts of your application diff --git a/cookbook/configuration/override_dir_structure.rst b/cookbook/configuration/override_dir_structure.rst index c2e341ccc03..105b225fd62 100644 --- a/cookbook/configuration/override_dir_structure.rst +++ b/cookbook/configuration/override_dir_structure.rst @@ -29,7 +29,7 @@ directory structure is: Override the ``cache`` Directory -------------------------------- -You can override the cache directory by overriding the ``getCacheDir`` method +You can change the default cache directory by overriding the ``getCacheDir`` method in the ``AppKernel`` class of you application:: // app/AppKernel.php @@ -53,8 +53,8 @@ the location of the cache directory to ``app/{environment}/cache``. You should keep the ``cache`` directory different for each environment, otherwise some unexpected behavior may happen. Each environment generates - its own cached config files, and so each needs its own directory to store - those cache files. + its own cached configuration files, and so each needs its own directory to + store those cache files. .. _override-logs-dir: @@ -62,7 +62,7 @@ Override the ``logs`` Directory ------------------------------- Overriding the ``logs`` directory is the same as overriding the ``cache`` -directory, the only difference is that you need to override the ``getLogDir`` +directory. The only difference is that you need to override the ``getLogDir`` method:: // app/AppKernel.php @@ -80,6 +80,8 @@ method:: Here you have changed the location of the directory to ``app/{environment}/logs``. +.. _override-web-dir: + Override the ``web`` Directory ------------------------------ @@ -87,7 +89,7 @@ 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 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 the paths inside these files:: +may need to modify these paths inside those files:: require_once __DIR__.'/../Symfony/app/bootstrap.php.cache'; require_once __DIR__.'/../Symfony/app/AppKernel.php'; @@ -116,8 +118,8 @@ file: .. note:: - If you use the AsseticBundle you need to configure this, so it can use - the correct ``web`` directory: + If you use the AsseticBundle, you need to configure the ``read_from`` option + to point to the correct ``web`` directory: .. configuration-block:: @@ -147,8 +149,8 @@ file: 'read_from' => '%kernel.root_dir%/../../public_html', )); - Now you just need to clear the cache and dump the assets again and your application should - work: + Now you just need to clear the cache and dump the assets again and your + application should work: .. code-block:: bash @@ -159,10 +161,7 @@ Override the ``vendor`` Directory --------------------------------- To override the ``vendor`` directory, you need to introduce changes in the -following files: - -* ``app/autoload.php`` -* ``composer.json`` +``app/autoload.php`` and ``composer.json`` files. The change in the ``composer.json`` will look like this: @@ -177,8 +176,8 @@ The change in the ``composer.json`` will look like this: ... } -In ``app/autoload.php``, you need to modify the path leading to the ``vendor/autoload.php`` -file:: +In ``app/autoload.php``, you need to modify the path leading to the +``vendor/autoload.php`` file:: // app/autoload.php // ... @@ -187,5 +186,5 @@ file:: .. tip:: This modification can be of interest if you are working in a virtual environment - and cannot use NFS - for example, if you're running a Symfony app using + and cannot use NFS - for example, if you're running a Symfony application using Vagrant/VirtualBox in a guest operating system. diff --git a/cookbook/configuration/pdo_session_storage.rst b/cookbook/configuration/pdo_session_storage.rst index 7abe63b1e93..72a30c6e36e 100644 --- a/cookbook/configuration/pdo_session_storage.rst +++ b/cookbook/configuration/pdo_session_storage.rst @@ -10,15 +10,14 @@ How to Use PdoSessionHandler to Store Sessions in the Database schema changed slightly. See :ref:`Symfony 2.6 Changes ` for details. -The default Symfony session storage writes the session information to -file(s). Most medium to large websites use a database to store the session -values instead of files, because databases are easier to use and scale in a +The default Symfony session storage writes the session information to files. +Most medium to large websites use a database to store the session values +instead of files, because databases are easier to use and scale in a multi-webserver environment. Symfony has a built-in solution for database session storage called :class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\PdoSessionHandler`. -To use it, you just need to change some parameters in ``config.yml`` (or the -configuration format of your choice): +To use it, you just need to change some parameters in the main configuration file: .. configuration-block:: @@ -127,18 +126,23 @@ a second array argument to ``PdoSessionHandler``: The ``db_lifetime_col`` was introduced in Symfony 2.6. Prior to 2.6, this column did not exist. -The following things can be configured: - -* ``db_table``: (default ``sessions``) The name of the session table in your - database; -* ``db_id_col``: (default ``sess_id``) The name of the id column in your - session table (VARCHAR(128)); -* ``db_data_col``: (default ``sess_data``) The name of the value column in - your session table (BLOB); -* ``db_time_col``: (default ``sess_time``) The name of the time column in - your session table (INTEGER); -* ``db_lifetime_col``: (default ``sess_lifetime``) The name of the lifetime - column in your session table (INTEGER). +These are parameters that you must configure: + +``db_table`` (default ``sessions``): + The name of the session table in your database; + +``db_id_col`` (default ``sess_id``): + The name of the id column in your session table (VARCHAR(128)); + +``db_data_col`` (default ``sess_data``): + The name of the value column in your session table (BLOB); + +``db_time_col`` (default ``sess_time``): + The name of the time column in your session table (INTEGER); + +``db_lifetime_col`` (default ``sess_lifetime``): + The name of the lifetime column in your session table (INTEGER). + Sharing your Database Connection Information -------------------------------------------- diff --git a/cookbook/configuration/using_parameters_in_dic.rst b/cookbook/configuration/using_parameters_in_dic.rst index 0d224ec5593..c2eef5b0ab1 100644 --- a/cookbook/configuration/using_parameters_in_dic.rst +++ b/cookbook/configuration/using_parameters_in_dic.rst @@ -11,9 +11,9 @@ There are special cases such as when you want, for instance, to use the debug mode. For this case there is more work to do in order to make the system understand the parameter value. By default your parameter ``%kernel.debug%`` will be treated as a -simple string. Consider this example with the AcmeDemoBundle:: +simple string. Consider the following example:: - // Inside Configuration class + // inside Configuration class $rootNode ->children() ->booleanNode('logging')->defaultValue('%kernel.debug%')->end() @@ -21,7 +21,7 @@ simple string. Consider this example with the AcmeDemoBundle:: ->end() ; - // Inside the Extension class + // inside the Extension class $config = $this->processConfiguration($configuration, $configs); var_dump($config['logging']); @@ -111,7 +111,7 @@ be injected with this parameter via the extension as follows:: public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('acme_demo'); + $rootNode = $treeBuilder->root('my_bundle'); $rootNode ->children() @@ -127,14 +127,14 @@ be injected with this parameter via the extension as follows:: And set it in the constructor of ``Configuration`` via the ``Extension`` class:: - namespace Acme\DemoBundle\DependencyInjection; + namespace AppBundle\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\Config\FileLocator; - class AcmeDemoExtension extends Extension + class AppExtension extends Extension { // ... @@ -147,7 +147,7 @@ And set it in the constructor of ``Configuration`` via the ``Extension`` class:: .. sidebar:: Setting the Default in the Extension There are some instances of ``%kernel.debug%`` usage within a ``Configurator`` - class in TwigBundle and AsseticBundle, however this is because the default + class in TwigBundle and AsseticBundle. However this is because the default parameter value is set by the Extension class. For example in AsseticBundle, you can find:: diff --git a/cookbook/configuration/web_server_configuration.rst b/cookbook/configuration/web_server_configuration.rst index f5e84c7c66d..9a8e2955009 100644 --- a/cookbook/configuration/web_server_configuration.rst +++ b/cookbook/configuration/web_server_configuration.rst @@ -8,9 +8,9 @@ The preferred way to develop your Symfony application is to use :doc:`PHP's internal web server `. However, when using an older PHP version or when running the application in the production environment, you'll need to use a fully-featured web server. This article -describes several ways to use Symfony with Apache2 or Nginx. +describes several ways to use Symfony with Apache or Nginx. -When using Apache2, you can configure PHP as an +When using Apache, you can configure PHP as an :ref:`Apache module ` or with FastCGI using :ref:`PHP FPM `. FastCGI also is the preferred way to use PHP :ref:`with Nginx `. @@ -25,14 +25,16 @@ to use PHP :ref:`with Nginx `. web server. In the examples below, the ``web/`` directory will be the document root. This directory is ``/var/www/project/web/``. + If your hosting provider requires you to change the ``web/`` directory to + another location (e.g. ``public_html/``) make sure you + :ref:`override the location of the web/ directory `. + .. _web-server-apache-mod-php: -Apache2 with mod_php/PHP-CGI ----------------------------- +Apache with mod_php/PHP-CGI +--------------------------- -For advanced Apache configuration options, see the official `Apache`_ -documentation. The minimum basics to get your application running under Apache2 -are: +The **minimum configuration** to get your application running under Apache is: .. code-block:: apache @@ -42,9 +44,8 @@ are: DocumentRoot /var/www/project/web - # enable the .htaccess rewrites AllowOverride All - Order allow,deny + Order allow, deny Allow from All @@ -58,42 +59,73 @@ are: CustomLog /var/log/apache2/project_access.log combined -.. note:: +.. tip:: If your system supports the ``APACHE_LOG_DIR`` variable, you may want - to use ``${APACHE_LOG_DIR}/`` instead of ``/var/log/apache2/``. + to use ``${APACHE_LOG_DIR}/`` instead of hardcoding ``/var/log/apache2/``. -.. note:: +Use the following **optimized configuration** to disable ``.htaccess`` support +and increase web server performance: - For performance reasons, you will probably want to set - ``AllowOverride None`` and implement the rewrite rules in the ``web/.htaccess`` - into the ``VirtualHost`` config. +.. code-block:: apache -If you are using **php-cgi**, Apache does not pass HTTP basic username and -password to PHP by default. To work around this limitation, you should use the -following configuration snippet: + + ServerName domain.tld + ServerAlias www.domain.tld -.. code-block:: apache + DocumentRoot /var/www/project/web + + AllowOverride None + Order allow, deny + Allow from All - RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + + Options -MultiViews + RewriteEngine On + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^(.*)$ app.php [QSA,L] + + -.. caution:: + # uncomment the following lines if you install assets as symlinks + # or run into problems when compiling LESS/Sass/CoffeScript assets + # + # Option FollowSymlinks + # - In Apache 2.4, ``Order allow,deny`` has been replaced by ``Require all granted``, - and hence you need to modify your ``Directory`` permission settings as follows: + ErrorLog /var/log/apache2/project_error.log + CustomLog /var/log/apache2/project_access.log combined + + +.. tip:: + + If you are using **php-cgi**, Apache does not pass HTTP basic username and + password to PHP by default. To work around this limitation, you should use + the following configuration snippet: .. code-block:: apache - - # enable the .htaccess rewrites - AllowOverride All - Require all granted - + RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + +Using mod_php/PHP-CGI with Apache 2.4 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +In Apache 2.4, ``Order allow,deny`` has been replaced by ``Require all granted``. +Hence, you need to modify your ``Directory`` permission settings as follows: + +.. code-block:: apache + + + Require all granted + # ... + + +For advanced Apache configuration options, read the official `Apache documentation`_. .. _web-server-apache-fpm: -Apache2 with PHP-FPM --------------------- +Apache with PHP-FPM +------------------- To make use of PHP5-FPM with Apache, you first have to ensure that you have the FastCGI process manager ``php-fpm`` binary and Apache's FastCGI module @@ -102,7 +134,7 @@ installed (for example, on a Debian based system you have to install the PHP-FPM uses so-called *pools* to handle incoming FastCGI requests. You can configure an arbitrary number of pools in the FPM configuration. In a pool -you configure either a TCP socket (IP and port) or a unix domain socket to +you configure either a TCP socket (IP and port) or a Unix domain socket to listen on. Each pool can also be run under a different UID and GID: .. code-block:: ini @@ -123,7 +155,7 @@ Using mod_proxy_fcgi with Apache 2.4 If you are running Apache 2.4, you can easily use ``mod_proxy_fcgi`` to pass incoming requests to PHP-FPM. Configure PHP-FPM to listen on a TCP socket -(``mod_proxy`` currently `does not support unix sockets`_), enable ``mod_proxy`` +(``mod_proxy`` currently `does not support Unix sockets`_), enable ``mod_proxy`` and ``mod_proxy_fcgi`` in your Apache configuration and use the ``SetHandler`` directive to pass requests for PHP files to PHP FPM: @@ -144,8 +176,10 @@ directive to pass requests for PHP files to PHP FPM: SetHandler proxy:fcgi://127.0.0.1:9000 + # If you use Apache version below 2.4.9 you must consider update or use this instead # ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/project/web/$1 + # If you run your Symfony application on a subpath of your document root, the # regular expression must be changed accordingly: # ProxyPassMatch ^/path-to-app/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/project/web/$1 @@ -189,7 +223,7 @@ should look something like this: # enable the .htaccess rewrites AllowOverride All - Order allow,deny + Order allow, deny Allow from all @@ -203,7 +237,7 @@ should look something like this: CustomLog /var/log/apache2/project_access.log combined -If you prefer to use a unix socket, you have to use the ``-socket`` option +If you prefer to use a Unix socket, you have to use the ``-socket`` option instead: .. code-block:: apache @@ -215,9 +249,7 @@ instead: Nginx ----- -For advanced Nginx configuration options, see the official `Nginx`_ -documentation. The minimum basics to get your application running under Nginx -are: +The **minimum configuration** to get your application running under Nginx is: .. code-block:: nginx @@ -267,12 +299,14 @@ are: the web directory. All other files will be served as text. You **must** also make sure that if you *do* deploy ``app_dev.php`` or ``config.php`` that these files are secured and not available to any outside user (the - IP checking code at the top of each file does this by default). + IP address checking code at the top of each file does this by default). If you have other PHP files in your web directory that need to be executed, be sure to include them in the ``location`` block above. -.. _`Apache`: http://httpd.apache.org/docs/current/mod/core.html#documentroot -.. _`does not support unix sockets`: https://issues.apache.org/bugzilla/show_bug.cgi?id=54101 +For advanced Nginx configuration options, read the official `Nginx documentation`_. + +.. _`Apache documentation`: http://httpd.apache.org/docs/ +.. _`does not support Unix sockets`: https://issues.apache.org/bugzilla/show_bug.cgi?id=54101 .. _`FastCgiExternalServer`: http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html#FastCgiExternalServer -.. _`Nginx`: http://wiki.nginx.org/Symfony +.. _`Nginx documentation`: http://wiki.nginx.org/Symfony diff --git a/cookbook/deployment/heroku.rst b/cookbook/deployment/heroku.rst index 2752d183961..1b6ed4a1bac 100644 --- a/cookbook/deployment/heroku.rst +++ b/cookbook/deployment/heroku.rst @@ -141,6 +141,13 @@ variables, you can issue a single command to prepare your app for a deployment: $ heroku config:set SYMFONY_ENV=prod +.. caution:: + + Be aware that dependencies from ``composer.json`` listed in the ``require-dev`` + section are never installed during a deploy on Heroku. This may cause problems + if your Symfony environment relies on such packages. The solution is to move these + packages from ``require-dev`` to the ``require`` section. + .. _heroku-push-code: .. _pushing-to-heroku: diff --git a/cookbook/doctrine/file_uploads.rst b/cookbook/doctrine/file_uploads.rst index 21910b7d2d2..64178d6dca2 100644 --- a/cookbook/doctrine/file_uploads.rst +++ b/cookbook/doctrine/file_uploads.rst @@ -152,15 +152,6 @@ rules:: .. configuration-block:: - .. code-block:: yaml - - # src/AppBundle/Resources/config/validation.yml - AppBundle\Entity\Document: - properties: - file: - - File: - maxSize: 6000000 - .. code-block:: php-annotations // src/AppBundle/Entity/Document.php @@ -179,6 +170,15 @@ rules:: // ... } + .. code-block:: yaml + + # src/AppBundle/Resources/config/validation.yml + AppBundle\Entity\Document: + properties: + file: + - File: + maxSize: 6000000 + .. code-block:: xml diff --git a/cookbook/validation/custom_constraint.rst b/cookbook/validation/custom_constraint.rst index 96a0e4f45ec..94c5b68d402 100644 --- a/cookbook/validation/custom_constraint.rst +++ b/cookbook/validation/custom_constraint.rst @@ -95,15 +95,6 @@ Using custom validators is very easy, just as the ones provided by Symfony itsel .. configuration-block:: - .. code-block:: yaml - - # src/AppBundle/Resources/config/validation.yml - AppBundle\Entity\AcmeEntity: - properties: - name: - - NotBlank: ~ - - AppBundle\Validator\Constraints\ContainsAlphanumeric: ~ - .. code-block:: php-annotations // src/AppBundle/Entity/AcmeEntity.php @@ -123,6 +114,15 @@ Using custom validators is very easy, just as the ones provided by Symfony itsel // ... } + .. code-block:: yaml + + # src/AppBundle/Resources/config/validation.yml + AppBundle\Entity\AcmeEntity: + properties: + name: + - NotBlank: ~ + - AppBundle\Validator\Constraints\ContainsAlphanumeric: ~ + .. code-block:: xml @@ -251,13 +251,6 @@ not to the property: .. configuration-block:: - .. code-block:: yaml - - # src/AppBundle/Resources/config/validation.yml - AppBundle\Entity\AcmeEntity: - constraints: - - AppBundle\Validator\Constraints\ContainsAlphanumeric: ~ - .. code-block:: php-annotations /** @@ -268,6 +261,13 @@ not to the property: // ... } + .. code-block:: yaml + + # src/AppBundle/Resources/config/validation.yml + AppBundle\Entity\AcmeEntity: + constraints: + - AppBundle\Validator\Constraints\ContainsAlphanumeric: ~ + .. code-block:: xml diff --git a/reference/constraints/All.rst b/reference/constraints/All.rst index 8fb48ffaf0d..f9f37b51a2c 100644 --- a/reference/constraints/All.rst +++ b/reference/constraints/All.rst @@ -23,17 +23,6 @@ entry in that array: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/UserBundle/Resources/config/validation.yml - Acme\UserBundle\Entity\User: - properties: - favoriteColors: - - All: - - NotBlank: ~ - - Length: - min: 5 - .. code-block:: php-annotations // src/Acme/UserBundle/Entity/User.php @@ -52,6 +41,17 @@ entry in that array: protected $favoriteColors = array(); } + .. code-block:: yaml + + # src/Acme/UserBundle/Resources/config/validation.yml + Acme\UserBundle\Entity\User: + properties: + favoriteColors: + - All: + - NotBlank: ~ + - Length: + min: 5 + .. code-block:: xml diff --git a/reference/constraints/Blank.rst b/reference/constraints/Blank.rst index 1823675f571..b83f40e0190 100644 --- a/reference/constraints/Blank.rst +++ b/reference/constraints/Blank.rst @@ -25,14 +25,6 @@ of an ``Author`` class were blank, you could do the following: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - firstName: - - Blank: ~ - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -48,6 +40,14 @@ of an ``Author`` class were blank, you could do the following: protected $firstName; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + firstName: + - Blank: ~ + .. code-block:: xml diff --git a/reference/constraints/Callback.rst b/reference/constraints/Callback.rst index 7480381c370..a43248ad449 100644 --- a/reference/constraints/Callback.rst +++ b/reference/constraints/Callback.rst @@ -33,13 +33,6 @@ Configuration .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - constraints: - - Callback: [validate] - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -61,6 +54,13 @@ Configuration } } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + constraints: + - Callback: [validate] + .. code-block:: xml @@ -183,13 +183,6 @@ You can then use the following configuration to invoke this validator: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - constraints: - - Callback: [Vendor\Package\Validator, validate] - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -204,6 +197,15 @@ You can then use the following configuration to invoke this validator: { } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + constraints: + - Callback: [Vendor\Package\Validator, validate] + + .. code-block:: xml + .. code-block:: xml diff --git a/reference/constraints/CardScheme.rst b/reference/constraints/CardScheme.rst index 7a6b7136418..38ee81c15b8 100644 --- a/reference/constraints/CardScheme.rst +++ b/reference/constraints/CardScheme.rst @@ -25,6 +25,21 @@ on an object that will contain a credit card number. .. configuration-block:: + .. code-block:: php-annotations + + // src/Acme/SubscriptionBundle/Entity/Transaction.php + namespace Acme\SubscriptionBundle\Entity\Transaction; + + use Symfony\Component\Validator\Constraints as Assert; + + class Transaction + { + /** + * @Assert\CardScheme(schemes = {"VISA"}, message = "Your credit card number is invalid.") + */ + protected $cardNumber; + } + .. code-block:: yaml # src/Acme/SubscriptionBundle/Resources/config/validation.yml @@ -55,21 +70,6 @@ on an object that will contain a credit card number. - .. code-block:: php-annotations - - // src/Acme/SubscriptionBundle/Entity/Transaction.php - namespace Acme\SubscriptionBundle\Entity\Transaction; - - use Symfony\Component\Validator\Constraints as Assert; - - class Transaction - { - /** - * @Assert\CardScheme(schemes = {"VISA"}, message = "Your credit card number is invalid.") - */ - protected $cardNumber; - } - .. code-block:: php // src/Acme/SubscriptionBundle/Entity/Transaction.php diff --git a/reference/constraints/Choice.rst b/reference/constraints/Choice.rst index 1e0d9345ad6..50840e22769 100644 --- a/reference/constraints/Choice.rst +++ b/reference/constraints/Choice.rst @@ -37,16 +37,6 @@ If your valid choice list is simple, you can pass them in directly via the .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - gender: - - Choice: - choices: [male, female] - message: Choose a valid gender. - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -62,6 +52,16 @@ If your valid choice list is simple, you can pass them in directly via the protected $gender; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + gender: + - Choice: + choices: [male, female] + message: Choose a valid gender. + .. code-block:: xml @@ -130,14 +130,6 @@ constraint. .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - gender: - - Choice: { callback: getGenders } - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -153,6 +145,14 @@ constraint. protected $gender; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + gender: + - Choice: { callback: getGenders } + .. code-block:: xml @@ -195,14 +195,6 @@ you can pass the class name and the method as an array. .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - gender: - - Choice: { callback: [Util, getGenders] } - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -218,6 +210,14 @@ you can pass the class name and the method as an array. protected $gender; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + gender: + - Choice: { callback: [Util, getGenders] } + .. code-block:: xml diff --git a/reference/constraints/Collection.rst b/reference/constraints/Collection.rst index 53e2ddeaeeb..019d6acd97a 100644 --- a/reference/constraints/Collection.rst +++ b/reference/constraints/Collection.rst @@ -53,22 +53,6 @@ blank but is no longer than 100 characters in length, you would do the following .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - profileData: - - Collection: - fields: - personal_email: Email - short_bio: - - NotBlank - - Length: - max: 100 - maxMessage: Your short bio is too long! - allowMissingFields: true - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -99,6 +83,22 @@ blank but is no longer than 100 characters in length, you would do the following ); } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + profileData: + - Collection: + fields: + personal_email: Email + short_bio: + - NotBlank + - Length: + max: 100 + maxMessage: Your short bio is too long! + allowMissingFields: true + .. code-block:: xml @@ -190,22 +190,6 @@ field is optional but must be a valid email if supplied, you can do the followin .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - profile_data: - - Collection: - fields: - personal_email: - - Required - - NotBlank: ~ - - Email: ~ - alternate_email: - - Optional: - - Email: ~ - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -226,6 +210,22 @@ field is optional but must be a valid email if supplied, you can do the followin protected $profileData = array('personal_email'); } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + profile_data: + - Collection: + fields: + personal_email: + - Required + - NotBlank: ~ + - Email: ~ + alternate_email: + - Optional: + - Email: ~ + .. code-block:: xml diff --git a/reference/constraints/Count.rst b/reference/constraints/Count.rst index 4274bab8998..9b391832101 100644 --- a/reference/constraints/Count.rst +++ b/reference/constraints/Count.rst @@ -27,18 +27,6 @@ you might add the following: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/EventBundle/Resources/config/validation.yml - Acme\EventBundle\Entity\Participant: - properties: - emails: - - Count: - min: 1 - max: 5 - minMessage: "You must specify at least one email" - maxMessage: "You cannot specify more than {{ limit }} emails" - .. code-block:: php-annotations // src/Acme/EventBundle/Entity/Participant.php @@ -59,6 +47,18 @@ you might add the following: protected $emails = array(); } + .. code-block:: yaml + + # src/Acme/EventBundle/Resources/config/validation.yml + Acme\EventBundle\Entity\Participant: + properties: + emails: + - Count: + min: 1 + max: 5 + minMessage: "You must specify at least one email" + maxMessage: "You cannot specify more than {{ limit }} emails" + .. code-block:: xml diff --git a/reference/constraints/Country.rst b/reference/constraints/Country.rst index 6f9b7ed1d09..29b89d1b963 100644 --- a/reference/constraints/Country.rst +++ b/reference/constraints/Country.rst @@ -19,14 +19,6 @@ Basic Usage .. configuration-block:: - .. code-block:: yaml - - # src/Acme/UserBundle/Resources/config/validation.yml - Acme\UserBundle\Entity\User: - properties: - country: - - Country: ~ - .. code-block:: php-annotations // src/Acme/UserBundle/Entity/User.php @@ -42,6 +34,14 @@ Basic Usage protected $country; } + .. code-block:: yaml + + # src/Acme/UserBundle/Resources/config/validation.yml + Acme\UserBundle\Entity\User: + properties: + country: + - Country: ~ + .. code-block:: xml diff --git a/reference/constraints/Currency.rst b/reference/constraints/Currency.rst index 55483843a39..d6222b4205e 100644 --- a/reference/constraints/Currency.rst +++ b/reference/constraints/Currency.rst @@ -25,14 +25,6 @@ currency, you could do the following: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/EcommerceBundle/Resources/config/validation.yml - Acme\EcommerceBundle\Entity\Order: - properties: - currency: - - Currency: ~ - .. code-block:: php-annotations // src/Acme/EcommerceBundle/Entity/Order.php @@ -48,6 +40,14 @@ currency, you could do the following: protected $currency; } + .. code-block:: yaml + + # src/Acme/EcommerceBundle/Resources/config/validation.yml + Acme\EcommerceBundle\Entity\Order: + properties: + currency: + - Currency: ~ + .. code-block:: xml diff --git a/reference/constraints/Date.rst b/reference/constraints/Date.rst index f972895cac5..5b7d97402da 100644 --- a/reference/constraints/Date.rst +++ b/reference/constraints/Date.rst @@ -21,14 +21,6 @@ Basic Usage .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - birthday: - - Date: ~ - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -44,6 +36,14 @@ Basic Usage protected $birthday; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + birthday: + - Date: ~ + .. code-block:: xml diff --git a/reference/constraints/DateTime.rst b/reference/constraints/DateTime.rst index c7420b75ad9..56a3777f627 100644 --- a/reference/constraints/DateTime.rst +++ b/reference/constraints/DateTime.rst @@ -21,14 +21,6 @@ Basic Usage .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - createdAt: - - DateTime: ~ - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -44,6 +36,14 @@ Basic Usage protected $createdAt; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + createdAt: + - DateTime: ~ + .. code-block:: xml diff --git a/reference/constraints/Email.rst b/reference/constraints/Email.rst index 047d774eed6..98a85e0d101 100644 --- a/reference/constraints/Email.rst +++ b/reference/constraints/Email.rst @@ -23,16 +23,6 @@ Basic Usage .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - email: - - Email: - message: The email "{{ value }}" is not a valid email. - checkMX: true - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -51,6 +41,16 @@ Basic Usage protected $email; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + email: + - Email: + message: The email "{{ value }}" is not a valid email. + checkMX: true + .. code-block:: xml diff --git a/reference/constraints/EqualTo.rst b/reference/constraints/EqualTo.rst index 88a5ab812ef..eaa32e6aa87 100644 --- a/reference/constraints/EqualTo.rst +++ b/reference/constraints/EqualTo.rst @@ -33,15 +33,6 @@ If you want to ensure that the ``age`` of a ``Person`` class is equal to .. configuration-block:: - .. code-block:: yaml - - # src/Acme/SocialBundle/Resources/config/validation.yml - Acme\SocialBundle\Entity\Person: - properties: - age: - - EqualTo: - value: 20 - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Person.php @@ -59,6 +50,15 @@ If you want to ensure that the ``age`` of a ``Person`` class is equal to protected $age; } + .. code-block:: yaml + + # src/Acme/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - EqualTo: + value: 20 + .. code-block:: xml diff --git a/reference/constraints/False.rst b/reference/constraints/False.rst index 483c25c1eef..a7f33ee397a 100644 --- a/reference/constraints/False.rst +++ b/reference/constraints/False.rst @@ -40,15 +40,6 @@ method returns **false**: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author - getters: - stateInvalid: - - 'False': - message: You've entered an invalid state. - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -69,6 +60,15 @@ method returns **false**: } } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author + getters: + stateInvalid: + - 'False': + message: You've entered an invalid state. + .. code-block:: xml diff --git a/reference/constraints/File.rst b/reference/constraints/File.rst index 503d0e1995b..e73c49c4b13 100644 --- a/reference/constraints/File.rst +++ b/reference/constraints/File.rst @@ -71,17 +71,6 @@ below a certain file size and a valid PDF, add the following: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - bioFile: - - File: - maxSize: 1024k - mimeTypes: [application/pdf, application/x-pdf] - mimeTypesMessage: Please upload a valid PDF - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -101,6 +90,17 @@ below a certain file size and a valid PDF, add the following: protected $bioFile; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + bioFile: + - File: + maxSize: 1024k + mimeTypes: [application/pdf, application/x-pdf] + mimeTypesMessage: Please upload a valid PDF + .. code-block:: xml diff --git a/reference/constraints/GreaterThan.rst b/reference/constraints/GreaterThan.rst index f18958061ea..06681203163 100644 --- a/reference/constraints/GreaterThan.rst +++ b/reference/constraints/GreaterThan.rst @@ -29,15 +29,6 @@ If you want to ensure that the ``age`` of a ``Person`` class is greater than .. configuration-block:: - .. code-block:: yaml - - # src/Acme/SocialBundle/Resources/config/validation.yml - Acme\SocialBundle\Entity\Person: - properties: - age: - - GreaterThan: - value: 18 - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Person.php @@ -55,6 +46,15 @@ If you want to ensure that the ``age`` of a ``Person`` class is greater than protected $age; } + .. code-block:: yaml + + # src/Acme/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - GreaterThan: + value: 18 + .. code-block:: xml diff --git a/reference/constraints/GreaterThanOrEqual.rst b/reference/constraints/GreaterThanOrEqual.rst index b4169479f94..f41d12d237e 100644 --- a/reference/constraints/GreaterThanOrEqual.rst +++ b/reference/constraints/GreaterThanOrEqual.rst @@ -28,15 +28,6 @@ or equal to ``18``, you could do the following: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/SocialBundle/Resources/config/validation.yml - Acme\SocialBundle\Entity\Person: - properties: - age: - - GreaterThanOrEqual: - value: 18 - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Person.php @@ -54,6 +45,15 @@ or equal to ``18``, you could do the following: protected $age; } + .. code-block:: yaml + + # src/Acme/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - GreaterThanOrEqual: + value: 18 + .. code-block:: xml diff --git a/reference/constraints/Iban.rst b/reference/constraints/Iban.rst index ecd02f52d91..8202175babf 100644 --- a/reference/constraints/Iban.rst +++ b/reference/constraints/Iban.rst @@ -28,15 +28,6 @@ will contain an International Bank Account Number. .. configuration-block:: - .. code-block:: yaml - - # src/Acme/SubscriptionBundle/Resources/config/validation.yml - Acme\SubscriptionBundle\Entity\Transaction: - properties: - bankAccountNumber: - - Iban: - message: This is not a valid International Bank Account Number (IBAN). - .. code-block:: php-annotations // src/Acme/SubscriptionBundle/Entity/Transaction.php @@ -52,6 +43,15 @@ will contain an International Bank Account Number. protected $bankAccountNumber; } + .. code-block:: yaml + + # src/Acme/SubscriptionBundle/Resources/config/validation.yml + Acme\SubscriptionBundle\Entity\Transaction: + properties: + bankAccountNumber: + - Iban: + message: This is not a valid International Bank Account Number (IBAN). + .. code-block:: xml diff --git a/reference/constraints/IdenticalTo.rst b/reference/constraints/IdenticalTo.rst index e3df6e872f4..7f895440ecb 100644 --- a/reference/constraints/IdenticalTo.rst +++ b/reference/constraints/IdenticalTo.rst @@ -34,15 +34,6 @@ If you want to ensure that the ``age`` of a ``Person`` class is equal to .. configuration-block:: - .. code-block:: yaml - - # src/Acme/SocialBundle/Resources/config/validation.yml - Acme\SocialBundle\Entity\Person: - properties: - age: - - IdenticalTo: - value: 20 - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Person.php @@ -60,6 +51,15 @@ If you want to ensure that the ``age`` of a ``Person`` class is equal to protected $age; } + .. code-block:: yaml + + # src/Acme/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - IdenticalTo: + value: 20 + .. code-block:: xml diff --git a/reference/constraints/Image.rst b/reference/constraints/Image.rst index abb9ac7e385..b73e75ac2e4 100644 --- a/reference/constraints/Image.rst +++ b/reference/constraints/Image.rst @@ -76,18 +76,6 @@ it is between a certain size, add the following: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author - properties: - headshot: - - Image: - minWidth: 200 - maxWidth: 400 - minHeight: 200 - maxHeight: 400 - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -108,6 +96,18 @@ it is between a certain size, add the following: protected $headshot; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author + properties: + headshot: + - Image: + minWidth: 200 + maxWidth: 400 + minHeight: 200 + maxHeight: 400 + .. code-block:: xml diff --git a/reference/constraints/Ip.rst b/reference/constraints/Ip.rst index 18a025a4fff..834e696bce2 100644 --- a/reference/constraints/Ip.rst +++ b/reference/constraints/Ip.rst @@ -22,14 +22,6 @@ Basic Usage .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - ipAddress: - - Ip: ~ - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -45,6 +37,14 @@ Basic Usage protected $ipAddress; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + ipAddress: + - Ip: ~ + .. code-block:: xml diff --git a/reference/constraints/Isbn.rst b/reference/constraints/Isbn.rst index 21fba6e1e17..9f9445383ef 100644 --- a/reference/constraints/Isbn.rst +++ b/reference/constraints/Isbn.rst @@ -37,16 +37,6 @@ on an object that will contain an ISBN. .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BookcaseBundle/Resources/config/validation.yml - Acme\BookcaseBundle\Entity\Book: - properties: - isbn: - - Isbn: - type: isbn10 - message: This value is not valid. - .. code-block:: php-annotations // src/Acme/BookcaseBundle/Entity/Book.php @@ -65,6 +55,17 @@ on an object that will contain an ISBN. protected $isbn; } + .. code-block:: yaml + + # src/Acme/BookcaseBundle/Resources/config/validation.yml + Acme\BookcaseBundle\Entity\Book: + properties: + isbn: + - Isbn: + type: isbn10 + message: This value is not valid. + + .. code-block:: xml diff --git a/reference/constraints/Issn.rst b/reference/constraints/Issn.rst index 172e4829365..9ce74cf3262 100644 --- a/reference/constraints/Issn.rst +++ b/reference/constraints/Issn.rst @@ -24,14 +24,6 @@ Basic Usage .. configuration-block:: - .. code-block:: yaml - - # src/Acme/JournalBundle/Resources/config/validation.yml - Acme\JournalBundle\Entity\Journal: - properties: - issn: - - Issn: ~ - .. code-block:: php-annotations // src/Acme/JournalBundle/Entity/Journal.php @@ -47,6 +39,14 @@ Basic Usage protected $issn; } + .. code-block:: yaml + + # src/Acme/JournalBundle/Resources/config/validation.yml + Acme\JournalBundle\Entity\Journal: + properties: + issn: + - Issn: ~ + .. code-block:: xml diff --git a/reference/constraints/Language.rst b/reference/constraints/Language.rst index bfbc9422e55..39abf0a7133 100644 --- a/reference/constraints/Language.rst +++ b/reference/constraints/Language.rst @@ -20,14 +20,6 @@ Basic Usage .. configuration-block:: - .. code-block:: yaml - - # src/Acme/UserBundle/Resources/config/validation.yml - Acme\UserBundle\Entity\User: - properties: - preferredLanguage: - - Language: ~ - .. code-block:: php-annotations // src/Acme/UserBundle/Entity/User.php @@ -43,6 +35,14 @@ Basic Usage protected $preferredLanguage; } + .. code-block:: yaml + + # src/Acme/UserBundle/Resources/config/validation.yml + Acme\UserBundle\Entity\User: + properties: + preferredLanguage: + - Language: ~ + .. code-block:: xml diff --git a/reference/constraints/Length.rst b/reference/constraints/Length.rst index c207f3f6ac6..9c7029ee3d9 100644 --- a/reference/constraints/Length.rst +++ b/reference/constraints/Length.rst @@ -27,18 +27,6 @@ To verify that the ``firstName`` field length of a class is between "2" and .. configuration-block:: - .. code-block:: yaml - - # src/Acme/EventBundle/Resources/config/validation.yml - Acme\EventBundle\Entity\Participant: - properties: - firstName: - - Length: - min: 2 - max: 50 - minMessage: "Your first name must be at least {{ limit }} characters long" - maxMessage: "Your first name cannot be longer than {{ limit }} characters" - .. code-block:: php-annotations // src/Acme/EventBundle/Entity/Participant.php @@ -59,6 +47,18 @@ To verify that the ``firstName`` field length of a class is between "2" and protected $firstName; } + .. code-block:: yaml + + # src/Acme/EventBundle/Resources/config/validation.yml + Acme\EventBundle\Entity\Participant: + properties: + firstName: + - Length: + min: 2 + max: 50 + minMessage: "Your first name must be at least {{ limit }} characters long" + maxMessage: "Your first name cannot be longer than {{ limit }} characters" + .. code-block:: xml diff --git a/reference/constraints/LessThan.rst b/reference/constraints/LessThan.rst index b29ae942c4e..3b1b3135f98 100644 --- a/reference/constraints/LessThan.rst +++ b/reference/constraints/LessThan.rst @@ -29,15 +29,6 @@ If you want to ensure that the ``age`` of a ``Person`` class is less than .. configuration-block:: - .. code-block:: yaml - - # src/Acme/SocialBundle/Resources/config/validation.yml - Acme\SocialBundle\Entity\Person: - properties: - age: - - LessThan: - value: 80 - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Person.php @@ -55,6 +46,15 @@ If you want to ensure that the ``age`` of a ``Person`` class is less than protected $age; } + .. code-block:: yaml + + # src/Acme/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - LessThan: + value: 80 + .. code-block:: xml diff --git a/reference/constraints/LessThanOrEqual.rst b/reference/constraints/LessThanOrEqual.rst index 72990a33ab6..024f2100e40 100644 --- a/reference/constraints/LessThanOrEqual.rst +++ b/reference/constraints/LessThanOrEqual.rst @@ -28,15 +28,6 @@ equal to ``80``, you could do the following: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/SocialBundle/Resources/config/validation.yml - Acme\SocialBundle\Entity\Person: - properties: - age: - - LessThanOrEqual: - value: 80 - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Person.php @@ -54,6 +45,15 @@ equal to ``80``, you could do the following: protected $age; } + .. code-block:: yaml + + # src/Acme/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - LessThanOrEqual: + value: 80 + .. code-block:: xml diff --git a/reference/constraints/Locale.rst b/reference/constraints/Locale.rst index 8b2ad74201a..96fae2f4cc0 100644 --- a/reference/constraints/Locale.rst +++ b/reference/constraints/Locale.rst @@ -23,14 +23,6 @@ Basic Usage .. configuration-block:: - .. code-block:: yaml - - # src/Acme/UserBundle/Resources/config/validation.yml - Acme\UserBundle\Entity\User: - properties: - locale: - - Locale: ~ - .. code-block:: php-annotations // src/Acme/UserBundle/Entity/User.php @@ -46,6 +38,14 @@ Basic Usage protected $locale; } + .. code-block:: yaml + + # src/Acme/UserBundle/Resources/config/validation.yml + Acme\UserBundle\Entity\User: + properties: + locale: + - Locale: ~ + .. code-block:: xml diff --git a/reference/constraints/Luhn.rst b/reference/constraints/Luhn.rst index a437f8b8546..efc2ae716ba 100644 --- a/reference/constraints/Luhn.rst +++ b/reference/constraints/Luhn.rst @@ -24,15 +24,6 @@ will contain a credit card number. .. configuration-block:: - .. code-block:: yaml - - # src/Acme/SubscriptionBundle/Resources/config/validation.yml - Acme\SubscriptionBundle\Entity\Transaction: - properties: - cardNumber: - - Luhn: - message: Please check your credit card number. - .. code-block:: php-annotations // src/Acme/SubscriptionBundle/Entity/Transaction.php @@ -48,6 +39,15 @@ will contain a credit card number. protected $cardNumber; } + .. code-block:: yaml + + # src/Acme/SubscriptionBundle/Resources/config/validation.yml + Acme\SubscriptionBundle\Entity\Transaction: + properties: + cardNumber: + - Luhn: + message: Please check your credit card number. + .. code-block:: xml diff --git a/reference/constraints/NotBlank.rst b/reference/constraints/NotBlank.rst index b56aa7eceb8..82bc7175007 100644 --- a/reference/constraints/NotBlank.rst +++ b/reference/constraints/NotBlank.rst @@ -24,14 +24,6 @@ were not blank, you could do the following: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - firstName: - - NotBlank: ~ - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -47,6 +39,14 @@ were not blank, you could do the following: protected $firstName; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + firstName: + - NotBlank: ~ + .. code-block:: xml diff --git a/reference/constraints/NotEqualTo.rst b/reference/constraints/NotEqualTo.rst index ec225f5b5c9..3ab71af1804 100644 --- a/reference/constraints/NotEqualTo.rst +++ b/reference/constraints/NotEqualTo.rst @@ -34,15 +34,6 @@ If you want to ensure that the ``age`` of a ``Person`` class is not equal to .. configuration-block:: - .. code-block:: yaml - - # src/Acme/SocialBundle/Resources/config/validation.yml - Acme\SocialBundle\Entity\Person: - properties: - age: - - NotEqualTo: - value: 15 - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Person.php @@ -60,6 +51,15 @@ If you want to ensure that the ``age`` of a ``Person`` class is not equal to protected $age; } + .. code-block:: yaml + + # src/Acme/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - NotEqualTo: + value: 15 + .. code-block:: xml diff --git a/reference/constraints/NotIdenticalTo.rst b/reference/constraints/NotIdenticalTo.rst index 7d2ef918fe9..c3a2f52bfe8 100644 --- a/reference/constraints/NotIdenticalTo.rst +++ b/reference/constraints/NotIdenticalTo.rst @@ -34,15 +34,6 @@ If you want to ensure that the ``age`` of a ``Person`` class is *not* equal to .. configuration-block:: - .. code-block:: yaml - - # src/Acme/SocialBundle/Resources/config/validation.yml - Acme\SocialBundle\Entity\Person: - properties: - age: - - NotIdenticalTo: - value: 15 - .. code-block:: php-annotations // src/Acme/SocialBundle/Entity/Person.php @@ -60,6 +51,15 @@ If you want to ensure that the ``age`` of a ``Person`` class is *not* equal to protected $age; } + .. code-block:: yaml + + # src/Acme/SocialBundle/Resources/config/validation.yml + Acme\SocialBundle\Entity\Person: + properties: + age: + - NotIdenticalTo: + value: 15 + .. code-block:: xml diff --git a/reference/constraints/NotNull.rst b/reference/constraints/NotNull.rst index 096ff6c13a3..6f70f40e236 100644 --- a/reference/constraints/NotNull.rst +++ b/reference/constraints/NotNull.rst @@ -24,14 +24,6 @@ were not strictly equal to ``null``, you would: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - firstName: - - NotNull: ~ - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -47,6 +39,14 @@ were not strictly equal to ``null``, you would: protected $firstName; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + firstName: + - NotNull: ~ + .. code-block:: xml diff --git a/reference/constraints/Null.rst b/reference/constraints/Null.rst index 246ae34af83..78bb79fd23a 100644 --- a/reference/constraints/Null.rst +++ b/reference/constraints/Null.rst @@ -24,14 +24,6 @@ of an ``Author`` class exactly equal to ``null``, you could do the following: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - firstName: - - 'Null': ~ - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -47,6 +39,14 @@ of an ``Author`` class exactly equal to ``null``, you could do the following: protected $firstName; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + firstName: + - 'Null': ~ + .. code-block:: xml diff --git a/reference/constraints/Range.rst b/reference/constraints/Range.rst index 2d68e6cd1af..1dc8d5d1bd7 100644 --- a/reference/constraints/Range.rst +++ b/reference/constraints/Range.rst @@ -26,18 +26,6 @@ the following: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/EventBundle/Resources/config/validation.yml - Acme\EventBundle\Entity\Participant: - properties: - height: - - Range: - min: 120 - max: 180 - minMessage: You must be at least {{ limit }}cm tall to enter - maxMessage: You cannot be taller than {{ limit }}cm to enter - .. code-block:: php-annotations // src/Acme/EventBundle/Entity/Participant.php @@ -58,6 +46,18 @@ the following: protected $height; } + .. code-block:: yaml + + # src/Acme/EventBundle/Resources/config/validation.yml + Acme\EventBundle\Entity\Participant: + properties: + height: + - Range: + min: 120 + max: 180 + minMessage: You must be at least {{ limit }}cm tall to enter + maxMessage: You cannot be taller than {{ limit }}cm to enter + .. code-block:: xml diff --git a/reference/constraints/Regex.rst b/reference/constraints/Regex.rst index 42eb325dbe7..c92a314c4e9 100644 --- a/reference/constraints/Regex.rst +++ b/reference/constraints/Regex.rst @@ -27,14 +27,6 @@ characters at the beginning of your string: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - description: - - Regex: '/^\w+/' - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -50,6 +42,14 @@ characters at the beginning of your string: protected $description; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + description: + - Regex: '/^\w+/' + .. code-block:: xml @@ -92,17 +92,6 @@ message: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - firstName: - - Regex: - pattern: '/\d/' - match: false - message: Your name cannot contain a number - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -122,6 +111,17 @@ message: protected $firstName; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + firstName: + - Regex: + pattern: '/\d/' + match: false + message: Your name cannot contain a number + .. code-block:: xml @@ -192,16 +192,6 @@ to specify the HTML5 compatible pattern in the ``htmlPattern`` option: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - name: - - Regex: - pattern: "/^[a-z]+$/i" - htmlPattern: "^[a-zA-Z]+$" - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -220,6 +210,16 @@ to specify the HTML5 compatible pattern in the ``htmlPattern`` option: protected $name; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + name: + - Regex: + pattern: "/^[a-z]+$/i" + htmlPattern: "^[a-zA-Z]+$" + .. code-block:: xml diff --git a/reference/constraints/Time.rst b/reference/constraints/Time.rst index d1d77ea4754..033eaa542f6 100644 --- a/reference/constraints/Time.rst +++ b/reference/constraints/Time.rst @@ -24,14 +24,6 @@ of the day when the event starts: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/EventBundle/Resources/config/validation.yml - Acme\EventBundle\Entity\Event: - properties: - startsAt: - - Time: ~ - .. code-block:: php-annotations // src/Acme/EventBundle/Entity/Event.php @@ -47,6 +39,14 @@ of the day when the event starts: protected $startsAt; } + .. code-block:: yaml + + # src/Acme/EventBundle/Resources/config/validation.yml + Acme\EventBundle\Entity\Event: + properties: + startsAt: + - Time: ~ + .. code-block:: xml diff --git a/reference/constraints/True.rst b/reference/constraints/True.rst index 980ea8bf4da..2b41004b300 100644 --- a/reference/constraints/True.rst +++ b/reference/constraints/True.rst @@ -45,15 +45,6 @@ Then you can constrain this method with ``True``. .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - getters: - tokenValid: - - 'True': - message: The token is invalid. - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -74,6 +65,15 @@ Then you can constrain this method with ``True``. } } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + getters: + tokenValid: + - 'True': + message: The token is invalid. + .. code-block:: xml diff --git a/reference/constraints/Type.rst b/reference/constraints/Type.rst index 96894fc7c3d..2be82188914 100644 --- a/reference/constraints/Type.rst +++ b/reference/constraints/Type.rst @@ -22,16 +22,6 @@ Basic Usage .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - age: - - Type: - type: integer - message: The value {{ value }} is not a valid {{ type }}. - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -47,6 +37,16 @@ Basic Usage protected $age; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + age: + - Type: + type: integer + message: The value {{ value }} is not a valid {{ type }}. + .. code-block:: xml diff --git a/reference/constraints/UniqueEntity.rst b/reference/constraints/UniqueEntity.rst index c9446beaf7e..c20f42fed64 100644 --- a/reference/constraints/UniqueEntity.rst +++ b/reference/constraints/UniqueEntity.rst @@ -31,16 +31,6 @@ table: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/UserBundle/Resources/config/validation.yml - Acme\UserBundle\Entity\Author: - constraints: - - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: email - properties: - email: - - Email: ~ - .. code-block:: php-annotations // Acme/UserBundle/Entity/Author.php @@ -69,6 +59,16 @@ table: // ... } + .. code-block:: yaml + + # src/Acme/UserBundle/Resources/config/validation.yml + Acme\UserBundle\Entity\Author: + constraints: + - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: email + properties: + email: + - Email: ~ + .. code-block:: xml @@ -167,16 +167,6 @@ Consider this example: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/AdministrationBundle/Resources/config/validation.yml - Acme\AdministrationBundle\Entity\Service: - constraints: - - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: - fields: [host, port] - errorPath: port - message: 'This port is already in use on that host.' - .. code-block:: php-annotations // src/Acme/AdministrationBundle/Entity/Service.php @@ -206,6 +196,16 @@ Consider this example: public $port; } + .. code-block:: yaml + + # src/Acme/AdministrationBundle/Resources/config/validation.yml + Acme\AdministrationBundle\Entity\Service: + constraints: + - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: + fields: [host, port] + errorPath: port + message: 'This port is already in use on that host.' + .. code-block:: xml diff --git a/reference/constraints/Url.rst b/reference/constraints/Url.rst index a5d2da48812..85d368ef4df 100644 --- a/reference/constraints/Url.rst +++ b/reference/constraints/Url.rst @@ -20,14 +20,6 @@ Basic Usage .. configuration-block:: - .. code-block:: yaml - - # src/Acme/BlogBundle/Resources/config/validation.yml - Acme\BlogBundle\Entity\Author: - properties: - bioUrl: - - Url: ~ - .. code-block:: php-annotations // src/Acme/BlogBundle/Entity/Author.php @@ -43,6 +35,14 @@ Basic Usage protected $bioUrl; } + .. code-block:: yaml + + # src/Acme/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + bioUrl: + - Url: ~ + .. code-block:: xml diff --git a/reference/constraints/UserPassword.rst b/reference/constraints/UserPassword.rst index 80f5a5df4ba..d7ecec0412d 100644 --- a/reference/constraints/UserPassword.rst +++ b/reference/constraints/UserPassword.rst @@ -31,15 +31,6 @@ password: .. configuration-block:: - .. code-block:: yaml - - # src/Acme/UserBundle/Resources/config/validation.yml - Acme\UserBundle\Form\Model\ChangePassword: - properties: - oldPassword: - - Symfony\Component\Security\Core\Validator\Constraints\UserPassword: - message: "Wrong value for your current password" - .. code-block:: php-annotations // src/Acme/UserBundle/Form/Model/ChangePassword.php @@ -57,6 +48,15 @@ password: protected $oldPassword; } + .. code-block:: yaml + + # src/Acme/UserBundle/Resources/config/validation.yml + Acme\UserBundle\Form\Model\ChangePassword: + properties: + oldPassword: + - Symfony\Component\Security\Core\Validator\Constraints\UserPassword: + message: "Wrong value for your current password" + .. code-block:: xml diff --git a/reference/constraints/Valid.rst b/reference/constraints/Valid.rst index 56b1d511637..afbaedeab48 100644 --- a/reference/constraints/Valid.rst +++ b/reference/constraints/Valid.rst @@ -49,27 +49,6 @@ an ``Address`` instance in the ``$address`` property. .. configuration-block:: - .. code-block:: yaml - - # src/Acme/HelloBundle/Resources/config/validation.yml - Acme\HelloBundle\Entity\Address: - properties: - street: - - NotBlank: ~ - zipCode: - - NotBlank: ~ - - Length: - max: 5 - - Acme\HelloBundle\Entity\Author: - properties: - firstName: - - NotBlank: ~ - - Length: - min: 4 - lastName: - - NotBlank: ~ - .. code-block:: php-annotations // src/Acme/HelloBundle/Entity/Address.php @@ -112,6 +91,27 @@ an ``Address`` instance in the ``$address`` property. protected $address; } + .. code-block:: yaml + + # src/Acme/HelloBundle/Resources/config/validation.yml + Acme\HelloBundle\Entity\Address: + properties: + street: + - NotBlank: ~ + zipCode: + - NotBlank: ~ + - Length: + max: 5 + + Acme\HelloBundle\Entity\Author: + properties: + firstName: + - NotBlank: ~ + - Length: + min: 4 + lastName: + - NotBlank: ~ + .. code-block:: xml @@ -192,14 +192,6 @@ property. .. configuration-block:: - .. code-block:: yaml - - # src/Acme/HelloBundle/Resources/config/validation.yml - Acme\HelloBundle\Entity\Author: - properties: - address: - - Valid: ~ - .. code-block:: php-annotations // src/Acme/HelloBundle/Entity/Author.php @@ -215,6 +207,14 @@ property. protected $address; } + .. code-block:: yaml + + # src/Acme/HelloBundle/Resources/config/validation.yml + Acme\HelloBundle\Entity\Author: + properties: + address: + - Valid: ~ + .. code-block:: xml