Skip to content

Commit 5cae596

Browse files
committed
Merge branch '2.6' into 2.7
* 2.6: (91 commits) [#5064] Minor language tweaks Fixing bad merge conflict (forgot to save!) Remove unnecessary component reference Correct RegisterListenersPass namespace Fix service id Switched the first example to a static constructor method added some more components for Tobion as a merger Fixed variable name in : Reference -> validation constraints -> count -> basic usage -> PHP [#5036] Typo fix (probably mine originally) caught by xabbuh reword to serves Adding a link to define "lts" Better wording Minor improvement for symfony-installer with LTS Updating for new security service names in 2.6 [#5033] Tweaking variable name to "match" the service id [#5017] Minor language tweaks [#5015] Updating the security service name for 2.6 - thanks to Cordoval [#5015] Very small tweak [#5011] Adding one more fix I missed [#5011] Fixing minor build issue ... Conflicts: book/security.rst
2 parents 22eee86 + ebca342 commit 5cae596

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+440
-244
lines changed

book/controller.rst

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -429,35 +429,47 @@ A great way to see the core functionality in action is to look in the
429429
Redirecting
430430
~~~~~~~~~~~
431431

432-
If you want to redirect the user to another page, use the
433-
:method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::redirect`
434-
method::
432+
If you want to redirect the user to another page, use the ``redirectToRoute()`` method::
435433

436434
public function indexAction()
437435
{
438-
return $this->redirect($this->generateUrl('homepage'));
436+
return $this->redirectToRoute('homepage');
437+
438+
// redirectToRoute is equivalent to using redirect() and generateUrl() together:
439+
// return $this->redirect($this->generateUrl('homepage'), 301);
439440
}
440441

441-
The ``generateUrl()`` method is just a helper function that generates the URL
442-
for a given route. For more information, see the :doc:`Routing </book/routing>`
443-
chapter.
442+
.. versionadded:: 2.6
443+
The ``redirectToRoute()`` method was added in Symfony 2.6. Previously (and still now), you
444+
could use ``redirect()`` and ``generateUrl()`` together for this (see the example above).
445+
446+
Or, if you want to redirect externally, just use ``redirect()`` and pass it the URL::
447+
448+
public function indexAction()
449+
{
450+
return $this->redirect('http://symfony.com/doc');
451+
}
444452

445-
By default, the ``redirect()`` method performs a 302 (temporary) redirect. To
453+
By default, the ``redirectToRoute()`` method performs a 302 (temporary) redirect. To
446454
perform a 301 (permanent) redirect, modify the second argument::
447455

448456
public function indexAction()
449457
{
450-
return $this->redirect($this->generateUrl('homepage'), 301);
458+
return $this->redirectToRoute('homepage', array(), 301);
451459
}
452460

453461
.. tip::
454462

455-
The ``redirect()`` method is simply a shortcut that creates a ``Response``
456-
object that specializes in redirecting the user. It's equivalent to::
463+
The ``redirectToRoute()`` method is simply a shortcut that creates a
464+
``Response`` object that specializes in redirecting the user. It's
465+
equivalent to::
457466

458467
use Symfony\Component\HttpFoundation\RedirectResponse;
459468

460-
return new RedirectResponse($this->generateUrl('homepage'));
469+
public function indexAction()
470+
{
471+
return new RedirectResponse($this->generateUrl('homepage'));
472+
}
461473

462474
.. index::
463475
single: Controller; Rendering templates
@@ -623,12 +635,14 @@ For example, imagine you're processing a form submit::
623635
if ($form->isValid()) {
624636
// do some sort of processing
625637

626-
$request->getSession()->getFlashBag()->add(
638+
$this->addFlash(
627639
'notice',
628640
'Your changes were saved!'
629641
);
630642

631-
return $this->redirect($this->generateUrl(...));
643+
// $this->addFlash is equivalent to $this->get('session')->getFlashBag()->add
644+
645+
return $this->redirectToRoute(...);
632646
}
633647

634648
return $this->render(...);
@@ -638,8 +652,8 @@ After processing the request, the controller sets a ``notice`` flash message
638652
in the session and then redirects. The name (``notice``) isn't significant -
639653
it's just something you invent and reference next.
640654

641-
In the template of the next page (or even better, in your base layout template),
642-
the following code will render the ``notice`` message:
655+
In the template of the next action, the following code could be used to render
656+
the ``notice`` message:
643657

644658
.. configuration-block::
645659

book/doctrine.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ you have a route that maps a product id to an update action in a controller::
667667
$product->setName('New product name!');
668668
$em->flush();
669669

670-
return $this->redirect($this->generateUrl('homepage'));
670+
return $this->redirectToRoute('homepage');
671671
}
672672

673673
Updating an object involves just three steps:
@@ -778,6 +778,8 @@ entities (the topic of :ref:`relations <book-doctrine-relations>` will be
778778
covered later), group, etc. For more information, see the official
779779
`Doctrine Query Language`_ documentation.
780780

781+
.. _book-doctrine-custom-repository-classes:
782+
781783
Custom Repository Classes
782784
~~~~~~~~~~~~~~~~~~~~~~~~~
783785

book/forms.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ controller::
234234
if ($form->isValid()) {
235235
// perform some action, such as saving the task to the database
236236

237-
return $this->redirect($this->generateUrl('task_success'));
237+
return $this->redirectToRoute('task_success');
238238
}
239239

240240
// ...
@@ -319,7 +319,7 @@ querying if the "Save and add" button was clicked::
319319
? 'task_new'
320320
: 'task_success';
321321

322-
return $this->redirect($this->generateUrl($nextAction));
322+
return $this->redirectToRoute($nextAction);
323323
}
324324

325325
.. index::
@@ -1237,7 +1237,7 @@ it after a form submission can be done when the form is valid::
12371237
$em->persist($task);
12381238
$em->flush();
12391239

1240-
return $this->redirect($this->generateUrl('task_success'));
1240+
return $this->redirectToRoute('task_success');
12411241
}
12421242

12431243
If, for some reason, you don't have access to your original ``$task`` object,

book/http_cache.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ kernel::
166166
The caching kernel will immediately act as a reverse proxy - caching responses
167167
from your application and returning them to the client.
168168

169+
.. caution::
170+
171+
If you're using the :ref:`framework.http_method_override <configuration-framework-http_method_override>`
172+
option to read the HTTP method from a ``_method`` parameter, see the
173+
above link for a tweak you need to make.
174+
169175
.. tip::
170176

171177
The cache kernel has a special ``getLog()`` method that returns a string

book/installation.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ number as the second argument of the ``new`` command:
9898
# Windows
9999
c:\projects\> php symfony.phar new my_project_name 2.3.23
100100
101+
If you want your project to be based on the latest :ref:`Symfony LTS version <releases-lts>`,
102+
pass ``lts`` as the second argument of the ``new`` command:
103+
104+
.. code-block:: bash
105+
106+
# Linux, Mac OS X
107+
$ symfony new my_project_name lts
108+
109+
# Windows
110+
c:\projects\> php symfony.phar new my_project_name lts
111+
101112
Read the :doc:`Symfony Release process </contributing/community/releases>`
102113
to better understand why there are several Symfony versions and which one
103114
to use for your projects.

book/performance.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ Use a Byte Code Cache (e.g. APC)
1818
One of the best (and easiest) things that you should do to improve your performance
1919
is to use a "byte code cache". The idea of a byte code cache is to remove
2020
the need to constantly recompile the PHP source code. There are a number of
21-
`byte code caches`_ available, some of which are open source. The most widely
22-
used byte code cache is probably `APC`_
21+
`byte code caches`_ available, some of which are open source. As of PHP 5.5,
22+
PHP comes with `OPcache`_ built-in. For older versions, the most widely used
23+
byte code cache is probably `APC`_
2324

2425
Using a byte code cache really has no downside, and Symfony has been architected
2526
to perform really well in this type of environment.
@@ -139,6 +140,7 @@ feature is disabled in the byte code cache (e.g. ``apc.stat=0`` in APC), there
139140
is no longer a reason to use a bootstrap file.
140141

141142
.. _`byte code caches`: http://en.wikipedia.org/wiki/List_of_PHP_accelerators
143+
.. _`OPcache`: http://php.net/manual/en/book.opcache.php
142144
.. _`APC`: http://php.net/manual/en/book.apc.php
143145
.. _`autoload.php`: https://github.com/symfony/symfony-standard/blob/master/app/autoload.php
144146
.. _`bootstrap file`: https://github.com/sensio/SensioDistributionBundle/blob/master/Composer/ScriptHandler.php

book/propel.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ have a route that maps a product id to an update action in a controller::
244244
$product->setName('New product name!');
245245
$product->save();
246246

247-
return $this->redirect($this->generateUrl('homepage'));
247+
return $this->redirectToRoute('homepage');
248248
}
249249
}
250250

book/routing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ The route is simple:
4545
class BlogController extends Controller
4646
{
4747
/**
48-
* @Route("/blog/{slug}")
48+
* @Route("/blog/{slug}", name="blog_show")
4949
*/
5050
public function showAction($slug)
5151
{

book/security.rst

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -813,20 +813,29 @@ You can easily deny access from inside a controller::
813813

814814
public function helloAction($name)
815815
{
816-
if (false === $this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) {
817-
throw $this->createAccessDeniedException();
818-
}
816+
// The second parameter is used to specify on what object the role is tested.
817+
$this->denyAccessUnlessGranted('ROLE_ADMIN', null, 'Unable to access this page!');
818+
819+
// Old way :
820+
// if (false === $this->get('security.context')->isGranted('ROLE_ADMIN')) {
821+
// throw $this->createAccessDeniedException('Unable to access this page!');
822+
// }
819823

820824
// ...
821825
}
822826

823827
.. versionadded:: 2.6
824-
The ``security.authorization_checker`` service was introduced in Symfony 2.6. Prior
825-
to Symfony 2.6, you had to use the ``isGranted()`` method of the ``security.context`` service.
828+
The ``denyAccessUnlessGranted()`` method was introduced in Symfony 2.6. Previously (and
829+
still now), you could check access directly and throw the ``AccessDeniedException`` as shown
830+
in the example above).
831+
832+
.. versionadded:: 2.6
833+
The ``security.authorization_checker`` service was introduced in Symfony 2.6. Prior
834+
to Symfony 2.6, you had to use the ``isGranted()`` method of the ``security.context`` service.
826835

827-
The :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::createAccessDeniedException`
828-
method creates a special :class:`Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException`
829-
object, which ultimately triggers a 403 HTTP response inside Symfony.
836+
In both cases, a special
837+
:class:`Symfony\\Component\\Security\\Core\\Exception\\AccessDeniedException`
838+
is thrown, which ultimately triggers a 403 HTTP response inside Symfony.
830839

831840
That's it! If the user isn't logged in yet, they will be asked to login (e.g.
832841
redirected to the login page). If they *are* logged in, they'll be shown

book/testing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ or perform more complex requests. Some useful examples::
394394
array('photo' => $photo)
395395
);
396396

397-
// Perform a DELETE requests and pass HTTP headers
397+
// Perform a DELETE request and pass HTTP headers
398398
$client->request(
399399
'DELETE',
400400
'/post/12',

book/validation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ workflow looks like the following from inside a controller::
232232
if ($form->isValid()) {
233233
// the validation passed, do something with the $author object
234234

235-
return $this->redirect($this->generateUrl(...));
235+
return $this->redirectToRoute(...);
236236
}
237237

238238
return $this->render('author/form.html.twig', array(

components/config/definition.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ Node Type
9595
~~~~~~~~~
9696

9797
It is possible to validate the type of a provided value by using the appropriate
98-
node definition. Node type are available for:
98+
node definition. Node types are available for:
9999

100-
* scalar
100+
* scalar (generic type that includes booleans, strings, integers, floats and ``null``)
101101
* boolean
102102
* integer
103103
* float
104-
* enum
104+
* enum (similar to scalar, but it only allows a finite set of values)
105105
* array
106106
* variable (no validation)
107107

@@ -288,7 +288,8 @@ All options can be documented using the
288288
:method:`Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::info`
289289
method.
290290

291-
The info will be printed as a comment when dumping the configuration tree.
291+
The info will be printed as a comment when dumping the configuration tree with
292+
the ``config:dump`` command.
292293

293294
.. versionadded:: 2.6
294295
Since Symfony 2.6, the info will also be added to the exception message

components/config/introduction.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ The Config Component
99
combine, autofill and validate configuration values of any kind, whatever
1010
their source may be (YAML, XML, INI files, or for instance a database).
1111

12-
.. caution::
13-
14-
The ``IniFileLoader`` parses the file contents using the
15-
:phpfunction:`parse_ini_file` function, therefore, you can only set
16-
parameters to string values. To set parameters to other data types
17-
(e.g. boolean, integer, etc), the other loaders are recommended.
18-
1912
Installation
2013
------------
2114

components/config/resources.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
Loading Resources
55
=================
66

7+
.. caution::
8+
9+
The ``IniFileLoader`` parses the file contents using the
10+
:phpfunction:`parse_ini_file` function. Therefore, you can only set
11+
parameters to string values. To set parameters to other data types
12+
(e.g. boolean, integer, etc), the other loaders are recommended.
13+
714
Locating Resources
815
------------------
916

components/console/introduction.rst

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@ You can install the component in 2 different ways:
2020
* :doc:`Install it via Composer </components/using_components>` (``symfony/console`` on `Packagist`_);
2121
* Use the official Git repository (https://github.com/symfony/Console).
2222

23-
.. note::
24-
25-
Windows does not support ANSI colors by default so the Console component detects and
26-
disables colors where Windows does not have support. However, if Windows is not
27-
configured with an ANSI driver and your console commands invoke other scripts which
28-
emit ANSI color sequences, they will be shown as raw escape characters.
29-
30-
To enable ANSI color support for Windows, please install `ANSICON`_.
31-
3223
Creating a basic Command
3324
------------------------
3425

@@ -124,6 +115,14 @@ This prints::
124115
Coloring the Output
125116
~~~~~~~~~~~~~~~~~~~
126117

118+
.. note::
119+
120+
By default, the Windows command console doesn't support output coloring. The
121+
Console component disables output coloring for Windows systems, but if your
122+
commands invoke other scripts which emit color sequences, they will be
123+
wrongly displayed as raw escape characters. Install the `ConEmu`_ or `ANSICON`_
124+
free applications to add coloring support to your Windows command console.
125+
127126
Whenever you output text, you can surround the text with tags to color its
128127
output. For example::
129128

@@ -324,9 +323,11 @@ declare a one-letter shortcut that you can call with a single dash like
324323

325324
.. tip::
326325

327-
It is also possible to make an option *optionally* accept a value (so that
328-
``--yell``, ``--yell=loud`` or ``--yell loud`` work). Options can also be configured to
329-
accept an array of values.
326+
There is nothing forbidding you to create a command with an option that
327+
optionally accepts a value. However, there is no way you can distinguish
328+
when the option was used without a value (``command --yell``) or when it
329+
wasn't used at all (``command``). In both cases, the value retrieved for
330+
the option will be ``null``.
330331

331332
For example, add a new option to the command that can be used to specify
332333
how many times in a row the message should be printed::
@@ -533,4 +534,5 @@ Learn More!
533534
* :doc:`/components/console/console_arguments`
534535

535536
.. _Packagist: https://packagist.org/packages/symfony/console
537+
.. _ConEmu: https://code.google.com/p/conemu-maximus5/
536538
.. _ANSICON: https://github.com/adoxa/ansicon/releases

components/dependency_injection/factories.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ configure the service container to use the
6969
7070
$container->setDefinition('newsletter_manager', $definition);
7171
72+
.. note::
73+
74+
When using a factory to create services, the value chosen for the ``class``
75+
option has no effect on the resulting service. The actual class name only
76+
depends on the object that is returned by the factory. However, the configured
77+
class name may be used by compiler passes and therefore should be set to a
78+
sensible value.
79+
7280
Now, the method will be called statically. If the factory class itself should
7381
be instantiated and the resulting object's method called, configure the factory
7482
itself as a service. In this case, the method (e.g. get) should be changed to

components/event_dispatcher/introduction.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,14 @@ instance of ``Symfony\Component\HttpKernel\Event\FilterResponseEvent``::
212212
and the
213213
:doc:`DependencyInjection component </components/dependency_injection/introduction>`,
214214
you can use the
215-
:class:`Symfony\\Component\\HttpKernel\\DependencyInjection\\RegisterListenersPass`
216-
from the HttpKernel component to tag services as event listeners::
215+
:class:`Symfony\\Component\\EventDispatcher\\DependencyInjection\\RegisterListenersPass`
216+
to tag services as event listeners::
217217

218218
use Symfony\Component\DependencyInjection\ContainerBuilder;
219219
use Symfony\Component\DependencyInjection\Definition;
220220
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
221221
use Symfony\Component\DependencyInjection\Reference;
222-
use Symfony\Component\HttpKernel\DependencyInjection\RegisterListenersPass;
222+
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
223223

224224
$containerBuilder = new ContainerBuilder(new ParameterBag());
225225
$containerBuilder->addCompilerPass(new RegisterListenersPass());

0 commit comments

Comments
 (0)