Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
7a376eb3
Commit
7a376eb3
authored
May 26, 2012
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed markup in the docs
parent
7c496d60
Changes
18
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
311 additions
and
350 deletions
+311
-350
doc/cookbook/form_no_csrf.rst
doc/cookbook/form_no_csrf.rst
+17
-16
doc/cookbook/index.rst
doc/cookbook/index.rst
+4
-2
doc/cookbook/json_request_body.rst
doc/cookbook/json_request_body.rst
+8
-12
doc/cookbook/session_storage.rst
doc/cookbook/session_storage.rst
+5
-6
doc/cookbook/validator_yaml.rst
doc/cookbook/validator_yaml.rst
+1
-3
doc/internals.rst
doc/internals.rst
+33
-43
doc/intro.rst
doc/intro.rst
+14
-16
doc/providers.rst
doc/providers.rst
+19
-24
doc/providers/monolog.rst
doc/providers/monolog.rst
+10
-15
doc/providers/session.rst
doc/providers/session.rst
+10
-9
doc/providers/swiftmailer.rst
doc/providers/swiftmailer.rst
+7
-10
doc/providers/symfony_bridges.rst
doc/providers/symfony_bridges.rst
+20
-17
doc/providers/translation.rst
doc/providers/translation.rst
+4
-2
doc/providers/twig.rst
doc/providers/twig.rst
+3
-3
doc/providers/url_generator.rst
doc/providers/url_generator.rst
+5
-5
doc/services.rst
doc/services.rst
+69
-82
doc/testing.rst
doc/testing.rst
+22
-18
doc/usage.rst
doc/usage.rst
+60
-67
No files found.
doc/cookbook/form_no_csrf.rst
View file @
7a376eb3
...
@@ -4,31 +4,32 @@ Disable CSRF Protection on a form using the FormExtension
...
@@ -4,31 +4,32 @@ Disable CSRF Protection on a form using the FormExtension
The *FormExtension* provides a service for building form in your application
The *FormExtension* provides a service for building form in your application
with the Symfony2 Form component. By default, the *FormExtension* uses the
with the Symfony2 Form component. By default, the *FormExtension* uses the
CSRF Protection avoiding Cross-site request forgery, a method by which a
CSRF Protection avoiding Cross-site request forgery, a method by which a
malicious user attempts to make your legitimate users unknowingly submit
malicious user attempts to make your legitimate users unknowingly submit
data
data
that they don't intend to submit.
that they don't intend to submit.
You can find more details about CSRF Protection and CSRF token in the `Symfony2 Book:
You can find more details about CSRF Protection and CSRF token in the
<http://symfony.com/doc/current/book/forms.html#csrf-protection>`
`Symfony2 Book
<http://symfony.com/doc/current/book/forms.html#csrf-protection>`_.
In some cases (for example, when embedding a form in an html email) you might want
In some cases (for example, when embedding a form in an html email) you might
not to use this protection. The easiest way to avoid this is to understand that it
want not to use this protection. The easiest way to avoid this is to
is possible to give specific options to your form builder through the `createBuilder()` function.
understand that it is possible to give specific options to your form builder
through the ``createBuilder()`` function.
Example
Example
-------
-------
::
.. code-block:: php
$form = $app['form.factory']->createBuilder('form', null, array('csrf_protection' => false));
$form = $app['form.factory']->createBuilder('form', null, array('csrf_protection' => false));
That's it, your form could be submited from everywhere without CSRF Protection.
That's it, your form could be submited from everywhere without CSRF Protection.
Going further
-------------
Going further..
This specific example showed how to change the ``csrf_protection`` in the
---------------
``$options`` parameter of the ``createBuilder()`` function. More of them could
be passed through this parameter, it is as simple as using the Symfony2
This specific example showed how to change the `csrf_protection` in the `$options`
``getDefaultOptions()`` method in your form classes. `See more here
parameter of the `createBuilder()` function. More of them could be passed through
<http://symfony.com/doc/current/book/forms.html#book-form-creating-form-classes>`_.
this parameter, it is as simple as using the Symfony2 `getDefaultOptions()` method
in your form classes. `See more here
<http://symfony.com/doc/current/book/forms.html#book-form-creating-form-classes>`
doc/cookbook/index.rst
View file @
7a376eb3
...
@@ -22,8 +22,10 @@ Recipes
...
@@ -22,8 +22,10 @@ Recipes
* :doc:`Translating Validation Messages<translating_validation_messages>`.
* :doc:`Translating Validation Messages<translating_validation_messages>`.
* :doc:`How to use PdoSessionStorage to store sessions in the database <session_storage>`.
* :doc:`How to use PdoSessionStorage to store sessions in the database
<session_storage>`.
* :doc:`How to disable the CSRF Protection on a form using the FormExtension <form_no_csrf>`.
* :doc:`How to disable the CSRF Protection on a form using the FormExtension
<form_no_csrf>`.
* :doc:`How to use YAML to configure validation <validator_yaml>`.
* :doc:`How to use YAML to configure validation <validator_yaml>`.
doc/cookbook/json_request_body.rst
View file @
7a376eb3
...
@@ -16,9 +16,9 @@ Request
...
@@ -16,9 +16,9 @@ Request
~~~~~~~
~~~~~~~
In the request we send the data for the blog post as a JSON object. We also
In the request we send the data for the blog post as a JSON object. We also
indicate that using the ``Content-Type`` header
.
indicate that using the ``Content-Type`` header
:
::
.. code-block:: text
POST /blog/posts
POST /blog/posts
Accept: application/json
Accept: application/json
...
@@ -32,9 +32,9 @@ Response
...
@@ -32,9 +32,9 @@ Response
The server responds with a 201 status code, telling us that the post was
The server responds with a 201 status code, telling us that the post was
created. It tells us the ``Content-Type`` of the response, which is also
created. It tells us the ``Content-Type`` of the response, which is also
JSON
.
JSON
:
::
.. code-block:: text
HTTP/1.1 201 Created
HTTP/1.1 201 Created
Content-Type: application/json
Content-Type: application/json
...
@@ -51,9 +51,7 @@ begins with ``application/json``. Since we want to do this for every request,
...
@@ -51,9 +51,7 @@ begins with ``application/json``. Since we want to do this for every request,
the easiest solution is to use a before filter.
the easiest solution is to use a before filter.
We simply use ``json_decode`` to parse the content of the request and then
We simply use ``json_decode`` to parse the content of the request and then
replace the request data on the ``$request`` object.
replace the request data on the ``$request`` object:
::
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\ParameterBag;
...
@@ -69,9 +67,7 @@ Controller implementation
...
@@ -69,9 +67,7 @@ Controller implementation
-------------------------
-------------------------
Our controller will create a new blog post from the data provided and will
Our controller will create a new blog post from the data provided and will
return the post object, including its ``id``, as JSON.
return the post object, including its ``id``, as JSON:
::
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Response;
...
@@ -91,9 +87,9 @@ Manual testing
...
@@ -91,9 +87,9 @@ Manual testing
--------------
--------------
In order to manually test our API, we can use the ``curl`` command line
In order to manually test our API, we can use the ``curl`` command line
utility, which allows sending HTTP requests
.
utility, which allows sending HTTP requests
:
::
.. code-block:: bash
$ curl http://blog.lo/blog/posts -d '{"title":"Hello World!","body":"This is my first post!"}' -H 'Content-Type: application/json'
$ curl http://blog.lo/blog/posts -d '{"title":"Hello World!","body":"This is my first post!"}' -H 'Content-Type: application/json'
{"id":"1","title":"Hello World!","body":"This is my first post!"}
{"id":"1","title":"Hello World!","body":"This is my first post!"}
doc/cookbook/session_storage.rst
View file @
7a376eb3
...
@@ -7,15 +7,14 @@ medium to large websites use a database to store sessions instead of files,
...
@@ -7,15 +7,14 @@ medium to large websites use a database to store sessions instead of files,
because databases are easier to use and scale in a multi-webserver
because databases are easier to use and scale in a multi-webserver
environment.
environment.
Symfony2's ``NativeSessionStorage`` has multiple storage handlers and one of them uses PDO to
Symfony2's ``NativeSessionStorage`` has multiple storage handlers and one of
store sessions, ``PdoSessionHandler``.
them uses PDO to store sessions, ``PdoSessionHandler``. To use it, replace the
To use it, replace the ``session.storage.handler`` service in your application like
``session.storage.handler`` service in your application like explained below.
explained below.
Example
Example
-------
-------
::
.. code-block:: php
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
...
@@ -59,4 +58,4 @@ PdoSessionStorage needs a database table with 3 columns:
...
@@ -59,4 +58,4 @@ PdoSessionStorage needs a database table with 3 columns:
You can find examples of SQL statements to create the session table in the
You can find examples of SQL statements to create the session table in the
`Symfony2 cookbook
`Symfony2 cookbook
<http://symfony.com/doc/current/cookbook/configuration/pdo_session_storage.html>`
<http://symfony.com/doc/current/cookbook/configuration/pdo_session_storage.html>`
_
doc/cookbook/validator_yaml.rst
View file @
7a376eb3
...
@@ -15,9 +15,7 @@ your ``composer.json`` file:
...
@@ -15,9 +15,7 @@ your ``composer.json`` file:
}
}
Next, you need to tell the Validation Service that you are not using
Next, you need to tell the Validation Service that you are not using
``StaticMethodLoader`` to load your class metadata but a YAML file:
``StaticMethodLoader`` to load your class metadata but a YAML file::
.. code-block:: php
$app->register(new ValidatorServiceProvider());
$app->register(new ValidatorServiceProvider());
...
...
doc/internals.rst
View file @
7a376eb3
...
@@ -10,68 +10,59 @@ Silex
...
@@ -10,68 +10,59 @@ Silex
Application
Application
~~~~~~~~~~~
~~~~~~~~~~~
The application is the main interface to Silex. It
The application is the main interface to Silex. It
implements Symfony2's
implements Symfony2's
`HttpKernelInterface
`HttpKernelInterface
<http://api.symfony.com/master/Symfony/Component/HttpKernel/HttpKernelInterface.html>`_,
<http://api.symfony.com/master/Symfony/Component/HttpKernel/HttpKernelInterface.html>`_,
so you can pass a `Request
so you can pass a `Request
<http://api.symfony.com/master/Symfony/Component/HttpFoundation/Request.html>`_
<http://api.symfony.com/master/Symfony/Component/HttpFoundation/Request.html>`_
to the ``handle`` method and it will return a `Response
to the ``handle`` method and it will return a `Response
<http://api.symfony.com/master/Symfony/Component/HttpFoundation/Response.html>`_.
<http://api.symfony.com/master/Symfony/Component/HttpFoundation/Response.html>`_.
It extends the ``Pimple`` service container, allowing
It extends the ``Pimple`` service container, allowing for flexibility on the
for flexibility on the outside as well as the inside. you
outside as well as the inside. you could replace any service, and you are also
could replace any service, and you are also able to read
able to read them.
them.
The application makes strong use of the `EventDispatcher
The application makes strong use of the `EventDispatcher
<http://api.symfony.com/master/Symfony/Component/EventDispatcher/EventDispatcher.html>`_
<http://api.symfony.com/master/Symfony/Component/EventDispatcher/EventDispatcher.html>`_
to hook into the Symfony2 `HttpKernel
to hook into the Symfony2 `HttpKernel
<http://api.symfony.com/master/Symfony/Component/HttpKernel/HttpKernel.html>`_ events. This allows
<http://api.symfony.com/master/Symfony/Component/HttpKernel/HttpKernel.html>`_
fetching the ``Request``, converting string responses into
events. This allows fetching the ``Request``, converting string responses into
``Response`` objects and handling Exceptions. We also use it
``Response`` objects and handling Exceptions. We also use it to dispatch some
to dispatch some custom events like before/after filters and
custom events like before/after filters and errors.
errors.
Controller
Controller
~~~~~~~~~~
~~~~~~~~~~
The Symfony2 `Route
The Symfony2 `Route
<http://api.symfony.com/master/Symfony/Component/Routing/Route.html>`_
<http://api.symfony.com/master/Symfony/Component/Routing/Route.html>`_ is
is actually quite powerful. Routes
actually quite powerful. Routes can be named, which allows for URL generation.
can be named, which allows for URL generation. They can
They can also have requirements for the variable parts. In order to allow
also have requirements for the variable parts. In order
settings these through a nice interface the ``match`` method (which is used by
to allow settings these through a nice interface the
``get``, ``post``, etc.) returns an instance of the ``Controller``, which
``match`` method (which is used by ``get``, ``post``, etc.)
wraps a route.
returns an instance of the ``Controller``, which wraps
a route.
ControllerCollection
ControllerCollection
~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~
One of the goals of exposing the `RouteCollection
One of the goals of exposing the `RouteCollection
<http://api.symfony.com/master/Symfony/Component/Routing/RouteCollection.html>`_
<http://api.symfony.com/master/Symfony/Component/Routing/RouteCollection.html>`_
was to make it mutable, so providers could add stuff to it.
was to make it mutable, so providers could add stuff to it. The challenge here
The challenge here is the fact that routes know nothing
is the fact that routes know nothing about their name. The name only has
about their name. The name only has meaning in context
meaning in context of the ``RouteCollection`` and cannot be changed.
of the ``RouteCollection`` and cannot be changed.
To solve this challenge we came up with a staging area for routes. The
To solve this challenge we came up with a staging area
``ControllerCollection`` holds the controllers until ``flush`` is called, at
for routes. The ``ControllerCollection`` holds the
which point the routes are added to the ``RouteCollection``. Also, the
controllers until ``flush`` is called, at which point
controllers are then frozen. This means that they can no longer be modified
the routes are added to the ``RouteCollection``. Also,
and will throw an Exception if you try to do so.
the controllers are then frozen. This means that they can
no longer be modified and will throw an Exception if
Unfortunately no good way for flushing implicitly could be found, which is why
you try to do so.
flushing is now always explicit. The Application will flush, but if you want
to read the ``ControllerCollection`` before the request takes place, you will
Unfortunately no good way for flushing implicitly
have to call flush yourself.
could be found, which is why flushing is now always
explicit. The Application will flush, but if you want
The ``Application`` provides a shortcut ``flush`` method for flushing the
to read the ``ControllerCollection`` before the
``ControllerCollection``.
request takes place, you will have to call flush
yourself.
The ``Application`` provides a shortcut ``flush``
method for flushing the ``ControllerCollection``.
Symfony2
Symfony2
--------
--------
...
@@ -88,5 +79,4 @@ Following Symfony2 components are used by Silex:
...
@@ -88,5 +79,4 @@ Following Symfony2 components are used by Silex:
* **EventDispatcher**: For hooking into the HttpKernel.
* **EventDispatcher**: For hooking into the HttpKernel.
For more information, `check out the Symfony website
For more information, `check out the Symfony website <http://symfony.com/>`_.
<http://symfony.com/>`_.
doc/intro.rst
View file @
7a376eb3
Introduction
Introduction
============
============
Silex is a PHP microframework for PHP 5.3. It is built on the shoulders
Silex is a PHP microframework for PHP 5.3. It is built on the shoulders
of
of
Symfony2 and Pimple and also inspired by sinatra.
Symfony2 and Pimple and also inspired by sinatra.
A microframework provides the guts for building simple single-file apps.
A microframework provides the guts for building simple single-file apps.
Silex
Silex
aims to be:
aims to be:
* *Concise*: Silex exposes an intuitive and concise API that is fun to use.
* *Concise*: Silex exposes an intuitive and concise API that is fun to use.
* *Extensible*: Silex has an extension system based around the Pimple
* *Extensible*: Silex has an extension system based around the Pimple micro
micro service-container that makes it even easier to tie in third party
service-container that makes it even easier to tie in third party libraries.
libraries.
* *Testable*: Silex uses Symfony2's HttpKernel which abstracts request and
* *Testable*: Silex uses Symfony2's HttpKernel which abstracts request and
response. This makes it very easy to test apps and the framework itself.
response. This makes it very easy to test apps and the framework itself.
It
It
also respects the HTTP specification and encourages its proper use.
also respects the HTTP specification and encourages its proper use.
In a nutshell, you define controllers and map them to routes, all in one
In a nutshell, you define controllers and map them to routes, all in one step.
step.
**Let's go!**::
**Let's go!**::
...
@@ -37,12 +35,12 @@ step.
...
@@ -37,12 +35,12 @@ step.
All that is needed to get access to the Framework is to include the
All that is needed to get access to the Framework is to include the
autoloader.
autoloader.
Next we define a route to ``/hello/{name}`` that matches for ``GET``
Next we define a route to ``/hello/{name}`` that matches for ``GET``
requests.
requests. When the route matches, the function is executed and the return
When the route matches, the function is executed and the return value is sent
value is sent
back to the client.
back to the client.
Finally, the app is run. Visit ``/hello/world`` to see the result.
Finally, the app is run. Visit ``/hello/world`` to see the result.
It's really
It's really
that easy!
that easy!
Installing Silex is as easy as it can get. Download the `silex.zip`_ file,
Installing Silex is as easy as it can get. Download the `silex.zip`_ file,
extract it, and you're done!
extract it, and you're done!
...
...
doc/providers.rst
View file @
7a376eb3
...
@@ -31,26 +31,23 @@ will be set **before** the provider is registered::
...
@@ -31,26 +31,23 @@ will be set **before** the provider is registered::
Conventions
Conventions
~~~~~~~~~~~
~~~~~~~~~~~
You need to watch out in what order you do certain things when
You need to watch out in what order you do certain things when
interacting
interacting
with providers. Just keep to these rules:
with providers. Just keep to these rules:
* Overriding existing services must occur **after** the
* Overriding existing services must occur **after** the
provider is
provider is
registered.
registered.
*Reason: If the services already exist, the provider
*Reason: If the services already exist, the provider will overwrite it.*
will overwrite it.*
* You can set parameters any time before the service is
* You can set parameters any time before the service is accessed.
accessed.
Make sure to stick to this behavior when creating your
Make sure to stick to this behavior when creating your own providers.
own providers.
Included providers
Included providers
~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~
There are a few provider that you get out of the box.
There are a few provider that you get out of the box.
All of these are within
All of these are within the ``Silex\Provider`` namespace.
the ``Silex\Provider`` namespace:
* :doc:`DoctrineServiceProvider <providers/doctrine>`
* :doc:`DoctrineServiceProvider <providers/doctrine>`
* :doc:`MonologServiceProvider <providers/monolog>`
* :doc:`MonologServiceProvider <providers/monolog>`
...
@@ -66,8 +63,8 @@ All of these are within the ``Silex\Provider`` namespace.
...
@@ -66,8 +63,8 @@ All of these are within the ``Silex\Provider`` namespace.
Third party providers
Third party providers
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
Some service providers are developed by the community. Those
Some service providers are developed by the community. Those
third-party
third-party providers are listed on `Silex' repository wiki
providers are listed on `Silex' repository wiki
<https://github.com/fabpot/Silex/wiki/Third-Party-ServiceProviders>`_.
<https://github.com/fabpot/Silex/wiki/Third-Party-ServiceProviders>`_.
You are encouraged to share yours.
You are encouraged to share yours.
...
@@ -82,10 +79,9 @@ Providers must implement the ``Silex\ServiceProviderInterface``::
...
@@ -82,10 +79,9 @@ Providers must implement the ``Silex\ServiceProviderInterface``::
function register(Application $app);
function register(Application $app);
}
}
This is very straight forward, just create a new class that
This is very straight forward, just create a new class that implements the
implements the ``register`` method. In this method you must
``register`` method. In this method you must define services on the
define services on the application which then may make use
application which then may make use of other services and parameters.
of other services and parameters.
Here is an example of such a provider::
Here is an example of such a provider::
...
@@ -107,10 +103,9 @@ Here is an example of such a provider::
...
@@ -107,10 +103,9 @@ Here is an example of such a provider::
}
}
}
}
This class provides a ``hello`` service which is a protected
This class provides a ``hello`` service which is a protected closure. It takes
closure. It takes a ``name`` argument and will return
a ``name`` argument and will return ``hello.default_name`` if no name is
``hello.default_name`` if no name is given. If the default
given. If the default is also missing, it will use an empty string.
is also missing, it will use an empty string.
You can now use this provider as follows::
You can now use this provider as follows::
...
@@ -126,8 +121,8 @@ You can now use this provider as follows::
...
@@ -126,8 +121,8 @@ You can now use this provider as follows::
return $app['hello']($name);
return $app['hello']($name);
});
});
In this example we are getting the ``name`` parameter from the
In this example we are getting the ``name`` parameter from the
query string,
query string,
so the request path would have to be ``/hello?name=Fabien``.
so the request path would have to be ``/hello?name=Fabien``.
Controllers providers
Controllers providers
---------------------
---------------------
...
...
doc/providers/monolog.rst
View file @
7a376eb3
MonologServiceProvider
MonologServiceProvider
======================
======================
The *MonologServiceProvider* provides a default logging mechanism
The *MonologServiceProvider* provides a default logging mechanism through
through Jordi Boggiano's `Monolog <https://github.com/Seldaek/monolog>`_
Jordi Boggiano's `Monolog <https://github.com/Seldaek/monolog>`_ library.
library.
It will log requests and errors and allow you to add debug
It will log requests and errors and allow you to add debug logging to your
logging to your application, so you don't have to use
application, so you don't have to use ``var_dump`` so much anymore. You can
``var_dump`` so much anymore. You can use the grown-up
use the grown-up version called ``tail -f``.
version called ``tail -f``.
Parameters
Parameters
----------
----------
...
@@ -33,9 +31,8 @@ Services
...
@@ -33,9 +31,8 @@ Services
$app['monolog']->addDebug('Testing the Monolog logging.');
$app['monolog']->addDebug('Testing the Monolog logging.');
* **monolog.configure**: Protected closure that takes the
* **monolog.configure**: Protected closure that takes the logger as an
logger as an argument. You can override it if you do not
argument. You can override it if you do not want the default behavior.
want the default behavior.
Registering
Registering
-----------
-----------
...
@@ -60,11 +57,9 @@ Registering
...
@@ -60,11 +57,9 @@ Registering
Usage
Usage
-----
-----
The MonologServiceProvider provides a ``monolog`` service. You can use
The MonologServiceProvider provides a ``monolog`` service. You can use it to
it to add log entries for any logging level through ``addDebug()``,
add log entries for any logging level through ``addDebug()``, ``addInfo()``,
``addInfo()``, ``addWarning()`` and ``addError()``.
``addWarning()`` and ``addError()``:
::
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Response;
...
...
doc/providers/session.rst
View file @
7a376eb3
...
@@ -24,8 +24,8 @@ Parameters
...
@@ -24,8 +24,8 @@ Parameters
* **secure**: Cookie secure (HTTPS)
* **secure**: Cookie secure (HTTPS)
* **httponly**: Whether the cookie is http only
* **httponly**: Whether the cookie is http only
However, all of these are optional. Sessions last as long as the browser
However, all of these are optional. Sessions last as long as the browser
is
is
open. To override this, set the ``lifetime`` option.
open. To override this, set the ``lifetime`` option.
Services
Services
--------
--------
...
@@ -33,11 +33,12 @@ Services
...
@@ -33,11 +33,12 @@ Services
* **session**: An instance of Symfony2's `Session
* **session**: An instance of Symfony2's `Session
<http://api.symfony.com/master/Symfony/Component/HttpFoundation/Session/Session.html>`_.
<http://api.symfony.com/master/Symfony/Component/HttpFoundation/Session/Session.html>`_.
* **session.storage**: A service that is used for persistence of the
* **session.storage**: A service that is used for persistence of the
session
session data. Defaults to a ``NativeSessionStorage``
data. Defaults to a ``NativeSessionStorage``.
* **session.storage.handler**: A service that is used by the ``session.storage``
* **session.storage.handler**: A service that is used by the
for data access. Defaults to a ``NativeFileSessionHandler`` storage handler.
``session.storage`` for data access. Defaults to a
``NativeFileSessionHandler`` storage handler.
Registering
Registering
-----------
-----------
...
@@ -49,8 +50,8 @@ Registering
...
@@ -49,8 +50,8 @@ Registering
Usage
Usage
-----
-----
The Session provider provides a ``session`` service. Here is an
The Session provider provides a ``session`` service. Here is an
example that
example that
authenticates a user and creates a session for him::
authenticates a user and creates a session for him::
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Response;
...
...
doc/providers/swiftmailer.rst
View file @
7a376eb3
SwiftmailerServiceProvider
SwiftmailerServiceProvider
==========================
==========================
The *SwiftmailerServiceProvider* provides a service for sending
The *SwiftmailerServiceProvider* provides a service for sending email through
email through the `Swift Mailer <http://swiftmailer.org>`_
the `Swift Mailer <http://swiftmailer.org>`_ library.
library.
You can use the ``mailer`` service to send messages easily.
You can use the ``mailer`` service to send messages easily.
By default, it
By default, it
will attempt to send emails through SMTP.
will attempt to send emails through SMTP.
Parameters
Parameters
----------
----------
* **swiftmailer.options**: An array of options for the default
* **swiftmailer.options**: An array of options for the default
SMTP-based
SMTP-based
configuration.
configuration.
The following options can be set:
The following options can be set:
...
@@ -75,9 +74,7 @@ Registering
...
@@ -75,9 +74,7 @@ Registering
Usage
Usage
-----
-----
The Swiftmailer provider provides a ``mailer`` service.
The Swiftmailer provider provides a ``mailer`` service:
::
$app->post('/feedback', function () use ($app) {
$app->post('/feedback', function () use ($app) {
$request = $app['request'];
$request = $app['request'];
...
...
doc/providers/symfony_bridges.rst
View file @
7a376eb3
...
@@ -12,23 +12,26 @@ none
...
@@ -12,23 +12,26 @@ none
Twig
Twig
----
----
When the ``SymfonyBridgesServiceProvider`` is enabled, the ``TwigServiceProvider`` will
When the ``SymfonyBridgesServiceProvider`` is enabled, the
provide you with the following additional capabilities:
``TwigServiceProvider`` will provide you with the following additional
capabilities:
* **UrlGeneratorServiceProvider**: If you are using the ``UrlGeneratorServiceProvider``,
you will get ``path`` and ``url`` helpers for Twig. You can find more
* **UrlGeneratorServiceProvider**: If you are using the
information in the
``UrlGeneratorServiceProvider``, you will get ``path`` and ``url`` helpers
`Symfony2 Routing documentation <http://symfony.com/doc/current/book/routing.html#generating-urls-from-a-template>`_.
for Twig. You can find more information in the `Symfony2 Routing
documentation
* **TranslationServiceProvider**: If you are using the ``TranslationServiceProvider``,
<http://symfony.com/doc/current/book/routing.html#generating-urls-from-a-template>`_.
you will get ``trans`` and ``transchoice`` helpers for translation in
Twig templates. You can find more information in the
* **TranslationServiceProvider**: If you are using the
`Symfony2 Translation documentation <http://symfony.com/doc/current/book/translation.html#twig-templates>`_.
``TranslationServiceProvider``, you will get ``trans`` and ``transchoice``
helpers for translation in Twig templates. You can find more information in
* **FormServiceProvider**: If you are using the ``FormServiceProvider``,
the `Symfony2 Translation documentation
you will get a set of helpers for working with forms in templates.
<http://symfony.com/doc/current/book/translation.html#twig-templates>`_.
You can find more information in the
`Symfony2 Forms reference <http://symfony.com/doc/current/reference/forms/twig_reference.html>`_.
* **FormServiceProvider**: If you are using the ``FormServiceProvider``, you
will get a set of helpers for working with forms in templates. You can find
more information in the `Symfony2 Forms reference
<http://symfony.com/doc/current/reference/forms/twig_reference.html>`_.
Registering
Registering
-----------
-----------
...
...
doc/providers/translation.rst
View file @
7a376eb3
...
@@ -24,7 +24,8 @@ Services
...
@@ -24,7 +24,8 @@ Services
that is used for translation.
that is used for translation.
* **translator.loader**: An instance of an implementation of the translation
* **translator.loader**: An instance of an implementation of the translation
`LoaderInterface <http://api.symfony.com/master/Symfony/Component/Translation/Loader/LoaderInterface.html>`_,
`LoaderInterface
<http://api.symfony.com/master/Symfony/Component/Translation/Loader/LoaderInterface.html>`_,
defaults to an `ArrayLoader
defaults to an `ArrayLoader
<http://api.symfony.com/master/Symfony/Component/Translation/Loader/ArrayLoader.html>`_.
<http://api.symfony.com/master/Symfony/Component/Translation/Loader/ArrayLoader.html>`_.
...
@@ -171,7 +172,8 @@ That's it.
...
@@ -171,7 +172,8 @@ That's it.
Accessing translations in Twig templates
Accessing translations in Twig templates
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Once loaded, the translation service provider is available from within Twig templates:
Once loaded, the translation service provider is available from within Twig
templates:
.. code-block:: jinja
.. code-block:: jinja
...
...
doc/providers/twig.rst
View file @
7a376eb3
...
@@ -29,9 +29,9 @@ Services
...
@@ -29,9 +29,9 @@ Services
that takes the Twig environment as an argument. You can use it to add more
that takes the Twig environment as an argument. You can use it to add more
custom globals.
custom globals.
* **twig.loader**: The loader for Twig templates which uses
* **twig.loader**: The loader for Twig templates which uses
the ``twig.path``
the ``twig.path`` and the ``twig.templates`` options. You
and the ``twig.templates`` options. You can also replace the loader
c
an also replace the loader c
ompletely.
completely.
Registering
Registering
-----------
-----------
...
...
doc/providers/url_generator.rst
View file @
7a376eb3
UrlGeneratorServiceProvider
UrlGeneratorServiceProvider
===========================
===========================
The *UrlGeneratorServiceProvider* provides a service for generating
The *UrlGeneratorServiceProvider* provides a service for generating
URLs for
URLs for
named routes.
named routes.
Parameters
Parameters
----------
----------
...
@@ -16,9 +16,9 @@ Services
...
@@ -16,9 +16,9 @@ Services
<http://api.symfony.com/master/Symfony/Component/Routing/Generator/UrlGenerator.html>`_,
<http://api.symfony.com/master/Symfony/Component/Routing/Generator/UrlGenerator.html>`_,
using the `RouteCollection
using the `RouteCollection
<http://api.symfony.com/master/Symfony/Component/Routing/RouteCollection.html>`_
<http://api.symfony.com/master/Symfony/Component/Routing/RouteCollection.html>`_
that is provided through the ``routes`` service.
that is provided through the ``routes`` service.
It has a ``generate``
It has a ``generate`` method, which takes the route name as an argument,
method, which takes the route name as an argument, followed by an array of
followed by an array of
route parameters.
route parameters.
Registering
Registering
-----------
-----------
...
...
doc/services.rst
View file @
7a376eb3
This diff is collapsed.
Click to expand it.
doc/testing.rst
View file @
7a376eb3
...
@@ -3,30 +3,32 @@ Testing
...
@@ -3,30 +3,32 @@ Testing
Because Silex is built on top of Symfony2, it is very easy to write functional
Because Silex is built on top of Symfony2, it is very easy to write functional
tests for your application. Functional tests are automated software tests that
tests for your application. Functional tests are automated software tests that
ensure that your code is working correctly. They go through the user
interface,
ensure that your code is working correctly. They go through the user
using a fake browser, and mimic the actions a user would do.
interface,
using a fake browser, and mimic the actions a user would do.
Why
Why
---
---
If you are not familiar with software tests, you may be wondering why you
would
If you are not familiar with software tests, you may be wondering why you
need this. Every time you make a change to your application, you have to test
would need this. Every time you make a change to your application, you have to
it. This means going through all the pages and making sure they are still
test
it. This means going through all the pages and making sure they are still
working. Functional tests save you a lot of time, because they enable you to
working. Functional tests save you a lot of time, because they enable you to
test your application in usually under a second by running a single command.
test your application in usually under a second by running a single command.
For more information on functional testing, unit testing, and automated
For more information on functional testing, unit testing, and automated
software tests in general, check out `PHPUnit <https://github.com/sebastianbergmann/phpunit>`_
software tests in general, check out `PHPUnit
and `Bulat Shakirzyanov's talk on Clean Code <http://www.slideshare.net/avalanche123/clean-code-5609451>`_.
<https://github.com/sebastianbergmann/phpunit>`_ and `Bulat Shakirzyanov's
talk on Clean Code
<http://www.slideshare.net/avalanche123/clean-code-5609451>`_.
PHPUnit
PHPUnit
-------
-------
`PHPUnit <https://github.com/sebastianbergmann/phpunit>`_
`PHPUnit <https://github.com/sebastianbergmann/phpunit>`_
is the de-facto
is the de-facto standard testing framework for PHP. It was built for
standard testing framework for PHP. It was built for writing unit tests, but
writing unit tests, but it can be used for functional tests too. You write
it can be used for functional tests too. You write tests by creating a new
tests by creating a new class, that extends the ``PHPUnit_Framework_TestCase``.
class, that extends the ``PHPUnit_Framework_TestCase``. Your test cases are
Your test cases are
methods prefixed with ``test``::
methods prefixed with ``test``::
class ContactFormTest extends PHPUnit_Framework_TestCase
class ContactFormTest extends PHPUnit_Framework_TestCase
{
{
...
@@ -120,8 +122,9 @@ executed before every test.
...
@@ -120,8 +122,9 @@ executed before every test.
// ...
// ...
}
}
The WebTestCase provides a ``createClient`` method. A client acts as a browser,
The WebTestCase provides a ``createClient`` method. A client acts as a
and allows you to interact with your application. Here's how it works::
browser, and allows you to interact with your application. Here's how it
works::
public function testInitialPage()
public function testInitialPage()
{
{
...
@@ -148,8 +151,8 @@ application.
...
@@ -148,8 +151,8 @@ application.
.. note::
.. note::
You can find some documentation for it in `the client section of the
testing
You can find some documentation for it in `the client section of the
chapter of the Symfony2 documentation
testing
chapter of the Symfony2 documentation
<http://symfony.com/doc/current/book/testing.html#the-test-client>`_.
<http://symfony.com/doc/current/book/testing.html#the-test-client>`_.
Crawler
Crawler
...
@@ -168,8 +171,9 @@ Configuration
...
@@ -168,8 +171,9 @@ Configuration
-------------
-------------
The suggested way to configure PHPUnit is to create a ``phpunit.xml.dist``
The suggested way to configure PHPUnit is to create a ``phpunit.xml.dist``
file, a ``tests`` folder and your tests in ``tests/YourApp/Tests/YourTest.php``.
file, a ``tests`` folder and your tests in
The ``phpunit.xml.dist`` file should look like this:
``tests/YourApp/Tests/YourTest.php``. The ``phpunit.xml.dist`` file should
look like this:
.. code-block:: xml
.. code-block:: xml
...
...
doc/usage.rst
View file @
7a376eb3
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment