From 458ce884c034735bc186efb53d03827e4c694500 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Wed, 7 Sep 2011 06:49:51 -0500 Subject: [PATCH 001/659] [cookbook][tools] Adding the versionadded tag for the useIncludePath method --- cookbook/tools/autoloader.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cookbook/tools/autoloader.rst b/cookbook/tools/autoloader.rst index 238d8a92291..78df6dfcc9f 100644 --- a/cookbook/tools/autoloader.rst +++ b/cookbook/tools/autoloader.rst @@ -21,6 +21,9 @@ need. Usage ----- +.. versionadded:: 2.1 + The ``useIncludePath`` method was added in Symfony 2.1. + Registering the :class:`Symfony\\Component\\ClassLoader\\UniversalClassLoader` autoloader is straightforward:: From e8ea59aa073139915feb38ef2471c16045c0a7bd Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 9 Sep 2011 07:19:54 -0500 Subject: [PATCH 002/659] [cookbook][tools] Re-adding details about setIncludePath(), was removed due to a branch mixup --- cookbook/tools/autoloader.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cookbook/tools/autoloader.rst b/cookbook/tools/autoloader.rst index d074b8284c3..5fb93bd58ee 100644 --- a/cookbook/tools/autoloader.rst +++ b/cookbook/tools/autoloader.rst @@ -32,6 +32,10 @@ autoloader is straightforward:: use Symfony\Component\ClassLoader\UniversalClassLoader; $loader = new UniversalClassLoader(); + + // You can search the include_path as a last resort. + $loader->useIncludePath(true); + $loader->register(); For minor performance gains class paths can be cached in memory using APC by From 68b94d2bd9de92411d7a5944f47f59959cefe80e Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Mon, 19 Sep 2011 21:44:54 -0400 Subject: [PATCH 003/659] [reference] Add header markup "templating" section title --- reference/configuration/framework.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index a95677b54e7..646200d5f36 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -104,6 +104,7 @@ lifetime This determines the lifetime of the session - in seconds. templating +~~~~~~~~~~ .. _ref-framework-assets-version: From 9367dc0ae03119f8c1bba228d9f2682ffdea63a5 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Mon, 19 Sep 2011 21:49:16 -0400 Subject: [PATCH 004/659] [book][cookbook][reference] Assetic should be capitalized as a proper noun --- book/templating.rst | 4 ++-- cookbook/assetic/asset_management.rst | 2 +- cookbook/assetic/jpeg_optimize.rst | 4 ++-- reference/configuration/framework.rst | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/book/templating.rst b/book/templating.rst index 6d15a8ccfa5..a2b08ac6db0 100644 --- a/book/templating.rst +++ b/book/templating.rst @@ -801,9 +801,9 @@ advantage of Symfony's template inheritance. This section will teach you the philosophy behind including stylesheet and Javascript assets in Symfony. Symfony also packages another library, - called assetic, which follows this philosophy but allows you to do much + called Assetic, which follows this philosophy but allows you to do much more interesting things with those assets. For more information on - using assetic see :doc:`/cookbook/assetic/asset_management`. + using Assetic see :doc:`/cookbook/assetic/asset_management`. Start by adding two blocks to your base template that will hold your assets: diff --git a/cookbook/assetic/asset_management.rst b/cookbook/assetic/asset_management.rst index 99a84fc5f7a..b88408b7fe9 100644 --- a/cookbook/assetic/asset_management.rst +++ b/cookbook/assetic/asset_management.rst @@ -214,7 +214,7 @@ done from the template and is relative to the public document root: .. note:: Symfony also contains a method for cache *busting*, where the final URL - generated by assetic in the ``prod`` environment contains a query parameter + generated by Assetic in the ``prod`` environment contains a query parameter that can be incremented via configuration on each deployment. For more information, see the :ref:`ref-framework-assets-version` configuration option. diff --git a/cookbook/assetic/jpeg_optimize.rst b/cookbook/assetic/jpeg_optimize.rst index d3a67cd20ed..f10dbb4fbcb 100644 --- a/cookbook/assetic/jpeg_optimize.rst +++ b/cookbook/assetic/jpeg_optimize.rst @@ -10,8 +10,8 @@ for your end users. Using Jpegoptim --------------- -`Jpegoptim`_ is a utility for optimizing JPEG files. To use it with assetic, -add the following to the assetic config: +`Jpegoptim`_ is a utility for optimizing JPEG files. To use it with Assetic, +add the following to the Assetic config: .. configuration-block:: diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index 646200d5f36..d20656470d5 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -116,7 +116,7 @@ assets_version This option is used to *bust* the cache on assets by globally adding a query parameter to all rendered asset paths (e.g. ``/images/logo.png?v2``). This applies only to assets rendered via the Twig ``asset`` function (or PHP equivalent) -as well as assets rendered with assetic. +as well as assets rendered with Assetic. For example, suppose you have the following: From a76c3dd8357bcd7a359d9c68c4b360f7cb89cbd5 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Mon, 19 Sep 2011 22:41:10 -0400 Subject: [PATCH 005/659] [reference] Rewrite assets_version_format docs and add tip for path prefixing Versioned path prefixes are useful for CDN's that do not support cache-busting via query strings. This seemed small enough to add as a tip, although it might be better expanded into a cookbook article (and this tip reduced to a "see cookbook" link). Also added a note about required escaping of percentage signs in the option value. --- reference/configuration/framework.rst | 38 ++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index d20656470d5..74fac88644c 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -170,12 +170,37 @@ option. assets_version_format ..................... -**type**: ``string`` **default**: ``%s?%s`` +**type**: ``string`` **default**: ``%%s?%%s`` -This option relates to the `assets_version`_ option and controls exactly -how the query string is constructed. For example, if ``assets_version_format`` -is set to ``%s?version=%s`` and ``assets_version`` is set to ``5``, rendered -assets would look like ``/images/logo.png?version=5``. +This specifies a `sprintf()`_ pattern that will be used with the `assets_version`_ +option to construct an asset's path. By default, the pattern adds the asset's +version as a query string. For example, if ``assets_version_format`` is set to +``%%s?version=%%s`` and ``assets_version`` is set to ``5``, the asset's path +would be ``/images/logo.png?version=5``. + +.. note:: + + All percentage signs (``%``) in the format string must be doubled to escape + the character. Without escaping, values might inadvertently be interpretted + as :ref:`_book-service-container-parameters`. + +.. tip:: + + Some CDN's do not support cache-busting via query strings, so injecting the + version into the actual file path is necessary. Thankfully, ``assets_version_format`` + is not limited to producing versioned query strings. + + The pattern receives the asset's original path and version as its first and + second parameters, respectively. Since the asset's path is one parameter, we + cannot modify it in-place (e.g. ``/images/logo-v5.png``); however, we can + prefix the asset's path using a pattern of ``version-%%2$s/%%1$s``, which + would result in the path ``version-5/images/logo.png``. + + URL rewrite rules could then be used to disregard the version prefix before + serving the asset. Alternatively, you could copy assets to the appropriate + version path as part of your deployment process and forgo any URL rewriting. + The latter option is useful if you would like older asset versions to remain + accessible at their original URL. Full Default Configuration -------------------------- @@ -277,5 +302,4 @@ Full Default Configuration file_cache_dir: %kernel.cache_dir%/annotations debug: true - - +.. _sprintf(): http://php.net/manual/en/function.sprintf.php From feb9cdbbbd4e60e05ffef41af93f7f2054fdca4b Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Mon, 19 Sep 2011 22:47:21 -0400 Subject: [PATCH 006/659] [reference] Escape percentage signs in assets_version_format config example --- reference/configuration/framework.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index 74fac88644c..c75cb48e6f4 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -263,7 +263,7 @@ Full Default Configuration # templating configuration templating: assets_version: ~ - assets_version_format: "%s?%s" + assets_version_format: "%%s?%%s" assets_base_urls: http: [] ssl: [] From 82741e76de327746100a799297cae47a5521c65b Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Mon, 19 Sep 2011 23:19:12 -0400 Subject: [PATCH 007/659] [reference] Wrap sprintf() footnote link in quotes --- reference/configuration/framework.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index c75cb48e6f4..58b11c066ea 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -302,4 +302,4 @@ Full Default Configuration file_cache_dir: %kernel.cache_dir%/annotations debug: true -.. _sprintf(): http://php.net/manual/en/function.sprintf.php +.. _`sprintf()`: http://php.net/manual/en/function.sprintf.php From 655a98915e7558ca3d2a989509a48492a798ac40 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Tue, 20 Sep 2011 11:21:48 -0500 Subject: [PATCH 008/659] [reference] Removing requirement for sqlite - no longer needed in 2.1 --- reference/requirements.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/reference/requirements.rst b/reference/requirements.rst index 230bee60bb5..8452ba11ec3 100644 --- a/reference/requirements.rst +++ b/reference/requirements.rst @@ -20,7 +20,6 @@ Required -------- * PHP needs to be a minimum version of PHP 5.3.2 -* Sqlite3 needs to be enabled * JSON needs to be enabled * ctype needs to be enabled * Your PHP.ini needs to have the date.timezone setting From fdd609cdfb0629d25ec7a00ecbae13944858db7f Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Tue, 20 Sep 2011 18:52:10 -0400 Subject: [PATCH 009/659] [reference] Add documentation for assets_base_urls option I decided to gloss over the details of how a single base URL is selected from a collection when generating an asset's path, as the internal behavior of UrlPackage is just that. --- reference/configuration/framework.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index 58b11c066ea..bf520f1ee8b 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -27,6 +27,7 @@ Configuration * `session`_ * `lifetime`_ * `templating`_ + * `assets_base_urls`_ * `assets_version`_ * `assets_version_format`_ @@ -106,6 +107,23 @@ This determines the lifetime of the session - in seconds. templating ~~~~~~~~~~ +assets_base_urls +................ + +**default**: ``{ http: [], https: [] }`` + +This option allows you to define base URL's to be used for assets referenced +from ``http`` and ``https`` pages. A string value may be provided in lieu of a +single-element array. If multiple base URL's are provided, Symfony2 will select +one from the collection each time it generates an asset's path. + +For your convenience, ``assets_base_urls`` can be set directly with a string or +array of strings, which will be automatically organized into collections of base +URL's for ``http`` and ``https`` requests. If a URL starts with ``https://`` or +is `protocol-relative`_ (i.e. starts with `//`) it will be added to both +collections. URL's starting with ``http://`` will only be added to the +``http`` collection. + .. _ref-framework-assets-version: assets_version @@ -302,4 +320,5 @@ Full Default Configuration file_cache_dir: %kernel.cache_dir%/annotations debug: true +.. _`protocol-relative`: http://tools.ietf.org/html/rfc3986#section-4.2 .. _`sprintf()`: http://php.net/manual/en/function.sprintf.php From c55af7f8028a398c5e06fac45df99824919326c2 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Tue, 20 Sep 2011 19:31:04 -0400 Subject: [PATCH 010/659] [reference] Add note about asset_base_urls merge behavior in 2.1 --- reference/configuration/framework.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index bf520f1ee8b..b9e1d7ce5d0 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -124,6 +124,16 @@ is `protocol-relative`_ (i.e. starts with `//`) it will be added to both collections. URL's starting with ``http://`` will only be added to the ``http`` collection. +.. versionadded:: 2.1 + + Unlike most configuration blocks, successive values for ``assets_base_urls`` + will overwrite each other instead of being merged. This behavior was chosen + because developers will typically define base URL's for each environment. + Given that most projects tend to inherit configurations + (e.g. ``config_test.yml`` imports ``config_dev.yml``) and/or share a common + base configuration (i.e. ``config.yml``), merging could yield a set of base + URL's for multiple environments. + .. _ref-framework-assets-version: assets_version From b22c5e666edb2586840884e32f8209425125c30d Mon Sep 17 00:00:00 2001 From: Helmer Aaviksoo Date: Wed, 21 Sep 2011 13:32:16 +0300 Subject: [PATCH 011/659] [Cookbook] How to change default target path behaviour --- cookbook/index.rst | 1 + cookbook/security/target_path.rst | 62 +++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 cookbook/security/target_path.rst diff --git a/cookbook/index.rst b/cookbook/index.rst index 99f6bdc3e00..f386e0ed41a 100644 --- a/cookbook/index.rst +++ b/cookbook/index.rst @@ -60,6 +60,7 @@ Cookbook security/entity_provider security/custom_provider security/custom_authentication_provider + security/target_path cache/varnish diff --git a/cookbook/security/target_path.rst b/cookbook/security/target_path.rst new file mode 100644 index 00000000000..49c89bd6561 --- /dev/null +++ b/cookbook/security/target_path.rst @@ -0,0 +1,62 @@ +How to change the default target path behaviour +=============================================== + +The security component retains the information of the last request URI in a session variable +named ``_security.target_path``. Upon a successful login, the user is redirected to this path, +as to help her continue from the last known page she visited. + +On some occasions, this is unexpected. For example when the last request URI was a HTTP POST +against a route which is configured to allow only POST method, the user is redirected to this route +only to get a 404 error, since no handler exists for a GET method. + +To get around this behaviour, you would simple need to extend the ``ExceptionListener`` class and +override the default method named ``setTargetPath()``. + +First, override the ``security.exception_listener.class`` parameter in your configuration file: + +.. configuration-block:: + + .. code-block:: yaml + + # src/Acme/HelloBundle/Resources/config/services.yml + parameters: + # ... + security.exception_listener.class: Acme\HelloBundle\Security\Firewall\ExceptionListener + + .. code-block:: xml + + + + + Acme\HelloBundle\Security\Firewall\ExceptionListener + + + .. code-block:: php + + // src/Acme/HelloBundle/Resources/config/services.php + // ... + $container->setParameter('security.exception_listener.class', 'Acme\HelloBundle\Security\Firewall\ExceptionListener'); + +Next, create your own ``ExceptionListener``:: + + isXmlHttpRequest() || 'GET' !== $request->getMethod()) { + return; + } + + $request->getSession()->set('_security.target_path', $request->getUri()); + } + } + +Add as much or few logic here as required for your scenario! From 715555e5079874c36a4dfd95cac3a5ddf5d12b5d Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Thu, 22 Sep 2011 07:00:26 -0500 Subject: [PATCH 012/659] [reference][constraints] Documenting the new UserPassword constraint --- reference/constraints.rst | 4 +- reference/constraints/UserPassword.rst | 75 ++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 reference/constraints/UserPassword.rst diff --git a/reference/constraints.rst b/reference/constraints.rst index b49bea4bf00..2b1ba97cf1a 100644 --- a/reference/constraints.rst +++ b/reference/constraints.rst @@ -38,8 +38,9 @@ Validation Constraints Reference constraints/Image constraints/Callback - constraints/Valid constraints/All + constraints/UserPassword + constraints/Valid The Validator is designed to validate objects against *constraints*. In real life, a constraint could be: "The cake must not be burned". In @@ -109,4 +110,5 @@ Other Constraints * :doc:`Callback ` * :doc:`All ` +* :doc:`UserPassword ` * :doc:`Valid ` \ No newline at end of file diff --git a/reference/constraints/UserPassword.rst b/reference/constraints/UserPassword.rst new file mode 100644 index 00000000000..2fc778f530b --- /dev/null +++ b/reference/constraints/UserPassword.rst @@ -0,0 +1,75 @@ +UserPassword +============ + +.. versionadded:: 2.1 + + This constraint is new in version 2.1. + +This validates that an input value is equal to the current authenticated +user's password. This is useful in a form where a user can change his password, +but needs to enter his old password for security. + +.. note:: + + This should **not** be used validate a login form, since this is done + automatically by the security system. + +When applied to an array (or Traversable object), this constraint allows +you to apply a collection of constraints to each element of the array. + ++----------------+----------------------------------------------------------------------------------------+ +| Applies to | :ref:`property or method` | ++----------------+----------------------------------------------------------------------------------------+ +| Options | - `message`_ | ++----------------+----------------------------------------------------------------------------------------+ +| Class | :class:`Symfony\\Component\\Validator\\Constraints\\UserPassword` | ++----------------+----------------------------------------------------------------------------------------+ +| Validator | :class:`Symfony\\Bundle\\SecurityBundle\\Validator\\Constraint\\UserPasswordValidator` | ++----------------+----------------------------------------------------------------------------------------+ + +Basic Usage +----------- + +Suppose you have a `PasswordChange` class, that's used in a form where the +user can change his password by entering his old password and a new password. +This constraint will validate that the old password matches the user's current +password: + +.. configuration-block:: + + .. code-block:: yaml + + # src/UserBundle/Resources/config/validation.yml + Acme\UserBundle\Form\Model\ChangePassword: + properties: + oldPassword: + - UserPassword: + message: "Wrong value for your current password" + + .. code-block:: php-annotations + + // src/Acme/UserBundle/Form/Model/ChangePassword.php + namespace Acme\UserBundle\Form\Model; + + use Symfony\Component\Validator\Constraints as Assert; + + class ChangePassword + { + /** + * @Assert\UserPassword( + * message = "Wrong value for your current password" + * ) + */ + protected $oldPassword; + } + +Options +------- + +message +~~~~~~~ + +**type**: ``message`` **default**: ``This value should be the user current password`` + +This is the message that's displayed when the underlying string does *not* +match the current user's password. From 95d56bc5055ca60a90293a5c960a076d8a143d62 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 23 Sep 2011 07:05:31 -0500 Subject: [PATCH 013/659] [cookbook][security] Tweaking new target path entry, adding a link to it --- cookbook/map.rst.inc | 1 + cookbook/security/form_login.rst | 8 ++++++++ cookbook/security/target_path.rst | 34 ++++++++++++++++++------------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/cookbook/map.rst.inc b/cookbook/map.rst.inc index a40f36b9fcc..be70e8e38e3 100644 --- a/cookbook/map.rst.inc +++ b/cookbook/map.rst.inc @@ -77,6 +77,7 @@ * :doc:`/cookbook/security/entity_provider` * :doc:`/cookbook/security/custom_provider` * :doc:`/cookbook/security/custom_authentication_provider` + * :doc:`/cookbook/security/target_path` * **Caching** diff --git a/cookbook/security/form_login.rst b/cookbook/security/form_login.rst index c0e85ce2e5b..7d98b1ff915 100644 --- a/cookbook/security/form_login.rst +++ b/cookbook/security/form_login.rst @@ -110,6 +110,14 @@ directly to the login page), then the user is redirected to the default page, which is ``/`` (i.e. the homepage) by default. You can change this behavior in several ways. +.. note:: + + As mentioned, by default the user is redirected back to the page he originally + requested. Sometimes, this can cause problems, like if a background AJAX + request "appears" to be the last visited URL, causing the user to be + redirected there. For information on controlling this behavior, see + :doc:`/cookbook/security/target_path`. + Changing the Default Page ~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/cookbook/security/target_path.rst b/cookbook/security/target_path.rst index 49c89bd6561..2aa42d9a40a 100644 --- a/cookbook/security/target_path.rst +++ b/cookbook/security/target_path.rst @@ -1,18 +1,24 @@ -How to change the default target path behaviour -=============================================== +.. index:: + single: Security; Target redirect path -The security component retains the information of the last request URI in a session variable -named ``_security.target_path``. Upon a successful login, the user is redirected to this path, -as to help her continue from the last known page she visited. +How to change the Default Target Path Behavior +============================================== -On some occasions, this is unexpected. For example when the last request URI was a HTTP POST -against a route which is configured to allow only POST method, the user is redirected to this route -only to get a 404 error, since no handler exists for a GET method. +By default, the security component retains the information of the last request +URI in a session variable named ``_security.target_path``. Upon a successful +login, the user is redirected to this path, as to help her continue from +the last known page she visited. -To get around this behaviour, you would simple need to extend the ``ExceptionListener`` class and -override the default method named ``setTargetPath()``. +On some occasions, this is unexpected. For example when the last request +URI was an HTTP POST against a route which is configured to allow only a POST +method, the user is redirected to this route only to get a 404 error. -First, override the ``security.exception_listener.class`` parameter in your configuration file: +To get around this behavior, you would simply need to extend the ``ExceptionListener`` +class and override the default method named ``setTargetPath()``. + +First, override the ``security.exception_listener.class`` parameter in your +configuration file. This can be done from your main configuration file (in +`app/config`) or from a configuration file being imported from a bundle: .. configuration-block:: @@ -39,8 +45,7 @@ First, override the ``security.exception_listener.class`` parameter in your conf Next, create your own ``ExceptionListener``:: - isXmlHttpRequest() || 'GET' !== $request->getMethod()) { return; } @@ -59,4 +65,4 @@ Next, create your own ``ExceptionListener``:: } } -Add as much or few logic here as required for your scenario! +Add as much or few logic here as required for your scenario! \ No newline at end of file From 2a728d2dd1a4e88d062a4fa9577ae529c4f2080d Mon Sep 17 00:00:00 2001 From: Igor Date: Mon, 26 Sep 2011 09:35:28 +0400 Subject: [PATCH 014/659] Edited reference/configuration/framework.rst via GitHub --- reference/configuration/framework.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index cd7c6fe86d1..afd1a3784d6 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -70,8 +70,8 @@ full TextMate string would look like this: .. code-block:: yaml -framework: -ide: "txmt://open?url=file://%%f&line=%%l" + framework: + ide: "txmt://open?url=file://%%f&line=%%l" Of course, since every developer uses a different IDE, it's better to set this on a system level. This can be done by setting the ``xdebug.file_link_format`` From 46c04c8b113e03a31ecdf985541cd64e0d672686 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Mon, 26 Sep 2011 22:08:42 -0500 Subject: [PATCH 015/659] [reference] Fixing formatting that was brought in by some strange 2.0 merge related to #714 --- reference/configuration/framework.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index 4c48eef3314..cf51923e047 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -20,16 +20,16 @@ Configuration * `ide`_ * `test`_ * `form`_ -* :ref:`enabled` + * :ref:`enabled` * `csrf_protection`_ -* :ref:`enabled` -* `field_name` + * :ref:`enabled` + * `field_name` * `session`_ -* `lifetime`_ + * `lifetime`_ * `templating`_ -* `assets_base_urls`_ -* `assets_version`_ -* `assets_version_format`_ + * `assets_base_urls`_ + * `assets_version`_ + * `assets_version_format`_ charset ~~~~~~~ @@ -70,8 +70,8 @@ full TextMate string would look like this: .. code-block:: yaml - framework: - ide: "txmt://open?url=file://%%f&line=%%l" + framework: + ide: "txmt://open?url=file://%%f&line=%%l" Of course, since every developer uses a different IDE, it's better to set this on a system level. This can be done by setting the ``xdebug.file_link_format`` From d739c578e765de86a8ad54d6ce9cd32b8a098a1f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 29 Sep 2011 11:55:42 +0200 Subject: [PATCH 016/659] renamed parameters.ini to parameters.yml --- book/doctrine.rst | 18 +++++++++--------- book/page_creation.rst | 6 +++--- cookbook/doctrine/reverse_engineering.rst | 2 +- cookbook/workflow/new_project_git.rst | 10 +++++----- quick_tour/the_architecture.rst | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index c240e3d41eb..60ad6d1ebef 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -44,21 +44,21 @@ Configuring the Database Before you really begin, you'll need to configure your database connection information. By convention, this information is usually configured in an -``app/config/parameters.ini`` file: +``app/config/parameters.yml`` file: .. code-block:: ini - ;app/config/parameters.ini - [parameters] - database_driver = pdo_mysql - database_host = localhost - database_name = test_project - database_user = root - database_password = password + ;app/config/parameters.yml + parameters: + database_driver: pdo_mysql + database_host: localhost + database_name: test_project + database_user: root + database_password: password .. note:: - Defining the configuration via ``parameters.ini`` is just a convention. + Defining the configuration via ``parameters.yml`` is just a convention. The parameters defined in that file are referenced by the main configuration file when setting up Doctrine: diff --git a/book/page_creation.rst b/book/page_creation.rst index 1818f8ed8e5..ca39e9974ed 100644 --- a/book/page_creation.rst +++ b/book/page_creation.rst @@ -721,7 +721,7 @@ format you prefer: # app/config/config.yml imports: - - { resource: parameters.ini } + - { resource: parameters.yml } - { resource: security.yml } framework: @@ -747,7 +747,7 @@ format you prefer: - + @@ -769,7 +769,7 @@ format you prefer: .. code-block:: php - $this->import('parameters.ini'); + $this->import('parameters.yml'); $this->import('security.yml'); $container->loadFromExtension('framework', array( diff --git a/cookbook/doctrine/reverse_engineering.rst b/cookbook/doctrine/reverse_engineering.rst index 0bba7abeb9e..c6287711304 100644 --- a/cookbook/doctrine/reverse_engineering.rst +++ b/cookbook/doctrine/reverse_engineering.rst @@ -47,7 +47,7 @@ to a post record thanks to a foreign key constraint. ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; Before diving into the recipe, be sure your database connection parameters are -correctly setup in the ``app/config/parameters.ini`` file (or wherever your +correctly setup in the ``app/config/parameters.yml`` file (or wherever your database configuration is kept) and that you have initialized a bundle that will host your future entity class. In this tutorial, we will assume that an ``AcmeBlogBundle`` exists and is located under the ``src/Acme/BlogBundle`` diff --git a/cookbook/workflow/new_project_git.rst b/cookbook/workflow/new_project_git.rst index ffe706ce995..68c1a0450f1 100644 --- a/cookbook/workflow/new_project_git.rst +++ b/cookbook/workflow/new_project_git.rst @@ -33,13 +33,13 @@ git repository: /app/cache/* /app/logs/* /vendor/ - /app/config/parameters.ini + /app/config/parameters.yml -4. Copy ``app/config/parameters.ini`` to ``app/config/parameters.ini.dist``. - The ``parameters.ini`` file is ignored by git (see above) so that machine-specific - settings like database passwords aren't committed. By creating the ``parameters.ini.dist`` +4. Copy ``app/config/parameters.yml`` to ``app/config/parameters.yml.dist``. + The ``parameters.yml`` file is ignored by git (see above) so that machine-specific + settings like database passwords aren't committed. By creating the ``parameters.yml.dist`` file, new developers can quickly clone the project, copy this file to - ``parameters.ini``, customize it, and start developing. + ``parameters.yml``, customize it, and start developing. 5. Initialize your git repository: diff --git a/quick_tour/the_architecture.rst b/quick_tour/the_architecture.rst index dbbf418b86a..781f8ea5e97 100644 --- a/quick_tour/the_architecture.rst +++ b/quick_tour/the_architecture.rst @@ -163,7 +163,7 @@ PHP. Have a look at the default configuration: # app/config/config.yml imports: - - { resource: parameters.ini } + - { resource: parameters.yml } - { resource: security.yml } framework: From f87f507810b6fcc4fef37eb605c9fb57b6532fef Mon Sep 17 00:00:00 2001 From: Jordan Alliot Date: Fri, 26 Aug 2011 16:22:39 +0100 Subject: [PATCH 017/659] Added new tag kernel.event_subscriber --- book/internals.rst | 6 ++++++ reference/dic_tags.rst | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/book/internals.rst b/book/internals.rst index ca801bf245d..20b4280a6a1 100644 --- a/book/internals.rst +++ b/book/internals.rst @@ -814,6 +814,12 @@ returned by the ``getSubscribedEvents`` method. This method returns an array indexed by event names and whose values are either the method name to call or an array composed of the method name to call and a priority. +.. tip:: + + If you use the Symfony2 MVC framework, subscribers can be registered via + your :ref:`configuration `. As an added + bonus, the subscriber objects are instantiated only when needed. + .. index:: single: Event Dispatcher; Stopping event flow diff --git a/reference/dic_tags.rst b/reference/dic_tags.rst index 42e42224eb6..0a8b3a47cbe 100644 --- a/reference/dic_tags.rst +++ b/reference/dic_tags.rst @@ -9,6 +9,7 @@ Tags: * ``form.type_guesser`` * ``kernel.cache_warmer`` * ``kernel.event_listener`` +* ``kernel.event_subscriber`` * ``monolog.logger`` * ``monolog.processor`` * ``templating.helper`` @@ -117,6 +118,47 @@ will be called: or negative integer. This allows you to make sure your listener will always be called before or after another listener listening for the same event. +.. _dic-tags-kernel-event-subscriber: + +Enabling Custom Subscribers +--------------------------- + +To enable a custom subscriber, add it as a regular service in one of your +configuration, and tag it with ``kernel.event_subscriber``: + +.. configuration-block:: + + .. code-block:: yaml + + services: + kernel.subscriber.your_subscriber_name: + class: Fully\Qualified\Subscriber\Class\Name + tags: + - { name: kernel.event_subscriber } + + .. code-block:: xml + + + + + + .. code-block:: php + + $container + ->register('kernel.subscriber.your_subscriber_name', 'Fully\Qualified\Subscriber\Class\Name') + ->addTag('kernel.event_subscriber') + ; + +.. note:: + + Your service must implement the :class:`Symfony\Component\EventDispatcher\EventSubscriberInterface` + interface. + +.. note:: + + If your service is created by a factory, you **MUST** correctly set the ``class`` + parameter for this tag to work correctly. + Enabling Custom Template Engines -------------------------------- From 02e610ac82321ca97a959376f0b21728ff1b4e09 Mon Sep 17 00:00:00 2001 From: Massimiliano Arione Date: Sun, 2 Oct 2011 12:01:07 +0300 Subject: [PATCH 018/659] fixed parameters.yml old ini references --- book/doctrine.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index 60ad6d1ebef..449ef8c2259 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -46,9 +46,9 @@ Before you really begin, you'll need to configure your database connection information. By convention, this information is usually configured in an ``app/config/parameters.yml`` file: -.. code-block:: ini +.. code-block:: yaml - ;app/config/parameters.yml + # app/config/parameters.yml parameters: database_driver: pdo_mysql database_host: localhost From 6527e8d9a337b3f0186acbeb4e6cb5e81f4d25da Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sun, 30 Oct 2011 14:50:20 -0500 Subject: [PATCH 019/659] Adding versionadded for new kernel subscriber --- reference/dic_tags.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/reference/dic_tags.rst b/reference/dic_tags.rst index 0a8b3a47cbe..243f5149e5b 100644 --- a/reference/dic_tags.rst +++ b/reference/dic_tags.rst @@ -118,11 +118,17 @@ will be called: or negative integer. This allows you to make sure your listener will always be called before or after another listener listening for the same event. + + .. _dic-tags-kernel-event-subscriber: Enabling Custom Subscribers --------------------------- +.. versionadded:: 2.1 + + The ability to add kernel event subscribers is new to 2.1. + To enable a custom subscriber, add it as a regular service in one of your configuration, and tag it with ``kernel.event_subscriber``: From e4a905e221583989b934345367cae65741dc7ef3 Mon Sep 17 00:00:00 2001 From: Dan Patrick Date: Sun, 30 Oct 2011 19:56:39 -0500 Subject: [PATCH 020/659] Added reference to bin/vendors lock --- cookbook/workflow/new_project_git.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cookbook/workflow/new_project_git.rst b/cookbook/workflow/new_project_git.rst index 68c1a0450f1..741c15bb038 100644 --- a/cookbook/workflow/new_project_git.rst +++ b/cookbook/workflow/new_project_git.rst @@ -117,6 +117,10 @@ script to ensure that all of the needed vendor libraries are downloaded. it. This command is used to freeze the versions of all of your vendor libraries by reading their current state and recording it into the ``deps.lock`` file. + Additionally, if you would simply like to update the ``deps.lock`` file + to what you already have installed, then you can simply run ``php bin/vendors lock`` + to store the appropriate git SHA identifiers in the deps.lock file. + Vendors and Submodules ~~~~~~~~~~~~~~~~~~~~~~ From 5d5cdf2d6994294fb7b867cb5a53f6fedbb9984d Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Tue, 1 Nov 2011 07:43:50 -0500 Subject: [PATCH 021/659] Changing reference from parameters.ini to parameters.yml --- cookbook/templating/global_variables.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookbook/templating/global_variables.rst b/cookbook/templating/global_variables.rst index 97173dbfd4e..fa0c3dd71a2 100644 --- a/cookbook/templating/global_variables.rst +++ b/cookbook/templating/global_variables.rst @@ -26,7 +26,7 @@ system, which lets you isolate or reuse the value: .. code-block:: ini - ; app/config/parameters.ini + ; app/config/parameters.yml [parameters] ga_tracking: UA-xxxxx-x From eb888940292d877f5b5c78f72e84c13f2f13e7cd Mon Sep 17 00:00:00 2001 From: Richard Miller Date: Sun, 6 Nov 2011 22:50:10 +0000 Subject: [PATCH 022/659] Added info on new controller getUser shortcut --- book/security.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/book/security.rst b/book/security.rst index 2e0549a936b..f6c76dddc5e 100644 --- a/book/security.rst +++ b/book/security.rst @@ -1181,6 +1181,16 @@ look like: $user = $this->get('security.context')->getToken()->getUser(); } +In a controller this can be shortcut to: + +.. code-block:: php + + public function indexAction() + { + $user = $this->getUser(); + } + + .. note:: Anonymous users are technically authenticated, meaning that the ``isAuthenticated()`` From 71960449cc7bbfde4bfd28248fae0bd043f1d1de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20G=C3=B3recki?= Date: Tue, 8 Nov 2011 10:19:58 +0100 Subject: [PATCH 023/659] Document the validation groups as callback feature. See PR: https://github.com/symfony/symfony/pull/2498 --- book/forms.rst | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/book/forms.rst b/book/forms.rst index f3e17f55036..ba32794e873 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -403,6 +403,34 @@ method:: In both of these cases, *only* the ``registration`` validation group will be used to validate the underlying object. +If you need some advanced logic to determine validation groups, eg: based on user +submitted data, you can set validation groups option to array callback, or ``Closure``. + + public function getDefaultOptions(array $options) + { + return array( + 'validation_groups' => array('Acme\\AcmeBundle\\Entity\\Client', 'determineValidationGroups'), + ); + } + +This will call static method ``determineValidationGroups()`` with current form object, +as a parameter, on Client entity, after the data was bind to form, but before validation +is actually ran. You can also define whole logic inside the type definition, using ``Closure``, eg: + + public function getDefaultOptions(array $options) + { + return array( + 'validation_groups' => function(FormInterface $form) { + $data = $form->getData(); + if (Entity\Client::TYPE_PERSON == $data->getType()) { + return array('person') + } else { + return array('company'); + } + }, + ); + } + .. index:: single: Forms; Built-in Field Types From 53a762127e568a5cd8fc734d06cafa4cad106511 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Tue, 15 Nov 2011 06:38:49 -0600 Subject: [PATCH 024/659] [book][forms] Tweaking details on validation groups as a callback/Closure --- book/forms.rst | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/book/forms.rst b/book/forms.rst index 8c28057baf4..be97afffa38 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -403,8 +403,16 @@ method:: In both of these cases, *only* the ``registration`` validation group will be used to validate the underlying object. -If you need some advanced logic to determine validation groups, eg: based on user -submitted data, you can set validation groups option to array callback, or ``Closure``. +Groups based on Submitted Data +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. versionadded:: 2.1 + The ability to specify a callback or Closure in ``validation_groups`` + is new to version 2.1 + +If you need some advanced logic to determine the validation groups (e.g. +based on submitted data), you can set the ``validation_groups`` option +to an array callback, or a ``Closure``:: public function getDefaultOptions(array $options) { @@ -413,9 +421,10 @@ submitted data, you can set validation groups option to array callback, or ``Clo ); } -This will call static method ``determineValidationGroups()`` with current form object, -as a parameter, on Client entity, after the data was bind to form, but before validation -is actually ran. You can also define whole logic inside the type definition, using ``Closure``, eg: +This will call the static method ``determineValidationGroups()`` on the +``Client``class after the form is bound, but before validation is executed. +The Form object is passed as an argument to that method (see next example). +You can also define whole logic inline by using a Closure:: public function getDefaultOptions(array $options) { From 320d93ceb16786577bfa34915fe97cba6cca76f6 Mon Sep 17 00:00:00 2001 From: Dan Patrick Date: Thu, 3 Nov 2011 09:59:35 -0500 Subject: [PATCH 025/659] Bringing locale stuff up to speed on 2.1 changes. --- book/translation.rst | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/book/translation.rst b/book/translation.rst index c49fe62d7ed..720d8aee068 100644 --- a/book/translation.rst +++ b/book/translation.rst @@ -482,18 +482,25 @@ locale. Handling the User's Locale -------------------------- -The locale of the current user is stored in the session and is accessible -via the ``session`` service: +The locale of the current user is stored in the request and is accessible +via the ``request`` object: .. code-block:: php - $locale = $this->get('session')->getLocale(); + $locale = $this->get('request')->getLocale(); - $this->get('session')->setLocale('en_US'); + $this->get('request')->setLocale('en_US'); .. index:: single: Translations; Fallback and default locale +It is also possible to store the locale in the session instead of on a per +request basis: + +.. code-block:: php + + $this->get('session')->set('_locale', 'en_US'); + Fallback and Default Locale ~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -501,8 +508,8 @@ If the locale hasn't been set explicitly in the session, the ``fallback_locale`` configuration parameter will be used by the ``Translator``. The parameter defaults to ``en`` (see `Configuration`_). -Alternatively, you can guarantee that a locale is set on the user's session -by defining a ``default_locale`` for the session service: +Alternatively, you can guarantee that a locale is set on each user's request +by defining a ``default_locale`` for the framework: .. configuration-block:: @@ -510,22 +517,28 @@ by defining a ``default_locale`` for the session service: # app/config/config.yml framework: - session: { default_locale: en } + default_locale: en .. code-block:: xml - + en .. code-block:: php // app/config/config.php $container->loadFromExtension('framework', array( - 'session' => array('default_locale' => 'en'), + 'default_locale' => 'en', )); +.. versionadded:: 2.1 + + The ``default_locale`` parameter was defined under the session key + originally, however, as of 2.1 this has been moved. This is because the + locale is now set on the request instead of the session. + .. _book-translation-locale-url: The Locale and the URL From ef4b0509503c36c79bf440fa53b013a9917206a2 Mon Sep 17 00:00:00 2001 From: Francesco Levorato Date: Thu, 17 Nov 2011 17:33:56 +0100 Subject: [PATCH 026/659] [Security] adding reference to new security option --- reference/configuration/security.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/reference/configuration/security.rst b/reference/configuration/security.rst index 7c15dd12616..806989bf8aa 100644 --- a/reference/configuration/security.rst +++ b/reference/configuration/security.rst @@ -23,6 +23,8 @@ Each part will be explained in the next section. always_authenticate_before_granting: false + erase_credentials: true + # strategy can be: none, migrate, invalidate session_fixation_strategy: migrate From 9c210991f2015d04181e22fedf93c7f31bcd83ea Mon Sep 17 00:00:00 2001 From: Dan Patrick Date: Fri, 25 Nov 2011 10:38:00 -0600 Subject: [PATCH 027/659] Fixed security doc to reflect change introduced in sha b9754f4 --- book/security.rst | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/book/security.rst b/book/security.rst index f6c76dddc5e..bfd80a46b04 100644 --- a/book/security.rst +++ b/book/security.rst @@ -51,9 +51,10 @@ authentication (i.e. the old-school username/password box): providers: in_memory: - users: - ryan: { password: ryanpass, roles: 'ROLE_USER' } - admin: { password: kitten, roles: 'ROLE_ADMIN' } + memory: + users: + ryan: { password: ryanpass, roles: 'ROLE_USER' } + admin: { password: kitten, roles: 'ROLE_ADMIN' } encoders: Symfony\Component\Security\Core\User\User: plaintext @@ -77,8 +78,10 @@ authentication (i.e. the old-school username/password box): - - + + + + @@ -103,9 +106,11 @@ authentication (i.e. the old-school username/password box): ), 'providers' => array( 'in_memory' => array( - 'users' => array( - 'ryan' => array('password' => 'ryanpass', 'roles' => 'ROLE_USER'), - 'admin' => array('password' => 'kitten', 'roles' => 'ROLE_ADMIN'), + 'memory' => array( + 'users' => array( + 'ryan' => array('password' => 'ryanpass', 'roles' => 'ROLE_USER'), + 'admin' => array('password' => 'kitten', 'roles' => 'ROLE_ADMIN'), + ), ), ), ), From 1718f04e19452b6c89855762b385d10b93380c7e Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 25 Nov 2011 18:30:00 -0600 Subject: [PATCH 028/659] Making further changes due to the locale being moved from the session to the request --- book/controller.rst | 4 +-- book/page_creation.rst | 27 ++---------------- book/routing.rst | 7 ++++- book/translation.rst | 28 +++++++++++++------ .../configuration/pdo_session_storage.rst | 2 +- quick_tour/the_architecture.rst | 7 ++++- quick_tour/the_controller.rst | 4 +-- reference/configuration/framework.rst | 2 +- 8 files changed, 40 insertions(+), 41 deletions(-) diff --git a/book/controller.rst b/book/controller.rst index cdc57bab053..081e76a1d5a 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -607,8 +607,8 @@ from any controller:: // in another controller for another request $foo = $session->get('foo'); - // set the user locale - $session->setLocale('fr'); + // use a default value of the key doesn't exist + $filters = $session->set('filters', array()); These attributes will remain on the user for the remainder of that user's session. diff --git a/book/page_creation.rst b/book/page_creation.rst index ca39e9974ed..475eca69572 100644 --- a/book/page_creation.rst +++ b/book/page_creation.rst @@ -728,13 +728,7 @@ format you prefer: secret: %secret% charset: UTF-8 router: { resource: "%kernel.root_dir%/config/routing.yml" } - form: true - csrf_protection: true - validation: { enable_annotations: true } - templating: { engines: ['twig'] } #assets_version: SomeVersionScheme - session: - default_locale: %locale% - auto_start: true + # ... # Twig Configuration twig: @@ -753,13 +747,7 @@ format you prefer: - - - - - - - + @@ -776,16 +764,7 @@ format you prefer: 'secret' => '%secret%', 'charset' => 'UTF-8', 'router' => array('resource' => '%kernel.root_dir%/config/routing.php'), - 'form' => array(), - 'csrf-protection' => array(), - 'validation' => array('annotations' => true), - 'templating' => array( - 'engines' => array('twig'), - #'assets_version' => "SomeVersionScheme", - ), - 'session' => array( - 'default_locale' => "%locale%", - 'auto_start' => true, + // ... ), )); diff --git a/book/routing.rst b/book/routing.rst index 53e2c0796b8..77c9586065e 100644 --- a/book/routing.rst +++ b/book/routing.rst @@ -783,7 +783,12 @@ that are special: each adds a unique piece of functionality inside your applicat * ``_format``: Used to set the request format (:ref:`read more`); -* ``_locale``: Used to set the locale on the session (:ref:`read more`); +* ``_locale``: Used to set the locale on the request (:ref:`read more`); + +.. tip:: + + If you use the ``_locale`` parameter in a route, that value will also + be stored on the session so that subsequent requests keep this same locale. .. index:: single: Routing; Controllers diff --git a/book/translation.rst b/book/translation.rst index 720d8aee068..1dd4acad7cc 100644 --- a/book/translation.rst +++ b/book/translation.rst @@ -35,7 +35,8 @@ the process has several common steps: 3. Create translation resources for each supported locale that translate each message in the application; -4. Determine, set and manage the user's locale in the session. +4. Determine, set and manage the user's locale for the request and optionally + on the user's entire session. .. index:: single: Translations; Configuration @@ -79,7 +80,8 @@ not exist in the user's locale. ``fr_FR`` for instance). If this also fails, it looks for a translation using the fallback locale. -The locale used in translations is the one stored in the user session. +The locale used in translations is the one stored on the request. This is +typically set via a ``_locale`` attribute on your routes (see :ref:`book-translation-locale-url`). .. index:: single: Translations; Basic translation @@ -146,7 +148,8 @@ The Translation Process To actually translate the message, Symfony2 uses a simple process: -* The ``locale`` of the current user, which is stored in the session, is determined; +* The ``locale`` of the current user, which is stored on the request (or + stored as ``_locale`` on the session), is determined; * A catalog of translated messages is loaded from translation resources defined for the ``locale`` (e.g. ``fr_FR``). Messages from the fallback locale are @@ -487,20 +490,26 @@ via the ``request`` object: .. code-block:: php - $locale = $this->get('request')->getLocale(); + // access the reqest object in a standard controller + $request = $this->getRequest(); - $this->get('request')->setLocale('en_US'); + $locale = $request->getLocale(); + + $request->setLocale('en_US'); .. index:: single: Translations; Fallback and default locale It is also possible to store the locale in the session instead of on a per -request basis: +request basis. If you do this, each subsequent request will have this locale. .. code-block:: php $this->get('session')->set('_locale', 'en_US'); +See the :ref:`.. _book-translation-locale-url:` section below about setting +the locale via routing. + Fallback and Default Locale ~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -544,7 +553,7 @@ by defining a ``default_locale`` for the framework: The Locale and the URL ~~~~~~~~~~~~~~~~~~~~~~ -Since the locale of the user is stored in the session, it may be tempting +Since you can store the locale of the user is in the session, it may be tempting to use the same URL to display a resource in many different languages based on the user's locale. For example, ``http://www.example.com/contact`` could show content in English for one user and French for another user. Unfortunately, @@ -805,7 +814,7 @@ The translator service is accessible in PHP templates through the Forcing the Translator Locale ----------------------------- -When translating a message, Symfony2 uses the locale from the user's session +When translating a message, Symfony2 uses the locale from the current request or the ``fallback`` locale if necessary. You can also manually specify the locale to use for translation: @@ -848,7 +857,8 @@ steps: files. Symfony2 discovers and processes each file because its name follows a specific convention; -* Manage the user's locale, which is stored in the session. +* Manage the user's locale, which is stored on the request, but can also + be set once the user's session. .. _`strtr function`: http://www.php.net/manual/en/function.strtr.php .. _`ISO 31-11`: http://en.wikipedia.org/wiki/Interval_%28mathematics%29#The_ISO_notation diff --git a/cookbook/configuration/pdo_session_storage.rst b/cookbook/configuration/pdo_session_storage.rst index 1d45b608c31..b9eeef2aa31 100644 --- a/cookbook/configuration/pdo_session_storage.rst +++ b/cookbook/configuration/pdo_session_storage.rst @@ -47,7 +47,7 @@ configuration format of your choice): - + diff --git a/quick_tour/the_architecture.rst b/quick_tour/the_architecture.rst index 781f8ea5e97..113e000d4a5 100644 --- a/quick_tour/the_architecture.rst +++ b/quick_tour/the_architecture.rst @@ -167,6 +167,8 @@ PHP. Have a look at the default configuration: - { resource: security.yml } framework: + #esi: ~ + #translator: { fallback: %locale% } secret: %secret% charset: UTF-8 router: { resource: "%kernel.root_dir%/config/routing.yml" } @@ -174,8 +176,8 @@ PHP. Have a look at the default configuration: csrf_protection: true validation: { enable_annotations: true } templating: { engines: ['twig'] } #assets_version: SomeVersionScheme + default_locale: %locale% session: - default_locale: %locale% auto_start: true # Twig Configuration @@ -187,6 +189,8 @@ PHP. Have a look at the default configuration: assetic: debug: %kernel.debug% use_controller: false + bundles: [ ] + # java: /usr/bin/java filters: cssrewrite: ~ # closure: @@ -199,6 +203,7 @@ PHP. Have a look at the default configuration: dbal: driver: %database_driver% host: %database_host% + port: %database_port% dbname: %database_name% user: %database_user% password: %database_password% diff --git a/quick_tour/the_controller.rst b/quick_tour/the_controller.rst index 9e4a00ab6db..0b3bf10af8f 100644 --- a/quick_tour/the_controller.rst +++ b/quick_tour/the_controller.rst @@ -126,8 +126,8 @@ from any controller:: // in another controller for another request $foo = $session->get('foo'); - // set the user locale - $session->setLocale('fr'); + // use a default value of the key doesn't exist + $filters = $session->set('filters', array()); You can also store small messages that will only be available for the very next request:: diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index 405362366b3..539cd373049 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -246,6 +246,7 @@ Full Default Configuration secret: ~ # Required ide: ~ test: ~ + default_locale: en # form configuration form: @@ -281,7 +282,6 @@ Full Default Configuration # session configuration session: auto_start: ~ - default_locale: en storage_id: session.storage.native name: ~ lifetime: 86400 From 58f723f74b4d380d90138061fd48d62f6fd264f4 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 25 Nov 2011 18:55:43 -0600 Subject: [PATCH 029/659] Adding quick note about erasing credentials --- reference/configuration/security.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/reference/configuration/security.rst b/reference/configuration/security.rst index 806989bf8aa..1d7640b06fd 100644 --- a/reference/configuration/security.rst +++ b/reference/configuration/security.rst @@ -23,6 +23,7 @@ Each part will be explained in the next section. always_authenticate_before_granting: false + # whether or not to call eraseCredentials on the token erase_credentials: true # strategy can be: none, migrate, invalidate From b0d9f65864bd96aa37031c9ae0852528db511632 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 25 Nov 2011 19:56:21 -0600 Subject: [PATCH 030/659] [security] Making more changes due to the memory and chain provider configuration changes in 2.1 --- book/security.rst | 74 ++++++++++++++++++---------- quick_tour/the_controller.rst | 7 +-- reference/configuration/security.rst | 20 ++++---- 3 files changed, 62 insertions(+), 39 deletions(-) diff --git a/book/security.rst b/book/security.rst index 3db3612b206..ce22fdcf459 100644 --- a/book/security.rst +++ b/book/security.rst @@ -897,9 +897,10 @@ In fact, you've seen this already in the example in this chapter. # ... providers: default_provider: - users: - ryan: { password: ryanpass, roles: 'ROLE_USER' } - admin: { password: kitten, roles: 'ROLE_ADMIN' } + memory: + users: + ryan: { password: ryanpass, roles: 'ROLE_USER' } + admin: { password: kitten, roles: 'ROLE_ADMIN' } .. code-block:: xml @@ -907,8 +908,10 @@ In fact, you've seen this already in the example in this chapter. - - + + + + @@ -919,9 +922,11 @@ In fact, you've seen this already in the example in this chapter. // ... 'providers' => array( 'default_provider' => array( - 'users' => array( - 'ryan' => array('password' => 'ryanpass', 'roles' => 'ROLE_USER'), - 'admin' => array('password' => 'kitten', 'roles' => 'ROLE_ADMIN'), + 'memory' => array( + 'users' => array( + 'ryan' => array('password' => 'ryanpass', 'roles' => 'ROLE_USER'), + 'admin' => array('password' => 'kitten', 'roles' => 'ROLE_ADMIN'), + ), ), ), ), @@ -1064,9 +1069,10 @@ do the following: # ... providers: in_memory: - users: - ryan: { password: bb87a29949f3a1ee0559f8a57357487151281386, roles: 'ROLE_USER' } - admin: { password: 74913f5cd5f61ec0bcfdb775414c2fb3d161b620, roles: 'ROLE_ADMIN' } + memory: + users: + ryan: { password: bb87a29949f3a1ee0559f8a57357487151281386, roles: 'ROLE_USER' } + admin: { password: 74913f5cd5f61ec0bcfdb775414c2fb3d161b620, roles: 'ROLE_ADMIN' } encoders: Symfony\Component\Security\Core\User\User: @@ -1080,8 +1086,10 @@ do the following: - - + + + + @@ -1094,9 +1102,11 @@ do the following: // ... 'providers' => array( 'in_memory' => array( - 'users' => array( - 'ryan' => array('password' => 'bb87a29949f3a1ee0559f8a57357487151281386', 'roles' => 'ROLE_USER'), - 'admin' => array('password' => '74913f5cd5f61ec0bcfdb775414c2fb3d161b620', 'roles' => 'ROLE_ADMIN'), + 'memory' => array( + 'users' => array( + 'ryan' => array('password' => 'bb87a29949f3a1ee0559f8a57357487151281386', 'roles' => 'ROLE_USER'), + 'admin' => array('password' => '74913f5cd5f61ec0bcfdb775414c2fb3d161b620', 'roles' => 'ROLE_ADMIN'), + ), ), ), ), @@ -1220,7 +1230,8 @@ a new provider that chains the two together: security: providers: chain_provider: - providers: [in_memory, user_db] + chain: + providers: [in_memory, user_db] in_memory: users: foo: { password: test } @@ -1232,8 +1243,10 @@ a new provider that chains the two together: - in_memory - user_db + + in_memory + user_db + @@ -1249,7 +1262,9 @@ a new provider that chains the two together: $container->loadFromExtension('security', array( 'providers' => array( 'chain_provider' => array( - 'providers' => array('in_memory', 'user_db'), + 'chain' => array( + 'providers' => array('in_memory', 'user_db'), + ), ), 'in_memory' => array( 'users' => array( @@ -1280,16 +1295,21 @@ the user from both the ``in_memory`` and ``user_db`` providers. security: providers: main_provider: - users: - foo: { password: test } - entity: { class: Acme\UserBundle\Entity\User, property: username } + memory: + users: + foo: { password: test } + entity: + class: Acme\UserBundle\Entity\User, + property: username .. code-block:: xml - + + + @@ -1300,8 +1320,10 @@ the user from both the ``in_memory`` and ``user_db`` providers. $container->loadFromExtension('security', array( 'providers' => array( 'main_provider' => array( - 'users' => array( - 'foo' => array('password' => 'test'), + 'memory' => array( + 'users' => array( + 'foo' => array('password' => 'test'), + ), ), 'entity' => array('class' => 'Acme\UserBundle\Entity\User', 'property' => 'username'), ), diff --git a/quick_tour/the_controller.rst b/quick_tour/the_controller.rst index 0b3bf10af8f..53588d778a5 100644 --- a/quick_tour/the_controller.rst +++ b/quick_tour/the_controller.rst @@ -160,9 +160,10 @@ fits most common needs: providers: in_memory: - users: - user: { password: userpass, roles: [ 'ROLE_USER' ] } - admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] } + memory: + users: + user: { password: userpass, roles: [ 'ROLE_USER' ] } + admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] } firewalls: dev: diff --git a/reference/configuration/security.rst b/reference/configuration/security.rst index 5b579518572..10ee9f01a2b 100644 --- a/reference/configuration/security.rst +++ b/reference/configuration/security.rst @@ -61,12 +61,12 @@ Each part will be explained in the next section. id: my.custom.encoder.service.id providers: - memory: - name: memory - users: - foo: { password: foo, roles: ROLE_USER } - bar: { password: bar, roles: [ROLE_USER, ROLE_ADMIN] } - entity: + memory_provider_name: + memory: + users: + foo: { password: foo, roles: ROLE_USER } + bar: { password: bar, roles: [ROLE_USER, ROLE_ADMIN] } + entity_provider_name: entity: { class: SecurityBundle:User, property: username } factories: @@ -79,15 +79,15 @@ Each part will be explained in the next section. access_denied_url: /foo/error403 access_denied_handler: some.service.id entry_point: some.service.id - provider: name + provider: some_provider_key_from_above context: name stateless: false x509: - provider: name + provider: some_provider_key_from_above http_basic: - provider: name + provider: some_provider_key_from_above http_digest: - provider: name + provider: some_provider_key_from_above form_login: check_path: /login_check login_path: /login From 79007f8c0eb069c3d68cfab6444e3afe3bc0fcc9 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 25 Nov 2011 20:10:50 -0600 Subject: [PATCH 031/659] Clarifying for 2.1 that you must have a route for your login_path and check_path URLs --- book/security.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/book/security.rst b/book/security.rst index ce22fdcf459..bdb3ab40d8c 100644 --- a/book/security.rst +++ b/book/security.rst @@ -386,8 +386,11 @@ login form submission (i.e. ``/login_check``): You will *not* need to implement a controller for the ``/login_check`` URL as the firewall will automatically catch and process any form submitted - to this URL. It's optional, but helpful, to create a route so that you - can use it to generate the form submission URL in the login template below. + to this URL. + +.. versionadded:: 2.1 + As of Symfony 2.1, you *must* have routes configured for your ``login_path`` + (e.g. ``/login``) and ``check_path`` (e.g. ``/login_check``) URLs. Notice that the name of the ``login`` route isn't important. What's important is that the URL of the route (``/login``) matches the ``login_path`` config From d191865cc6ddbf18e9a2e032ed8c255a9bff3f42 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 25 Nov 2011 20:13:09 -0600 Subject: [PATCH 032/659] Fixing markup problem --- book/forms.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/forms.rst b/book/forms.rst index be97afffa38..a056c026e5f 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -422,7 +422,7 @@ to an array callback, or a ``Closure``:: } This will call the static method ``determineValidationGroups()`` on the -``Client``class after the form is bound, but before validation is executed. +``Client`` class after the form is bound, but before validation is executed. The Form object is passed as an argument to that method (see next example). You can also define whole logic inline by using a Closure:: From 387775cd9f963fa4113ff410bb930596ecff2b84 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 25 Nov 2011 20:18:29 -0600 Subject: [PATCH 033/659] [reference][form] Adding a reference to the new translation_domain option. We should probably mention this in more places --- reference/forms/types/field.rst | 2 ++ reference/forms/types/options/translation_domain.rst.inc | 7 +++++++ 2 files changed, 9 insertions(+) create mode 100644 reference/forms/types/options/translation_domain.rst.inc diff --git a/reference/forms/types/field.rst b/reference/forms/types/field.rst index 51b7dec035c..bc6c40c63c6 100644 --- a/reference/forms/types/field.rst +++ b/reference/forms/types/field.rst @@ -20,3 +20,5 @@ The ``field`` type predefines a couple of options: .. include:: /reference/forms/types/options/property_path.rst.inc .. include:: /reference/forms/types/options/attr.rst.inc + +.. include:: /reference/forms/types/options/translation_domain.rst.inc diff --git a/reference/forms/types/options/translation_domain.rst.inc b/reference/forms/types/options/translation_domain.rst.inc new file mode 100644 index 00000000000..5317f2c372e --- /dev/null +++ b/reference/forms/types/options/translation_domain.rst.inc @@ -0,0 +1,7 @@ +translation_domain +~~~~~~~~~~~~~~~~~~ + +**type**: ``string`` **default**: ``messages`` + +This is the translation domain that will be used for any labels or options +that are rendered for this field. From 8ca9b8576f45f3ada90e33de25160f782c061bed Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 25 Nov 2011 20:24:10 -0600 Subject: [PATCH 034/659] Adding note about referer login behavior that's new to 2.1 --- cookbook/security/form_login.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cookbook/security/form_login.rst b/cookbook/security/form_login.rst index 7d98b1ff915..61cce3b5ef0 100644 --- a/cookbook/security/form_login.rst +++ b/cookbook/security/form_login.rst @@ -208,7 +208,7 @@ Using the Referring URL ~~~~~~~~~~~~~~~~~~~~~~~ In case no previous URL was stored in the session, you may wish to try using -the ``HTTP_REFERER`` instead, as this will often be the same. You can do +the ``HTTP_REFERER`` instead, as this will often be the same. You can do this by setting ``use_referer`` to true (it defaults to false): .. configuration-block:: @@ -246,6 +246,10 @@ this by setting ``use_referer`` to true (it defaults to false): ), )); +.. versionadded:: 2.1 + As of 2.1, if the referer is equal to the ``login_path`` option, the + user will be redirected to the ``default_target_path``. + Control the Redirect URL from inside the Form ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From dc0c0ab2c40db0c44a2053b955c9fc5f0ee0fd1c Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 25 Nov 2011 20:44:18 -0600 Subject: [PATCH 035/659] [reference][constraints] Adding the new size-relation options to the Image constraint --- reference/constraints/Image.rst | 208 +++++++++++++++++++++++++++++++- 1 file changed, 205 insertions(+), 3 deletions(-) diff --git a/reference/constraints/Image.rst b/reference/constraints/Image.rst index 9607cb76884..317470deaaa 100644 --- a/reference/constraints/Image.rst +++ b/reference/constraints/Image.rst @@ -5,21 +5,223 @@ The Image constraint works exactly like the :doc:`File` constraint for the bulk of the documentation on this constraint. ++----------------+----------------------------------------------------------------------+ +| Applies to | :ref:`property or method` | ++----------------+----------------------------------------------------------------------+ +| Options | - `mimeTypes`_ | +| | - `minWidth`_ | +| | - `maxWidth`_ | +| | - `maxHeight`_ | +| | - `minHeight`_ | +| | - `mimeTypesMessage`_ | +| | - `sizeNotDetectedMessage`_ | +| | - `maxWidthMessage`_ | +| | - `minWidthMessage`_ | +| | - `maxHeightMessage`_ | +| | - `minHeightMessage`_ | +| | - See :doc:`File` for inherited options | ++----------------+----------------------------------------------------------------------+ +| Class | :class:`Symfony\\Component\\Validator\\Constraints\\File` | ++----------------+----------------------------------------------------------------------+ +| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\FileValidator` | ++----------------+----------------------------------------------------------------------+ + +Basic Usage +----------- + +This constraint is most commonly used on a property that will be rendered +in a form as a :doc:`file` form type. For example, +suppose you're creating an author form where you can upload a "headshot" +image for the author. In your form, the ``headshot`` property would be a +``file`` type. The ``Author`` class might look as follows:: + + // src/Acme/BlogBundle/Entity/Author.php + namespace Acme\BlogBundle\Entity; + + use Symfony\Component\HttpFoundation\File\File; + + class Author + { + protected $headshot; + + public function setHeadshot(File $file = null) + { + $this->headshot = $file; + } + + public function getHeadshot() + { + return $this->headshot; + } + } + +To guarantee that the ``headshot`` ``File`` object is a valid image and that +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 + use Symfony\Component\Validator\Constraints as Assert; + + class Author + { + /** + * @Assert\File( + * minWidth = 200, + * maxWidth = 400, + * minHeight = 200, + * maxHeight = 400, + * ) + */ + protected $headshot; + } + + .. code-block:: xml + + + + + + + + + + + + + + .. code-block:: php + + // src/Acme/BlogBundle/Entity/Author.php + // ... + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints\File; + + class Author + { + // ... + + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('headshot', new File(array( + 'minWidth' => 200, + 'maxWidth' => 400, + 'minHeight' => 200, + 'maxHeight' => 400, + ))); + } + } + +The ``headshot`` property is validated to guarantee that it is a real image +and that it is between a certain width and height. + Options ------- This constraint shares all of its options with the :doc:`File` -constraint. It does, however, modify two of the default option values: +constraint. It does, however, modify two of the default option values and +add several other options. mimeTypes ~~~~~~~~~ -**type**: ``array`` or ``string`` **default**: an array of jpg, gif and png image mime types +**type**: ``array`` or ``string`` **default**: ``image/*`` mimeTypesMessage ~~~~~~~~~~~~~~~~ -**type**: ``string`` **default**: ``This file is not a valid image`` \ No newline at end of file +**type**: ``string`` **default**: ``This file is not a valid image`` + +.. versionadded:: 2.1 + All of the min/max width/height options are new to Symfony 2.1. + +minWidth +~~~~~~~~ + +**type**: ``integer`` + +If set, the width of the image file must be greater than or equal to this +value in pixels. + +maxWidth +~~~~~~~~ + +**type**: ``integer`` + +If set, the width of the image file must be less than or equal to this +value in pixels. + +minHeight +~~~~~~~~~ + +**type**: ``integer`` + +If set, the height of the image file must be greater than or equal to this +value in pixels. + +maxHeight +~~~~~~~~~ + +**type**: ``integer`` + +If set, the height of the image file must be less than or equal to this +value in pixels. + +sizeNotDetectedMessage +~~~~~~~~~~~~~~~~~~~~~~ + +**type**: ``string`` **default**: ``The size of the image could not be detected`` + +If the system is unable to determine the size of the image, this error will +be displayed. This will only occur when at least one of the four size constraint +options has been set. + +maxWidthMessage +~~~~~~~~~~~~~~~ + +**type**: ``string`` **default**: ``The image width is too big ({{ width }}px). Allowed maximum width is {{ max_width }}px`` + +The error message if the width of the image exceeds `maxWidth`_. + +minWidthMessage +~~~~~~~~~~~~~~~ + +**type**: ``string`` **default**: ``The image width is too small ({{ width }}px). Minimum width expected is {{ min_width }}px`` + +The error message if the width of the image is less than `minWidth`_. + +maxHeightMessage +~~~~~~~~~~~~~~~~ + +**type**: ``string`` **default**: ``The image height is too big ({{ height }}px). Allowed maximum height is {{ max_height }}px`` + +The error message if the height of the image exceeds `maxHeight`_. + +minHeightMessage +~~~~~~~~~~~~~~~~ + +**type**: ``string`` **default**: ``The image height is too small ({{ height }}px). Minimum height expected is {{ min_height }}px`` + +The error message if the height of the image is less than `minHeight`_. \ No newline at end of file From cba777187bf9851b1d82dce3b09e53c13a970347 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 25 Nov 2011 21:06:01 -0600 Subject: [PATCH 036/659] [reference][UniqueEntity] Adding note about the change to the em in the UniqueEntity constraint --- reference/constraints/UniqueEntity.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/reference/constraints/UniqueEntity.rst b/reference/constraints/UniqueEntity.rst index 79f941c9966..bb120b1d212 100644 --- a/reference/constraints/UniqueEntity.rst +++ b/reference/constraints/UniqueEntity.rst @@ -99,4 +99,6 @@ em **type**: ``string`` The name of the entity manager to use for making the query to determine the -uniqueness. If left blank, the default entity manager will be used. +uniqueness. If left blank, the correct entity manager will determined for +this class. For that reason, this option should probably not need to be +used. From ca4004074fc0943d9c973b4a39c0f2330776df7a Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Mon, 19 Dec 2011 10:14:28 +0100 Subject: [PATCH 037/659] Update required PHPUnit version to 3.6.4 --- contributing/code/patches.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contributing/code/patches.rst b/contributing/code/patches.rst index c8803ad874e..d5d19105f1d 100644 --- a/contributing/code/patches.rst +++ b/contributing/code/patches.rst @@ -79,7 +79,7 @@ software: * PHP version 5.3.2 or above; -* PHPUnit 3.5.11 or above. +* PHPUnit 3.6.4 or above. Set up your user information with your real name and a working email address: From 5d824ba3a88da3ad1ce4ffce5c81891b3b3256b7 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Mon, 19 Dec 2011 10:18:46 +0100 Subject: [PATCH 038/659] Update required PHPUnit version to 3.6.4 - part 2 --- contributing/code/tests.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contributing/code/tests.rst b/contributing/code/tests.rst index cf12f150887..bc6ffbe0825 100644 --- a/contributing/code/tests.rst +++ b/contributing/code/tests.rst @@ -7,7 +7,7 @@ Symfony2 test suite to check that you have not broken anything. PHPUnit ------- -To run the Symfony2 test suite, `install`_ PHPUnit 3.5.0 or later first: +To run the Symfony2 test suite, `install`_ PHPUnit 3.6.4 or later first: .. code-block:: bash From 5f6896953e44ba9e5aaf9cdbf54fea8a035fe56c Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sat, 24 Dec 2011 12:56:52 -0600 Subject: [PATCH 039/659] Clarifying PHPUnit versionin end-user tests versus core tests for master --- book/testing.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/book/testing.rst b/book/testing.rst index 57c7c5ee469..fab9b3b1fc7 100644 --- a/book/testing.rst +++ b/book/testing.rst @@ -17,7 +17,8 @@ it has its own excellent `documentation`_. .. note:: - Symfony2 works with PHPUnit 3.5.11 or later. + Symfony2 works with PHPUnit 3.5.11 or later, though version 3.6.4 is + needed to test the Symfony core code itself. Each test - whether it's a unit test or a functional test - is a PHP class that should live in the `Tests/` subdirectory of your bundles. If you follow From 442385f976a01db3204d5040e7c0c889f17551a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20G=C3=B3recki?= Date: Fri, 13 Jan 2012 09:35:50 +0100 Subject: [PATCH 040/659] Document BC Break introduced in commit 741859dc --- book/security.rst | 7 +++++ cookbook/security/entity_provider.rst | 39 ++++++++++++++++++--------- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/book/security.rst b/book/security.rst index 121d9074bec..8119990c635 100644 --- a/book/security.rst +++ b/book/security.rst @@ -1001,6 +1001,13 @@ custom user class is that it implements the :class:`Symfony\\Component\\Security interface. This means that your concept of a "user" can be anything, as long as it implements this interface. +.. versionadded:: 2.1 + + In Symfony 2.1 the ``Symfony\\Component\\Security\\Core\\User\\EquatableInterface`` + was introduced, it contains single method ``isEqualTo(UserInterface $user)``. + You can implement this interface if you need to override default implementation + of comparsion logic in authentication mechanism. + .. note:: The user object will be serialized and saved in the session during requests, diff --git a/cookbook/security/entity_provider.rst b/cookbook/security/entity_provider.rst index 92c92d42ed6..31e1a9e92a9 100644 --- a/cookbook/security/entity_provider.rst +++ b/cookbook/security/entity_provider.rst @@ -40,6 +40,13 @@ To make it shorter, the getter and setter methods for each have been removed to focus on the most important methods that come from the :class:`Symfony\\Component\\Security\\Core\\User\\UserInterface`. +.. versionadded:: 2.1 + + In Symfony 2.1 the ``Symfony\\Component\\Security\\Core\\User\\EquatableInterface`` + was introduced, it contains single method ``isEqualTo(UserInterface $user)``. + You can implement this interface if you need to override default implementation + of comparsion logic in authentication mechanism. + .. code-block:: php // src/Acme/UserBundle/Entity/User.php @@ -47,6 +54,7 @@ focus on the most important methods that come from the namespace Acme\UserBundle\Entity; use Symfony\Component\Security\Core\User\UserInterface; + use Symfony\Component\Security\Core\User\EquatableInterface; use Doctrine\ORM\Mapping as ORM; /** @@ -100,11 +108,6 @@ focus on the most important methods that come from the return array('ROLE_USER'); } - public function equals(UserInterface $user) - { - return $user->getUsername() === $this->username; - } - public function eraseCredentials() { } @@ -123,18 +126,30 @@ focus on the most important methods that come from the { return $this->password; } + + /** + * EquatableInterface + */ + public function isEqualTo(UserInterface $user) + { + return $user->getUsername() === $this->username; + } } In order to use an instance of the ``AcmeUserBundle:User`` class in the Symfony security layer, the entity class must implement the :class:`Symfony\\Component\\Security\\Core\\User\\UserInterface`. This -interface forces the class to implement the six following methods: ``getRoles()``, -``getPassword()``, ``getSalt()``, ``getUsername()``, ``eraseCredentials()``, -``equals()``. For more details on each of these, see :class:`Symfony\\Component\\Security\\Core\\User\\UserInterface`. - -To keep it simple, the ``equals()`` method just compares the ``username`` field -but it's also possible to do more checks depending on the complexity of your -data model. On the other hand, the ``eraseCredentials()`` method remains empty +interface forces the class to implement the five following methods: ``getRoles()``, +``getPassword()``, ``getSalt()``, ``getUsername()``, ``eraseCredentials()``. +For more details on each of these, see :class:`Symfony\\Component\\Security\\Core\\User\\UserInterface`. + +To keep it simple, the ``isEqualTo()`` method form ``EquatableInterface`` +just compares the ``username`` field but it's also possible to do more checks +depending on the complexity of your data model, also in most cases, implementing +``EquatableInterface`` is not nessesery, because security component has good default +implementation, see the ``hasUserChanged()`` method of +:class:`Symfony\\Component\\Security\\Core\\Authentication\\Token\\AbstractToken`. +On the other hand, the ``eraseCredentials()`` method remains empty as we don't care about it in this tutorial. Below is an export of my ``User`` table from MySQL. For details on how to From 93a575a422a968358d8db6f305aaf647cd978d9b Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sun, 22 Jan 2012 12:22:28 -0600 Subject: [PATCH 041/659] [security] Clarifying the UserInterface change for 2.1 --- book/security.rst | 8 ++++---- cookbook/security/entity_provider.rst | 26 ++++---------------------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/book/security.rst b/book/security.rst index 62a64b00825..5ab28196147 100644 --- a/book/security.rst +++ b/book/security.rst @@ -1006,10 +1006,10 @@ as it implements this interface. .. versionadded:: 2.1 - In Symfony 2.1 the ``Symfony\\Component\\Security\\Core\\User\\EquatableInterface`` - was introduced, it contains single method ``isEqualTo(UserInterface $user)``. - You can implement this interface if you need to override default implementation - of comparsion logic in authentication mechanism. + In Symfony 2.1, the ``equals`` method was removed from ``UserInterface``. + If you need to override the default implementation of comparison logic, + implement the new :class:`Symfony\\Component\\Security\\Core\\User\\EquatableInterface` + interface. .. note:: diff --git a/cookbook/security/entity_provider.rst b/cookbook/security/entity_provider.rst index 31e1a9e92a9..5eaffde9dda 100644 --- a/cookbook/security/entity_provider.rst +++ b/cookbook/security/entity_provider.rst @@ -42,10 +42,10 @@ focus on the most important methods that come from the .. versionadded:: 2.1 - In Symfony 2.1 the ``Symfony\\Component\\Security\\Core\\User\\EquatableInterface`` - was introduced, it contains single method ``isEqualTo(UserInterface $user)``. - You can implement this interface if you need to override default implementation - of comparsion logic in authentication mechanism. + In Symfony 2.1, the ``equals`` method was removed from ``UserInterface``. + If you need to override the default implementation of comparison logic, + implement the new :class:`Symfony\\Component\\Security\\Core\\User\\EquatableInterface` + interface. .. code-block:: php @@ -54,7 +54,6 @@ focus on the most important methods that come from the namespace Acme\UserBundle\Entity; use Symfony\Component\Security\Core\User\UserInterface; - use Symfony\Component\Security\Core\User\EquatableInterface; use Doctrine\ORM\Mapping as ORM; /** @@ -126,14 +125,6 @@ focus on the most important methods that come from the { return $this->password; } - - /** - * EquatableInterface - */ - public function isEqualTo(UserInterface $user) - { - return $user->getUsername() === $this->username; - } } In order to use an instance of the ``AcmeUserBundle:User`` class in the Symfony @@ -143,15 +134,6 @@ interface forces the class to implement the five following methods: ``getRoles() ``getPassword()``, ``getSalt()``, ``getUsername()``, ``eraseCredentials()``. For more details on each of these, see :class:`Symfony\\Component\\Security\\Core\\User\\UserInterface`. -To keep it simple, the ``isEqualTo()`` method form ``EquatableInterface`` -just compares the ``username`` field but it's also possible to do more checks -depending on the complexity of your data model, also in most cases, implementing -``EquatableInterface`` is not nessesery, because security component has good default -implementation, see the ``hasUserChanged()`` method of -:class:`Symfony\\Component\\Security\\Core\\Authentication\\Token\\AbstractToken`. -On the other hand, the ``eraseCredentials()`` method remains empty -as we don't care about it in this tutorial. - Below is an export of my ``User`` table from MySQL. For details on how to create user records and encode their password, see :ref:`book-security-encoding-user-password`. From 13f3a11eef211d4e9710d1c05d120c4d34f918b8 Mon Sep 17 00:00:00 2001 From: Duane Gran Date: Fri, 27 Jan 2012 11:35:07 -0500 Subject: [PATCH 042/659] Fixed method call for rendering the label in twig --- reference/forms/types/options/label.rst.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/forms/types/options/label.rst.inc b/reference/forms/types/options/label.rst.inc index a8e99e57e62..e57c7505874 100644 --- a/reference/forms/types/options/label.rst.inc +++ b/reference/forms/types/options/label.rst.inc @@ -8,4 +8,4 @@ also be directly set inside the template: .. code-block:: jinja - {{ render_label(form.name, 'Your name') }} \ No newline at end of file + {{ form_label(form.name, 'Your name') }} \ No newline at end of file From a8842a3b1a2aba685bf1491b3b7d285f385bb31d Mon Sep 17 00:00:00 2001 From: Maks3w Date: Thu, 26 Jan 2012 23:15:20 +0100 Subject: [PATCH 043/659] Added relevant fields inherited from from field --- reference/forms/types/hidden.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/reference/forms/types/hidden.rst b/reference/forms/types/hidden.rst index a51978892d6..f5c609060f2 100644 --- a/reference/forms/types/hidden.rst +++ b/reference/forms/types/hidden.rst @@ -9,7 +9,19 @@ The hidden type represents a hidden input field. +-------------+----------------------------------------------------------------------+ | Rendered as | ``input`` ``hidden`` field | +-------------+----------------------------------------------------------------------+ -| Parent type | ``field`` | +| Inherited | - ``data`` | +| options | - ``property_path`` | ++-------------+----------------------------------------------------------------------+ +| Parent type | :doc:`field` | +-------------+----------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\HiddenType` | +-------------+----------------------------------------------------------------------+ + +Inherited Options +----------------- + +These options inherit from the :doc:`field` type: + +.. include:: /reference/forms/types/options/data.rst.inc + +.. include:: /reference/forms/types/options/property_path.rst.inc From bb00b61c571d9e9ba97bbbaf3da097b6b835ef6f Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 31 Jan 2012 09:23:41 -0700 Subject: [PATCH 044/659] Removes deprecated 'security_factories' directive in the cookbook article in favor of adding the extension in the Bundle. --- .../custom_authentication_provider.rst | 40 ++++++++----------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/cookbook/security/custom_authentication_provider.rst b/cookbook/security/custom_authentication_provider.rst index 66beba564d6..b5e119d12a2 100644 --- a/cookbook/security/custom_authentication_provider.rst +++ b/cookbook/security/custom_authentication_provider.rst @@ -428,35 +428,27 @@ factory service, tagged as ``security.listener.factory``: -Now, import the factory configuration via the the ``factories`` key in your -security configuration: +As a final step, add the factory to the security extension in your bundle class. -.. configuration-block:: - - .. code-block:: yaml - - # app/config/security.yml - security: - factories: - - "%kernel.root_dir%/../src/Acme/DemoBundle/Resources/config/security_factories.yml" +.. code-block:: php - .. code-block:: xml + // src/Acme/DemoBundle/AcmeDemoBundle.php + namespace Acme\DemoBundle; - - - - "%kernel.root_dir%/../src/Acme/DemoBundle/Resources/config/security_factories.xml - - + use Acme\DemoBundle\DependencyInjection\Security\Factory\WsseFactory; + use Symfony\Component\HttpKernel\Bundle\Bundle; + use Symfony\Component\DependencyInjection\ContainerBuilder; - .. code-block:: php + class AcmeDemoBundle extends Bundle + { + public function build(ContainerBuilder $container) + { + parent::build($container); - // app/config/security.php - $container->loadFromExtension('security', array( - 'factories' => array( - "%kernel.root_dir%/../src/Acme/DemoBundle/Resources/config/security_factories.php" - ), - )); + $extension = $container->getExtension('security'); + $extension->addSecurityListenerFactory(new WsseFactory()); + } + } You are finished! You can now define parts of your app as under WSSE protection. From 1a485e29796b3586f225cd565caf4a00ca991148 Mon Sep 17 00:00:00 2001 From: Manuel de Ruiter Date: Sun, 12 Feb 2012 19:44:10 +0100 Subject: [PATCH 045/659] For more information see: 5b7ef116507fa05e1042065f61a50733c19116cb --- cookbook/configuration/pdo_session_storage.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cookbook/configuration/pdo_session_storage.rst b/cookbook/configuration/pdo_session_storage.rst index 5cecf7e0eaa..6b90b923a0b 100644 --- a/cookbook/configuration/pdo_session_storage.rst +++ b/cookbook/configuration/pdo_session_storage.rst @@ -40,7 +40,7 @@ configuration format of your choice): password: mypassword session.storage.pdo: - class: Symfony\Component\HttpFoundation\SessionStorage\PdoSessionStorage + class: Symfony\Component\HttpFoundation\Session\Storage\PdoSessionStorage arguments: [@pdo, %session.storage.options%, %pdo.db_options%] .. code-block:: xml @@ -66,7 +66,7 @@ configuration format of your choice): mypassword - + %session.storage.options% %pdo.db_options% @@ -101,7 +101,7 @@ configuration format of your choice): )); $container->setDefinition('pdo', $pdoDefinition); - $storageDefinition = new Definition('Symfony\Component\HttpFoundation\SessionStorage\PdoSessionStorage', array( + $storageDefinition = new Definition('Symfony\Component\HttpFoundation\Session\Storage\PdoSessionStorage', array( new Reference('pdo'), '%session.storage.options%', '%pdo.db_options%', From b9fc63e13174495ff3c7c4551431b6d09d0ef5db Mon Sep 17 00:00:00 2001 From: Manuel de Ruiter Date: Sun, 12 Feb 2012 20:02:03 +0100 Subject: [PATCH 046/659] Switched the parameters to match the constructor signature --- cookbook/configuration/pdo_session_storage.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cookbook/configuration/pdo_session_storage.rst b/cookbook/configuration/pdo_session_storage.rst index 6b90b923a0b..b1af4b13a14 100644 --- a/cookbook/configuration/pdo_session_storage.rst +++ b/cookbook/configuration/pdo_session_storage.rst @@ -41,7 +41,7 @@ configuration format of your choice): session.storage.pdo: class: Symfony\Component\HttpFoundation\Session\Storage\PdoSessionStorage - arguments: [@pdo, %session.storage.options%, %pdo.db_options%] + arguments: [@pdo, %pdo.db_options%, %session.storage.options%] .. code-block:: xml @@ -68,8 +68,8 @@ configuration format of your choice): - %session.storage.options% %pdo.db_options% + %session.storage.options% @@ -103,8 +103,8 @@ configuration format of your choice): $storageDefinition = new Definition('Symfony\Component\HttpFoundation\Session\Storage\PdoSessionStorage', array( new Reference('pdo'), - '%session.storage.options%', '%pdo.db_options%', + '%session.storage.options%', )); $container->setDefinition('session.storage.pdo', $storageDefinition); From b7dd11ace7ad13dc72eb159f5910a572b09795d1 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Mon, 13 Feb 2012 23:32:37 -0600 Subject: [PATCH 047/659] Adding versionadded tag about new security factory location --- cookbook/security/custom_authentication_provider.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cookbook/security/custom_authentication_provider.rst b/cookbook/security/custom_authentication_provider.rst index 85166210c57..6b777d38724 100644 --- a/cookbook/security/custom_authentication_provider.rst +++ b/cookbook/security/custom_authentication_provider.rst @@ -427,6 +427,9 @@ factory service, tagged as ``security.listener.factory``: +.. versionadded:: 2.1 + Before 2.1, the factory below was added via ``security.yml`` instead. + As a final step, add the factory to the security extension in your bundle class. .. code-block:: php From 769ff8665386a9bde0018291ace4ed5e1229f40a Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Wed, 15 Feb 2012 08:53:17 -0500 Subject: [PATCH 048/659] added config:dump-reference docs --- book/page_creation.rst | 28 +++++++++++++--- cookbook/bundles/extension.rst | 58 +++++++++++++++++++++++++++++++--- 2 files changed, 77 insertions(+), 9 deletions(-) diff --git a/book/page_creation.rst b/book/page_creation.rst index 66bc8b3b477..a9e55be8f7f 100644 --- a/book/page_creation.rst +++ b/book/page_creation.rst @@ -251,10 +251,10 @@ application should greet you: .. code-block:: text http://localhost/app.php/hello/Ryan - + If you get an error, it's likely because you need to clear your cache by running: - + .. code-block:: bash php app/console cache:clear --env=prod --no-debug @@ -723,7 +723,7 @@ format you prefer: imports: - { resource: parameters.yml } - { resource: security.yml } - + framework: secret: %secret% charset: UTF-8 @@ -744,7 +744,7 @@ format you prefer: - + @@ -803,6 +803,26 @@ options of each feature. * *PHP*: Very powerful but less readable than standard configuration formats. +Default Configuration Dump +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. versionadded:: 2.1 + The ``config:dump-reference`` command was added in Symfony 2.1 + +You can dump the default configuration for a bundle in yaml to the console using +the ``config:dump-reference`` command. Here is an example of dumping the default +FrameworkBundle configuration: + +.. code-block:: text + + app/console config:dump-reference FrameworkBundle + +.. note:: + + See the cookbook article: :doc:`How to expose a Semantic Configuration for + a Bundle` for information on adding + configuration for your own bundle. + .. index:: single: Environments; Introduction diff --git a/cookbook/bundles/extension.rst b/cookbook/bundles/extension.rst index 06058cbb7e1..48d3ce36d04 100644 --- a/cookbook/bundles/extension.rst +++ b/cookbook/bundles/extension.rst @@ -18,19 +18,19 @@ as integration of other related components: .. configuration-block:: .. code-block:: yaml - + framework: # ... form: true .. code-block:: xml - + .. code-block:: php - + $container->loadFromExtension('framework', array( // ... 'form' => true, @@ -304,7 +304,7 @@ option is passed and set to true:: // prepare your $config variable $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - + if (isset($config['enabled']) && $config['enabled']) { $loader->load('services.xml'); } @@ -470,7 +470,7 @@ that an unsupported option was passed:: $processor = new Processor(); $configuration = new Configuration(); $config = $processor->processConfiguration($configuration, $configs); - + // ... } @@ -484,6 +484,54 @@ normalization and advanced merging. The best way to see this in action is to checkout out some of the core Configuration classes, such as the one from the `FrameworkBundle Configuration`_ or the `TwigBundle Configuration`_. +Default Configuration Dump +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. versionadded:: 2.1 + The ``config:dump-reference`` command was added in Symfony 2.1 + +The ``config:dump-reference`` command allows a bundle's default configuration to +be output to the console in yaml. + +As long as your bundle's configuration is located in the standard location +(``YourBundle\DependencyInjection\Configuration``) and does not have a +``__constructor()`` it will work automatically. If you have a something +different your ``Extension`` class will have to override the +``Extension::getConfiguration()`` method. Have it return an instance of your +``Configuration``. + +Comments and examples can be added to your configuration nodes using the +``->setInfo()`` and ``->setExample()`` methods:: + + // src/Acme/HelloBundle/DependencyExtension/Configuration.php + namespace Acme\HelloBundle\DependencyInjection; + + use Symfony\Component\Config\Definition\Builder\TreeBuilder; + use Symfony\Component\Config\Definition\ConfigurationInterface; + + class Configuration implements ConfigurationInterface + { + public function getConfigTreeBuilder() + { + $treeBuilder = new TreeBuilder(); + $rootNode = $treeBuilder->root('acme_hello'); + + $rootNode + ->children() + ->scalarNode('my_type') + ->defaultValue('bar') + ->setInfo('what my_type configures') + ->setExample('example setting') + ->end() + ->end() + ; + + return $treeBuilder; + } + +This text appears as yaml comments in the output of the ``config:dump-reference`` +command. + .. index:: pair: Convention; Configuration From 1bf6e4211efdf5c31b4f3a29ef0d1358af18f8e2 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Mon, 20 Feb 2012 08:30:08 -0500 Subject: [PATCH 049/659] added note about using extension alias for config:dump-reference --- book/page_creation.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/book/page_creation.rst b/book/page_creation.rst index a9e55be8f7f..b7d86b5bcf9 100644 --- a/book/page_creation.rst +++ b/book/page_creation.rst @@ -817,6 +817,12 @@ FrameworkBundle configuration: app/console config:dump-reference FrameworkBundle +The extension alias (configuration key) can also be used: + +.. code-block:: text + + app/console config:dump-reference framework + .. note:: See the cookbook article: :doc:`How to expose a Semantic Configuration for From fc99ceae6d12bd80b7bc090fb744ec2669af55e0 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Mon, 20 Feb 2012 09:40:05 -0500 Subject: [PATCH 050/659] [book][templating] added hinclude.js docs --- book/templating.rst | 71 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 8 deletions(-) diff --git a/book/templating.rst b/book/templating.rst index 3b005642ea5..c038fb2e028 100644 --- a/book/templating.rst +++ b/book/templating.rst @@ -122,16 +122,16 @@ Throughout this chapter, template examples will be shown in both Twig and PHP. not program logic. The more you use Twig, the more you'll appreciate and benefit from this distinction. And of course, you'll be loved by web designers everywhere. - + Twig can also do things that PHP can't, such as true template inheritance (Twig templates compile down to PHP classes that inherit from each other), whitespace control, sandboxing, and the inclusion of custom functions and filters that only affect templates. Twig contains little features that make writing templates easier and more concise. Take the following example, which combines a loop with a logical ``if`` statement: - + .. code-block:: html+jinja - +