From 4904db888570dfdf96e879745e4071a5561b75da Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 17 Nov 2015 09:22:26 +0100 Subject: [PATCH 01/16] Updated article for modern Symfony practices and the use of bcrypt --- cookbook/security/custom_provider.rst | 81 +++++++++++++-------------- 1 file changed, 38 insertions(+), 43 deletions(-) diff --git a/cookbook/security/custom_provider.rst b/cookbook/security/custom_provider.rst index 60a53517bbe..4a03350174e 100644 --- a/cookbook/security/custom_provider.rst +++ b/cookbook/security/custom_provider.rst @@ -35,8 +35,8 @@ method. This is how your ``WebserviceUser`` class looks in action:: - // src/Acme/WebserviceUserBundle/Security/User/WebserviceUser.php - namespace Acme\WebserviceUserBundle\Security\User; + // src/AppBundle/Security/User/WebserviceUser.php + namespace AppBundle\Security\User; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\EquatableInterface; @@ -120,8 +120,8 @@ more details, see :class:`Symfony\\Component\\Security\\Core\\User\\UserProvider Here's an example of how this might look:: - // src/Acme/WebserviceUserBundle/Security/User/WebserviceUserProvider.php - namespace Acme\WebserviceUserBundle\Security\User; + // src/AppBundle/Security/User/WebserviceUserProvider.php + namespace AppBundle\Security\User; use Symfony\Component\Security\Core\User\UserProviderInterface; use Symfony\Component\Security\Core\User\UserInterface; @@ -162,7 +162,7 @@ Here's an example of how this might look:: public function supportsClass($class) { - return $class === 'Acme\WebserviceUserBundle\Security\User\WebserviceUser'; + return $class === 'AppBundle\Security\User\WebserviceUser'; } } @@ -177,8 +177,8 @@ Now you make the user provider available as a service: # app/config/services.yml services: - webservice_user_provider: - class: Acme\WebserviceUserBundle\Security\User\WebserviceUserProvider + app.webservice_user_provider: + class: AppBundle\Security\User\WebserviceUserProvider .. code-block:: xml @@ -190,8 +190,8 @@ Now you make the user provider available as a service: http://symfony.com/schema/dic/services/services-1.0.xsd"> - @@ -202,8 +202,8 @@ Now you make the user provider available as a service: use Symfony\Component\DependencyInjection\Definition; $container->setDefinition( - 'webservice_user_provider', - new Definition('Acme\WebserviceUserBundle\Security\User\WebserviceUserProvider') + 'app.webservice_user_provider', + new Definition('AppBundle\Security\User\WebserviceUserProvider') ); .. tip:: @@ -222,7 +222,7 @@ Modify ``security.yml`` Everything comes together in your security configuration. Add the user provider to the list of providers in the "security" section. Choose a name for the user provider -(e.g. "webservice") and mention the id of the service you just defined. +(e.g. "webservice") and mention the ``id`` of the service you just defined. .. configuration-block:: @@ -234,7 +234,7 @@ to the list of providers in the "security" section. Choose a name for the user p providers: webservice: - id: webservice_user_provider + id: app.webservice_user_provider .. code-block:: xml @@ -249,7 +249,7 @@ to the list of providers in the "security" section. Choose a name for the user p - + @@ -261,7 +261,7 @@ to the list of providers in the "security" section. Choose a name for the user p 'providers' => array( 'webservice' => array( - 'id' => 'webservice_user_provider', + 'id' => 'app.webservice_user_provider', ), ), )); @@ -279,7 +279,7 @@ users, e.g. by filling in a login form. You can do this by adding a line to the # ... encoders: - Acme\WebserviceUserBundle\Security\User\WebserviceUser: sha512 + AppBundle\Security\User\WebserviceUser: bcrypt .. code-block:: xml @@ -294,9 +294,8 @@ users, e.g. by filling in a login form. You can do this by adding a line to the - + @@ -307,16 +306,15 @@ users, e.g. by filling in a login form. You can do this by adding a line to the // ... 'encoders' => array( - 'Acme\WebserviceUserBundle\Security\User\WebserviceUser' => 'sha512', + 'AppBundle\Security\User\WebserviceUser' => 'bcrypt', ), + // ... )); The value here should correspond with however the passwords were originally encoded when creating your users (however those users were created). When -a user submits their password, the salt value is appended to the password and -then encoded using this algorithm before being compared to the hashed password -returned by your ``getPassword()`` method. Additionally, depending on your -options, the password may be encoded multiple times and encoded to base64. +a user submits their password, it's encoded using this algorithm and the result +is compared to the hashed password returned by your ``getPassword()`` method. .. sidebar:: Specifics on how Passwords are Encoded @@ -331,12 +329,12 @@ options, the password may be encoded multiple times and encoded to base64. If your external users have their passwords salted via a different method, then you'll need to do a bit more work so that Symfony properly encodes the password. That is beyond the scope of this entry, but would include - sub-classing ``MessageDigestPasswordEncoder`` and overriding the ``mergePasswordAndSalt`` - method. + sub-classing ``MessageDigestPasswordEncoder`` and overriding the + ``mergePasswordAndSalt`` method. - Additionally, the hash, by default, is encoded multiple times and encoded - to base64. For specific details, see `MessageDigestPasswordEncoder`_. - To prevent this, configure it in your configuration file: + Additionally, you can configure the details of the algorithm used to hash + passwords. In this example, the application sets explicitly the cost of + the bcrypt hashing: .. configuration-block:: @@ -347,10 +345,9 @@ options, the password may be encoded multiple times and encoded to base64. # ... encoders: - Acme\WebserviceUserBundle\Security\User\WebserviceUser: - algorithm: sha512 - encode_as_base64: false - iterations: 1 + AppBundle\Security\User\WebserviceUser: + algorithm: bcrypt + cost: 12 .. code-block:: xml @@ -365,11 +362,9 @@ options, the password may be encoded multiple times and encoded to base64. - + @@ -380,12 +375,12 @@ options, the password may be encoded multiple times and encoded to base64. // ... 'encoders' => array( - 'Acme\WebserviceUserBundle\Security\User\WebserviceUser' => array( - 'algorithm' => 'sha512', - 'encode_as_base64' => false, - 'iterations' => 1, - ), + 'AppBundle\Security\User\WebserviceUser' => array( + 'algorithm' => 'bcrypt', + 'cost' => 12, + ) ), + // ... )); .. _MessageDigestPasswordEncoder: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Security/Core/Encoder/MessageDigestPasswordEncoder.php From 337a9cd8cf65a565d886c6dced791cda20b1555e Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 14 Dec 2015 19:44:21 +0100 Subject: [PATCH 02/16] [Assetic] complete XML configuration examples --- cookbook/assetic/apply_to_option.rst | 50 +++++--- cookbook/assetic/asset_management.rst | 36 ++++-- cookbook/assetic/jpeg_optimize.rst | 115 ++++++++++++------ cookbook/assetic/php.rst | 12 +- cookbook/assetic/uglifyjs.rst | 61 +++++++--- cookbook/assetic/yuicompressor.rst | 25 ++-- .../configuration/override_dir_structure.rst | 14 ++- reference/configuration/assetic.rst | 90 +++++++------- 8 files changed, 274 insertions(+), 129 deletions(-) diff --git a/cookbook/assetic/apply_to_option.rst b/cookbook/assetic/apply_to_option.rst index 22c7506075f..264f1787a1c 100644 --- a/cookbook/assetic/apply_to_option.rst +++ b/cookbook/assetic/apply_to_option.rst @@ -27,14 +27,23 @@ An example configuration might look like this: .. code-block:: xml - - - /usr/lib/node_modules/ - - + + + + + + /usr/lib/node_modules/ + + + .. code-block:: php @@ -137,14 +146,23 @@ In this case you can specify that the ``coffee`` filter is applied to all .. code-block:: xml - - - /usr/lib/node_modules/ - + + + + + + /usr/lib/node_modules/ + + .. code-block:: php diff --git a/cookbook/assetic/asset_management.rst b/cookbook/assetic/asset_management.rst index af0055f5795..37fceba54fd 100644 --- a/cookbook/assetic/asset_management.rst +++ b/cookbook/assetic/asset_management.rst @@ -301,7 +301,11 @@ configuration under the ``assetic`` section. Read more in the + xmlns:assetic="http://symfony.com/schema/dic/assetic" + xsi:schemaLocation="http://symfony.com/schema/dic/services + http://symfony.com/schema/dic/services/services-1.0.xsd + http://symfony.com/schema/dic/assetic + http://symfony.com/schema/dic/assetic/assetic-1.0.xsd"> @@ -388,11 +392,20 @@ should be defined: .. code-block:: xml - - - + + + + + + + .. code-block:: php @@ -528,7 +541,16 @@ the following change in your ``config_dev.yml`` file: .. code-block:: xml - + + + + + .. code-block:: php diff --git a/cookbook/assetic/jpeg_optimize.rst b/cookbook/assetic/jpeg_optimize.rst index c55a32dc800..0c8745155ba 100644 --- a/cookbook/assetic/jpeg_optimize.rst +++ b/cookbook/assetic/jpeg_optimize.rst @@ -30,11 +30,20 @@ using the ``bin`` option of the ``jpegoptim`` filter: .. code-block:: xml - - - + + + + + + + .. code-block:: php @@ -88,12 +97,21 @@ to ``true``: .. code-block:: xml - - - + + + + + + + .. code-block:: php @@ -129,12 +147,21 @@ be at the expense of its quality: .. code-block:: xml - - - + + + + + + + .. code-block:: php @@ -171,15 +198,24 @@ following configuration: .. code-block:: xml - - - - - - + + + + + + + + + + .. code-block:: php @@ -221,16 +257,25 @@ file: .. code-block:: xml - - - - + + + + - - + bin="path/to/jpegoptim" /> + + + + + .. code-block:: php diff --git a/cookbook/assetic/php.rst b/cookbook/assetic/php.rst index c7e8c2e6b26..52fba78e593 100644 --- a/cookbook/assetic/php.rst +++ b/cookbook/assetic/php.rst @@ -91,7 +91,11 @@ First, configure a new ``scssphp`` Assetic filter: + xmlns:assetic="http://symfony.com/schema/dic/assetic" + xsi:schemaLocation="http://symfony.com/schema/dic/services + http://symfony.com/schema/dic/services/services-1.0.xsd + http://symfony.com/schema/dic/assetic + http://symfony.com/schema/dic/assetic/assetic-1.0.xsd"> @@ -159,7 +163,11 @@ First, configure a new ``jsqueeze`` Assetic filter as follows: + xmlns:assetic="http://symfony.com/schema/dic/assetic" + xsi:schemaLocation="http://symfony.com/schema/dic/services + http://symfony.com/schema/dic/services/services-1.0.xsd + http://symfony.com/schema/dic/assetic + http://symfony.com/schema/dic/assetic/assetic-1.0.xsd"> diff --git a/cookbook/assetic/uglifyjs.rst b/cookbook/assetic/uglifyjs.rst index a08569647a3..dfcf67453ef 100644 --- a/cookbook/assetic/uglifyjs.rst +++ b/cookbook/assetic/uglifyjs.rst @@ -79,12 +79,21 @@ your JavaScripts: .. code-block:: xml - - - - + + + + + + + + .. code-block:: php @@ -137,12 +146,21 @@ can configure its location using the ``node`` key: .. code-block:: xml - - - + + + + + + + .. code-block:: php @@ -253,11 +271,20 @@ Next, add the configuration for this filter: .. code-block:: xml - - - + + + + + + + .. code-block:: php diff --git a/cookbook/assetic/yuicompressor.rst b/cookbook/assetic/yuicompressor.rst index 6ae078a8eac..83e6c3e2dfe 100644 --- a/cookbook/assetic/yuicompressor.rst +++ b/cookbook/assetic/yuicompressor.rst @@ -43,14 +43,23 @@ stylesheets: .. code-block:: xml - - - - + + + + + + + + .. code-block:: php diff --git a/cookbook/configuration/override_dir_structure.rst b/cookbook/configuration/override_dir_structure.rst index 821c9601ac7..d355269afc9 100644 --- a/cookbook/configuration/override_dir_structure.rst +++ b/cookbook/configuration/override_dir_structure.rst @@ -135,9 +135,17 @@ the ``extra.symfony-web-dir`` option in the ``composer.json`` file: .. code-block:: xml - - - + + + + + + .. code-block:: php diff --git a/reference/configuration/assetic.rst b/reference/configuration/assetic.rst index 8c0ba8be7fc..6b54878827d 100644 --- a/reference/configuration/assetic.rst +++ b/reference/configuration/assetic.rst @@ -55,49 +55,57 @@ Full Default Configuration .. code-block:: xml - - - FrameworkBundle - SecurityBundle - TwigBundle - MonologBundle - SwiftmailerBundle - DoctrineBundle - AsseticBundle - ... - - - - - - - - - - - - - - + + + + - - - - + + FrameworkBundle + SecurityBundle + TwigBundle + MonologBundle + SwiftmailerBundle + DoctrineBundle + AsseticBundle + ... - - + + + + + + + + + + + + + + + - - + - + + + + + + + + From f70947f1f58c5aa74e7447dabde0f9520093157a Mon Sep 17 00:00:00 2001 From: WouterJ Date: Fri, 18 Dec 2015 01:32:40 +0100 Subject: [PATCH 03/16] [#6015] Add missing xsi namespace definition --- cookbook/assetic/apply_to_option.rst | 2 ++ cookbook/assetic/asset_management.rst | 3 +++ cookbook/assetic/jpeg_optimize.rst | 5 +++++ cookbook/assetic/php.rst | 2 ++ cookbook/assetic/uglifyjs.rst | 3 +++ cookbook/assetic/yuicompressor.rst | 1 + cookbook/configuration/override_dir_structure.rst | 1 + reference/configuration/assetic.rst | 1 + 8 files changed, 18 insertions(+) diff --git a/cookbook/assetic/apply_to_option.rst b/cookbook/assetic/apply_to_option.rst index 264f1787a1c..0e329087506 100644 --- a/cookbook/assetic/apply_to_option.rst +++ b/cookbook/assetic/apply_to_option.rst @@ -30,6 +30,7 @@ An example configuration might look like this: Date: Sat, 19 Dec 2015 11:41:40 +0100 Subject: [PATCH 07/16] [#5829] Change highlighting language --- cookbook/security/_ircmaxwell_password-compat.rst.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookbook/security/_ircmaxwell_password-compat.rst.inc b/cookbook/security/_ircmaxwell_password-compat.rst.inc index 4c1bf62ce31..8171132ba50 100644 --- a/cookbook/security/_ircmaxwell_password-compat.rst.inc +++ b/cookbook/security/_ircmaxwell_password-compat.rst.inc @@ -3,6 +3,6 @@ If you're using PHP 5.4 or lower, you'll need to install the ``ircmaxell/password-compat`` library via Composer in order to be able to use the ``bcrypt`` encoder: - .. code-block:: json + .. code-block:: bash $ require ircmaxell/password-compat "~1.0" From 7b4a649f658e6c21dc09e77a5e54e103f1172a2c Mon Sep 17 00:00:00 2001 From: Mathias STRASSER Date: Wed, 21 Oct 2015 00:46:37 +0200 Subject: [PATCH 08/16] Remove AppBundle The twig file is in `app/Resources/views`. Fix error `Unable to find template "AppBundle:Form:fields.html.twig"` --- cookbook/form/create_custom_field_type.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cookbook/form/create_custom_field_type.rst b/cookbook/form/create_custom_field_type.rst index 88139dd9e67..23792bf9ca3 100644 --- a/cookbook/form/create_custom_field_type.rst +++ b/cookbook/form/create_custom_field_type.rst @@ -164,14 +164,14 @@ link for details), create a ``gender_widget`` block to handle this: twig: form: resources: - - 'AppBundle:Form:fields.html.twig' + - ':form/fields.html.twig' .. code-block:: xml - AppBundle:Form:fields.html.twig + :form/fields.html.twig @@ -181,7 +181,7 @@ link for details), create a ``gender_widget`` block to handle this: $container->loadFromExtension('twig', array( 'form' => array( 'resources' => array( - 'AppBundle:Form:fields.html.twig', + ':form/fields.html.twig', ), ), )); @@ -197,7 +197,7 @@ link for details), create a ``gender_widget`` block to handle this: templating: form: resources: - - 'AppBundle:Form' + - ':form:fields.html.twig' .. code-block:: xml @@ -212,7 +212,7 @@ link for details), create a ``gender_widget`` block to handle this: - AppBundle:Form + :form:fields.html.twig @@ -225,7 +225,7 @@ link for details), create a ``gender_widget`` block to handle this: 'templating' => array( 'form' => array( 'resources' => array( - 'AppBundle:Form', + ':form:fields.html.twig', ), ), ), From 4a412529ff09d696a923f5fcefff4e82742d107f Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 19 Dec 2015 11:46:54 +0100 Subject: [PATCH 09/16] [#5819] Fix notation and PHP template references --- cookbook/form/create_custom_field_type.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cookbook/form/create_custom_field_type.rst b/cookbook/form/create_custom_field_type.rst index 23792bf9ca3..ea25570efe0 100644 --- a/cookbook/form/create_custom_field_type.rst +++ b/cookbook/form/create_custom_field_type.rst @@ -164,7 +164,7 @@ link for details), create a ``gender_widget`` block to handle this: twig: form: resources: - - ':form/fields.html.twig' + - 'form/fields.html.twig' .. code-block:: xml @@ -181,7 +181,7 @@ link for details), create a ``gender_widget`` block to handle this: $container->loadFromExtension('twig', array( 'form' => array( 'resources' => array( - ':form/fields.html.twig', + 'form/fields.html.twig', ), ), )); @@ -197,7 +197,7 @@ link for details), create a ``gender_widget`` block to handle this: templating: form: resources: - - ':form:fields.html.twig' + - ':form:fields.html.php' .. code-block:: xml @@ -212,7 +212,7 @@ link for details), create a ``gender_widget`` block to handle this: - :form:fields.html.twig + :form:fields.html.php @@ -225,7 +225,7 @@ link for details), create a ``gender_widget`` block to handle this: 'templating' => array( 'form' => array( 'resources' => array( - ':form:fields.html.twig', + ':form:fields.html.php', ), ), ), From ff2386851500d946e665278bbbd9b03e93a36436 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 19 Dec 2015 13:02:06 +0100 Subject: [PATCH 10/16] [#5819] fix notation in XML configuration --- cookbook/form/create_custom_field_type.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookbook/form/create_custom_field_type.rst b/cookbook/form/create_custom_field_type.rst index ea25570efe0..9a03ef7f501 100644 --- a/cookbook/form/create_custom_field_type.rst +++ b/cookbook/form/create_custom_field_type.rst @@ -171,7 +171,7 @@ link for details), create a ``gender_widget`` block to handle this: - :form/fields.html.twig + form/fields.html.twig From fa3b0bf50e772523af1d4608d277e42a56ce29d2 Mon Sep 17 00:00:00 2001 From: Daniel Parejo Date: Wed, 25 Nov 2015 13:44:48 +0100 Subject: [PATCH 11/16] Update php_soap_extension.rst I think $client = new \Soapclient('http://example.com/app.php/soap?wsdl', true); doesn't accept "true" as a default parameter anymore --- cookbook/web_services/php_soap_extension.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookbook/web_services/php_soap_extension.rst b/cookbook/web_services/php_soap_extension.rst index de5a8a20dab..134c67fb044 100644 --- a/cookbook/web_services/php_soap_extension.rst +++ b/cookbook/web_services/php_soap_extension.rst @@ -124,7 +124,7 @@ Below is an example calling the service using a `NuSOAP`_ client. This example assumes that the ``indexAction`` in the controller above is accessible via the route ``/soap``:: - $client = new \Soapclient('http://example.com/app.php/soap?wsdl', true); + $client = new \Soapclient('http://example.com/app.php/soap?wsdl'); $result = $client->call('hello', array('name' => 'Scott')); From 716a4f246127dcd290cae70718038879cdd9e10b Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Sat, 17 Oct 2015 10:57:54 +0200 Subject: [PATCH 12/16] added app_ prefix to form type names --- book/forms.rst | 8 ++++---- cookbook/form/create_custom_field_type.rst | 6 +++--- cookbook/form/create_form_type_extension.rst | 2 +- cookbook/form/dynamic_form_modification.rst | 12 ++++++------ 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/book/forms.rst b/book/forms.rst index a4b95fd62c9..d5c969b8d1c 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -1066,7 +1066,7 @@ that will house the logic for building the task form:: public function getName() { - return 'task'; + return 'app_task'; } } @@ -1174,7 +1174,7 @@ easy to use in your application. app.form.type.task: class: AppBundle\Form\Type\TaskType tags: - - { name: form.type, alias: task } + - { name: form.type, alias: app_task } .. code-block:: xml @@ -1186,7 +1186,7 @@ easy to use in your application. - + @@ -1200,7 +1200,7 @@ easy to use in your application. 'AppBundle\Form\Type\TaskType' ) ->addTag('form.type', array( - 'alias' => 'task', + 'alias' => 'app_task', )) ; diff --git a/cookbook/form/create_custom_field_type.rst b/cookbook/form/create_custom_field_type.rst index 9a03ef7f501..c49147b8a4c 100644 --- a/cookbook/form/create_custom_field_type.rst +++ b/cookbook/form/create_custom_field_type.rst @@ -308,14 +308,14 @@ the ``genders`` parameter value as the first argument to its to-be-created arguments: - '%genders%' tags: - - { name: form.type, alias: gender } + - { name: form.type, alias: app_gender } .. code-block:: xml %genders% - + .. code-block:: php @@ -329,7 +329,7 @@ the ``genders`` parameter value as the first argument to its to-be-created array('%genders%') )) ->addTag('form.type', array( - 'alias' => 'gender', + 'alias' => 'app_gender', )) ; diff --git a/cookbook/form/create_form_type_extension.rst b/cookbook/form/create_form_type_extension.rst index 153b0b7fc57..39e23350f80 100644 --- a/cookbook/form/create_form_type_extension.rst +++ b/cookbook/form/create_form_type_extension.rst @@ -312,7 +312,7 @@ next to the file field. For example:: public function getName() { - return 'media'; + return 'app_media'; } } diff --git a/cookbook/form/dynamic_form_modification.rst b/cookbook/form/dynamic_form_modification.rst index 006955d9d67..7b5a5d589d2 100644 --- a/cookbook/form/dynamic_form_modification.rst +++ b/cookbook/form/dynamic_form_modification.rst @@ -246,7 +246,7 @@ Using an event listener, your form might look like this:: public function getName() { - return 'friend_message'; + return 'app_friend_message'; } public function setDefaultOptions(OptionsResolverInterface $resolver) @@ -393,7 +393,7 @@ it with :ref:`dic-tags-form-type`. class: AppBundle\Form\Type\FriendMessageFormType arguments: ['@security.context'] tags: - - { name: form.type, alias: friend_message } + - { name: form.type, alias: app_friend_message } .. code-block:: xml @@ -401,7 +401,7 @@ it with :ref:`dic-tags-form-type`. - + @@ -409,7 +409,7 @@ it with :ref:`dic-tags-form-type`. // app/config/config.php $definition = new Definition('AppBundle\Form\Type\FriendMessageFormType'); - $definition->addTag('form.type', array('alias' => 'friend_message')); + $definition->addTag('form.type', array('alias' => 'app_friend_message')); $container->setDefinition( 'app.form.friend_message', $definition, @@ -430,7 +430,7 @@ class, you can simply call:: { public function newAction(Request $request) { - $form = $this->createForm('friend_message'); + $form = $this->createForm('app_friend_message'); // ... } @@ -441,7 +441,7 @@ You can also easily embed the form type into another form:: // inside some other "form type" class public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->add('message', 'friend_message'); + $builder->add('message', 'app_friend_message'); } .. _cookbook-form-events-submitted-data: From e47fa90b977335bc69ea10b60d52c43e6704d91d Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 19 Dec 2015 14:40:06 +0100 Subject: [PATCH 13/16] Updated getName() to return with app_ prefix --- cookbook/form/create_custom_field_type.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookbook/form/create_custom_field_type.rst b/cookbook/form/create_custom_field_type.rst index c49147b8a4c..8a8e0e96e0a 100644 --- a/cookbook/form/create_custom_field_type.rst +++ b/cookbook/form/create_custom_field_type.rst @@ -45,7 +45,7 @@ for form fields, which is ``\Form\Type``. Make sure the field extend public function getName() { - return 'gender'; + return 'app_gender'; } } From a81ffd4ba6c1f433109c1642aa2aad5267230b5f Mon Sep 17 00:00:00 2001 From: Michael H Date: Thu, 17 Dec 2015 18:48:42 -0800 Subject: [PATCH 14/16] Fixed misspelling of human in glossary.rst YAML --- glossary.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glossary.rst b/glossary.rst index c672e4afe32..53da796cfb2 100644 --- a/glossary.rst +++ b/glossary.rst @@ -121,7 +121,7 @@ Glossary YAML *YAML* is a recursive acronym for "YAML Ain't a Markup Language". It's a - lightweight, humane data serialization language used extensively in + lightweight, human friendly data serialization language used extensively in Symfony's configuration files. See the :doc:`/components/yaml/introduction` chapter. From 2b418659cdaa1fc07c93fe9b0159debcf4263566 Mon Sep 17 00:00:00 2001 From: Muhammad Iqbal Date: Tue, 20 Oct 2015 00:59:35 +0500 Subject: [PATCH 15/16] Conversion from mysql to PDO --- book/from_flat_php_to_symfony2.rst | 61 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/book/from_flat_php_to_symfony2.rst b/book/from_flat_php_to_symfony2.rst index bfbc99b2138..9086e7ba183 100644 --- a/book/from_flat_php_to_symfony2.rst +++ b/book/from_flat_php_to_symfony2.rst @@ -29,12 +29,12 @@ persisted to the database. Writing in flat PHP is quick and dirty: query('SELECT id, title FROM post'); + $result->setFetchMode(PDO::FETCH_ASSOC); ?> - + @@ -43,7 +43,7 @@ persisted to the database. Writing in flat PHP is quick and dirty:

List of Posts

- + That's quick to write, fast to execute, and, as your app grows, impossible @@ -86,21 +86,22 @@ the code that prepares the HTML "presentation": .. code-block:: html+php // index.php - $link = mysql_connect('localhost', 'myuser', 'mypassword'); - mysql_select_db('blog_db', $link); - - $result = mysql_query('SELECT id, title FROM post', $link); - + $link = new PDO("mysql:host=localhost;dbname=blog_db", 'myuser', 'mypassword'); + + $result = $link->query('SELECT id, title FROM post'); + $result->setFetchMode(PDO::FETCH_ASSOC); + $posts = array(); - while ($row = mysql_fetch_assoc($result)) { + while ($row = $result->fetch()) { $posts[] = $row; } - - mysql_close($link); - + + $link = null; + // include the HTML presentation code require 'templates/list.php'; + The HTML code is now stored in a separate file (``templates/list.php``), which is primarily an HTML file that uses a template-like PHP syntax: @@ -148,28 +149,28 @@ of the application are isolated in a new file called ``model.php``: // model.php function open_database_connection() { - $link = mysql_connect('localhost', 'myuser', 'mypassword'); - mysql_select_db('blog_db', $link); - + $link = new PDO("mysql:host=localhost;dbname=blog_db", 'myuser', 'mypassword'); return $link; } - + function close_database_connection($link) { - mysql_close($link); + $link = null; } - + function get_all_posts() { $link = open_database_connection(); - - $result = mysql_query('SELECT id, title FROM post', $link); + + $result = $link->query('SELECT id, title FROM post'); + $result->setFetchMode(PDO::FETCH_ASSOC); + $posts = array(); - while ($row = mysql_fetch_assoc($result)) { + while ($row = $result->fetch()) { $posts[] = $row; } close_database_connection($link); - + return $posts; } @@ -261,11 +262,9 @@ an individual blog result based on a given id:: function get_post_by_id($id) { $link = open_database_connection(); - $id = intval($id); - $query = 'SELECT created_at, title, body FROM post WHERE id = '.$id; - $result = mysql_query($query); - $row = mysql_fetch_assoc($result); + $result = $link->query('SELECT created_at, title, body FROM post WHERE id = '.$id); + $row = $result->fetch(PDO::FETCH_ASSOC); close_database_connection($link); From 9960f9cf67b4411cb49111f1ea4f4d99c2698461 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Mon, 21 Dec 2015 11:12:02 +0100 Subject: [PATCH 16/16] [#5811] Minor fixes to flat PHP to Symfony article --- book/from_flat_php_to_symfony2.rst | 82 ++++++++++++------------------ 1 file changed, 32 insertions(+), 50 deletions(-) diff --git a/book/from_flat_php_to_symfony2.rst b/book/from_flat_php_to_symfony2.rst index 9086e7ba183..63243ef3a23 100644 --- a/book/from_flat_php_to_symfony2.rst +++ b/book/from_flat_php_to_symfony2.rst @@ -30,11 +30,10 @@ persisted to the database. Writing in flat PHP is quick and dirty: query('SELECT id, title FROM post'); - $result->setFetchMode(PDO::FETCH_ASSOC); ?> - + @@ -43,7 +42,7 @@ persisted to the database. Writing in flat PHP is quick and dirty:

List of Posts

- + @@ -81,23 +80,20 @@ Isolating the Presentation ~~~~~~~~~~~~~~~~~~~~~~~~~~ The code can immediately gain from separating the application "logic" from -the code that prepares the HTML "presentation": - -.. code-block:: html+php +the code that prepares the HTML "presentation":: // index.php $link = new PDO("mysql:host=localhost;dbname=blog_db", 'myuser', 'mypassword'); - + $result = $link->query('SELECT id, title FROM post'); - $result->setFetchMode(PDO::FETCH_ASSOC); - + $posts = array(); - while ($row = $result->fetch()) { + while ($row = $result->fetch(PDO::FETCH_ASSOC)) { $posts[] = $row; } - + $link = null; - + // include the HTML presentation code require 'templates/list.php'; @@ -142,35 +138,33 @@ Isolating the Application (Domain) Logic So far the application contains only one page. But what if a second page needed to use the same database connection, or even the same array of blog posts? Refactor the code so that the core behavior and data-access functions -of the application are isolated in a new file called ``model.php``: - -.. code-block:: html+php +of the application are isolated in a new file called ``model.php``:: // model.php function open_database_connection() { - $link = new PDO("mysql:host=localhost;dbname=blog_db", 'myuser', 'mypassword'); + $link = new PDO("mysql:host=localhost;dbname=blog_db", 'myuser', 'mypassword'); + return $link; } - + function close_database_connection($link) { $link = null; } - + function get_all_posts() { $link = open_database_connection(); - - $result = $link->query('SELECT id, title FROM post'); - $result->setFetchMode(PDO::FETCH_ASSOC); - + + $result = $link->query('SELECT id, title FROM post'); + $posts = array(); - while ($row = $result->fetch()) { + while ($row = $result->fetch(PDO::FETCH_ASSOC)) { $posts[] = $row; } close_database_connection($link); - + return $posts; } @@ -183,9 +177,7 @@ of the application are isolated in a new file called ``model.php``: in this example, only a portion (or none) of the model is actually concerned with accessing a database. -The controller (``index.php``) is now very simple: - -.. code-block:: html+php +The controller (``index.php``) is now very simple:: require_once 'model.php'; @@ -263,8 +255,8 @@ an individual blog result based on a given id:: { $link = open_database_connection(); $id = intval($id); - $result = $link->query('SELECT created_at, title, body FROM post WHERE id = '.$id); - $row = $result->fetch(PDO::FETCH_ASSOC); + $result = $link->query('SELECT created_at, title, body FROM post WHERE id = '.$id); + $row = $result->fetch(PDO::FETCH_ASSOC); close_database_connection($link); @@ -272,9 +264,7 @@ an individual blog result based on a given id:: } Next, create a new file called ``show.php`` - the controller for this new -page: - -.. code-block:: html+php +page:: require_once 'model.php'; @@ -352,9 +342,7 @@ You're about to take a **big** step with the application. With one file handling all requests, you can centralize things such as security handling, configuration loading, and routing. In this application, ``index.php`` must now be smart enough to render the blog post list page *or* the blog post show page based -on the requested URI: - -.. code-block:: html+php +on the requested URI:: // index.php @@ -364,9 +352,9 @@ on the requested URI: // route the request internally $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); - if ('/index.php' == $uri) { + if ('/index.php' === $uri) { list_action(); - } elseif ('/index.php/show' == $uri && isset($_GET['id'])) { + } elseif ('/index.php/show' === $uri && isset($_GET['id'])) { show_action($_GET['id']); } else { header('Status: 404 Not Found'); @@ -374,9 +362,7 @@ on the requested URI: } For organization, both controllers (formerly ``index.php`` and ``show.php``) -are now PHP functions and each has been moved into a separate file, ``controllers.php``: - -.. code-block:: php +are now PHP functions and each has been moved into a separate file, ``controllers.php``:: function list_action() { @@ -454,9 +440,7 @@ to interpret each request and return a response. To this end, Symfony provides both a :class:`Symfony\\Component\\HttpFoundation\\Request` and a :class:`Symfony\\Component\\HttpFoundation\\Response` class. These classes are object-oriented representations of the raw HTTP request being processed and -the HTTP response being returned. Use them to improve the blog: - -.. code-block:: html+php +the HTTP response being returned. Use them to improve the blog:: // index.php require_once 'vendor/autoload.php'; @@ -467,9 +451,9 @@ the HTTP response being returned. Use them to improve the blog: $request = Request::createFromGlobals(); $uri = $request->getPathInfo(); - if ('/' == $uri) { + if ('/' === $uri) { $response = list_action(); - } elseif ('/show' == $uri && $request->query->has('id')) { + } elseif ('/show' === $uri && $request->query->has('id')) { $response = show_action($request->query->get('id')); } else { $html = '

Page Not Found

'; @@ -481,9 +465,7 @@ the HTTP response being returned. Use them to improve the blog: The controllers are now responsible for returning a ``Response`` object. To make this easier, you can add a new ``render_template()`` function, which, -incidentally, acts quite a bit like the Symfony templating engine: - -.. code-block:: php +incidentally, acts quite a bit like the Symfony templating engine:: // controllers.php use Symfony\Component\HttpFoundation\Response;