Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

[cookbook][form][data_transformer] some formatting tweaks #1200

Closed
wants to merge 5 commits into
from
@@ -22,7 +22,8 @@ will enter the issue number. The field will display an error if a non existing n
was entered::
// src/Acme/TaskBundle/Form/IssueSelectorType.php
- namespace Acme\TaskBundle\Form\Type;
+
+ namespace Acme\TaskBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
@@ -31,8 +32,14 @@ was entered::
class IssueSelectorType extends AbstractType
{
+ /**
+ * @var ObjectManager
+ */
private $om;
+ /**
+ * @param ObjectManager $om
+ */
public function __construct(ObjectManager $om)
{
$this->om = $om;
@@ -47,7 +54,7 @@ was entered::
public function getDefaultOptions(array $options)
{
return array(
- 'invalid_message'=>'The selected issue does not exist'
+ 'invalid_message' => 'The selected issue does not exist',
);
}
@@ -98,6 +105,7 @@ Next, we create the data transformer, which does the actual conversion::
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\DataTransformerInterface;
use Doctrine\Common\Persistence\ObjectManager;
+ use Acme\TaskBundle\Entity;
class IssueToNumberTransformer implements DataTransformerInterface
{
@@ -115,12 +123,12 @@ Next, we create the data transformer, which does the actual conversion::
}
/**
- * Transforms an issue object to a string.
+ * Transforms an object (issue) to a string (number).
*
- * @param \Acme\TaskBundle\Entity\Issue|null $issue
+ * @param Entity\Issue|null $user
* @return string
*/
- public function transform($issue)
+ public function transform($issue = null)
{
if (null === $issue) {
return "";
@@ -130,12 +138,11 @@ Next, we create the data transformer, which does the actual conversion::
}
/**
- * Transforms a string to an issue object.
+ * Transforms a string (number) to an object (issue).
*
* @param string $number
- * @return \Acme\TaskBundle\Entity\Issue|null
- *
- * @throws TransformationFailedException if issue object is not found.
+ * @return Entity\Issue|null
+ * @throws TransformationFailedException if object (issue) is not found.
*/
public function reverseTransform($number)
{
@@ -183,9 +190,9 @@ manager can be automatically injected:
You can now add the type to your form by its alias as follows::
- // src/Acme/TaskBundle/Form/Type/TaskType.php
+ // src/Acme/TaskBundle/Form/TaskType.php
- namespace Acme\TaskBundle\Form\Type;
+ namespace Acme\TaskBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
@@ -194,9 +201,11 @@ You can now add the type to your form by its alias as follows::
{
public function buildForm(FormBuilder $builder, array $options)
{
- $builder->add('task');
- $builder->add('dueDate', null, array('widget' => 'single_text'));
- $builder->add('issue', 'issue_selector');
+ $builder
+ ->add('task')
+ ->add('dueDate', null, array('widget' => 'single_text'));
+ ->add('issue', 'issue_selector')
+ ;
}
public function getName()
@@ -3,50 +3,53 @@ How to add "Remember Me" Login Functionality
Once a user is authenticated, their credentials are typically stored in the
session. This means that when the session ends they will be logged out and
-have to provide their login details again next time they wish to access the
-application. You can allow users to choose to stay logged in for longer than
-the session lasts using a cookie with the ``remember_me`` firewall option.
-The firewall needs to have a secret key configured, which is used to encrypt
-the cookie's content. It also has several options with default values which
+have to provide their login details again next time they wish to access the
+application. You can allow users to choose to stay logged in for longer than
+the session lasts using a cookie with the ``remember_me`` firewall option.
+The firewall needs to have a secret key configured, which is used to encrypt
+the cookie's content. It also has several options with default values which
are shown here:
.. configuration-block::
.. code-block:: yaml
# app/config/security.yml
+
firewalls:
main:
remember_me:
- key: aSecretKey
+ key: %secret%
lifetime: 3600
path: /
domain: ~ # Defaults to the current domain from $_SERVER
.. code-block:: xml
<!-- app/config/security.xml -->
+
<config>
<firewall>
<remember-me
- key="aSecretKey"
- lifetime="3600"
- path="/"
- domain="" <!-- Defaults to the current domain from $_SERVER -->
+ key = "%secret%"
+ lifetime = "3600"
+ path = "/"
+ domain = "" <!-- Defaults to the current domain from $_SERVER -->
/>
</firewall>
</config>
.. code-block:: php
// app/config/security.php
+
$container->loadFromExtension('security', array(
'firewalls' => array(
'main' => array('remember_me' => array(
- 'key' => 'aSecretKey',
- 'lifetime' => 3600,
- 'path' => '/',
- 'domain' => '', // Defaults to the current domain from $_SERVER
+ 'key' => '%secret%',
+ 'lifetime' => 3600,
+ 'path' => '/',
+ 'domain' => '', // Defaults to the current domain from $_SERVER
)),
),
));
@@ -89,7 +92,7 @@ might ultimately look like this:
<form action="<?php echo $view['router']->generate('login_check') ?>" method="post">
<label for="username">Username:</label>
- <input type="text" id="username"
+ <input type="text" id="username"
name="_username" value="<?php echo $last_username ?>" />
<label for="password">Password:</label>
@@ -117,12 +120,12 @@ before accessing certain resources. For example, you might allow a "remember me"
user to see basic account information, but then require them to actually
re-authenticate before modifying that information.
-The security component provides an easy way to do this. In addition to roles
+The security component provides an easy way to do this. In addition to roles
explicitly assigned to them, users are automatically given one of the following
roles depending on how they are authenticated:
-* ``IS_AUTHENTICATED_ANONYMOUSLY`` - automatically assigned to a user who is
- in a firewall protected part of the site but who has not actually logged in.
+* ``IS_AUTHENTICATED_ANONYMOUSLY`` - automatically assigned to a user who is
+ in a firewall protected part of the site but who has not actually logged in.
This is only possible if anonymous access has been allowed.
* ``IS_AUTHENTICATED_REMEMBERED`` - automatically assigned to a user who
@@ -140,14 +143,14 @@ You can use these to control access beyond the explicitly assigned roles.
role, then you also have the other two roles. In other words, these roles
represent three levels of increasing "strength" of authentication.
-You can use these additional roles for finer grained control over access to
-parts of a site. For example, you may want you user to be able to view their
-account at ``/account`` when authenticated by cookie but to have to provide
+You can use these additional roles for finer grained control over access to
+parts of a site. For example, you may want you user to be able to view their
+account at ``/account`` when authenticated by cookie but to have to provide
their login details to be able to edit the account details. You can do this
by securing specific controller actions using these roles. The edit action
-in the controller could be secured using the service context.
+in the controller could be secured using the service context.
-In the following example, the action is only allowed if the user has the
+In the following example, the action is only allowed if the user has the
``IS_AUTHENTICATED_FULLY`` role.
.. code-block:: php
@@ -186,10 +189,10 @@ which can secure your controller using annotations:
If you also had an access control in your security configuration that
required the user to have a ``ROLE_USER`` role in order to access any
of the account area, then you'd have the following situation:
-
+
* If a non-authenticated (or anonymously authenticated user) tries to
access the account area, the user will be asked to authenticate.
-
+
* Once the user has entered his username and password, assuming the
user receives the ``ROLE_USER`` role per your configuration, the user
will have the ``IS_AUTHENTICATED_FULLY`` role and be able to access