8000 Merge branch '2.0' · symfony/symfony-docs@4c59201 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4c59201

Browse files
committed
Merge branch '2.0'
Conflicts: cookbook/security/entity_provider.rst
2 parents 21b7735 + 1dd779d commit 4c59201

File tree

4 files changed

+100
-35
lines changed

4 files changed

+100
-35
lines changed

book/installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ Now, the vendor directory won't be committed to source control. This is fine
231231
project, he/she can simply run the ``php composer.phar install`` script to
232232
download all the necessary vendor libraries.
233233

234-
.. _`enable ACL support`: https://help.ubuntu.com/community/FilePermissions#ACLs
234+
.. _`enable ACL support`: https://help.ubuntu.com/community/FilePermissionsACLs
235235
.. _`http://symfony.com/download`: http://symfony.com/download
236236
.. _`Git`: http://git-scm.com/
237237
.. _`GitHub Bootcamp`: http://help.github.com/set-up-git-redirect

cookbook/security/entity_provider.rst

Lines changed: 75 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ focus on the most important methods that come from the
5353
5454
namespace Acme\UserBundle\Entity;
5555
56-
use Symfony\Component\Security\Core\User\UserInterface;
5756
use Doctrine\ORM\Mapping as ORM;
57+
use Symfony\Component\Security\Core\User\UserInterface;
5858
5959
/**
6060
* Acme\UserBundle\Entity\User
@@ -65,29 +65,29 @@ focus on the most important methods that come from the
6565
class User implements UserInterface
6666
{
6767
/**
68-
* @ORM\Column(name="id", type="integer")
69-
* @ORM\Id()
68+
* @ORM\Column(type="integer")
69+
* @ORM\Id
7070
* @ORM\GeneratedValue(strategy="AUTO")
7171
*/
7272
private $id;
7373
7474
/**
75-
* @ORM\Column(name="username", type="string", length=25, unique=true)
75+
* @ORM\Column(type="string", length=25, unique=true)
7676
*/
7777
private $username;
7878
7979
/**
80-
* @ORM\Column(name="salt", type="string", length=40)
80+
* @ORM\Column(type="string", length=32)
8181
*/
8282
private $salt;
8383
8484
/**
85-
* @ORM\Column(name="password", type="string", length=40)
85+
* @ORM\Column(type="string", length=40)
8686
*/
8787
private $password;
8888
8989
/**
90-
* @ORM\Column(name="email", type="string", length=60, unique=true)
90+
* @ORM\Column(type="string", length=60, unique=true)
9191
*/
9292
private $email;
9393
@@ -99,39 +99,68 @@ focus on the most important methods that come from the
9999
public function __construct()
100100
{
101101
$this->isActive = true;
102-
$this->salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
103-
}
104-
105-
public function getRoles()
106-
{
107-
return array('ROLE_USER');
108-
}
109-
110-
public function eraseCredentials()
111-
{
102+
$this->salt = md5(uniqid(null, true));
112103
}
113104
105+
/**
106+
* @inheritDoc
107+
*/
114108
public function getUsername()
115109
{
116110
return $this->username;
117111
}
118112
113+
/**
114+
* @inheritDoc
115+
*/
119116
public function getSalt()
120117
{
121118
return $this->salt;
122119
}
123120
121+
/**
122+
* @inheritDoc
123+
*/
124124
public function getPassword()
125125
{
126126
return $this->password;
127127
}
128+
129+
/**
130+
* @inheritDoc
131+
*/
132+
public function getRoles()
133+
{
134+
return array('ROLE_USER');
135+
}
136+
137+
/**
138+
* @inheritDoc
139+
*/
140+
public function eraseCredentials()
141+
{
142+
}
143+
144+
/**
145+
* @inheritDoc
146+
*/
147+
public function equals(UserInterface $user)
148+
{
149+
return $this->username === $user->getUsername();
150+
}
128151
}
129152
130153
In order to use an instance of the ``AcmeUserBundle:User`` class in the Symfony
131154
security layer, the entity class must implement the
132155
:class:`Symfony\\Component\\Security\\Core\\User\\UserInterface`. This
133-
interface forces the class to implement the five following methods: ``getRoles()``,
134-
``getPassword()``, ``getSalt()``, ``getUsername()``, ``eraseCredentials()``.
156+
interface forces the class to implement the five following methods:
157+
158+
* ``getRoles()``,
159+
* ``getPassword()``,
160+
* ``getSalt()``,
161+
* ``getUsername()``,
162+
* ``eraseCredentials()``
163+
135164
For more details on each of these, see :class:`Symfony\\Component\\Security\\Core\\User\\UserInterface`.
136165

137166
Below is an export of my ``User`` table from MySQL. For details on how to
@@ -140,14 +169,14 @@ create user records and encode their password, see :ref:`book-security-encoding-
140169
.. code-block:: text
141170
142171
mysql> select * from user;
143-
+----+----------+------------------------------------------+------------------------------------------+--------------------+-----------+
144-
| id | username | salt | password | email | is_active |
145-
+----+----------+------------------------------------------+------------------------------------------+--------------------+-----------+
146-
| 1 | hhamon | 7308e59b97f6957fb42d66f894793079c366d7c2 | 09610f61637408828a35d7debee5b38a8350eebe | hhamon@example.com | 1 |
147-
| 2 | jsmith | ce617a6cca9126 10000 bf4036ca0c02e82deea081e564 | 8390105917f3a3d533815250ed7c64b4594d7ebf | jsmith@example.com | 1 |
148-
| 3 | maxime | cd01749bb995dc658fa56ed45458d807b523e4cf | 9764731e5f7fb944de5fd8efad4949b995b72a3c | maxime@example.com | 0 |
149-
| 4 | donald | 6683c2bfd90c0426088402930cadd0f84901f2f4 | 5c3bcec385f59edcc04490d1db95fdb8673bf612 | donald@example.com | 1 |
150-
+----+----------+------------------------------------------+------------------------------------------+--------------------+-----------+
172+
+----+----------+----------------------------------+------------------------------------------+--------------------+-----------+
173+
| id | username | salt | password | email | is_active |
174+
+----+----------+----------------------------------+------------------------------------------+--------------------+-----------+
175+
| 1 | hhamon | 7308e59b97f6957fb42d66f894793079 | 09610f61637408828a35d7debee5b38a8350eebe | hhamon@example.com | 1 |
176+
| 2 | jsmith | ce617a6cca9126bf4036ca0c02e82dee | 8390105917f3a3d533815250ed7c64b4594d7ebf | jsmith@example.com | 1 |
177+
| 3 | maxime | cd01749bb995dc658fa56ed45458d807 | 9764731e5f7fb944de5fd8efad4949b995b72a3c | maxime@example.com | 0 |
178+
| 4 | donald | 6683c2bfd90c0426088402930cadd0f8 | 5c3bcec385f59edcc04490d1db95fdb8673bf612 | donald@example.com | 1 |
179+
+----+----------+----------------------------------+------------------------------------------+--------------------+-----------+
151180
4 rows in set (0.00 sec)
152181
153182
The database now contains four users with different usernames, emails and
@@ -172,12 +201,17 @@ then be checked against our User entity records in the database:
172201
.. code-block:: yaml
173202
174203
# app/config/security.yml
204+
175205
security:
176206
encoders:
177207
Acme\UserBundle\Entity\User:
178-
algorithm: sha1
208+
algorithm: sha1
179209
encode_as_base64: false
180-
iterations: 1
210+
iterations: 1
211+
212+
role_hierarchy:
213+
ROLE_ADMIN: ROLE_USER
214+
ROLE_SUPER_ADMIN: [ ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH ]
181215
182216
providers:
183217
administrators:
@@ -441,13 +475,19 @@ that forces it to have a ``getRole()`` method::
441475
*/
442476
private $id;
443477

444-
/** @ORM\Column(name="name", type="string", length=30) */
478+
/**
479+
* @ORM\Column(name="name", type="string", length=30)
480+
*/
445481
private $name;
446482

447-
/** @ORM\Column(name="role", type="string", length=20, unique=true) */
483+
/**
484+
* @ORM\Column(name="role", type="string", length=20, unique=true)
485+
*/
448486
private $role;
449487

450-
/** @ORM\ManyToMany(targetEntity="User", mappedBy="groups") */
488+
/**
489+
* @ORM\ManyToMany(targetEntity="User", mappedBy="groups")
490+
*/
451491
private $users;
452492

453493
public function __construct()
@@ -457,7 +497,9 @@ that forces it to have a ``getRole()`` method::
457497

458498
// ... getters and setters for each property
459499

460-
/** @see RoleInterface */
500+
/**
501+
* @see RoleInterface
502+
*/
461503
public function getRole()
462504
{
463505
return $this->role;

cookbook/validation/custom_constraint.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Furthering our example, take a look at the ``ProtocolValidator`` as an example:
6262
public function isValid($value, Constraint $constraint)
6363
{
6464
if (in_array($value, $constraint->protocols));
65+
$this->setMessage($constraint->message, array('%protocols%' => $constraint->protocols));
6566
6667
return true;
6768
}
@@ -70,6 +71,11 @@ Furthering our example, take a look at the ``ProtocolValidator`` as an example:
7071
}
7172
}
7273
74+
.. note::
75+
76+
Don't forget to call ``setMessage`` to construct an error message when the
77+
value is invalid.
78+
7379
Constraint Validators with Dependencies
7480
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7581

reference/constraints/Email.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,24 @@ Basic Usage
2929
- Email:
3030
message: The email "{{ value }}" is not a valid email.
3131
checkMX: true
32-
32+
.. code-block:: xml
33+
34+
<!-- src/Acme/BlogBundle/Resources/config/validation.xml -->
35+
<?xml version="1.0" encoding="UTF-8" ?>
36+
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
37+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
38+
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
39+
40+
<class name="Acme\BlogBundle\Entity\Author">
41+
<property name="email">
42+
<constraint name="Email">
43+
<option name="message">The email "{{ value }}" is not a valid email.</option>
44+
<option name="checkMX">true</option>
45+
</constraint>
46+
</property>
47+
</class>
48+
</constraint-mapping>
49+
3350
.. code-block:: php-annotations
3451
3552
// src/Acme/BlogBundle/Entity/Author.php

0 commit comments

Comments
 (0)
0