Skip to content

Commit 0885c58

Browse files
committed
Merge branch '3.3' into 3.4
* 3.3: (22 commits) add note about same-state transitions minor #8205 Move JavaScript to separate file (technetium, javiereguiluz) [error_pages] Removing misleading checker in code example Updated LDAP documentation for Symfony 3.1 Updating example README to match note below it Update docs for setting custom response code in exception handler add default option value for collection type minor #8831 Update collection.rst (babaorum) minor #8987 Fix YAML config bug (Holicz, javiereguiluz) Move JavaScript to seperate file Remove section about forms using validation Removed extra class Update fomr testing sentence Renamed TestedTypeTests to TestedTypeTest ...
2 parents bac7c7a + ccc781f commit 0885c58

File tree

7 files changed

+118
-84
lines changed

7 files changed

+118
-84
lines changed

bundles/best_practices.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ following standardized instructions in your ``README.md`` file.
210210
following command to download the latest stable version of this bundle:
211211
212212
```console
213-
$ composer require <package-name> "~1"
213+
$ composer require <package-name>
214214
```
215215
216216
This command requires you to have Composer installed globally, as explained
@@ -257,7 +257,7 @@ following standardized instructions in your ``README.md`` file.
257257
258258
.. code-block:: terminal
259259
260-
$ composer require <package-name> "~1"
260+
$ composer require <package-name>
261261
262262
This command requires you to have Composer installed globally, as explained
263263
in the `installation chapter`_ of the Composer documentation.

components/ldap.rst

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ and query against an LDAP server.
2525

2626
The ``Ldap`` class uses an :class:`Symfony\\Component\\Ldap\\Adapter\\AdapterInterface`
2727
to communicate with an LDAP server. The :class:`adapter <Symfony\\Component\\Ldap\\Adapter\\ExtLdap\\Adapter>`
28-
for PHP's built-in LDAP extension, for example, can be configured
29-
using the following options:
28+
for PHP's built-in LDAP extension, for example, can be configured using the
29+
following options:
3030

3131
``host``
3232
IP or hostname of the LDAP server
@@ -38,31 +38,39 @@ using the following options:
3838
The version of the LDAP protocol to use
3939

4040
``encryption``
41-
The encryption protocol : ``ssl``, ``tls`` or ``none`` (default)
41+
The encryption protocol: ``ssl``, ``tls`` or ``none`` (default)
42+
43+
``connection_string``
44+
  You may use this option instead of ``host`` and ``port`` to connect to the
45+
LDAP server
46+
47+
``optReferrals``
48+
Specifies whether to automatically follow referrals returned by the LDAP server
4249

4350
``options``
44-
LDAP server's options as defined in :class:`ConnectionOptions <Symfony\\Component\\Ldap\\Adapter\\ExtLdap\\ConnectionOptions>`
51+
LDAP server's options as defined in
52+
:class:`ConnectionOptions <Symfony\\Component\\Ldap\\Adapter\\ExtLdap\\ConnectionOptions>`
4553

4654
For example, to connect to a start-TLS secured LDAP server::
4755

48-
use Symfony\Component\Ldap\Adapter\ExtLdap\Adapter;
4956
use Symfony\Component\Ldap\Ldap;
5057

51-
$adapter = new Adapter(array(
58+
$ldap = Ldap::create('ext_ldap', array(
5259
'host' => 'my-server',
53-
'port' => 389,
54-
'encryption' => 'tls',
55-
'options' => array(
56-
'protocol_version' => 3,
57-
'referrals' => false,
58-
),
60+
'encryption' => 'ssl',
5961
));
60-
$ldap = new Ldap($adapter);
62+
63+
Or you could directly specify a connection string::
64+
65+
use Symfony\Component\Ldap\Ldap;
66+
67+
$ldap = Ldap::create('ext_ldap', array('connection_string' => 'ldaps://my-server:636'));
6168

6269
The :method:`Symfony\\Component\\Ldap\\Ldap::bind` method
6370
authenticates a previously configured connection using both the
6471
distinguished name (DN) and the password of a user::
6572

73+
use Symfony\Component\Ldap\Ldap;
6674
// ...
6775

6876
$ldap->bind($dn, $password);
@@ -71,6 +79,7 @@ Once bound (or if you enabled anonymous authentication on your
7179
LDAP server), you may query the LDAP server using the
7280
:method:`Symfony\\Component\\Ldap\\Ldap::query` method::
7381

82+
use Symfony\Component\Ldap\Ldap;
7483
// ...
7584

7685
$query = $ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))');
@@ -85,19 +94,21 @@ all entries in a single call and do something with the results'
8594
array, you may use the
8695
:method:`Symfony\\Component\\Ldap\\Adapter\\ExtLdap\\Collection::toArray` method::
8796

97+
use Symfony\Component\Ldap\Ldap;
8898
// ...
8999

90100
$query = $ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))');
91101
$results = $query->execute()->toArray();
92102

93103
// Do something with the results array
94104

95-
Creating or updating entries
105+
Creating or Updating Entries
96106
----------------------------
97107

98-
Since version 3.1, The Ldap component provides means to create
99-
new LDAP entries, update or even delete existing ones::
108+
The Ldap component provides means to create new LDAP entries, update or even
109+
delete existing ones::
100110

111+
use Symfony\Component\Ldap\Ldap;
101112
use Symfony\Component\Ldap\Entry;
102113
// ...
103114

controller/error_pages.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ To override the 404 error template for HTML pages, create a new
9999
{% block body %}
100100
<h1>Page not found</h1>
101101

102-
{% if is_granted('IS_AUTHENTICATED_FULLY') %}
103-
{# ... #}
104-
{% endif %}
105-
106102
<p>
107103
The requested page couldn't be located. Checkout for any URL
108104
misspelling or <a href="{{ path('homepage') }}">return to the homepage</a>.

form/unit_testing.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ To solve this, you have to mock the injected dependencies, instantiate your own
115115
form type and use the :class:`Symfony\\Component\\Form\\PreloadedExtension` to
116116
make sure the ``FormRegistry`` uses the created instance::
117117

118-
// tests/AppBundle/Form/Type/TestedTypeTests.php
118+
// tests/AppBundle/Form/Type/TestedTypeTest.php
119119
namespace Tests\AppBundle\Form\Type;
120120

121121
use AppBundle\Form\Type\TestedType;
@@ -169,7 +169,7 @@ will be raised if you try to test a class that depends on other extensions.
169169
The :method:`Symfony\\Component\\Form\\Test\\TypeTestCase::getExtensions` method
170170
allows you to return a list of extensions to register::
171171

172-
// tests/AppBundle/Form/Type/TestedTypeTests.php
172+
// tests/AppBundle/Form/Type/TestedTypeTest.php
173173
namespace Tests\AppBundle\Form\Type;
174174

175175
// ...
@@ -220,7 +220,7 @@ Testing against Different Sets of Data
220220
If you are not familiar yet with PHPUnit's `data providers`_, this might be
221221
a good opportunity to use them::
222222

223-
// tests/AppBundle/Form/Type/TestedTypeTests.php
223+
// tests/AppBundle/Form/Type/TestedTypeTest.php
224224
namespace Tests\AppBundle\Form\Type;
225225

226226
use AppBundle\Form\Type\TestedType;

reference/events.rst

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -217,22 +217,35 @@ sent as response::
217217
that forwards the ``Request`` to a given controller defined by the
218218
``exception_listener.controller`` parameter.
219219

220-
.. note::
220+
Symfony uses the following logic to determine the HTTP status code of the
221+
response:
222+
223+
* If :method:`Symfony\\Component\\HttpFoundation\\Response::isClientError`,
224+
:method:`Symfony\\Component\\HttpFoundation\\Response::isServerError` or
225+
:method:`Symfony\\Component\\HttpFoundation\\Response::isRedirect` is true,
226+
then the status code on your ``Response`` object is used;
227+
228+
* If the original exception implements
229+
:class:`Symfony\\Component\\HttpKernel\\Exception\\HttpExceptionInterface`,
230+
then ``getStatusCode()`` is called on the exception and used (the headers
231+
from ``getHeaders()`` are also added);
221232

222-
Symfony uses the following logic to determine the HTTP status code of the
223-
response:
233+
* If both of the above aren't true, then a 500 status code is used.
224234

225-
* If :method:`Symfony\\Component\\HttpFoundation\\Response::isClientError`,
226-
:method:`Symfony\\Component\\HttpFoundation\\Response::isServerError` or
227-
:method:`Symfony\\Component\\HttpFoundation\\Response::isRedirect` is true,
228-
then the status code on your ``Response`` object is used;
235+
.. note::
236+
237+
If you want to overwrite the status code of the exception response, which
238+
you should not without a good reason, call
239+
``GetResponseForExceptionEvent::allowSuccessfulResponse()`` first and then
240+
set the status code on the response::
229241

230-
* If the original exception implements
231-
:class:`Symfony\\Component\\HttpKernel\\Exception\\HttpExceptionInterface`,
232-
then ``getStatusCode()`` is called on the exception and used (the headers
233-
from ``getHeaders()`` are also added);
242+
$event->allowSuccessfulResponse();
243+
$response = new Response('No Content', 204);
244+
$event->setResponse($response);
234245

235-
* If both of the above aren't true, then a 500 status code is used.
246+
The status code sent to the client in the above example will be ``204``. If
247+
``$event->allowSuccessfulResponse()`` is omitted, then the kernel will set
248+
an appropriate status code based on the type of exception thrown.
236249

237250
.. seealso::
238251

reference/forms/types/collection.rst

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -160,55 +160,64 @@ Using jQuery, a simple example might look like this. If you're rendering
160160
your collection fields all at once (e.g. ``form_row(form.emails)``), then
161161
things are even easier because the ``data-prototype`` attribute is rendered
162162
automatically for you (with a slight difference - see note below) and all
163-
you need is the JavaScript:
163+
you need is this JavaScript code:
164+
165+
.. code-block:: javascript
166+
167+
// add-collection-widget.js
168+
jQuery(document).ready(function () {
169+
jQuery('.add-another-collection-widget').click(function (e) {
170+
e.preventDefault();
171+
var list = jQuery(jQuery(this).attr('data-list'));
172+
// Try to find the counter of the list
173+
var counter = list.data('widget-counter') | list.children().length;
174+
// If the counter does not exist, use the length of the list
175+
if (!counter) { counter = list.children().length; }
176+
177+
// grab the prototype template
178+
var newWidget = list.attr('data-prototype');
179+
// replace the "__name__" used in the id and name of the prototype
180+
// with a number that's unique to your emails
181+
// end name attribute looks like name="contact[emails][2]"
182+
newWidget = newWidget.replace(/__name__/g, counter);
183+
// Increase the counter
184+
counter++;
185+
// And store it, the length cannot be used if deleting widgets is allowed
186+
list.data(' widget-counter', counter);
187+
188+
// create a new list element and add it to the list
189+
var newElem = jQuery(list.attr('data-widget-tags')).html(newWidget);
190+
newElem.appendTo(list);
191+
});
192+
});
193+
194+
And update the template as follows:
195+
196+
.. code-block:: html+twig
197+
198+
{{ form_start(form) }}
199+
{# ... #}
200+
201+
{# store the prototype on the data-prototype attribute #}
202+
<ul id="email-fields-list"
203+
data-prototype="{{ form_widget(form.emails.vars.prototype)|e }}"
204+
data-widget-tags="{{ '<li></li>'|e }}">
205+
{% for emailField in form.emails %}
206+
<li>
207+
{{ form_errors(emailField) }}
208+
{{ form_widget(emailField) }}
209+
</li>
210+
{% endfor %}
211+
</ul>
164212
165-
.. configuration-block::
213+
<a href="#"
214+
class="add-another-collection-widget"
215+
data-list="#email-field-list>Add another email</a>
166216

167-
.. code-block:: html+twig
217+
{# ... #}
218+
{{ form_end(form) }}
168219

169-
{{ form_start(form) }}
170-
{# ... #}
171-
172-
{# store the prototype on the data-prototype attribute #}
173-
<ul id="email-fields-list"
174-
data-prototype="{{ form_widget(form.emails.vars.prototype)|e }}">
175-
{% for emailField in form.emails %}
176-
<li>
177-
{{ form_errors(emailField) }}
178-
{{ form_widget(emailField) }}
179-
</li>
180-
{% endfor %}
181-
</ul>
182-
183-
<a href="#" id="add-another-email">Add another email</a>
184-
185-
{# ... #}
186-
{{ form_end(form) }}
187-
188-
<script type="text/javascript">
189-
// keep track of how many email fields have been rendered
190-
var emailCount = '{{ form.emails|length }}';
191-
192-
jQuery(document).ready(function() {
193-
jQuery('#add-another-email').click(function(e) {
194-
e.preventDefault();
195-
196-
var emailList = jQuery('#email-fields-list');
197-
198-
// grab the prototype template
199-
var newWidget = emailList.attr('data-prototype');
200-
// replace the "__name__" used in the id and name of the prototype
201-
// with a number that's unique to your emails
202-
// end name attribute looks like name="contact[emails][2]"
203-
newWidget = newWidget.replace(/__name__/g, emailCount);
204-
emailCount++;
205-
206-
// create a new list element and add it to the list
207-
var newLi = jQuery('<li></li>').html(newWidget);
208-
newLi.appendTo(emailList);
209-
});
210-
})
211-
</script>
220+
<script src="add-collection-widget.js"></script>
212221

213222
.. tip::
214223

workflow/usage.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,12 @@ order:
260260
* ``workflow.[workflow name].announce``
261261
* ``workflow.[workflow name].announce.[transition name]``
262262

263-
Here is an example of how to enable logging for every time a the "blog_publishing"
263+
.. note::
264+
265+
The leaving and entering events are triggered even for transitions that stay
266+
in same place.
267+
268+
Here is an example of how to enable logging for every time a "blog_publishing"
264269
workflow leaves a place::
265270

266271
use Psr\Log\LoggerInterface;

0 commit comments

Comments
 (0)