diff --git a/best_practices/business-logic.rst b/best_practices/business-logic.rst index 8f22e5efb22..d25a457314b 100644 --- a/best_practices/business-logic.rst +++ b/best_practices/business-logic.rst @@ -57,9 +57,7 @@ The blog application needs a utility that can transform a post title (e.g. part of the post URL. Let's create a new ``Slugger`` class inside ``src/AppBundle/Utils/`` and -add the following ``slugify()`` method: - -.. code-block:: php +add the following ``slugify()`` method:: // src/AppBundle/Utils/Slugger.php namespace AppBundle\Utils; @@ -96,9 +94,7 @@ your code will be easier to read and use. you ever need to. Now you can use the custom slugger in any controller class, such as the -``AdminController``: - -.. code-block:: php +``AdminController``:: public function createAction(Request $request) { @@ -203,9 +199,7 @@ PHP and annotations. Use annotations to define the mapping information of the Doctrine entities. Annotations are by far the most convenient and agile way of setting up and -looking for mapping information: - -.. code-block:: php +looking for mapping information:: namespace AppBundle\Entity; @@ -284,9 +278,7 @@ the following command to install the Doctrine fixtures bundle: $ composer require "doctrine/doctrine-fixtures-bundle" Then, enable the bundle in ``AppKernel.php``, but only for the ``dev`` and -``test`` environments: - -.. code-block:: php +``test`` environments:: use Symfony\Component\HttpKernel\Kernel; diff --git a/best_practices/configuration.rst b/best_practices/configuration.rst index 3bff5b2dda4..e4f4907b7e3 100644 --- a/best_practices/configuration.rst +++ b/best_practices/configuration.rst @@ -133,9 +133,7 @@ Constants can be used for example in your Twig templates thanks to the

And Doctrine entities and repositories can now easily access these values, -whereas they cannot access the container parameters: - -.. code-block:: php +whereas they cannot access the container parameters:: namespace AppBundle\Repository; diff --git a/best_practices/controllers.rst b/best_practices/controllers.rst index d40c7406c8c..000293ae1dd 100644 --- a/best_practices/controllers.rst +++ b/best_practices/controllers.rst @@ -89,9 +89,7 @@ What does the Controller look like ---------------------------------- Considering all this, here is an example of what the controller should look like -for the homepage of our app: - -.. code-block:: php +for the homepage of our app:: namespace AppBundle\Controller; @@ -129,9 +127,7 @@ to automatically query for an entity and pass it as an argument to your controll Use the ParamConverter trick to automatically query for Doctrine entities when it's simple and convenient. -For example: - -.. code-block:: php +For example:: use AppBundle\Entity\Post; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; @@ -161,9 +157,7 @@ When Things Get More Advanced The above example works without any configuration because the wildcard name ``{id}`` matches the name of the property on the entity. If this isn't true, or if you have even more complex logic, the easiest thing to do is just query for the entity -manually. In our application, we have this situation in ``CommentController``: - -.. code-block:: php +manually. In our application, we have this situation in ``CommentController``:: /** * @Route("/comment/{postSlug}/new", name="comment_new") @@ -182,9 +176,7 @@ manually. In our application, we have this situation in ``CommentController``: } You can also use the ``@ParamConverter`` configuration, which is infinitely -flexible: - -.. code-block:: php +flexible:: use AppBundle\Entity\Post; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; diff --git a/best_practices/forms.rst b/best_practices/forms.rst index a53b7f35c6f..ef1595e7797 100644 --- a/best_practices/forms.rst +++ b/best_practices/forms.rst @@ -94,9 +94,7 @@ makes them easier to re-use later. Since Symfony 2.3, you can add buttons as fields on your form. This is a nice way to simplify the template that renders your form. But if you add the buttons -directly in your form class, this would effectively limit the scope of that form: - -.. code-block:: php +directly in your form class, this would effectively limit the scope of that form:: class PostType extends AbstractType { @@ -178,9 +176,7 @@ can control *how* the form renders at a global level using form theming. Handling Form Submits --------------------- -Handling a form submit usually follows a similar template: - -.. code-block:: php +Handling a form submit usually follows a similar template:: public function newAction(Request $request) { diff --git a/best_practices/security.rst b/best_practices/security.rst index e05a6cb72d4..939fb70cf42 100644 --- a/best_practices/security.rst +++ b/best_practices/security.rst @@ -130,9 +130,7 @@ Using Expressions for Complex Security Restrictions If your security logic is a little bit more complex, you can use an :doc:`expression ` inside ``@Security``. In the following example, a user can only access the controller if their email matches the value returned by the ``getAuthorEmail()`` -method on the ``Post`` object: - -.. code-block:: php +method on the ``Post`` object:: use AppBundle\Entity\Post; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; @@ -163,9 +161,7 @@ need to repeat the expression code using Twig syntax: {% endif %} The easiest solution - if your logic is simple enough - is to add a new method -to the ``Post`` entity that checks if a given user is its author: - -.. code-block:: php +to the ``Post`` entity that checks if a given user is its author:: // src/AppBundle/Entity/Post.php // ... @@ -185,9 +181,7 @@ to the ``Post`` entity that checks if a given user is its author: } } -Now you can reuse this method both in the template and in the security expression: - -.. code-block:: php +Now you can reuse this method both in the template and in the security expression:: use AppBundle\Entity\Post; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; @@ -217,9 +211,7 @@ Checking Permissions without @Security The above example with ``@Security`` only works because we're using the :ref:`ParamConverter `, which gives the expression access to the ``post`` variable. If you don't use this, or have some other -more advanced use-case, you can always do the same security check in PHP: - -.. code-block:: php +more advanced use-case, you can always do the same security check in PHP:: /** * @Route("/{id}/edit", name="admin_post_edit") @@ -257,9 +249,7 @@ of magnitude easier than :doc:`ACLs ` and will give you the flexibility you need in almost all cases. First, create a voter class. The following example shows a voter that implements -the same ``getAuthorEmail()`` logic you used above: - -.. code-block:: php +the same ``getAuthorEmail()`` logic you used above:: namespace AppBundle\Security; @@ -313,9 +303,7 @@ To enable the security voter in the application, define a new service: tags: - { name: security.voter } -Now, you can use the voter with the ``@Security`` annotation: - -.. code-block:: php +Now, you can use the voter with the ``@Security`` annotation:: /** * @Route("/{id}/edit", name="admin_post_edit") @@ -327,9 +315,7 @@ Now, you can use the voter with the ``@Security`` annotation: } You can also use this directly with the ``security.authorization_checker`` service or -via the even easier shortcut in a controller: - -.. code-block:: php +via the even easier shortcut in a controller:: /** * @Route("/{id}/edit", name="admin_post_edit") diff --git a/best_practices/templates.rst b/best_practices/templates.rst index e3aebd3204f..26219bf815b 100644 --- a/best_practices/templates.rst +++ b/best_practices/templates.rst @@ -115,9 +115,7 @@ Markdown content into HTML:: Next, create a new Twig extension and define a new filter called ``md2html`` using the ``Twig_SimpleFilter`` class. Inject the newly defined ``markdown`` -service in the constructor of the Twig extension: - -.. code-block:: php +service in the constructor of the Twig extension:: namespace AppBundle\Twig; diff --git a/best_practices/tests.rst b/best_practices/tests.rst index 1f41afb9de7..6cf6bd88225 100644 --- a/best_practices/tests.rst +++ b/best_practices/tests.rst @@ -80,9 +80,7 @@ generator service: generator. Consider the following functional test that uses the ``router`` service to -generate the URL of the tested page: - -.. code-block:: php +generate the URL of the tested page:: public function testBlogArchives() { diff --git a/components/config/definition.rst b/components/config/definition.rst index 559ed61c0dd..48d4abdb6d8 100644 --- a/components/config/definition.rst +++ b/components/config/definition.rst @@ -417,9 +417,7 @@ Documenting the Option All options can be documented using the :method:`Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::info` -method. - -.. code-block:: php +method:: $rootNode ->children() diff --git a/components/dom_crawler.rst b/components/dom_crawler.rst index 7883028cf0d..bf98ddecf57 100644 --- a/components/dom_crawler.rst +++ b/components/dom_crawler.rst @@ -260,9 +260,7 @@ The crawler supports multiple ways of adding the content:: As the Crawler's implementation is based on the DOM extension, it is also able to interact with native :phpclass:`DOMDocument`, :phpclass:`DOMNodeList` -and :phpclass:`DOMNode` objects: - -.. code-block:: php +and :phpclass:`DOMNode` objects:: $document = new \DOMDocument(); $document->loadXml(''); diff --git a/components/expression_language/extending.rst b/components/expression_language/extending.rst index 5c681a6e671..690990ea223 100644 --- a/components/expression_language/extending.rst +++ b/components/expression_language/extending.rst @@ -68,9 +68,7 @@ This interface requires one method: :method:`Symfony\\Component\\ExpressionLanguage\\ExpressionFunctionProviderInterface::getFunctions`, which returns an array of expression functions (instances of :class:`Symfony\\Component\\ExpressionLanguage\\ExpressionFunction`) to -register. - -.. code-block:: php +register:: use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; diff --git a/components/filesystem/lock_handler.rst b/components/filesystem/lock_handler.rst index 47bd2e2f9c3..0639dfee6a6 100644 --- a/components/filesystem/lock_handler.rst +++ b/components/filesystem/lock_handler.rst @@ -22,9 +22,7 @@ Usage The lock handler only works if you're using just one server. If you have several hosts, you must not use this helper. -A lock can be used, for example, to allow only one instance of a command to run. - -.. code-block:: php +A lock can be used, for example, to allow only one instance of a command to run:: use Symfony\Component\Filesystem\LockHandler; diff --git a/components/http_foundation/trusting_proxies.rst b/components/http_foundation/trusting_proxies.rst index 13dda122fc7..8c9687aeb2a 100644 --- a/components/http_foundation/trusting_proxies.rst +++ b/components/http_foundation/trusting_proxies.rst @@ -17,9 +17,7 @@ the actual host may be stored in an ``X-Forwarded-Host`` header. Since HTTP headers can be spoofed, Symfony does *not* trust these proxy headers by default. If you are behind a proxy, you should manually whitelist -your proxy as follows: - -.. code-block:: php +your proxy as follows:: use Symfony\Component\HttpFoundation\Request; diff --git a/components/process.rst b/components/process.rst index daef81e637b..c6df3a06aaf 100644 --- a/components/process.rst +++ b/components/process.rst @@ -310,9 +310,7 @@ Process Pid The ``getPid()`` method was introduced in Symfony 2.3. You can access the `pid`_ of a running process with the -:method:`Symfony\\Component\\Process\\Process::getPid` method. - -.. code-block:: php +:method:`Symfony\\Component\\Process\\Process::getPid` method:: use Symfony\Component\Process\Process; diff --git a/components/templating.rst b/components/templating.rst index 98ea31eb2dc..70229fce5a1 100644 --- a/components/templating.rst +++ b/components/templating.rst @@ -188,9 +188,7 @@ takes a list of engines and acts just like a normal templating engine. The only difference is that it delegates the calls to one of the other engines. To choose which one to use for the template, the :method:`EngineInterface::supports() ` -method is used. - -.. code-block:: php +method is used:: use Acme\Templating\CustomEngine; use Symfony\Component\Templating\PhpEngine; diff --git a/components/translation.rst b/components/translation.rst index 30b69797414..91a64c68227 100644 --- a/components/translation.rst +++ b/components/translation.rst @@ -29,9 +29,7 @@ catalogs*). Configuration ~~~~~~~~~~~~~ -The constructor of the ``Translator`` class needs one argument: The locale. - -.. code-block:: php +The constructor of the ``Translator`` class needs one argument: The locale:: use Symfony\Component\Translation\Translator; diff --git a/components/yaml.rst b/components/yaml.rst index 93a8448609b..c96ccbf9afe 100644 --- a/components/yaml.rst +++ b/components/yaml.rst @@ -96,9 +96,7 @@ Reading YAML Files ~~~~~~~~~~~~~~~~~~ The :method:`Symfony\\Component\\Yaml\\Yaml::parse` method parses a YAML -string and converts it to a PHP array: - -.. code-block:: php +string and converts it to a PHP array:: use Symfony\Component\Yaml\Yaml; @@ -113,9 +111,7 @@ string and converts it to a PHP array: If an error occurs during parsing, the parser throws a :class:`Symfony\\Component\\Yaml\\Exception\\ParseException` exception indicating the error type and the line in the original YAML string where the -error occurred: - -.. code-block:: php +error occurred:: use Symfony\Component\Yaml\Exception\ParseException; @@ -145,9 +141,7 @@ Writing YAML Files ~~~~~~~~~~~~~~~~~~ The :method:`Symfony\\Component\\Yaml\\Yaml::dump` method dumps any PHP -array to its YAML representation: - -.. code-block:: php +array to its YAML representation:: use Symfony\Component\Yaml\Yaml; @@ -179,9 +173,7 @@ representation: The second argument of the :method:`Symfony\\Component\\Yaml\\Yaml::dump` method customizes the level at which the output switches from the expanded -representation to the inline one: - -.. code-block:: php +representation to the inline one:: echo Yaml::dump($array, 1); diff --git a/components/yaml/yaml_format.rst b/components/yaml/yaml_format.rst index 9e4b8219778..357cfdcac70 100644 --- a/components/yaml/yaml_format.rst +++ b/components/yaml/yaml_format.rst @@ -177,9 +177,7 @@ Sequences use a dash followed by a space: - Perl - Python -The previous YAML file is equivalent to the following PHP code: - -.. code-block:: php +The previous YAML file is equivalent to the following PHP code:: array('PHP', 'Perl', 'Python'); @@ -191,9 +189,7 @@ Mappings use a colon followed by a space (``:`` ) to mark each key/value pair: MySQL: 5.1 Apache: 2.2.20 -which is equivalent to this PHP code: - -.. code-block:: php +which is equivalent to this PHP code:: array('PHP' => 5.2, 'MySQL' => 5.1, 'Apache' => '2.2.20'); @@ -220,9 +216,7 @@ YAML uses indentation with one or more spaces to describe nested collections: PHP: 5.2 Propel: 1.3 -The above YAML is equivalent to the following PHP code: - -.. code-block:: php +The above YAML is equivalent to the following PHP code:: array( 'symfony 1.0' => array( diff --git a/configuration/environments.rst b/configuration/environments.rst index d7f4394a964..ea430a6beb1 100644 --- a/configuration/environments.rst +++ b/configuration/environments.rst @@ -31,9 +31,7 @@ are used: * for the ``test`` environment: ``app/config/config_test.yml`` This works via a simple standard that's used by default inside the ``AppKernel`` -class: - -.. code-block:: php +class:: // app/AppKernel.php diff --git a/configuration/external_parameters.rst b/configuration/external_parameters.rst index 93ee262ed91..68a629558bd 100644 --- a/configuration/external_parameters.rst +++ b/configuration/external_parameters.rst @@ -124,7 +124,7 @@ You can now reference these parameters wherever you need them. - .. code-block:: php + :: $container->loadFromExtension('doctrine', array( 'dbal' => array( @@ -184,9 +184,7 @@ in the container. The following imports a file named ``parameters.php``. In ``parameters.php``, tell the service container the parameters that you wish to set. This is useful when important configuration is in a non-standard format. The example below includes a Drupal database configuration in -the Symfony service container. - -.. code-block:: php +the Symfony service container:: // app/config/parameters.php include_once('/path/to/drupal/sites/default/settings.php'); diff --git a/contributing/documentation/standards.rst b/contributing/documentation/standards.rst index ec65cc08538..b0471945feb 100644 --- a/contributing/documentation/standards.rst +++ b/contributing/documentation/standards.rst @@ -13,8 +13,8 @@ Sphinx * Each line should break approximately after the first word that crosses the 72nd character (so most lines end up being 72-78 characters); * The ``::`` shorthand is *preferred* over ``.. code-block:: php`` to begin a PHP - code block (read `the Sphinx documentation`_ to see when you should use the - shorthand); + code block unless it results in the marker being on its own line (read + `the Sphinx documentation`_ to see when you should use the shorthand); * Inline hyperlinks are **not** used. Separate the link and their target definition, which you add on the bottom of the page; * Inline markup should be closed on the same line as the open-string; diff --git a/controller.rst b/controller.rst index 8048b005f45..07d5c374f67 100644 --- a/controller.rst +++ b/controller.rst @@ -308,9 +308,7 @@ method is just a shortcut to create a special object, which ultimately triggers a 404 HTTP response inside Symfony. Of course, you're free to throw any ``Exception`` class in your controller - -Symfony will automatically return a 500 HTTP response code. - -.. code-block:: php +Symfony will automatically return a 500 HTTP response code:: throw new \Exception('Something went wrong!'); diff --git a/controller/soap_web_service.rst b/controller/soap_web_service.rst index 47908796beb..954f89556ee 100644 --- a/controller/soap_web_service.rst +++ b/controller/soap_web_service.rst @@ -92,9 +92,7 @@ a ``HelloService`` object properly: Below is an example of a controller that is capable of handling a SOAP request. If ``indexAction()`` is accessible via the route ``/soap``, then the -WSDL document can be retrieved via ``/soap?wsdl``. - -.. code-block:: php +WSDL document can be retrieved via ``/soap?wsdl``:: namespace Acme\SoapBundle\Controller; diff --git a/doctrine/repository.rst b/doctrine/repository.rst index 8a97ed1f638..4d69b2699a4 100644 --- a/doctrine/repository.rst +++ b/doctrine/repository.rst @@ -58,9 +58,7 @@ from ``Doctrine\ORM\EntityRepository``. Next, add a new method - ``findAllOrderedByName()`` - to the newly-generated ``ProductRepository`` class. This method will query for all the ``Product`` -entities, ordered alphabetically by name. - -.. code-block:: php +entities, ordered alphabetically by name:: // src/AppBundle/Repository/ProductRepository.php namespace AppBundle\Repository; diff --git a/email/dev_environment.rst b/email/dev_environment.rst index fc5919ceb94..739c9fe9f8b 100644 --- a/email/dev_environment.rst +++ b/email/dev_environment.rst @@ -95,9 +95,7 @@ via the ``delivery_addresses`` option: 'delivery_addresses' => array("dev@example.com"), )); -Now, suppose you're sending an email to ``recipient@example.com``. - -.. code-block:: php +Now, suppose you're sending an email to ``recipient@example.com``:: public function indexAction($name) { diff --git a/event_dispatcher/class_extension.rst b/event_dispatcher/class_extension.rst index 7fc89671c54..776ee1b92e1 100644 --- a/event_dispatcher/class_extension.rst +++ b/event_dispatcher/class_extension.rst @@ -5,9 +5,7 @@ How to Extend a Class without Using Inheritance =============================================== To allow multiple classes to add methods to another one, you can define the -magic ``__call()`` method in the class you want to be extended like this: - -.. code-block:: php +magic ``__call()`` method in the class you want to be extended like this:: class Foo { @@ -31,9 +29,7 @@ magic ``__call()`` method in the class you want to be extended like this: This uses a special ``HandleUndefinedMethodEvent`` that should also be created. This is a generic class that could be reused each time you need to -use this pattern of class extension: - -.. code-block:: php +use this pattern of class extension:: use Symfony\Component\EventDispatcher\Event; @@ -89,9 +85,7 @@ use this pattern of class extension: } Next, create a class that will listen to the ``foo.method_is_not_found`` event -and *add* the method ``bar()``: - -.. code-block:: php +and *add* the method ``bar()``:: class Bar { @@ -117,9 +111,7 @@ and *add* the method ``bar()``: } Finally, add the new ``bar()`` method to the ``Foo`` class by registering an -instance of ``Bar`` with the ``foo.method_is_not_found`` event: - -.. code-block:: php +instance of ``Bar`` with the ``foo.method_is_not_found`` event:: $bar = new Bar(); $dispatcher->addListener('foo.method_is_not_found', array($bar, 'onFooMethodIsNotFound')); diff --git a/event_dispatcher/method_behavior.rst b/event_dispatcher/method_behavior.rst index 3b25b0deb1a..c637bce93b6 100644 --- a/event_dispatcher/method_behavior.rst +++ b/event_dispatcher/method_behavior.rst @@ -44,9 +44,7 @@ in this example, the variables ``$foo``, ``$bar`` and ``$ret`` to be retrieved and set by the listeners. For example, assuming the ``FilterSendReturnValue`` has a ``setReturnValue()`` -method, one listener might look like this: - -.. code-block:: php +method, one listener might look like this:: public function onFooPostSend(FilterSendReturnValue $event) { diff --git a/form/form_customization.rst b/form/form_customization.rst index d67d19a2cbf..5bbf593fc99 100644 --- a/form/form_customization.rst +++ b/form/form_customization.rst @@ -382,9 +382,7 @@ When the ``form.age`` widget is rendered, Symfony will use the customized the ``div`` element. If you want to apply a theme to a specific child form, pass it to the ``setTheme()`` -method: - -.. code-block:: php +method:: setTheme($form['child'], ':form'); ?> diff --git a/form/validation_group_service_resolver.rst b/form/validation_group_service_resolver.rst index 79d0791d1eb..ec575067696 100644 --- a/form/validation_group_service_resolver.rst +++ b/form/validation_group_service_resolver.rst @@ -4,9 +4,7 @@ How to Dynamically Configure Form Validation Groups Sometimes you need advanced logic to determine the validation groups. If they can't be determined by a simple callback, you can use a service. Create a service that implements ``__invoke()`` which accepts a ``FormInterface`` as a -parameter. - -.. code-block:: php +parameter:: // src/AppBundle/Validation/ValidationGroupResolver.php namespace AppBundle\Validation; @@ -39,9 +37,7 @@ parameter. } } -Then in your form, inject the resolver and set it as the ``validation_groups``. - -.. code-block:: php +Then in your form, inject the resolver and set it as the ``validation_groups``:: // src/AppBundle/Form/MyClassType.php; namespace AppBundle\Form; diff --git a/form/without_class.rst b/form/without_class.rst index 9ad72ee7346..c4715af32dc 100644 --- a/form/without_class.rst +++ b/form/without_class.rst @@ -77,9 +77,7 @@ your form? The answer is to setup the constraints yourself, and attach them to the individual fields. The overall approach is covered a bit more in :doc:`this validation article `, -but here's a short example: - -.. code-block:: php +but here's a short example:: use Symfony\Component\Validator\Constraints\Length; use Symfony\Component\Validator\Constraints\NotBlank; diff --git a/http_cache/esi.rst b/http_cache/esi.rst index 61b4e4cc279..de68875293f 100644 --- a/http_cache/esi.rst +++ b/http_cache/esi.rst @@ -95,9 +95,7 @@ First, to use ESI, be sure to enable it in your application configuration: Now, suppose you have a page that is relatively static, except for a news ticker at the bottom of the content. With ESI, you can cache the news ticker -independent of the rest of the page. - -.. code-block:: php +independent of the rest of the page:: // src/AppBundle/Controller/DefaultController.php @@ -191,9 +189,7 @@ used ``render()``. proxy. The embedded action can now specify its own caching rules, entirely independent -of the master page. - -.. code-block:: php +of the master page:: // src/AppBundle/Controller/NewsController.php namespace AppBundle\Controller; diff --git a/logging/processors.rst b/logging/processors.rst index 78fe83ec3b9..61df235f2a8 100644 --- a/logging/processors.rst +++ b/logging/processors.rst @@ -14,9 +14,7 @@ Adding a Session/Request Token Sometimes it is hard to tell which entries in the log belong to which session and/or request. The following example will add a unique token for each request -using a processor. - -.. code-block:: php +using a processor:: namespace AppBundle\Logger; diff --git a/reference/constraints/Choice.rst b/reference/constraints/Choice.rst index 57b82e1f0aa..d7a5912940a 100644 --- a/reference/constraints/Choice.rst +++ b/reference/constraints/Choice.rst @@ -129,9 +129,7 @@ Supplying the Choices with a Callback Function You can also use a callback function to specify your options. This is useful if you want to keep your choices in some central location so that, for example, you can easily access those choices for validation or for building a select -form element. - -.. code-block:: php +form element:: // src/AppBundle/Entity/Author.php namespace AppBundle\Entity; diff --git a/reference/constraints/Valid.rst b/reference/constraints/Valid.rst index 3e3c8d70ba9..b97744a27fe 100644 --- a/reference/constraints/Valid.rst +++ b/reference/constraints/Valid.rst @@ -22,9 +22,7 @@ Basic Usage In the following example, create two classes ``Author`` and ``Address`` that both have constraints on their properties. Furthermore, ``Author`` -stores an ``Address`` instance in the ``$address`` property. - -.. code-block:: php +stores an ``Address`` instance in the ``$address`` property:: // src/AppBundle/Entity/Address.php namespace AppBundle\Entity; diff --git a/reference/forms/types/options/choice_value.rst.inc b/reference/forms/types/options/choice_value.rst.inc index 78ab46650ce..b75c30f150a 100644 --- a/reference/forms/types/options/choice_value.rst.inc +++ b/reference/forms/types/options/choice_value.rst.inc @@ -16,9 +16,7 @@ integer is used as the value. If you pass a callable, it will receive one argument: the choice itself. When using the :doc:`/reference/forms/types/entity`, the argument will be the entity object -for each choice or ``null`` in some cases, which you need to handle: - -.. code-block:: php +for each choice or ``null`` in some cases, which you need to handle:: 'choice_value' => function (MyOptionEntity $entity = null) { return $entity ? $entity->getId() : ''; diff --git a/reference/forms/types/options/data_class.rst.inc b/reference/forms/types/options/data_class.rst.inc index 7fc8fa1df74..2cfc3bbc6e7 100644 --- a/reference/forms/types/options/data_class.rst.inc +++ b/reference/forms/types/options/data_class.rst.inc @@ -4,9 +4,7 @@ data_class **type**: ``string`` This option is used to set the appropriate data mapper to be used by the -form, so you can use it for any form field type which requires an object. - -.. code-block:: php +form, so you can use it for any form field type which requires an object:: use AppBundle\Entity\Media; // ... diff --git a/routing/hostname_pattern.rst b/routing/hostname_pattern.rst index 27de3228387..79d50cb12ae 100644 --- a/routing/hostname_pattern.rst +++ b/routing/hostname_pattern.rst @@ -408,9 +408,7 @@ Testing your Controllers ------------------------ You need to set the Host HTTP header on your request objects if you want to get -past url matching in your functional tests. - -.. code-block:: php +past url matching in your functional tests:: $crawler = $client->request( 'GET', diff --git a/security/access_denied_handler.rst b/security/access_denied_handler.rst index 132346a4c44..ab79ec71808 100644 --- a/security/access_denied_handler.rst +++ b/security/access_denied_handler.rst @@ -43,9 +43,7 @@ Your handler must implement the :class:`Symfony\\Component\\Security\\Http\\Authorization\\AccessDeniedHandlerInterface`. This interface defines one method called ``handle()`` that implements the logic to execute when access is denied to the current user (send a mail, log a message, or -generally return a custom response). - -.. code-block:: php +generally return a custom response):: namespace AppBundle\Security; diff --git a/security/acl.rst b/security/acl.rst index 43af8a9da18..905ed98c7b2 100644 --- a/security/acl.rst +++ b/security/acl.rst @@ -223,9 +223,7 @@ operation such as view, edit, etc. on the domain object, there are cases where you may want to grant these permissions explicitly. The ``MaskBuilder`` can be used for creating bit masks easily by combining -several base permissions: - -.. code-block:: php +several base permissions:: $builder = new MaskBuilder(); $builder @@ -237,9 +235,7 @@ several base permissions: $mask = $builder->get(); // int(29) This integer bitmask can then be used to grant a user the base permissions you -added above: - -.. code-block:: php +added above:: $identity = new UserSecurityIdentity('johannes', 'AppBundle\Entity\User'); $acl->insertObjectAce($identity, $mask); diff --git a/security/api_key_authentication.rst b/security/api_key_authentication.rst index 8dcb3d95efe..698985f6caa 100644 --- a/security/api_key_authentication.rst +++ b/security/api_key_authentication.rst @@ -272,9 +272,7 @@ In order for your ``ApiKeyAuthenticator`` to correctly display a 401 http status when either bad credentials or authentication fails you will need to implement the :class:`Symfony\\Component\\Security\\Http\\Authentication\\AuthenticationFailureHandlerInterface` on your Authenticator. This will provide a method ``onAuthenticationFailure()`` which -you can use to create an error ``Response``. - -.. code-block:: php +you can use to create an error ``Response``:: // src/AppBundle/Security/ApiKeyAuthenticator.php namespace AppBundle\Security; diff --git a/security/custom_authentication_provider.rst b/security/custom_authentication_provider.rst index a49aba4e722..118c81c31ad 100644 --- a/security/custom_authentication_provider.rst +++ b/security/custom_authentication_provider.rst @@ -58,9 +58,7 @@ A token represents the user authentication data present in the request. Once a request is authenticated, the token retains the user's data, and delivers this data across the security context. First, you'll create your token class. This will allow the passing of all relevant information to your authentication -provider. - -.. code-block:: php +provider:: // src/AppBundle/Security/Authentication/Token/WsseUserToken.php namespace AppBundle\Security\Authentication\Token; @@ -104,9 +102,7 @@ provider. A listener must be an instance of :class:`Symfony\\Component\\Security\\Http\\Firewall\\ListenerInterface`. A security listener should handle the :class:`Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent` event, and -set an authenticated token in the token storage if successful. - -.. code-block:: php +set an authenticated token in the token storage if successful:: // src/AppBundle/Security/Firewall/WsseListener.php namespace AppBundle\Security\Firewall; @@ -200,9 +196,7 @@ The Authentication Provider The authentication provider will do the verification of the ``WsseUserToken``. Namely, the provider will verify the ``Created`` header value is valid within five minutes, the ``Nonce`` header value is unique within five minutes, and -the ``PasswordDigest`` header value matches with the user's password. - -.. code-block:: php +the ``PasswordDigest`` header value matches with the user's password:: // src/AppBundle/Security/Authentication/Provider/WsseProvider.php namespace AppBundle\Security\Authentication\Provider; @@ -309,9 +303,7 @@ for every firewall? The answer is by using a *factory*. A factory is where you hook into the Security component, telling it the name of your provider and any configuration options available for it. First, you must create a class which implements -:class:`Symfony\\Bundle\\SecurityBundle\\DependencyInjection\\Security\\Factory\\SecurityFactoryInterface`. - -.. code-block:: php +:class:`Symfony\\Bundle\\SecurityBundle\\DependencyInjection\\Security\\Factory\\SecurityFactoryInterface`:: // src/AppBundle/DependencyInjection/Security/Factory/WsseFactory.php namespace AppBundle\DependencyInjection\Security\Factory; @@ -469,9 +461,7 @@ to service ids that do not exist yet: ``wsse.security.authentication.provider`` ->setPublic(false); Now that your services are defined, tell your security context about your -factory in your bundle class: - -.. code-block:: php +factory in your bundle class:: // src/AppBundle/AppBundle.php namespace AppBundle; @@ -563,9 +553,7 @@ by default, is 5 minutes. Make this configurable, so different firewalls can have different timeout lengths. You will first need to edit ``WsseFactory`` and define the new option in -the ``addConfiguration()`` method. - -.. code-block:: php +the ``addConfiguration()`` method:: class WsseFactory implements SecurityFactoryInterface { @@ -583,9 +571,7 @@ the ``addConfiguration()`` method. Now, in the ``create()`` method of the factory, the ``$config`` argument will contain a ``lifetime`` key, set to 5 minutes (300 seconds) unless otherwise set in the configuration. Pass this argument to your authentication provider -in order to put it to use. - -.. code-block:: php +in order to put it to use:: class WsseFactory implements SecurityFactoryInterface { diff --git a/security/entity_provider.rst b/security/entity_provider.rst index fc506f2c400..6b71ce66292 100644 --- a/security/entity_provider.rst +++ b/security/entity_provider.rst @@ -38,9 +38,7 @@ and :ref:`user serialization to the session ` For this entry, suppose that you already have a ``User`` entity inside an ``AppBundle`` with the following fields: ``id``, ``username``, ``password``, -``email`` and ``isActive``: - -.. code-block:: php +``email`` and ``isActive``:: // src/AppBundle/Entity/User.php namespace AppBundle\Entity; diff --git a/security/impersonating_user.rst b/security/impersonating_user.rst index 0b34e0ce0c2..d961ff4e991 100644 --- a/security/impersonating_user.rst +++ b/security/impersonating_user.rst @@ -234,9 +234,7 @@ the sticky locale: .. caution:: - The listener implementation assumes your ``User`` entity has a ``getLocale()`` method. - -.. code-block:: php + The listener implementation assumes your ``User`` entity has a ``getLocale()`` method:: // src/AppBundle/EventListener/SwitchUserListener.php namespace AppBundle\EventListener; diff --git a/security/remember_me.rst b/security/remember_me.rst index d89d26dad65..7b35f7ef8f5 100644 --- a/security/remember_me.rst +++ b/security/remember_me.rst @@ -236,9 +236,7 @@ by securing specific controller actions using these roles. The edit action in the controller could be secured using the service context. In the following example, the action is only allowed if the user has the -``IS_AUTHENTICATED_FULLY`` role. - -.. code-block:: php +``IS_AUTHENTICATED_FULLY`` role:: // ... use Symfony\Component\Security\Core\Exception\AccessDeniedException; @@ -252,9 +250,7 @@ In the following example, the action is only allowed if the user has the } If your application is based on the Symfony Standard Edition, you can also secure -your controller using annotations: - -.. code-block:: php +your controller using annotations:: use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; diff --git a/security/voters.rst b/security/voters.rst index 5f4e4e0bad6..30a41303cf4 100644 --- a/security/voters.rst +++ b/security/voters.rst @@ -36,9 +36,7 @@ The Voter Interface A custom voter needs to implement :class:`Symfony\\Component\\Security\\Core\\Authorization\\Voter\\VoterInterface` or extend :class:`Symfony\\Component\\Security\\Core\\Authorization\\Voter\\AbstractVoter`, -which makes creating a voter even easier. - -.. code-block:: php +which makes creating a voter even easier:: abstract class AbstractVoter implements VoterInterface { @@ -58,9 +56,7 @@ Creating the custom Voter ------------------------- The goal is to create a voter that checks if a user has access to view or -edit a particular object. Here's an example implementation: - -.. code-block:: php +edit a particular object. Here's an example implementation:: // src/AppBundle/Security/Authorization/Voter/PostVoter.php namespace AppBundle\Security\Authorization\Voter; diff --git a/session/locale_sticky_session.rst b/session/locale_sticky_session.rst index 8ff500ee609..81176981ec9 100644 --- a/session/locale_sticky_session.rst +++ b/session/locale_sticky_session.rst @@ -127,9 +127,7 @@ you can hook into the login process and update the user's session with this locale value before they are redirected to their first page. To do this, you need an event listener for the ``security.interactive_login`` -event: - -.. code-block:: php +event:: // src/AppBundle/EventListener/UserLocaleListener.php namespace AppBundle\EventListener; diff --git a/translation/debug.rst b/translation/debug.rst index eed2d465e2f..330fc695f2f 100644 --- a/translation/debug.rst +++ b/translation/debug.rst @@ -23,9 +23,7 @@ tag or filter usages in Twig templates: {% transchoice 1 %}Symfony is great{% endtranschoice %} -It will also detect the following translator usages in PHP templates: - -.. code-block:: php +It will also detect the following translator usages in PHP templates:: $view['translator']->trans("Symfony is great");