Skip to content

Commit b94fc35

Browse files
committed
Merge branch '2.3' into 2.7
Conflicts: cookbook/form/create_custom_field_type.rst cookbook/form/dynamic_form_modification.rst
2 parents 9fe5455 + 9960f9c commit b94fc35

18 files changed

+382
-249
lines changed

book/forms.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ that will house the logic for building the task form::
10701070

10711071
public function getName()
10721072
{
1073-
return 'task';
1073+
return 'app_task';
10741074
}
10751075
}
10761076

@@ -1178,7 +1178,7 @@ easy to use in your application.
11781178
app.form.type.task:
11791179
class: AppBundle\Form\Type\TaskType
11801180
tags:
1181-
- { name: form.type, alias: task }
1181+
- { name: form.type, alias: app_task }
11821182
11831183
.. code-block:: xml
11841184
@@ -1190,7 +1190,7 @@ easy to use in your application.
11901190
11911191
<services>
11921192
<service id="app.form.type.task" class="AppBundle\Form\Type\TaskType">
1193-
<tag name="form.type" alias="task" />
1193+
<tag name="form.type" alias="app_task" />
11941194
</service>
11951195
</services>
11961196
</container>
@@ -1204,7 +1204,7 @@ easy to use in your application.
12041204
'AppBundle\Form\Type\TaskType'
12051205
)
12061206
->addTag('form.type', array(
1207-
'alias' => 'task',
1207+
'alias' => 'app_task',
12081208
))
12091209
;
12101210

book/from_flat_php_to_symfony2.rst

Lines changed: 28 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ persisted to the database. Writing in flat PHP is quick and dirty:
2929

3030
<?php
3131
// index.php
32-
$link = mysql_connect('localhost', 'myuser', 'mypassword');
33-
mysql_select_db('blog_db', $link);
32+
$link = new PDO("mysql:host=localhost;dbname=blog_db", 'myuser', 'mypassword');
3433

35-
$result = mysql_query('SELECT id, title FROM post', $link);
34+
$result = $link->query('SELECT id, title FROM post');
3635
?>
3736

3837
<!DOCTYPE html>
@@ -43,7 +42,7 @@ persisted to the database. Writing in flat PHP is quick and dirty:
4342
<body>
4443
<h1>List of Posts</h1>
4544
<ul>
46-
<?php while ($row = mysql_fetch_assoc($result)): ?>
45+
<?php while ($row = $result->fetch(PDO::FETCH_ASSOC)): ?>
4746
<li>
4847
<a href="/show.php?id=<?php echo $row['id'] ?>">
4948
<?php echo $row['title'] ?>
@@ -55,7 +54,7 @@ persisted to the database. Writing in flat PHP is quick and dirty:
5554
</html>
5655

5756
<?php
58-
mysql_close($link);
57+
$link = null;
5958
?>
6059

6160
That's quick to write, fast to execute, and, as your app grows, impossible
@@ -81,26 +80,24 @@ Isolating the Presentation
8180
~~~~~~~~~~~~~~~~~~~~~~~~~~
8281

8382
The code can immediately gain from separating the application "logic" from
84-
the code that prepares the HTML "presentation":
85-
86-
.. code-block:: html+php
83+
the code that prepares the HTML "presentation"::
8784

8885
// index.php
89-
$link = mysql_connect('localhost', 'myuser', 'mypassword');
90-
mysql_select_db('blog_db', $link);
86+
$link = new PDO("mysql:host=localhost;dbname=blog_db", 'myuser', 'mypassword');
9187

92-
$result = mysql_query('SELECT id, title FROM post', $link);
88+
$result = $link->query('SELECT id, title FROM post');
9389

9490
$posts = array();
95-
while ($row = mysql_fetch_assoc($result)) {
91+
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
9692
$posts[] = $row;
9793
}
9894

99-
mysql_close($link);
95+
$link = null;
10096

10197
// include the HTML presentation code
10298
require 'templates/list.php';
10399

100+
104101
The HTML code is now stored in a separate file (``templates/list.php``), which
105102
is primarily an HTML file that uses a template-like PHP syntax:
106103

@@ -141,31 +138,29 @@ Isolating the Application (Domain) Logic
141138
So far the application contains only one page. But what if a second page
142139
needed to use the same database connection, or even the same array of blog
143140
posts? Refactor the code so that the core behavior and data-access functions
144-
of the application are isolated in a new file called ``model.php``:
145-
146-
.. code-block:: html+php
141+
of the application are isolated in a new file called ``model.php``::
147142

148143
// model.php
149144
function open_database_connection()
150145
{
151-
$link = mysql_connect('localhost', 'myuser', 'mypassword');
152-
mysql_select_db('blog_db', $link);
146+
$link = new PDO("mysql:host=localhost;dbname=blog_db", 'myuser', 'mypassword');
153147

154148
return $link;
155149
}
156150

157151
function close_database_connection($link)
158152
{
159-
mysql_close($link);
153+
$link = null;
160154
}
161155

162156
function get_all_posts()
163157
{
164158
$link = open_database_connection();
165159

166-
$result = mysql_query('SELECT id, title FROM post', $link);
160+
$result = $link->query('SELECT id, title FROM post');
161+
167162
$posts = array();
168-
while ($row = mysql_fetch_assoc($result)) {
163+
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
169164
$posts[] = $row;
170165
}
171166
close_database_connection($link);
@@ -182,9 +177,7 @@ of the application are isolated in a new file called ``model.php``:
182177
in this example, only a portion (or none) of the model is actually concerned
183178
with accessing a database.
184179

185-
The controller (``index.php``) is now very simple:
186-
187-
.. code-block:: html+php
180+
The controller (``index.php``) is now very simple::
188181

189182
require_once 'model.php';
190183

@@ -261,21 +254,17 @@ an individual blog result based on a given id::
261254
function get_post_by_id($id)
262255
{
263256
$link = open_database_connection();
264-
265257
$id = intval($id);
266-
$query = 'SELECT created_at, title, body FROM post WHERE id = '.$id;
267-
$result = mysql_query($query);
268-
$row = mysql_fetch_assoc($result);
258+
$result = $link->query('SELECT created_at, title, body FROM post WHERE id = '.$id);
259+
$row = $result->fetch(PDO::FETCH_ASSOC);
269260

270261
close_database_connection($link);
271262

272263
return $row;
273264
}
274265

275266
Next, create a new file called ``show.php`` - the controller for this new
276-
page:
277-
278-
.. code-block:: html+php
267+
page::
279268

280269
require_once 'model.php';
281270

@@ -353,9 +342,7 @@ You're about to take a **big** step with the application. With one file handling
353342
all requests, you can centralize things such as security handling, configuration
354343
loading, and routing. In this application, ``index.php`` must now be smart
355344
enough to render the blog post list page *or* the blog post show page based
356-
on the requested URI:
357-
358-
.. code-block:: html+php
345+
on the requested URI::
359346

360347
// index.php
361348

@@ -365,19 +352,17 @@ on the requested URI:
365352

366353
// route the request internally
367354
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
368-
if ('/index.php' == $uri) {
355+
if ('/index.php' === $uri) {
369356
list_action();
370-
} elseif ('/index.php/show' == $uri && isset($_GET['id'])) {
357+
} elseif ('/index.php/show' === $uri && isset($_GET['id'])) {
371358
show_action($_GET['id']);
372359
} else {
373360
header('Status: 404 Not Found');
374361
echo '<html><body><h1>Page Not Found</h1></body></html>';
375362
}
376363

377364
For organization, both controllers (formerly ``index.php`` and ``show.php``)
378-
are now PHP functions and each has been moved into a separate file, ``controllers.php``:
379-
380-
.. code-block:: php
365+
are now PHP functions and each has been moved into a separate file, ``controllers.php``::
381366

382367
function list_action()
383368
{
@@ -455,9 +440,7 @@ to interpret each request and return a response. To this end, Symfony provides
455440
both a :class:`Symfony\\Component\\HttpFoundation\\Request` and a
456441
:class:`Symfony\\Component\\HttpFoundation\\Response` class. These classes are
457442
object-oriented representations of the raw HTTP request being processed and
458-
the HTTP response being returned. Use them to improve the blog:
459-
460-
.. code-block:: html+php
443+
the HTTP response being returned. Use them to improve the blog::
461444

462445
// index.php
463446
require_once 'vendor/autoload.php';
@@ -468,9 +451,9 @@ the HTTP response being returned. Use them to improve the blog:
468451
$request = Request::createFromGlobals();
469452

470453
$uri = $request->getPathInfo();
471-
if ('/' == $uri) {
454+
if ('/' === $uri) {
472455
$response = list_action();
473-
} elseif ('/show' == $uri && $request->query->has('id')) {
456+
} elseif ('/show' === $uri && $request->query->has('id')) {
474457
$response = show_action($request->query->get('id'));
475458
} else {
476459
$html = '<html><body><h1>Page Not Found</h1></body></html>';
@@ -482,9 +465,7 @@ the HTTP response being returned. Use them to improve the blog:
482465

483466
The controllers are now responsible for returning a ``Response`` object.
484467
To make this easier, you can add a new ``render_template()`` function, which,
485-
incidentally, acts quite a bit like the Symfony templating engine:
486-
487-
.. code-block:: php
468+
incidentally, acts quite a bit like the Symfony templating engine::
488469

489470
// controllers.php
490471
use Symfony\Component\HttpFoundation\Response;

cookbook/assetic/apply_to_option.rst

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,24 @@ An example configuration might look like this:
2727
.. code-block:: xml
2828
2929
<!-- app/config/config.xml -->
30-
<assetic:config>
31-
<assetic:filter
32-
name="coffee"
33-
bin="/usr/bin/coffee/"
34-
node="/usr/bin/node/">
35-
<assetic:node-path>/usr/lib/node_modules/</assetic:node-path>
36-
</assetic:filter>
37-
</assetic:config>
30+
<?xml version="1.0" encoding="UTF-8"?>
31+
<container xmlns="http://symfony.com/schema/dic/services"
32+
xmlns:assetic="http://symfony.com/schema/dic/assetic"
33+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
34+
xsi:schemaLocation="http://symfony.com/schema/dic/services
35+
http://symfony.com/schema/dic/services/services-1.0.xsd
36+
http://symfony.com/schema/dic/assetic
37+
http://symfony.com/schema/dic/assetic/assetic-1.0.xsd">
38+
39+
<assetic:config>
40+
<assetic:filter
41+
name="coffee"
42+
bin="/usr/bin/coffee/"
43+
node="/usr/bin/node/">
44+
<assetic:node-path>/usr/lib/node_modules/</assetic:node-path>
45+
</assetic:filter>
46+
</assetic:config>
47+
</container>
3848
3949
.. code-block:: php
4050
@@ -137,14 +147,24 @@ In this case you can specify that the ``coffee`` filter is applied to all
137147
.. code-block:: xml
138148
139149
<!-- app/config/config.xml -->
140-
<assetic:config>
141-
<assetic:filter
142-
name="coffee"
143-
bin="/usr/bin/coffee"
144-
node="/usr/bin/node"
145-
apply_to="\.coffee$" />
146-
<assetic:node-paths>/usr/lib/node_modules/</assetic:node-path>
147-
</assetic:config>
150+
<?xml version="1.0" encoding="UTF-8"?>
151+
<container xmlns="http://symfony.com/schema/dic/services"
152+
xmlns:assetic="http://symfony.com/schema/dic/assetic"
153+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
154+
xsi:schemaLocation="http://symfony.com/schema/dic/services
155+
http://symfony.com/schema/dic/services/services-1.0.xsd
156+
http://symfony.com/schema/dic/assetic
157+
http://symfony.com/schema/dic/assetic/assetic-1.0.xsd">
158+
159+
<assetic:config>
160+
<assetic:filter
161+
name="coffee"
162+
bin="/usr/bin/coffee"
163+
node="/usr/bin/node"
164+
apply_to="\.coffee$" />
165+
<assetic:node-paths>/usr/lib/node_modules/</assetic:node-path>
166+
</assetic:config>
167+
</container>
148168
149169
.. code-block:: php
150170

cookbook/assetic/asset_management.rst

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,12 @@ configuration under the ``assetic`` section. Read more in the
301301
<!-- app/config/config.xml -->
302302
<?xml version="1.0" encoding="UTF-8"?>
303303
<container xmlns="http://symfony.com/schema/dic/services"
304-
xmlns:assetic="http://symfony.com/schema/dic/assetic">
304+
xmlns:assetic="http://symfony.com/schema/dic/assetic"
305+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
306+
xsi:schemaLocation="http://symfony.com/schema/dic/services
307+
http://symfony.com/schema/dic/services/services-1.0.xsd
308+
http://symfony.com/schema/dic/assetic
309+
http://symfony.com/schema/dic/assetic/assetic-1.0.xsd">
305310
306311
<assetic:config>
307312
<assetic:asset name="jquery_and_ui">
@@ -388,11 +393,21 @@ should be defined:
388393
.. code-block:: xml
389394
390395
<!-- app/config/config.xml -->
391-
<assetic:config>
392-
<assetic:filter
393-
name="uglifyjs2"
394-
bin="/usr/local/bin/uglifyjs" />
395-
</assetic:config>
396+
<?xml version="1.0" encoding="UTF-8"?>
397+
<container xmlns="http://symfony.com/schema/dic/services"
398+
xmlns:assetic="http://symfony.com/schema/dic/assetic"
399+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
400+
xsi:schemaLocation="http://symfony.com/schema/dic/services
401+
http://symfony.com/schema/dic/services/services-1.0.xsd
402+
http://symfony.com/schema/dic/assetic
403+
http://symfony.com/schema/dic/assetic/assetic-1.0.xsd">
404+
405+
<assetic:config>
406+
<assetic:filter
407+
name="uglifyjs2"
408+
bin="/usr/local/bin/uglifyjs" />
409+
</assetic:config>
410+
</container>
396411
397412
.. code-block:: php
398413
@@ -528,7 +543,17 @@ the following change in your ``config_dev.yml`` file:
528543
.. code-block:: xml
529544
530545
<!-- app/config/config_dev.xml -->
531-
<assetic:config use-controller="false" />
546+
<?xml version="1.0" encoding="UTF-8"?>
547+
<container xmlns="http://symfony.com/schema/dic/services"
548+
xmlns:assetic="http://symfony.com/schema/dic/assetic"
549+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
550+
xsi:schemaLocation="http://symfony.com/schema/dic/services
551+
http://symfony.com/schema/dic/services/services-1.0.xsd
552+
http://symfony.com/schema/dic/assetic
553+
http://symfony.com/schema/dic/assetic/assetic-1.0.xsd">
554+
555+
<assetic:config use-controller="false" />
556+
</container>
532557
533558
.. code-block:: php
534559

0 commit comments

Comments
 (0)