Skip to content

Commit 4a583b2

Browse files
committed
minor #8315 Referencing custom encoders as named encoders (morille, javiereguiluz)
This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #8315). Discussion ---------- Referencing custom encoders as named encoders Commits ------- 37db964 Minor reword 9045d4b Referencing custom encoders as named encoders
2 parents ca0c86c + 37db964 commit 4a583b2

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

security/named_encoders.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,51 @@ the name of the encoder to use::
124124
return null; // use the default encoder
125125
}
126126
}
127+
128+
If you created your own password encoder implementing the
129+
:class:`Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface`,
130+
you must register a service for it in order to use it as a named encoder:
131+
132+
.. configuration-block::
133+
134+
.. code-block:: yaml
135+
136+
# app/config/security.yml
137+
security:
138+
# ...
139+
encoders:
140+
app_encoder:
141+
id: 'app.password_encoder_service'
142+
143+
.. code-block:: xml
144+
145+
<!-- app/config/security.xml -->
146+
<?xml version="1.0" encoding="UTF-8" ?>
147+
<srv:container xmlns="http://symfony.com/schema/dic/security"
148+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
149+
xmlns:srv="http://symfony.com/schema/dic/services"
150+
xsi:schemaLocation="http://symfony.com/schema/dic/services
151+
http://symfony.com/schema/dic/services/services-1.0.xsd"
152+
>
153+
154+
<config>
155+
<!-- ... -->
156+
<encoder class="app_encoder"
157+
id="app.password_encoder_service" />
158+
</config>
159+
</srv:container>
160+
161+
.. code-block:: php
162+
163+
// app/config/security.php
164+
$container->loadFromExtension('security', array(
165+
// ...
166+
'encoders' => array(
167+
'app_encoder' => array(
168+
'id' => 'app.password_encoder_service'
169+
),
170+
),
171+
));
172+
173+
This creates an encoder named ``app_encoder`` from a service named
174+
``app.password_encoder_service``.

0 commit comments

Comments
 (0)