Skip to content

Commit 9611c39

Browse files
committed
Merge branch '2.0' into 2.1
Conflicts: book/from_flat_php_to_symfony2.rst book/performance.rst book/translation.rst components/finder.rst components/http_foundation/introduction.rst components/process.rst reference/dic_tags.rst
2 parents 2703543 + cb110a3 commit 9611c39

Some content is hidden

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

42 files changed

+339
-365
lines changed

book/controller.rst

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,8 @@ Route Parameters as Controller Arguments
202202
You already know that the ``_controller`` parameter ``AcmeHelloBundle:Hello:index``
203203
refers to a ``HelloController::indexAction()`` method that lives inside the
204204
``AcmeHelloBundle`` bundle. What's more interesting is the arguments that are
205-
passed to that method:
205+
passed to that method::
206206

207-
.. code-block:: php
208-
209-
<?php
210207
// src/Acme/HelloBundle/Controller/HelloController.php
211208
namespace Acme\HelloBundle\Controller;
212209

@@ -344,9 +341,7 @@ access to any resource it might need. By extending this ``Controller`` class,
344341
you can take advantage of several helper methods.
345342

346343
Add the ``use`` statement atop the ``Controller`` class and then modify the
347-
``HelloController`` to extend it:
348-
349-
.. code-block:: php
344+
``HelloController`` to extend it::
350345

351346
// src/Acme/HelloBundle/Controller/HelloController.php
352347
namespace Acme\HelloBundle\Controller;
@@ -358,7 +353,7 @@ Add the ``use`` statement atop the ``Controller`` class and then modify the
358353
{
359354
public function indexAction($name)
360355
{
361-
return new Response('<html><body>Hello '.$name.'!</body></html>');
356+
return new Response('<html><body>Hello '.$name.'!</body></html>');
362357
}
363358
}
364359

@@ -375,13 +370,12 @@ itself.
375370

376371
Extending the base class is *optional* in Symfony; it contains useful
377372
shortcuts but nothing mandatory. You can also extend
378-
``Symfony\Component\DependencyInjection\ContainerAware``. The service
373+
:class:`Symfony\\Component\\DependencyInjection\\ContainerAware`. The service
379374
container object will then be accessible via the ``container`` property.
380375

381376
.. note::
382377

383-
You can also define your :doc:`Controllers as Services
384-
</cookbook/controller/service>`.
378+
You can also define your :doc:`Controllers as Services</cookbook/controller/service>`.
385379

386380
.. index::
387381
single: Controller; Common tasks
@@ -422,9 +416,7 @@ perform a 301 (permanent) redirect, modify the second argument::
422416
.. tip::
423417

424418
The ``redirect()`` method is simply a shortcut that creates a ``Response``
425-
object that specializes in redirecting the user. It's equivalent to:
426-
427-
.. code-block:: php
419+
object that specializes in redirecting the user. It's equivalent to::
428420

429421
use Symfony\Component\HttpFoundation\RedirectResponse;
430422

book/doctrine.rst

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ be.
1515

1616
Doctrine is totally decoupled from Symfony and using it is optional.
1717
This chapter is all about the Doctrine ORM, which aims to let you map
18-
objects to a relational database (such as *MySQL*, *PostgreSQL* or *Microsoft SQL*).
19-
If you prefer to use raw database queries, this is easy, and explained
20-
in the ":doc:`/cookbook/doctrine/dbal`" cookbook entry.
18+
objects to a relational database (such as *MySQL*, *PostgreSQL* or
19+
*Microsoft SQL*). If you prefer to use raw database queries, this is
20+
easy, and explained in the ":doc:`/cookbook/doctrine/dbal`" cookbook entry.
2121

2222
You can also persist data to `MongoDB`_ using Doctrine ODM library. For
2323
more information, read the ":doc:`/bundles/DoctrineMongoDBBundle/index`"
@@ -171,12 +171,6 @@ properties should be *mapped* to the database. This metadata can be specified
171171
in a number of different formats including YAML, XML or directly inside the
172172
``Product`` class via annotations:
173173

174-
.. note::
175-
176-
A bundle can accept only one metadata definition format. For example, it's
177-
not possible to mix YAML metadata definitions with annotated PHP entity
178-
class definitions.
179-
180174
.. configuration-block::
181175

182176
.. code-block:: php-annotations
@@ -253,6 +247,12 @@ in a number of different formats including YAML, XML or directly inside the
253247
</entity>
254248
</doctrine-mapping>
255249
250+
.. note::
251+
252+
A bundle can accept only one metadata definition format. For example, it's
253+
not possible to mix YAML metadata definitions with annotated PHP entity
254+
class definitions.
255+
256256
.. tip::
257257

258258
The table name is optional and if omitted, will be determined automatically
@@ -295,6 +295,7 @@ see the :ref:`book-doctrine-field-types` section.
295295
* @IgnoreAnnotation("fn")
296296
*/
297297
class Product
298+
// ...
298299

299300
Generating Getters and Setters
300301
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -318,10 +319,10 @@ doesn't replace your existing methods).
318319

319320
With the ``doctrine:generate:entities`` command you can:
320321

321-
* generate getters and setters,
322+
* generate getters and setters;
322323

323324
* generate repository classes configured with the
324-
``@ORM\Entity(repositoryClass="...")`` annotation,
325+
``@ORM\Entity(repositoryClass="...")`` annotation;
325326

326327
* generate the appropriate constructor for 1:n and n:m relations.
327328

@@ -422,11 +423,11 @@ of the bundle:
422423
Let's walk through this example:
423424

424425
* **lines 9-12** In this section, you instantiate and work with the ``$product``
425-
object like any other, normal PHP object;
426+
object like any other, normal PHP object.
426427

427428
* **line 14** This line fetches Doctrine's *entity manager* object, which is
428429
responsible for handling the process of persisting and fetching objects
429-
to and from the database;
430+
to and from the database.
430431

431432
* **line 15** The ``persist()`` method tells Doctrine to "manage" the ``$product``
432433
object. This does not actually cause a query to be made to the database (yet).
@@ -560,9 +561,9 @@ you have a route that maps a product id to an update action in a controller::
560561

561562
Updating an object involves just three steps:
562563

563-
1. fetching the object from Doctrine;
564-
2. modifying the object;
565-
3. calling ``flush()`` on the entity manager
564+
#. fetching the object from Doctrine;
565+
#. modifying the object;
566+
#. calling ``flush()`` on the entity manager
566567

567568
Notice that calling ``$em->persist($product)`` isn't necessary. Recall that
568569
this method simply tells Doctrine to manage or "watch" the ``$product`` object.
@@ -886,7 +887,6 @@ object, you'll want to add a ``$category`` property to the ``Product`` class:
886887
// src/Acme/StoreBundle/Entity/Product.php
887888
888889
// ...
889-
890890
class Product
891891
{
892892
// ...

book/forms.rst

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ Creating a Simple Form
2424
Suppose you're building a simple todo list application that will need to
2525
display "tasks". Because your users will need to edit and create tasks, you're
2626
going to need to build a form. But before you begin, first focus on the generic
27-
``Task`` class that represents and stores the data for a single task:
28-
29-
.. code-block:: php
27+
``Task`` class that represents and stores the data for a single task::
3028

3129
// src/Acme/TaskBundle/Entity/Task.php
3230
namespace Acme\TaskBundle\Entity;
@@ -791,9 +789,7 @@ Creating Form Classes
791789
As you've seen, a form can be created and used directly in a controller.
792790
However, a better practice is to build the form in a separate, standalone PHP
793791
class, which can then be reused anywhere in your application. Create a new class
794-
that will house the logic for building the task form:
795-
796-
.. code-block:: php
792+
that will house the logic for building the task form::
797793

798794
// src/Acme/TaskBundle/Form/Type/TaskType.php
799795
namespace Acme\TaskBundle\Form\Type;
@@ -817,9 +813,7 @@ that will house the logic for building the task form:
817813

818814
This new class contains all the directions needed to create the task form
819815
(note that the ``getName()`` method should return a unique identifier for this
820-
form "type"). It can be used to quickly build a form object in the controller:
821-
822-
.. code-block:: php
816+
form "type"). It can be used to quickly build a form object in the controller::
823817

824818
// src/Acme/TaskBundle/Controller/DefaultController.php
825819

@@ -1135,7 +1129,7 @@ The ``form_row`` form fragment is used when rendering most fields via the
11351129
fragment defined above, add the following to the top of the template that
11361130
renders the form:
11371131

1138-
.. configuration-block:: php
1132+
.. configuration-block::
11391133

11401134
.. code-block:: html+jinja
11411135

@@ -1456,7 +1450,7 @@ section.
14561450
The ``intention`` option is optional but greatly enhances the security of
14571451
the generated token by making it different for each form.
14581452

1459-
.. index:
1453+
.. index::
14601454
single: Forms; With no class
14611455

14621456
Using a Form without a Class
@@ -1496,10 +1490,10 @@ By default, a form actually assumes that you want to work with arrays of
14961490
data, instead of an object. There are exactly two ways that you can change
14971491
this behavior and tie the form to an object instead:
14981492

1499-
1. Pass an object when creating the form (as the first argument to ``createFormBuilder``
1493+
#. Pass an object when creating the form (as the first argument to ``createFormBuilder``
15001494
or the second argument to ``createForm``);
15011495

1502-
2. Declare the ``data_class`` option on your form.
1496+
#. Declare the ``data_class`` option on your form.
15031497

15041498
If you *don't* do either of these, then the form will return the data as
15051499
an array. In this example, since ``$defaultData`` is not an object (and
@@ -1509,9 +1503,7 @@ an array.
15091503
.. tip::
15101504

15111505
You can also access POST values (in this case "name") directly through
1512-
the request object, like so:
1513-
1514-
.. code-block:: php
1506+
the request object, like so::
15151507

15161508
$this->get('request')->request->get('name');
15171509

book/from_flat_php_to_symfony2.rst

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ persisted to the database. Writing in flat PHP is quick and dirty:
3333
$result = mysql_query('SELECT id, title FROM post', $link);
3434
?>
3535

36-
<!doctype html>
36+
<!DOCTYPE html>
3737
<html>
3838
<head>
3939
<title>List of Posts</title>
@@ -70,6 +70,7 @@ to maintain. There are several problems that need to be addressed:
7070
way to reuse any part of the application for other "pages" of the blog.
7171

7272
.. note::
73+
7374
Another problem not mentioned here is the fact that the database is
7475
tied to MySQL. Though not covered here, Symfony2 fully integrates `Doctrine`_,
7576
a library dedicated to database abstraction and mapping.
@@ -106,7 +107,7 @@ is primarily an HTML file that uses a template-like PHP syntax:
106107

107108
.. code-block:: html+php
108109

109-
<!doctype html>
110+
<!DOCTYPE html>
110111
<html>
111112
<head>
112113
<title>List of Posts</title>
@@ -211,6 +212,7 @@ that by creating a new ``layout.php`` file:
211212
.. code-block:: html+php
212213

213214
<!-- templates/layout.php -->
215+
<!DOCTYPE html>
214216
<html>
215217
<head>
216218
<title><?php echo $title ?></title>
@@ -366,9 +368,9 @@ on the requested URI:
366368

367369
// route the request internally
368370
$uri = $_SERVER['REQUEST_URI'];
369-
if ($uri == '/index.php') {
371+
if ('/index.php' == $uri) {
370372
list_action();
371-
} elseif ($uri == '/index.php/show' && isset($_GET['id'])) {
373+
} elseif ('/index.php/show' == $uri && isset($_GET['id'])) {
372374
show_action($_GET['id']);
373375
} else {
374376
header('Status: 404 Not Found');
@@ -466,9 +468,9 @@ the HTTP response being returned. Use them to improve the blog:
466468
$request = Request::createFromGlobals();
467469

468470
$uri = $request->getPathInfo();
469-
if ($uri == '/') {
471+
if ('/' == $uri) {
470472
$response = list_action();
471-
} elseif ($uri == '/show' && $request->query->has('id')) {
473+
} elseif ('/show' == $uri && $request->query->has('id')) {
472474
$response = show_action($request->query->get('id'));
473475
} else {
474476
$html = '<html><body><h1>Page Not Found</h1></body></html>';
@@ -537,11 +539,8 @@ from scratch, you could at least use Symfony's standalone `Routing`_ and
537539
`Templating`_ components, which already solve these problems.
538540

539541
Instead of re-solving common problems, you can let Symfony2 take care of
540-
them for you. Here's the same sample application, now built in Symfony2:
541-
542-
.. code-block:: html+php
542+
them for you. Here's the same sample application, now built in Symfony2::
543543

544-
<?php
545544
// src/Acme/BlogBundle/Controller/BlogController.php
546545
namespace Acme\BlogBundle\Controller;
547546

@@ -563,8 +562,8 @@ them for you. Here's the same sample application, now built in Symfony2:
563562
$post = $this->get('doctrine')
564563
->getManager()
565564
->getRepository('AcmeBlogBundle:Post')
566-
->find($id);
567-
565+
->find($id)
566+
;
568567
if (!$post) {
569568
// cause the 404 page not found to be displayed
570569
throw $this->createNotFoundException();
@@ -602,7 +601,7 @@ The layout is nearly identical:
602601
.. code-block:: html+php
603602

604603
<!-- app/Resources/views/layout.html.php -->
605-
<!doctype html>
604+
<!DOCTYPE html>
606605
<html>
607606
<head>
608607
<title><?php echo $view['slots']->output('title', 'Default title') ?></title>
@@ -635,11 +634,8 @@ A routing configuration map provides this information in a readable format:
635634
Now that Symfony2 is handling all the mundane tasks, the front controller
636635
is dead simple. And since it does so little, you'll never have to touch
637636
it once it's created (and if you use a Symfony2 distribution, you won't
638-
even need to create it!):
637+
even need to create it!)::
639638

640-
.. code-block:: html+php
641-
642-
<?php
643639
// web/app.php
644640
require_once __DIR__.'/../app/bootstrap.php';
645641
require_once __DIR__.'/../app/AppKernel.php';
@@ -667,18 +663,18 @@ migrating the blog from flat PHP to Symfony2 has improved life:
667663

668664
* Your application now has **clear and consistently organized code** (though
669665
Symfony doesn't force you into this). This promotes **reusability** and
670-
allows for new developers to be productive in your project more quickly.
666+
allows for new developers to be productive in your project more quickly;
671667

672668
* 100% of the code you write is for *your* application. You **don't need
673669
to develop or maintain low-level utilities** such as :ref:`autoloading<autoloading-introduction-sidebar>`,
674-
:doc:`routing</book/routing>`, or rendering :doc:`controllers</book/controller>`.
670+
:doc:`routing</book/routing>`, or rendering :doc:`controllers</book/controller>`;
675671

676672
* Symfony2 gives you **access to open source tools** such as Doctrine and the
677673
Templating, Security, Form, Validation and Translation components (to name
678-
a few).
674+
a few);
679675

680676
* The application now enjoys **fully-flexible URLs** thanks to the ``Routing``
681-
component.
677+
component;
682678

683679
* Symfony2's HTTP-centric architecture gives you access to powerful tools
684680
such as **HTTP caching** powered by **Symfony2's internal HTTP cache** or
@@ -701,6 +697,7 @@ for example, the list template written in Twig:
701697

702698
{# src/Acme/BlogBundle/Resources/views/Blog/list.html.twig #}
703699
{% extends "::layout.html.twig" %}
700+
704701
{% block title %}List of Posts{% endblock %}
705702

706703
{% block body %}
@@ -721,7 +718,7 @@ The corresponding ``layout.html.twig`` template is also easier to write:
721718
.. code-block:: html+jinja
722719

723720
{# app/Resources/views/layout.html.twig #}
724-
<!doctype html>
721+
<!DOCTYPE html>
725722
<html>
726723
<head>
727724
<title>{% block title %}Default title{% endblock %}</title>
@@ -747,5 +744,5 @@ Learn more from the Cookbook
747744
.. _`Templating`: https://github.com/symfony/Templating
748745
.. _`KnpBundles.com`: http://knpbundles.com/
749746
.. _`Twig`: http://twig.sensiolabs.org
750-
.. _`Varnish`: http://www.varnish-cache.org
747+
.. _`Varnish`: https://www.varnish-cache.org/
751748
.. _`PHPUnit`: http://www.phpunit.de

0 commit comments

Comments
 (0)