diff --git a/book/controller.rst b/book/controller.rst index c8e01927de2..beb8386509d 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -156,9 +156,16 @@ to the controller: .. code-block:: xml - - AcmeHelloBundle:Hello:index - + + + + + AcmeHelloBundle:Hello:index + + .. code-block:: php @@ -235,10 +242,17 @@ example: .. code-block:: xml - - AcmeHelloBundle:Hello:index - green - + + + + + AcmeHelloBundle:Hello:index + green + + .. code-block:: php diff --git a/book/doctrine.rst b/book/doctrine.rst index a91c3368f7c..033a72447a9 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -80,15 +80,24 @@ information. By convention, this information is usually configured in an .. code-block:: xml - - - + + + + + + + + .. code-block:: php @@ -161,13 +170,22 @@ for you: .. code-block:: xml - - - + + + + + + + + .. code-block:: php @@ -299,6 +317,7 @@ in a number of different formats including YAML, XML or directly inside the .. code-block:: xml + + @@ -1332,9 +1353,11 @@ the current date, only when the entity is first persisted (i.e. inserted): .. code-block:: xml - - - + + diff --git a/book/forms.rst b/book/forms.rst index b23e895b1b6..e8836ebd9ed 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -357,8 +357,12 @@ object. .. code-block:: xml - - + + + @@ -1092,10 +1096,16 @@ easy to use in your application. .. code-block:: xml - - - + + + + + .. code-block:: php @@ -1548,12 +1558,20 @@ file: .. code-block:: xml - - - AcmeTaskBundle:Form:fields.html.twig - - - + + + + + + AcmeTaskBundle:Form:fields.html.twig + + + + .. code-block:: php @@ -1626,14 +1644,22 @@ file: .. code-block:: xml - - - - AcmeTaskBundle:Form - - - - + + + + + + + AcmeTaskBundle:Form + + + + + .. code-block:: php diff --git a/book/http_cache.rst b/book/http_cache.rst index 1856ee5ce80..c1c0b737bea 100644 --- a/book/http_cache.rst +++ b/book/http_cache.rst @@ -845,10 +845,19 @@ First, to use ESI, be sure to enable it in your application configuration: .. code-block:: xml - - - - + + + + + + + + + .. code-block:: php @@ -957,9 +966,17 @@ listener that must be enabled in your configuration: .. code-block:: xml - - - + + + + + + + .. code-block:: php diff --git a/book/http_fundamentals.rst b/book/http_fundamentals.rst index 8ead7a1299b..1654678bffc 100644 --- a/book/http_fundamentals.rst +++ b/book/http_fundamentals.rst @@ -429,9 +429,16 @@ by adding an entry for ``/contact`` to your routing configuration file: .. code-block:: xml - - AcmeDemoBundle:Main:contact - + + + + + AcmeDemoBundle:Main:contact + + .. code-block:: php diff --git a/book/internals.rst b/book/internals.rst index cc01001f1c3..5a7ebc0bfc8 100644 --- a/book/internals.rst +++ b/book/internals.rst @@ -563,20 +563,27 @@ the configuration for the development environment: .. code-block:: xml - - - - - - - - - - + + + + + + + + + + + .. code-block:: php @@ -611,10 +618,17 @@ If you enable the web profiler, you also need to mount the profiler routes: .. code-block:: xml - + + + + + .. code-block:: php diff --git a/book/page_creation.rst b/book/page_creation.rst index 2d3b776a7ae..0e482b683ad 100644 --- a/book/page_creation.rst +++ b/book/page_creation.rst @@ -147,7 +147,6 @@ an entry when you generated the ``AcmeHelloBundle``: - - - - + + + + + + + + + + + + + + + - - - - - - - - + .. code-block:: php @@ -972,18 +980,25 @@ the configuration file for the ``dev`` environment. .. code-block:: xml - - - - - - - - - - + + + + + + + + + + + + + .. code-block:: php diff --git a/book/propel.rst b/book/propel.rst index 900d0d81847..4c6443f9a01 100644 --- a/book/propel.rst +++ b/book/propel.rst @@ -90,7 +90,7 @@ of your ``AcmeStoreBundle``: .. code-block:: xml - + diff --git a/book/routing.rst b/book/routing.rst index c655932f0e9..ba116b044a9 100644 --- a/book/routing.rst +++ b/book/routing.rst @@ -166,10 +166,18 @@ file: .. code-block:: xml - - - - + + + + + + + + .. code-block:: php @@ -207,7 +215,6 @@ A basic route consists of just two parts: the ``path`` to match and a .. code-block:: xml - - - - - - - - - - - - - - - - + xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> @@ -311,16 +308,14 @@ First, enable form login under your firewall: .. code-block:: xml + - - - @@ -387,7 +382,6 @@ submission (i.e. ``/login_check``): - AcmeSecurityBundle:Security:login - + .. code-block:: php @@ -650,7 +644,7 @@ see :doc:`/cookbook/security/form_login`. - + .. code-block:: php @@ -1782,14 +1776,12 @@ a route so that you can use it to generate the URL: - - .. code-block:: php diff --git a/book/service_container.rst b/book/service_container.rst index 01c2e541426..c8e64bc7c4f 100644 --- a/book/service_container.rst +++ b/book/service_container.rst @@ -116,11 +116,17 @@ be specified in YAML, XML or PHP: .. code-block:: xml - - - sendmail - - + + + + + + sendmail + + + .. code-block:: php @@ -206,16 +212,22 @@ straightforward. Parameters make defining services more organized and flexible: .. code-block:: xml - - Acme\HelloBundle\Mailer - sendmail - - - - - %my_mailer.transport% - - + + + + + Acme\HelloBundle\Mailer + sendmail + + + + + %my_mailer.transport% + + + .. code-block:: php @@ -345,16 +357,22 @@ directories don't exist, create them. .. code-block:: xml - - Acme\HelloBundle\Mailer - sendmail - - - - - %my_mailer.transport% - - + + + + + Acme\HelloBundle\Mailer + sendmail + + + + + %my_mailer.transport% + + + .. code-block:: php @@ -385,9 +403,15 @@ configuration. .. code-block:: xml - - - + + + + + + + .. code-block:: php @@ -455,12 +479,20 @@ invokes the service container extension inside the ``FrameworkBundle``: .. code-block:: xml - - - - - - + + + + + + + + + + .. code-block:: php @@ -586,19 +618,25 @@ the service container gives you a much more appealing option: .. code-block:: xml - - - Acme\HelloBundle\Newsletter\NewsletterManager - - - - - - - - - - + + + + + + Acme\HelloBundle\Newsletter\NewsletterManager + + + + + + + + + + + .. code-block:: php @@ -677,21 +715,27 @@ Injecting the dependency by the setter method just needs a change of syntax: .. code-block:: xml - - - Acme\HelloBundle\Newsletter\NewsletterManager - - - - - - - - - - - - + + + + + + Acme\HelloBundle\Newsletter\NewsletterManager + + + + + + + + + + + + + .. code-block:: php @@ -744,15 +788,20 @@ it exists and do nothing if it doesn't: .. code-block:: xml - - - - - - - - - + + + + + + + + + + + + .. code-block:: php @@ -850,10 +899,16 @@ Configuring the service container is easy: .. code-block:: xml - - - - + + + + + + + + .. code-block:: php @@ -899,10 +954,16 @@ to be used for a specific purpose. Take the following example: .. code-block:: xml - - - + + + + + + + .. code-block:: php diff --git a/book/templating.rst b/book/templating.rst index 36f63d7d2b3..fa124e9eee8 100644 --- a/book/templating.rst +++ b/book/templating.rst @@ -719,9 +719,17 @@ tags: .. code-block:: xml - - - + + + + + + + .. code-block:: php @@ -747,10 +755,18 @@ in your application configuration: .. code-block:: xml - - - + + + + + + + .. code-block:: php @@ -834,9 +850,16 @@ configuration: .. code-block:: xml - - AcmeDemoBundle:Welcome:index - + + + + + AcmeDemoBundle:Welcome:index + + .. code-block:: php @@ -872,9 +895,16 @@ route: .. code-block:: xml - - AcmeArticleBundle:Article:show - + + + + + AcmeArticleBundle:Article:show + + .. code-block:: php @@ -1131,9 +1161,19 @@ configuration file: .. code-block:: xml - - - + + + + + + + + + .. code-block:: php diff --git a/book/testing.rst b/book/testing.rst index f012cbc4ae0..5ec4ebaf683 100644 --- a/book/testing.rst +++ b/book/testing.rst @@ -708,7 +708,13 @@ configuration option: .. code-block:: xml - + + + @@ -814,4 +820,4 @@ Learn more .. _`DemoControllerTest`: https://github.com/symfony/symfony-standard/blob/master/src/Acme/DemoBundle/Tests/Controller/DemoControllerTest.php .. _`$_SERVER`: http://php.net/manual/en/reserved.variables.server.php -.. _`documentation`: http://www.phpunit.de/manual/3.5/en/ +.. _`documentation`: http://phpunit.de/manual/current/en/ diff --git a/book/translation.rst b/book/translation.rst index 360c17b602b..fd1c71c2c8c 100644 --- a/book/translation.rst +++ b/book/translation.rst @@ -61,9 +61,17 @@ enable the ``Translator`` in your configuration: .. code-block:: xml - - - + + + + + + + .. code-block:: php @@ -333,6 +341,7 @@ taste. You can also store translations in a database, or any other storage by providing a custom class implementing the :class:`Symfony\\Component\\Translation\\Loader\\LoaderInterface` interface. + See the :ref:`dic-tags-translation-loader` tag for more information. .. index:: single: Translations; Creating translation resources @@ -546,9 +555,17 @@ by defining a ``default_locale`` for the framework: .. code-block:: xml - - en - + + + + + en + + .. code-block:: php @@ -590,11 +607,18 @@ by the routing system using the special ``_locale`` parameter: .. code-block:: xml - - AcmeDemoBundle:Contact:index - en - en|fr|de - + + + + + AcmeDemoBundle:Contact:index + en + en|fr|de + + .. code-block:: php diff --git a/book/validation.rst b/book/validation.rst index b541b41568c..5deeed0fcf0 100644 --- a/book/validation.rst +++ b/book/validation.rst @@ -130,9 +130,9 @@ simple example from inside a controller:: if (count($errors) > 0) { return new Response(print_r($errors, true)); - } else { - return new Response('The author is valid! Yes!'); } + + return new Response('The author is valid! Yes!'); } If the ``$name`` property is empty, you will see the following error @@ -161,9 +161,7 @@ You could also pass the collection of errors into a template. return $this->render('AcmeBlogBundle:Author:validate.html.twig', array( 'errors' => $errors, )); - } else { - // ... - } + } Inside the template, you can output the list of errors exactly as needed: @@ -261,9 +259,17 @@ annotations if you're using the annotation method to specify your constraints: .. code-block:: xml - - - + + + + + + + .. code-block:: php @@ -524,14 +530,20 @@ class to have at least 3 characters. .. code-block:: xml - - - - - - - - + + + + + + + + + + + + .. code-block:: php @@ -603,13 +615,19 @@ this method must return ``true``: .. code-block:: xml - - - - - - - + + + + + + + + + + + .. code-block:: php @@ -633,7 +651,7 @@ Now, create the ``isPasswordLegal()`` method, and include the logic you need:: public function isPasswordLegal() { - return ($this->firstName != $this->password); + return $this->firstName != $this->password; } .. note:: @@ -715,33 +733,39 @@ user registers and when a user updates his/her contact information later: .. code-block:: xml - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + .. code-block:: php @@ -872,26 +896,32 @@ username and the password are different only if all other validation passes .. code-block:: xml - - - - - - - - - - - - - - - User - Strict - - + + + + + + + + + + + + + + + + + + User + Strict + + + .. code-block:: php @@ -981,22 +1011,28 @@ entity and a new constraint group called ``Premium``: .. code-block:: xml - - - - - - - - - - - - + + + + + + + + + + + + + + + + .. code-block:: php @@ -1024,9 +1060,9 @@ entity and a new constraint group called ``Premium``: } Now, change the ``User`` class to implement -:class:`Symfony\\Component\\Validation\\GroupSequenceProviderInterface` and +:class:`Symfony\\Component\\Validator\\GroupSequenceProviderInterface` and add the -:method:`Symfony\\Component\\Validation\\GroupSequenceProviderInterface::getGroupSequence`, +:method:`Symfony\\Component\\Validator\\GroupSequenceProviderInterface::getGroupSequence`, which should return an array of groups to use. Also, add the ``@Assert\GroupSequenceProvider`` annotation to the class. If you imagine that a method called ``isPremium`` returns true if the user is a premium member, @@ -1036,7 +1072,7 @@ then your code might look like this:: namespace Acme\DemoBundle\Entity; // ... - use Symfony\Component\Validation\GroupSequenceProviderInterface; + use Symfony\Component\Validator\GroupSequenceProviderInterface; /** * @Assert\GroupSequenceProvider diff --git a/components/config/definition.rst b/components/config/definition.rst index d43aea02052..dc471b6dd20 100644 --- a/components/config/definition.rst +++ b/components/config/definition.rst @@ -490,7 +490,7 @@ By changing a string value into an associative array with ``name`` as the key:: ->children() ->arrayNode('connection') ->beforeNormalization() - ->ifString() + ->ifString() ->then(function($v) { return array('name'=> $v); }) ->end() ->children() diff --git a/components/dependency_injection/parameters.rst b/components/dependency_injection/parameters.rst index 129d766cd61..8722e962808 100644 --- a/components/dependency_injection/parameters.rst +++ b/components/dependency_injection/parameters.rst @@ -97,6 +97,27 @@ rather than being tied up and hidden with the service definition: ->register('mailer', 'Mailer') ->addArgument('%mailer.transport%'); +.. caution:: + + The values between ``parameter`` tags in XML configuration files are not + trimmed. + + This means that the following configuration sample will have the value + ``\n sendmail\n``: + + .. code-block:: xml + + + sendmail + + + In some cases (for constants or class names), this could throw errors. In + order to prevent this, you must always inline your parameters as follow: + + .. code-block:: xml + + sendmail + If you were using this elsewhere as well, then you would only need to change the parameter value in one place if needed. @@ -264,3 +285,72 @@ key, and define the type as ``constant``. # app/config/config.yml imports: - { resource: parameters.xml } + +PHP Keywords in XML +------------------- + +By default, ``true``, ``false`` and ``null`` in XML are converted to the PHP +keywords (respectively ``true``, ``false`` and ``null``): + +.. code-block:: xml + + + false + + + + +To disable this behavior, use the ``string`` type: + +.. code-block:: xml + + + true + + + + +.. note:: + + This is not available for Yaml and PHP, because they already have built-in + support for the PHP keywords. + +Syntax for Referencing Services +------------------------------- + +You can of course also reference services, which looks a bit different in +each format. You can configure the behavior if the referenced service does +not exist. By default, an exception is thrown when a non-existent service +is referenced. + +Yaml +~~~~ + +Start the string with ``@`` or ``@?`` to reference a service in Yaml. + +* ``@mailer`` references the ``mailer`` service. If the service does not + exists, an exception will be thrown; +* ``@?mailer`` references the ``mailer`` service. If the service does not + exists, it will be ignored; + +Xml +~~~ + +In XML, use the ``service`` type. The behavior if the service does not exist +can be specified using the ``on-invalid`` argument. By default, an exception +is thrown. Valid values for ``on-invalid`` are ``null`` (uses ``null`` in place +of the missing service) or ``ignored`` (very similar, except if used on a +method call, the method call is removed). + +Php +~~~ + +In PHP, you can use the +:class:`Symfony\\Component\\DependencyInjection\\Reference` class to reference +a service. The invalid behavior is configured using the second constructor +argument and constants from +:class:`Symfony\\Component\\DependencyInjection\\ContainerInterface`. diff --git a/contributing/code/standards.rst b/contributing/code/standards.rst index 49f92b77035..de074474756 100644 --- a/contributing/code/standards.rst +++ b/contributing/code/standards.rst @@ -68,15 +68,12 @@ example containing most features described below: } if ('string' === $dummy) { if ('values' === $mergedOptions['some_default']) { - $dummy = substr($dummy, 0, 5); - } else { - $dummy = ucwords($dummy); + return substr($dummy, 0, 5); } - } else { - throw new \RuntimeException(sprintf('Unrecognized dummy option "%s"', $dummy)); + + return ucwords($dummy); } - - return $dummy; + throw new \RuntimeException(sprintf('Unrecognized dummy option "%s"', $dummy)); } } diff --git a/cookbook/assetic/uglifyjs.rst b/cookbook/assetic/uglifyjs.rst index c97368e6028..0fa70ba3306 100644 --- a/cookbook/assetic/uglifyjs.rst +++ b/cookbook/assetic/uglifyjs.rst @@ -230,13 +230,13 @@ helper: .. code-block:: html+jinja - {% javascripts '@AcmeFooBundle/Resources/public/css/*' filter='uglifycss' %} + {% stylesheets '@AcmeFooBundle/Resources/public/css/*' filter='uglifycss' %} - {% endjavascripts %} + {% endstylesheets %} .. code-block:: html+php - javascripts( + stylesheets( array('@AcmeFooBundle/Resources/public/css/*'), array('uglifycss') ) as $url): ?> diff --git a/cookbook/bundles/extension.rst b/cookbook/bundles/extension.rst index 3ea0fca18bb..9a565b0b0c5 100644 --- a/cookbook/bundles/extension.rst +++ b/cookbook/bundles/extension.rst @@ -62,7 +62,8 @@ When you create a bundle, you have two choices on how to handle configuration: The second option - which you'll learn about in this article - is much more flexible, but also requires more time to setup. If you're wondering which method you should use, it's probably a good idea to start with method #1, -and then change to #2 later if you need to. +and then change to #2 later if you need to. If you plan to distribute your +bundle, the second option is recommended. The second method has several specific advantages: diff --git a/cookbook/doctrine/reverse_engineering.rst b/cookbook/doctrine/reverse_engineering.rst index f915a37ce44..0c5c22c355e 100644 --- a/cookbook/doctrine/reverse_engineering.rst +++ b/cookbook/doctrine/reverse_engineering.rst @@ -56,11 +56,11 @@ folder. The first step towards building entity classes from an existing database is to ask Doctrine to introspect the database and generate the corresponding metadata files. Metadata files describe the entity class to generate based on -tables fields. +table fields. .. code-block:: bash - $ php app/console doctrine:mapping:convert xml ./src/Acme/BlogBundle/Resources/config/doctrine --from-database --force + $ php app/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`` @@ -69,8 +69,8 @@ folder of your bundle. This generates two files: ``BlogPost.orm.xml`` and .. tip:: - It's also possible to generate metadata class in YAML format by changing the - first argument to ``yml``. + It's also possible to generate the metadata files in YAML format by changing + the last argument to ``yml``. The generated ``BlogPost.orm.xml`` metadata file looks as follows: @@ -78,7 +78,7 @@ The generated ``BlogPost.orm.xml`` metadata file looks as follows: - + @@ -88,13 +88,6 @@ The generated ``BlogPost.orm.xml`` metadata file looks as follows: -Update the namespace in the ``name`` attribute of the ``entity`` element like -this: - -.. code-block:: xml - - - Once the metadata files are generated, you can ask Doctrine to build related entity classes by executing the following two commands. @@ -103,14 +96,14 @@ entity classes by executing the following two commands. $ php app/console doctrine:mapping:convert annotation ./src $ php app/console doctrine:generate:entities AcmeBlogBundle -The first command generates entity classes with an annotations mapping. But +The first command generates entity classes with annotation mappings. But if you want to use yml or xml mapping instead of annotations, you should execute the second command only. .. tip:: - If you want to use annotations, you can safely delete the XML files after - running these two commands. + If you want to use annotations, you can safely delete the XML (or YAML) files + after running these two commands. For example, the newly created ``BlogComment`` entity class looks as follow:: diff --git a/cookbook/form/unit_testing.rst b/cookbook/form/unit_testing.rst index a17ad3d72da..35d21c54c6f 100644 --- a/cookbook/form/unit_testing.rst +++ b/cookbook/form/unit_testing.rst @@ -77,7 +77,7 @@ be the first test you write:: $form = $this->factory->create($type); This test checks that none of your data transformers used by the form -failed. The :method:`Symfony\\Component\\Form\\FormInterface::isSynchronized`` +failed. The :method:`Symfony\\Component\\Form\\FormInterface::isSynchronized` method is only set to ``false`` if a data transformer throws an exception:: $form->submit($formData); diff --git a/cookbook/validation/custom_constraint.rst b/cookbook/validation/custom_constraint.rst index 04311ee17d8..6cb2f45f581 100644 --- a/cookbook/validation/custom_constraint.rst +++ b/cookbook/validation/custom_constraint.rst @@ -52,7 +52,7 @@ In other words, if you create a custom ``Constraint`` (e.g. ``MyConstraint``), Symfony2 will automatically look for another class, ``MyConstraintValidator`` when actually performing the validation. -The validator class is also simple, and only has one required method: ``validate``:: +The validator class is also simple, and only has one required method ``validate()``:: // src/Acme/DemoBundle/Validator/Constraints/ContainsAlphanumericValidator.php namespace Acme\DemoBundle\Validator\Constraints; @@ -202,7 +202,7 @@ Class Constraint Validator ~~~~~~~~~~~~~~~~~~~~~~~~~~ Beside validating a class property, a constraint can have a class scope by -providing a target:: +providing a target in its ``Constraint`` class:: public function getTargets() { diff --git a/quick_tour/the_big_picture.rst b/quick_tour/the_big_picture.rst index 72e6d21ab78..9ba1161c7a6 100644 --- a/quick_tour/the_big_picture.rst +++ b/quick_tour/the_big_picture.rst @@ -75,10 +75,10 @@ If you have PHP 5.4, you can use the built-in web server: .. code-block:: bash # check your PHP CLI configuration - $ php php app/check.php + $ php app/check.php # run the built-in web server - $ php php app/console server:run + $ php app/console server:run Then the URL to your application will be "http://localhost:8000/app_dev.php" diff --git a/reference/configuration/doctrine.rst b/reference/configuration/doctrine.rst index c2115238e27..2a9ce3b0151 100644 --- a/reference/configuration/doctrine.rst +++ b/reference/configuration/doctrine.rst @@ -170,6 +170,7 @@ Doctrine Configuration Reference .. code-block:: xml + - Acme\HelloBundle\DQL\NumericFunction - Acme\HelloBundle\DQL\StringFunction + Acme\HelloBundle\DQL\NumericFunction + Acme\HelloBundle\DQL\DatetimeFunction diff --git a/reference/dic_tags.rst b/reference/dic_tags.rst index ca23140ddcb..5ec44025adb 100644 --- a/reference/dic_tags.rst +++ b/reference/dic_tags.rst @@ -886,6 +886,8 @@ templates): ->addTag('templating.helper', array('alias' => 'alias_name')) ; +.. _dic-tags-translation-loader: + translation.loader ------------------