Skip to content

Commit 19056ab

Browse files
committed
created the cookbook
1 parent 997b465 commit 19056ab

File tree

17 files changed

+219
-163
lines changed

17 files changed

+219
-163
lines changed

contributing/code/patches.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ software:
1414

1515
* PHP version 5.3.2 or above;
1616

17-
* PHPUnit 3.5.0 or above.
17+
* PHPUnit 3.5.11 or above.
1818

1919
Set up your user information with your real name and a working email address:
2020

@@ -46,7 +46,7 @@ Get the Symfony2 code source:
4646
.. code-block:: bash
4747
4848
$ cd symfony
49-
$ git remote add upstream git://github.com/fabpot/symfony.git
49+
$ git remote add upstream git://github.com/symfony/symfony.git
5050
5151
Now that Symfony2 is installed, check that all unit tests pass for your
5252
environment as explained in the dedicated :doc:`document <tests>`.
@@ -122,11 +122,11 @@ Check that all tests still pass and push your branch remotely:
122122
$ git push origin BRANCH_NAME
123123
124124
You can now discuss your patch on the `dev mailing-list`_ or make a pull
125-
request (they must be done on the ``fabpot/symfony`` repository).
125+
request (they must be done on the ``symfony/symfony`` repository).
126126

127127
If you are going to send an email to the mailing-list, don't forget to
128-
reference you branch URL (``http://github.com/USERNAME/symfony.git
129-
BRANCH_NAME``).
128+
reference you branch URL (``https://github.com/USERNAME/symfony.git
129+
BRANCH_NAME``) or the pull request URL.
130130

131131
Based on the feedback from the mailing-list or via the pull request on Github,
132132
you might need to rework your patch. Before re-submitting the patch, rebase
@@ -139,5 +139,5 @@ with master, don't merge; and force the push to the origin:
139139
140140
.. _ProGit: http://progit.org/
141141
.. _Github: https://github.com/signup/free
142-
.. _Symfony2 repository: http://www.github.com/fabpot/symfony
142+
.. _Symfony2 repository: https://github.com/symfony/symfony
143143
.. _dev mailing-list: http://groups.google.com/group/symfony-devs

guides/tools/autoloader.rst renamed to cookbook/autoloader.rst

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. index::
22
pair: Autoloader; Configuration
33

4-
Autoloader
5-
==========
4+
How to autoload Classes
5+
=======================
66

77
Whenever you use an undefined class, PHP uses the autoloading mechanism to
88
delegate the loading of a file defining the class. Symfony2 provides a
@@ -21,13 +21,12 @@ need.
2121
Usage
2222
-----
2323

24-
Registering the
25-
:class:`Symfony\\Component\\HttpFoundation\\UniversalClassLoader` autoloader is
26-
straightforward::
24+
Registering the :class:`Symfony\\Component\\ClassLoader\\UniversalClassLoader`
25+
autoloader is straightforward::
2726

28-
require_once '/path/to/src/Symfony/Component/HttpFoundation/UniversalClassLoader.php';
27+
require_once '/path/to/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
2928

30-
use Symfony\Component\HttpFoundation\UniversalClassLoader;
29+
use Symfony\Component\ClassLoader\UniversalClassLoader;
3130

3231
$loader = new UniversalClassLoader();
3332
$loader->register();
@@ -40,8 +39,9 @@ The autoloader is useful only if you add some libraries to autoload.
4039
``app/autoload.php``).
4140

4241
If the classes to autoload use namespaces, use the
43-
:method:`Symfony\\Component\\HttpFoundation\\UniversalClassLoader::registerNamespace` or
44-
:method:`Symfony\\Component\\HttpFoundation\\UniversalClassLoader::registerNamespaces`
42+
:method:`Symfony\\Component\\ClassLoader\\UniversalClassLoader::registerNamespace`
43+
or
44+
:method:`Symfony\\Component\\ClassLoader\\UniversalClassLoader::registerNamespaces`
4545
methods::
4646

4747
$loader->registerNamespace('Symfony', __DIR__.'/vendor/symfony/src');
@@ -52,8 +52,9 @@ methods::
5252
));
5353

5454
For classes that follow the PEAR naming convention, use the
55-
:method:`Symfony\\Component\\HttpFoundation\\UniversalClassLoader::registerPrefix` or
56-
:method:`Symfony\\Component\\HttpFoundation\\UniversalClassLoader::registerPrefixes`
55+
:method:`Symfony\\Component\\ClassLoader\\UniversalClassLoader::registerPrefix`
56+
or
57+
:method:`Symfony\\Component\\ClassLoader\\UniversalClassLoader::registerPrefixes`
5758
methods::
5859

5960
$loader->registerPrefix('Twig_', __DIR__.'/vendor/twig/lib');

guides/emails.rst renamed to cookbook/email.rst

Lines changed: 17 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
.. index::
22
single: Emails
33

4-
Emails
5-
======
4+
How to send an Email
5+
====================
66

7-
Symfony2 leverages the power of `Swiftmailer`_ to send emails.
7+
One solution to send emails is to use the ``SwiftmailerBundle``, which
8+
leverages the power of the `Swiftmailer`_ library.
89

9-
Installation
10-
------------
10+
.. note::
1111

12-
Enable ``SwiftmailerBundle`` in your kernel::
12+
Don't forget to enable the bundle in your kernel before using it::
1313

14-
public function registerBundles()
15-
{
16-
$bundles = array(
17-
// ...
18-
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
19-
);
14+
public function registerBundles()
15+
{
16+
$bundles = array(
17+
// ...
18+
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
19+
);
2020

21-
// ...
22-
}
21+
// ...
22+
}
2323

2424
Configuration
2525
-------------
@@ -110,43 +110,9 @@ The mailer is accessible via the ``mailer`` service; from an action::
110110
To keep things decoupled, the email body has been stored in a template,
111111
rendered with the ``renderView()`` method.
112112

113-
Using Gmail
114-
-----------
115-
116-
If you want to use your Gmail account to send emails, use the special ``gmail``
117-
transport:
118-
119-
.. configuration-block::
120-
121-
.. code-block:: yaml
122-
123-
# app/config/config.yml
124-
swiftmailer:
125-
transport: gmail
126-
username: your_gmail_username
127-
password: your_gmail_password
128-
129-
.. code-block:: xml
113+
.. tip::
130114

131-
<!-- app/config/config.xml -->
132-
133-
<!--
134-
xmlns:swiftmailer="http://www.symfony-project.org/schema/dic/swiftmailer"
135-
http://www.symfony-project.org/schema/dic/swiftmailer http://www.symfony-project.org/schema/dic/swiftmailer/swiftmailer-1.0.xsd
136-
-->
137-
138-
<swiftmailer:config
139-
transport="gmail"
140-
username="your_gmail_username"
141-
password="your_gmail_password" />
142-
143-
.. code-block:: php
144-
145-
// app/config/config.php
146-
$container->loadFromExtension('swiftmailer', array(
147-
'transport' => "gmail",
148-
'username' => "your_gmail_username",
149-
'password' => "your_gmail_password",
150-
));
115+
Read the ":doc:`gmail`" recipe if you want to use Gmail as a transport in
116+
the development environment.
151117

152118
.. _`Swiftmailer`: http://www.swiftmailer.org/

guides/tools/finder.rst renamed to cookbook/finder.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. index::
22
single: Finder
33

4-
The Finder
5-
==========
4+
How to locate Files
5+
===================
66

77
The :namespace:`Symfony\\Component\\Finder` component helps you to find files
88
and directories quickly and easily.

cookbook/gmail.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
.. index::
2+
single: Emails
3+
4+
How to use Gmail to send Emails
5+
===============================
6+
7+
During development, instead of using a regular SMTP server to send emails, you
8+
might find using Gmail easier and more practical. The Swiftmailer bundle makes
9+
it really easy.
10+
11+
.. tip::
12+
13+
Instead of using your regular Gmail account, it's of course recommended
14+
that you create a special account.
15+
16+
In the development configuration file, change the ``transport`` setting to
17+
``gmail`` and set the ``username`` and ``password`` to the Google credentials:
18+
19+
.. configuration-block::
20+
21+
.. code-block:: yaml
22+
23+
# app/config/config_dev.yml
24+
swiftmailer:
25+
transport: gmail
26+
username: your_gmail_username
27+
password: your_gmail_password
28+
29+
.. code-block:: xml
30+
31+
<!-- app/config/config_dev.xml -->
32+
33+
<!--
34+
xmlns:swiftmailer="http://www.symfony-project.org/schema/dic/swiftmailer"
35+
http://www.symfony-project.org/schema/dic/swiftmailer http://www.symfony-project.org/schema/dic/swiftmailer/swiftmailer-1.0.xsd
36+
-->
37+
38+
<swiftmailer:config
39+
transport="gmail"
40+
username="your_gmail_username"
41+
password="your_gmail_password" />
42+
43+
.. code-block:: php
44+
45+
// app/config/config_dev.php
46+
$container->loadFromExtension('swiftmailer', array(
47+
'transport' => "gmail",
48+
'username' => "your_gmail_username",
49+
'password' => "your_gmail_password",
50+
));
51+
52+
You're done!

cookbook/index.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Cookbook
2+
========
3+
4+
Dive into Symfony2 cookbook:
5+
6+
.. toctree::
7+
:hidden:
8+
9+
email
10+
gmail
11+
autoloader
12+
finder
13+
varnish
14+
symfony1
15+
16+
.. include:: map.rst.inc

cookbook/map.rst.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
* :doc:`/cookbook/email`
2+
* :doc:`/cookbook/gmail`
3+
* :doc:`/cookbook/autoloader`
4+
* :doc:`/cookbook/finder`
5+
* :doc:`/cookbook/varnish`
6+
* :doc:`/cookbook/symfony1`
7+

guides/symfony1.rst renamed to cookbook/symfony1.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Symfony2 for symfony1 Users
2-
===========================
1+
How Symfony2 differs from symfony1
2+
==================================
33

44
The Symfony2 framework embodies a signficant evolution when compared with
55
the first version of the framework. Fortunately, with the MVC architecture

cookbook/varnish.rst

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
.. index::
2+
single: Cache; Varnish
3+
4+
How to use Varnish to speedup my Website
5+
========================================
6+
7+
Because Symfony2's cache uses the standard HTTP cache headers, the
8+
:ref:`symfony-gateway-cache` can easily be replaced with any other reverse
9+
proxy. Varnish is a powerful, open-source, HTTP accelerator capable of serving
10+
cached content quickly and including support for :ref:`Edge Side
11+
Includes<edge-side-includes>`.
12+
13+
.. index::
14+
single: Varnish; configuration
15+
16+
Configuration
17+
-------------
18+
19+
As seen previously, Symfony2 is smart enough to detect whether it talks to a
20+
reverse proxy that understands ESI or not. It works out of the box when you
21+
use the Symfony2 reverse proxy, but you need a special configuration to make
22+
it work with Varnish. Thankfully, Symfony2 relies on yet another standard
23+
written by Akamaï (`Edge Architecture`_), so the configuration tips in this
24+
chapter can be useful even if you don't use Symfony2.
25+
26+
.. note::
27+
28+
Varnish only supports the ``src`` attribute for ESI tags (``onerror`` and
29+
``alt`` attributes are ignored).
30+
31+
First, configure Varnish so that it advertises its ESI support by adding a
32+
``Surrogate-Capability`` header to requests forwarded to the backend
33+
application:
34+
35+
.. code-block:: text
36+
37+
sub vcl_recv {
38+
set req.http.Surrogate-Capability = "abc=ESI/1.0";
39+
}
40+
41+
Then, optimize Varnish so that it only parses the Response contents when there
42+
is at least one ESI tag by checking the ``Surrogate-Control`` header that
43+
Symfony2 adds automatically:
44+
45+
.. code-block:: text
46+
47+
sub vcl_fetch {
48+
if (beresp.http.Surrogate-Control ~ "ESI/1.0") {
49+
unset beresp.http.Surrogate-Control;
50+
esi;
51+
}
52+
}
53+
54+
.. caution::
55+
56+
Don't use compression with ESI as Varnish won't be able to parse the
57+
response content. If you want to use compression, put a web server in
58+
front of Varnish to do the job.
59+
60+
.. index::
61+
single: Varnish; Invalidation
62+
63+
Cache Invalidation
64+
------------------
65+
66+
You should never need to invalidate cached data because invalidation is already
67+
taken into account natively in the HTTP cache models (see :ref:`http-cache-invalidation`).
68+
69+
Still, Varnish can be configured to accept a special HTTP ``PURGE`` method
70+
that will invalidate the cache for a given resource:
71+
72+
.. code-block:: text
73+
74+
sub vcl_hit {
75+
if (req.request == "PURGE") {
76+
set obj.ttl = 0s;
77+
error 200 "Purged";
78+
}
79+
}
80+
81+
sub vcl_miss {
82+
if (req.request == "PURGE") {
83+
error 404 "Not purged";
84+
}
85+
}
86+
87+
.. caution::
88+
89+
You must protect the ``PURGE`` HTTP method somehow to avoid random people
90+
purging your cached data.

0 commit comments

Comments
 (0)