Commit 82e73deb authored by Fabien Potencier's avatar Fabien Potencier

fixed doc markup so that it is more consistent

parent 934bf3ea
...@@ -8,16 +8,14 @@ Loading extensions ...@@ -8,16 +8,14 @@ Loading extensions
------------------ ------------------
In order to load and use an extension, you must register it In order to load and use an extension, you must register it
on the application. :: on the application::
$app = new Silex\Application(); $app = new Silex\Application();
$app->register(new Acme\DatabaseExtension()); $app->register(new Acme\DatabaseExtension());
You can also provide some parameters as a second argument. These You can also provide some parameters as a second argument. These
will be set **before** the extension is registered. will be set **before** the extension is registered::
::
$app->register(new Acme\DatabaseExtension(), array( $app->register(new Acme\DatabaseExtension(), array(
'database.dsn' => 'mysql:host=localhost;dbname=myapp', 'database.dsn' => 'mysql:host=localhost;dbname=myapp',
...@@ -70,9 +68,7 @@ All of these are within the ``Silex\Extension`` namespace. ...@@ -70,9 +68,7 @@ All of these are within the ``Silex\Extension`` namespace.
Creating an extension Creating an extension
--------------------- ---------------------
Extensions must implement the ``Silex\ExtensionInterface``. Extensions must implement the ``Silex\ExtensionInterface``::
::
interface ExtensionInterface interface ExtensionInterface
{ {
......
...@@ -56,9 +56,7 @@ Registering ...@@ -56,9 +56,7 @@ Registering
----------- -----------
Make sure you place a copy of *Doctrine DBAL* in ``vendor/doctrine-dbal`` Make sure you place a copy of *Doctrine DBAL* in ``vendor/doctrine-dbal``
and *Doctrine Common* in ``vendor/doctrine-common``. and *Doctrine Common* in ``vendor/doctrine-common``::
::
$app->register(new Silex\Extension\DoctrineExtension(), array( $app->register(new Silex\Extension\DoctrineExtension(), array(
'db.options' => array( 'db.options' => array(
......
...@@ -44,9 +44,7 @@ Registering ...@@ -44,9 +44,7 @@ Registering
----------- -----------
Make sure you place a copy of *Monolog* in the ``vendor/monolog`` Make sure you place a copy of *Monolog* in the ``vendor/monolog``
directory. directory::
::
$app->register(new Silex\Extension\MonologExtension(), array( $app->register(new Silex\Extension\MonologExtension(), array(
'monolog.logfile' => __DIR__.'/development.log', 'monolog.logfile' => __DIR__.'/development.log',
......
...@@ -38,9 +38,7 @@ Registering ...@@ -38,9 +38,7 @@ Registering
----------- -----------
Make sure you place a copy of the Symfony2 Translation component in Make sure you place a copy of the Symfony2 Translation component in
``vendor/symfony/src``. You can simply clone the whole Symfony2 into vendor. ``vendor/symfony/src``. You can simply clone the whole Symfony2 into vendor::
::
$app->register(new Silex\Extension\TranslationExtension(), array( $app->register(new Silex\Extension\TranslationExtension(), array(
'locale_fallback' => 'en', 'locale_fallback' => 'en',
...@@ -51,9 +49,7 @@ Usage ...@@ -51,9 +49,7 @@ Usage
----- -----
The Translation extension provides a ``translator`` service and makes use of The Translation extension provides a ``translator`` service and makes use of
the ``translator.messages`` parameter. the ``translator.messages`` parameter::
::
$app['translator.messages'] = array( $app['translator.messages'] = array(
'en' => array( 'en' => array(
...@@ -101,9 +97,7 @@ show you how to load translations from external YAML files. ...@@ -101,9 +97,7 @@ show you how to load translations from external YAML files.
First you will need the ``Config`` and ``Yaml`` components from Symfony2. Also First you will need the ``Config`` and ``Yaml`` components from Symfony2. Also
make sure you register them with the autoloader. You can just clone the entire make sure you register them with the autoloader. You can just clone the entire
Symfony2 repository into ``vendor/symfony``. Symfony2 repository into ``vendor/symfony``::
::
$app['autoloader']->registerNamespace('Symfony', __DIR__.'/vendor/symfony/src'); $app['autoloader']->registerNamespace('Symfony', __DIR__.'/vendor/symfony/src');
......
...@@ -39,9 +39,7 @@ Registering ...@@ -39,9 +39,7 @@ Registering
----------- -----------
Make sure you place a copy of *Twig* in the ``vendor/twig`` Make sure you place a copy of *Twig* in the ``vendor/twig``
directory. directory::
::
$app->register(new Silex\Extension\TwigExtension(), array( $app->register(new Silex\Extension\TwigExtension(), array(
'twig.path' => __DIR__.'/views', 'twig.path' => __DIR__.'/views',
...@@ -56,9 +54,7 @@ directory. ...@@ -56,9 +54,7 @@ directory.
Usage Usage
----- -----
The Twig extension provides a ``twig`` service. The Twig extension provides a ``twig`` service::
::
$app->get('/hello/{name}', function ($name) use ($app) { $app->get('/hello/{name}', function ($name) use ($app) {
return $app['twig']->render('hello.twig', array( return $app['twig']->render('hello.twig', array(
......
...@@ -30,9 +30,7 @@ Registering ...@@ -30,9 +30,7 @@ Registering
Usage Usage
----- -----
The UrlGenerator extension provides a ``url_generator`` service. The UrlGenerator extension provides a ``url_generator`` service::
::
$app->get('/', function () { $app->get('/', function () {
return 'welcome to the homepage'; return 'welcome to the homepage';
......
...@@ -33,9 +33,7 @@ Registering ...@@ -33,9 +33,7 @@ Registering
----------- -----------
Make sure you place a copy of the Symfony2 Validator component in Make sure you place a copy of the Symfony2 Validator component in
``vendor/symfony/src``. You can simply clone the whole Symfony2 into vendor. ``vendor/symfony/src``. You can simply clone the whole Symfony2 into vendor::
::
$app->register(new Silex\Extension\ValidatorExtension(), array( $app->register(new Silex\Extension\ValidatorExtension(), array(
'validator.class_path' => __DIR__.'/vendor/symfony/src', 'validator.class_path' => __DIR__.'/vendor/symfony/src',
...@@ -49,9 +47,8 @@ The Validator extension provides a ``validator`` service. ...@@ -49,9 +47,8 @@ The Validator extension provides a ``validator`` service.
Validating values Validating values
~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~
You can validate values directly using the ``validateValue`` validator method. You can validate values directly using the ``validateValue`` validator
method::
::
use Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraints;
...@@ -68,9 +65,7 @@ Validating object properties ...@@ -68,9 +65,7 @@ Validating object properties
If you want to add validations to a class, you can implement a static If you want to add validations to a class, you can implement a static
``loadValidatorMetadata`` method as described under *Services*. This allows ``loadValidatorMetadata`` method as described under *Services*. This allows
you to define constraints for your object properties. It also works with you to define constraints for your object properties. It also works with
getters. getters::
::
use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraints;
......
...@@ -65,11 +65,11 @@ makes strong use of closures implements the ArrayAccess interface. ...@@ -65,11 +65,11 @@ makes strong use of closures implements the ArrayAccess interface.
We will start off by creating a new instance of Pimple -- and We will start off by creating a new instance of Pimple -- and
because ``Silex\Application`` extends ``Pimple`` all of this because ``Silex\Application`` extends ``Pimple`` all of this
applies to Silex as well. :: applies to Silex as well::
$container = new Pimple(); $container = new Pimple();
or :: or::
$app = new Silex\Application(); $app = new Silex\Application();
...@@ -82,12 +82,12 @@ an array key on the container:: ...@@ -82,12 +82,12 @@ an array key on the container::
$app['some_parameter'] = 'value'; $app['some_parameter'] = 'value';
The array key can be anything, by convention periods are The array key can be anything, by convention periods are
used for namespacing. :: used for namespacing::
$app['asset.host'] = 'http://cdn.mysite.com/'; $app['asset.host'] = 'http://cdn.mysite.com/';
Reading parameter values is possible with the same Reading parameter values is possible with the same
syntax. :: syntax::
echo $app['some_parameter']; echo $app['some_parameter'];
...@@ -97,9 +97,7 @@ Service definitions ...@@ -97,9 +97,7 @@ Service definitions
Defining services is no different than defining parameters. Defining services is no different than defining parameters.
You just set an array key on the container to be a closure. You just set an array key on the container to be a closure.
However, when you retrieve the service, the closure is executed. However, when you retrieve the service, the closure is executed.
This allows for lazy service creation. This allows for lazy service creation::
::
$app['some_service'] = function () { $app['some_service'] = function () {
return new Service(); return new Service();
...@@ -117,7 +115,7 @@ Shared services ...@@ -117,7 +115,7 @@ Shared services
You may want to use the same instance of a service across all You may want to use the same instance of a service across all
of your code. In order to do that you can make a *shared* of your code. In order to do that you can make a *shared*
service. :: service::
$app['some_service'] = $app->share(function () { $app['some_service'] = $app->share(function () {
return new Service(); return new Service();
...@@ -134,7 +132,7 @@ from within a service definition closure. For example when ...@@ -134,7 +132,7 @@ from within a service definition closure. For example when
fetching services the current service depends on. fetching services the current service depends on.
Because of this, the container is passed to the closure as Because of this, the container is passed to the closure as
an argument. :: an argument::
$app['some_service'] = function ($app) { $app['some_service'] = function ($app) {
return new Service($app['some_other_service'], $app['some_service.config']); return new Service($app['some_other_service'], $app['some_service.config']);
...@@ -162,9 +160,7 @@ as a parameter, so that you can fetch it and execute it ...@@ -162,9 +160,7 @@ as a parameter, so that you can fetch it and execute it
yourself -- with your own arguments. yourself -- with your own arguments.
This is why Pimple allows you to protect your closures This is why Pimple allows you to protect your closures
from being executed, by using the ``protect`` method. from being executed, by using the ``protect`` method::
::
$app['closure_parameter'] = $app->protect(function ($a, $b) { $app['closure_parameter'] = $app->protect(function ($a, $b) {
return $a + $b; return $a + $b;
......
...@@ -26,9 +26,7 @@ PHPUnit ...@@ -26,9 +26,7 @@ PHPUnit
is the de-facto standard testing framework for PHP. It was built for is the de-facto standard testing framework for PHP. It was built for
writing unit tests, but it can be used for functional tests too. You write writing unit tests, but it can be used for functional tests too. You write
tests by creating a new class, that extends the ``PHPUnit_Framework_TestCase``. tests by creating a new class, that extends the ``PHPUnit_Framework_TestCase``.
Your test cases are methods prefixed with ``test``. Your test cases are methods prefixed with ``test``::
::
class ContactFormTest extends PHPUnit_Framework_TestCase class ContactFormTest extends PHPUnit_Framework_TestCase
{ {
...@@ -40,9 +38,7 @@ Your test cases are methods prefixed with ``test``. ...@@ -40,9 +38,7 @@ Your test cases are methods prefixed with ``test``.
In your test cases, you do assertions on the state of what you are testing. In In your test cases, you do assertions on the state of what you are testing. In
this case we are testing a contact form, so we would want to assert that the this case we are testing a contact form, so we would want to assert that the
page loaded correctly and contains our form. page loaded correctly and contains our form::
::
public function testInitialPage() public function testInitialPage()
{ {
......
...@@ -8,9 +8,7 @@ Bootstrap ...@@ -8,9 +8,7 @@ Bootstrap
To include the Silex all you need to do is require the ``silex.phar`` To include the Silex all you need to do is require the ``silex.phar``
file and create an instance of ``Silex\Application``. After your file and create an instance of ``Silex\Application``. After your
controller definitions, call the ``run`` method on your application. controller definitions, call the ``run`` method on your application::
::
require_once __DIR__.'/silex.phar'; require_once __DIR__.'/silex.phar';
...@@ -146,9 +144,7 @@ Example POST route ...@@ -146,9 +144,7 @@ Example POST route
POST routes signify the creation of a resource. An example for this is a POST routes signify the creation of a resource. An example for this is a
feedback form. We will use `Swift Mailer feedback form. We will use `Swift Mailer
<http://swiftmailer.org/>`_ and assume a copy of it to be present in the <http://swiftmailer.org/>`_ and assume a copy of it to be present in the
``vendor/swiftmailer`` directory. ``vendor/swiftmailer`` directory::
::
require_once __DIR__.'/vendor/swiftmailer/lib/swift_required.php'; require_once __DIR__.'/vendor/swiftmailer/lib/swift_required.php';
...@@ -193,9 +189,7 @@ Other methods ...@@ -193,9 +189,7 @@ Other methods
You can create controllers for most HTTP methods. Just call one of these You can create controllers for most HTTP methods. Just call one of these
methods on your application: ``get``, ``post``, ``put``, ``delete``. You methods on your application: ``get``, ``post``, ``put``, ``delete``. You
can also call ``match``, which will match all methods. can also call ``match``, which will match all methods::
::
$app->match('/blog', function () { $app->match('/blog', function () {
... ...
...@@ -223,9 +217,7 @@ As has been show before you can define variable parts in a route like this:: ...@@ -223,9 +217,7 @@ As has been show before you can define variable parts in a route like this::
}); });
It is also possible to have more than one variable part, just make sure the It is also possible to have more than one variable part, just make sure the
closure arguments match the names of the variable parts. closure arguments match the names of the variable parts::
::
$app->get('/blog/show/{postId}/{commentId}', function ($postId, $commentId) { $app->get('/blog/show/{postId}/{commentId}', function ($postId, $commentId) {
... ...
...@@ -314,9 +306,7 @@ Default values ...@@ -314,9 +306,7 @@ Default values
~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~
You can define a default value for any route variable by calling ``value`` on You can define a default value for any route variable by calling ``value`` on
the ``Controller`` object. the ``Controller`` object::
::
$app->get('/{pageName}', function ($pageName) { $app->get('/{pageName}', function ($pageName) {
... ...
...@@ -332,9 +322,7 @@ Named routes ...@@ -332,9 +322,7 @@ Named routes
Certain extensions (such as ``UrlGenerator``) can make use of named routes. Certain extensions (such as ``UrlGenerator``) can make use of named routes.
By default Silex will generate a route name for you, that cannot really be By default Silex will generate a route name for you, that cannot really be
used. You can give a route a name by calling ``bind`` on the ``Controller`` used. You can give a route a name by calling ``bind`` on the ``Controller``
object that is returned by the routing methods. object that is returned by the routing methods::
::
$app->get('/', function () { $app->get('/', function () {
... ...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment