diff --git a/book/controller.rst b/book/controller.rst
index 273799255b4..bd23094c9cb 100644
--- a/book/controller.rst
+++ b/book/controller.rst
@@ -472,10 +472,13 @@ value to each variable.
object::
$httpKernel = $this->container->get('http_kernel');
- $response = $httpKernel->forward('AcmeHelloBundle:Hello:fancy', array(
- 'name' => $name,
- 'color' => 'green',
- ));
+ $response = $httpKernel->forward(
+ 'AcmeHelloBundle:Hello:fancy',
+ array(
+ 'name' => $name,
+ 'color' => 'green',
+ )
+ );
.. index::
single: Controller; Rendering templates
@@ -490,14 +493,20 @@ that's responsible for generating the HTML (or other format) for the controller.
The ``renderView()`` method renders a template and returns its content. The
content from the template can be used to create a ``Response`` object::
- $content = $this->renderView('AcmeHelloBundle:Hello:index.html.twig', array('name' => $name));
+ $content = $this->renderView(
+ 'AcmeHelloBundle:Hello:index.html.twig',
+ array('name' => $name)
+ );
return new Response($content);
This can even be done in just one step with the ``render()`` method, which
returns a ``Response`` object containing the content from the template::
- return $this->render('AcmeHelloBundle:Hello:index.html.twig', array('name' => $name));
+ return $this->render(
+ 'AcmeHelloBundle:Hello:index.html.twig',
+ array('name' => $name)
+ );
In both cases, the ``Resources/views/Hello/index.html.twig`` template inside
the ``AcmeHelloBundle`` will be rendered.
@@ -517,7 +526,10 @@ The Symfony templating engine is explained in great detail in the
service. The ``templating`` service can also be used directly::
$templating = $this->get('templating');
- $content = $templating->render('AcmeHelloBundle:Hello:index.html.twig', array('name' => $name));
+ $content = $templating->render(
+ 'AcmeHelloBundle:Hello:index.html.twig',
+ array('name' => $name)
+ );
.. note::
@@ -525,7 +537,10 @@ The Symfony templating engine is explained in great detail in the
be careful to avoid the pitfall of making your directory structure unduly
elaborate::
- $templating->render('AcmeHelloBundle:Hello/Greetings:index.html.twig', array('name' => $name));
+ $templating->render(
+ 'AcmeHelloBundle:Hello/Greetings:index.html.twig',
+ array('name' => $name)
+ );
// index.html.twig found in Resources/views/Hello/Greetings is rendered.
.. index::
@@ -642,7 +657,10 @@ For example, imagine you're processing a form submit::
if ($form->isValid()) {
// do some sort of processing
- $this->get('session')->setFlash('notice', 'Your changes were saved!');
+ $this->get('session')->setFlash(
+ 'notice',
+ 'Your changes were saved!'
+ );
return $this->redirect($this->generateUrl(...));
}
diff --git a/book/doctrine.rst b/book/doctrine.rst
index 8dde967b0ca..60b32770259 100644
--- a/book/doctrine.rst
+++ b/book/doctrine.rst
@@ -470,7 +470,9 @@ on its ``id`` value::
->find($id);
if (!$product) {
- throw $this->createNotFoundException('No product found for id '.$id);
+ throw $this->createNotFoundException(
+ 'No product found for id '.$id
+ );
}
// ... do something, like pass the $product object into a template
@@ -555,7 +557,9 @@ you have a route that maps a product id to an update action in a controller::
$product = $em->getRepository('AcmeStoreBundle:Product')->find($id);
if (!$product) {
- throw $this->createNotFoundException('No product found for id '.$id);
+ throw $this->createNotFoundException(
+ 'No product found for id '.$id
+ );
}
$product->setName('New product name!');
@@ -1306,7 +1310,8 @@ and ``nullable``. Take a few examples:
/**
* A string field with length 255 that cannot be null
- * (reflecting the default values for the "type", "length" and *nullable* options)
+ * (reflecting the default values for the "type", "length"
+ * and *nullable* options)
*
* @ORM\Column()
*/
diff --git a/book/forms.rst b/book/forms.rst
index 471ac5e551c..2038047b0db 100644
--- a/book/forms.rst
+++ b/book/forms.rst
@@ -1477,7 +1477,9 @@ method to specify the option::
{
$collectionConstraint = new Collection(array(
'name' => new MinLength(5),
- 'email' => new Email(array('message' => 'Invalid email address')),
+ 'email' => new Email(
+ array('message' => 'Invalid email address')
+ ),
));
return array('validation_constraint' => $collectionConstraint);
diff --git a/book/from_flat_php_to_symfony2.rst b/book/from_flat_php_to_symfony2.rst
index f9ad97ee141..1894a9483a1 100644
--- a/book/from_flat_php_to_symfony2.rst
+++ b/book/from_flat_php_to_symfony2.rst
@@ -554,7 +554,10 @@ them for you. Here's the same sample application, now built in Symfony2::
->createQuery('SELECT p FROM AcmeBlogBundle:Post p')
->execute();
- return $this->render('AcmeBlogBundle:Blog:list.html.php', array('posts' => $posts));
+ return $this->render(
+ 'AcmeBlogBundle:Blog:list.html.php',
+ array('posts' => $posts)
+ );
}
public function showAction($id)
@@ -570,7 +573,10 @@ them for you. Here's the same sample application, now built in Symfony2::
throw $this->createNotFoundException();
}
- return $this->render('AcmeBlogBundle:Blog:show.html.php', array('post' => $post));
+ return $this->render(
+ 'AcmeBlogBundle:Blog:show.html.php',
+ array('post' => $post)
+ );
}
}
@@ -590,7 +596,10 @@ now quite a bit simpler:
-
-
+
getTitle() ?>
@@ -605,7 +614,10 @@ The layout is nearly identical:
- output('title', 'Default title') ?>
+ output(
+ 'title',
+ 'Default title'
+ ) ?>
output('_content') ?>
diff --git a/book/page_creation.rst b/book/page_creation.rst
index 1a6c303e222..71788d1dbd7 100644
--- a/book/page_creation.rst
+++ b/book/page_creation.rst
@@ -290,10 +290,16 @@ of writing the HTML inside the controller, render a template instead:
{
public function indexAction($name)
{
- return $this->render('AcmeHelloBundle:Hello:index.html.twig', array('name' => $name));
+ return $this->render(
+ 'AcmeHelloBundle:Hello:index.html.twig',
+ array('name' => $name)
+ );
// render a PHP template instead
- // return $this->render('AcmeHelloBundle:Hello:index.html.php', array('name' => $name));
+ // return $this->render(
+ // 'AcmeHelloBundle:Hello:index.html.php',
+ // array('name' => $name)
+ // );
}
}
@@ -902,7 +908,9 @@ file of your choice::
// app/AppKernel.php
public function registerContainerConfiguration(LoaderInterface $loader)
{
- $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
+ $loader->load(
+ __DIR__.'/config/config_'.$this->getEnvironment().'.yml'
+ );
}
You already know that the ``.yml`` extension can be changed to ``.xml`` or
diff --git a/book/propel.rst b/book/propel.rst
index 3b6c645bca5..ad3e74cba7b 100644
--- a/book/propel.rst
+++ b/book/propel.rst
@@ -18,8 +18,8 @@ persist it to the database and fetch it back out.
.. sidebar:: Code along with the example
If you want to follow along with the example in this chapter, create an
- ``AcmeStoreBundle`` via:
-
+ ``AcmeStoreBundle`` via:
+
.. code-block:: bash
$ php app/console generate:bundle --namespace=Acme/StoreBundle
@@ -171,19 +171,21 @@ Fetching Objects from the Database
Fetching an object back from the database is even easier. For example, suppose
you've configured a route to display a specific ``Product`` based on its ``id``
value::
-
+
// ...
use Acme\StoreBundle\Model\ProductQuery;
-
+
public function showAction($id)
{
$product = ProductQuery::create()
->findPk($id);
-
+
if (!$product) {
- throw $this->createNotFoundException('No product found for id '.$id);
+ throw $this->createNotFoundException(
+ 'No product found for id '.$id
+ );
}
-
+
// ... do something, like pass the $product object into a template
}
@@ -192,22 +194,24 @@ Updating an Object
Once you've fetched an object from Propel, updating it is easy. Suppose you
have a route that maps a product id to an update action in a controller::
-
+
// ...
use Acme\StoreBundle\Model\ProductQuery;
-
+
public function updateAction($id)
{
$product = ProductQuery::create()
->findPk($id);
-
+
if (!$product) {
- throw $this->createNotFoundException('No product found for id '.$id);
+ throw $this->createNotFoundException(
+ 'No product found for id '.$id
+ );
}
-
+
$product->setName('New product name!');
$product->save();
-
+
return $this->redirect($this->generateUrl('homepage'));
}
@@ -227,12 +231,12 @@ method on the object::
Querying for Objects
--------------------
-
+
Propel provides generated ``Query`` classes to run both basic and complex queries
without any work::
-
+
\Acme\StoreBundle\Model\ProductQuery::create()->findPk($id);
-
+
\Acme\StoreBundle\Model\ProductQuery::create()
->filterByName('Foo')
->findOne();
@@ -287,13 +291,13 @@ Start by adding the ``category`` definition in your ``schema.xml``:
-
+
-
+
@@ -326,23 +330,23 @@ Now, let's see the code in action. Imagine you're inside a controller::
use Acme\StoreBundle\Model\Category;
use Acme\StoreBundle\Model\Product;
use Symfony\Component\HttpFoundation\Response;
-
+
class DefaultController extends Controller
{
public function createProductAction()
{
$category = new Category();
$category->setName('Main Products');
-
+
$product = new Product();
$product->setName('Foo');
$product->setPrice(19.99);
// relate this product to the category
$product->setCategory($category);
-
+
// save the whole
$product->save();
-
+
return new Response(
'Created product id: '.$product->getId().' and category id: '.$category->getId()
);
@@ -363,15 +367,15 @@ before. First, fetch a ``$product`` object and then access its related
// ...
use Acme\StoreBundle\Model\ProductQuery;
-
+
public function showAction($id)
{
$product = ProductQuery::create()
->joinWithCategory()
->findPk($id);
-
+
$categoryName = $product->getCategory()->getName();
-
+
// ...
}
@@ -395,7 +399,7 @@ inserted, updated, deleted, etc).
To add a hook, just add a new method to the object class::
// src/Acme/StoreBundle/Model/Product.php
-
+
// ...
class Product extends BaseProduct
{
diff --git a/book/routing.rst b/book/routing.rst
index 8829b2f7ff1..7c5d0428795 100644
--- a/book/routing.rst
+++ b/book/routing.rst
@@ -417,7 +417,7 @@ match, giving the ``page`` parameter a value of ``2``. Perfect.
.. tip::
- Routes with optional parameters at the end will not match on requests
+ Routes with optional parameters at the end will not match on requests
with a trailing slash (i.e. ``/blog/`` will not match, ``/blog`` will match).
.. index::
@@ -1068,7 +1068,10 @@ a route+parameters back to a URL. The
system. Take the ``blog_show`` example route from earlier::
$params = $router->match('/blog/my-blog-post');
- // array('slug' => 'my-blog-post', '_controller' => 'AcmeBlogBundle:Blog:show')
+ // array(
+ // 'slug' => 'my-blog-post',
+ // '_controller' => 'AcmeBlogBundle:Blog:show',
+ // )
$uri = $router->generate('blog_show', array('slug' => 'my-blog-post'));
// /blog/my-blog-post
@@ -1081,9 +1084,12 @@ that route. With this information, any URL can easily be generated::
{
public function showAction($slug)
{
- // ...
+ // ...
- $url = $this->get('router')->generate('blog_show', array('slug' => 'my-blog-post'));
+ $url = $this->get('router')->generate(
+ 'blog_show',
+ array('slug' => 'my-blog-post')
+ );
}
}
@@ -1097,7 +1103,10 @@ In an upcoming section, you'll learn how to generate URLs from inside templates.
.. code-block:: javascript
- var url = Routing.generate('blog_show', { "slug": 'my-blog-post'});
+ var url = Routing.generate(
+ 'blog_show',
+ {"slug": 'my-blog-post'}
+ );
For more information, see the documentation for that bundle.
diff --git a/book/security.rst b/book/security.rst
index b56d17216ee..61d7ad295c4 100644
--- a/book/security.rst
+++ b/book/security.rst
@@ -423,18 +423,25 @@ Next, create the controller that will display the login form::
$session = $request->getSession();
// get the login error if there is one
- if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
- $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
+ if (
+ $request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)
+ ) {
+ $error = $request->attributes->get(
+ SecurityContext::AUTHENTICATION_ERROR
+ );
} else {
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
}
- return $this->render('AcmeSecurityBundle:Security:login.html.twig', array(
- // last username entered by the user
- 'last_username' => $session->get(SecurityContext::LAST_USERNAME),
- 'error' => $error,
- ));
+ return $this->render(
+ 'AcmeSecurityBundle:Security:login.html.twig',
+ array(
+ // last username entered by the user
+ 'last_username' => $session->get(SecurityContext::LAST_USERNAME),
+ 'error' => $error,
+ )
+ );
}
}
diff --git a/book/service_container.rst b/book/service_container.rst
index 0d59e1c37fa..4e4c9f7d365 100644
--- a/book/service_container.rst
+++ b/book/service_container.rst
@@ -567,10 +567,14 @@ something like this::
Without using the service container, you can create a new ``NewsletterManager``
fairly easily from inside a controller::
+ use Acme\HelloBundle\Newsletter\NewsletterManager;
+
+ // ...
+
public function sendNewsletterAction()
{
$mailer = $this->get('my_mailer');
- $newsletter = new Acme\HelloBundle\Newsletter\NewsletterManager($mailer);
+ $newsletter = new NewsletterManager($mailer);
// ...
}
@@ -620,7 +624,10 @@ the service container gives you a much more appealing option:
use Symfony\Component\DependencyInjection\Reference;
// ...
- $container->setParameter('newsletter_manager.class', 'Acme\HelloBundle\Newsletter\NewsletterManager');
+ $container->setParameter(
+ 'newsletter_manager.class',
+ 'Acme\HelloBundle\Newsletter\NewsletterManager'
+ );
$container->setDefinition('my_mailer', ...);
$container->setDefinition('newsletter_manager', new Definition(
@@ -710,7 +717,10 @@ Injecting the dependency by the setter method just needs a change of syntax:
use Symfony\Component\DependencyInjection\Reference;
// ...
- $container->setParameter('newsletter_manager.class', 'Acme\HelloBundle\Newsletter\NewsletterManager');
+ $container->setParameter(
+ 'newsletter_manager.class',
+ 'Acme\HelloBundle\Newsletter\NewsletterManager'
+ );
$container->setDefinition('my_mailer', ...);
$container->setDefinition('newsletter_manager', new Definition(
@@ -769,12 +779,18 @@ it exists and do nothing if it doesn't:
use Symfony\Component\DependencyInjection\ContainerInterface;
// ...
- $container->setParameter('newsletter_manager.class', 'Acme\HelloBundle\Newsletter\NewsletterManager');
+ $container->setParameter(
+ 'newsletter_manager.class',
+ 'Acme\HelloBundle\Newsletter\NewsletterManager'
+ );
$container->setDefinition('my_mailer', ...);
$container->setDefinition('newsletter_manager', new Definition(
'%newsletter_manager.class%',
- array(new Reference('my_mailer', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))
+ array(new Reference(
+ 'my_mailer',
+ ContainerInterface::IGNORE_ON_INVALID_REFERENCE
+ ))
));
In YAML, the special ``@?`` syntax tells the service container that the dependency
diff --git a/book/templating.rst b/book/templating.rst
index 7b4b77cefcb..dd1b3a13df3 100644
--- a/book/templating.rst
+++ b/book/templating.rst
@@ -532,7 +532,9 @@ Including this template from any other template is simple:
Recent Articles
{% for article in articles %}
- {% include 'AcmeArticleBundle:Article:articleDetails.html.twig' with {'article': article} %}
+ {% include 'AcmeArticleBundle:Article:articleDetails.html.twig'
+ with {'article': article}
+ %}
{% endfor %}
{% endblock %}
@@ -582,10 +584,14 @@ articles::
{
public function recentArticlesAction($max = 3)
{
- // make a database call or other logic to get the "$max" most recent articles
+ // make a database call or other logic
+ // to get the "$max" most recent articles
$articles = ...;
- return $this->render('AcmeArticleBundle:Article:recentList.html.twig', array('articles' => $articles));
+ return $this->render(
+ 'AcmeArticleBundle:Article:recentList.html.twig',
+ array('articles' => $articles)
+ );
}
}
@@ -761,7 +767,11 @@ correctly:
.. code-block:: html+php
- Home
+ Home
.. index::
single: Templating; Linking to assets
@@ -1008,7 +1018,10 @@ customize the markup specifically for your application. By digging into the
// some logic to retrieve the blogs
$blogs = ...;
- $this->render('AcmeBlogBundle:Blog:index.html.twig', array('blogs' => $blogs));
+ $this->render(
+ 'AcmeBlogBundle:Blog:index.html.twig',
+ array('blogs' => $blogs)
+ );
}
When the ``AcmeBlogBundle:Blog:index.html.twig`` is rendered, Symfony2 actually
diff --git a/book/testing.rst b/book/testing.rst
index a9bd650a7bf..34bc4f461d4 100644
--- a/book/testing.rst
+++ b/book/testing.rst
@@ -144,7 +144,10 @@ for its ``DemoController`` (`DemoControllerTest`_) that reads as follows::
$crawler = $client->request('GET', '/demo/hello/Fabien');
- $this->assertGreaterThan(0, $crawler->filter('html:contains("Hello Fabien")')->count());
+ $this->assertGreaterThan(
+ 0,
+ $crawler->filter('html:contains("Hello Fabien")')->count()
+ );
}
}
@@ -216,7 +219,10 @@ Or, test against the Response content directly if you just want to assert that
the content contains some text, or if the Response is not an XML/HTML
document::
- $this->assertRegExp('/Hello Fabien/', $client->getResponse()->getContent());
+ $this->assertRegExp(
+ '/Hello Fabien/',
+ $client->getResponse()->getContent()
+ );
.. _book-testing-request-method-sidebar:
@@ -259,14 +265,23 @@ document::
To get you started faster, here is a list of the most common and
useful test assertions::
- // Assert that there is at least one h2 tag with the class "subtitle"
- $this->assertGreaterThan(0, $crawler->filter('h2.subtitle')->count());
+ // Assert that there is at least one h2 tag
+ // with the class "subtitle"
+ $this->assertGreaterThan(
+ 0,
+ $crawler->filter('h2.subtitle')->count()
+ );
// Assert that there are exactly 4 h2 tags on the page
$this->assertCount(4, $crawler->filter('h2'));
// Assert that the "Content-Type" header is "application/json"
- $this->assertTrue($client->getResponse()->headers->contains('Content-Type', 'application/json'));
+ $this->assertTrue(
+ $client->getResponse()->headers->contains(
+ 'Content-Type',
+ 'application/json'
+ )
+ );
// Assert that the response content matches a regexp.
$this->assertRegExp('/foo/', $client->getResponse()->getContent());
@@ -276,10 +291,15 @@ document::
// Assert that the response status code is 404
$this->assertTrue($client->getResponse()->isNotFound());
// Assert a specific 200 status code
- $this->assertEquals(200, $client->getResponse()->getStatusCode());
+ $this->assertEquals(
+ 200,
+ $client->getResponse()->getStatusCode()
+ );
// Assert that the response is a redirect to /demo/contact
- $this->assertTrue($client->getResponse()->isRedirect('/demo/contact'));
+ $this->assertTrue(
+ $client->getResponse()->isRedirect('/demo/contact')
+ );
// or simply check that the response is a redirect to any URL
$this->assertTrue($client->getResponse()->isRedirect());
@@ -523,8 +543,10 @@ The Crawler can extract information from the nodes::
// Returns the node value for the first node
$crawler->text();
- // Extracts an array of attributes for all nodes (_text returns the node value)
- // returns an array for each element in crawler, each with the value and href
+ // Extracts an array of attributes for all nodes
+ // (_text returns the node value)
+ // returns an array for each element in crawler,
+ // each with the value and href
$info = $crawler->extract(array('_text', 'href'));
// Executes a lambda for each node and return an array of results
diff --git a/book/translation.rst b/book/translation.rst
index 966a323d91a..84129086dcb 100644
--- a/book/translation.rst
+++ b/book/translation.rst
@@ -14,7 +14,8 @@ the user::
// text will *always* print out in English
echo 'Hello World';
- // text can be translated into the end-user's language or default to English
+ // text can be translated into the end-user's language or
+ // default to English
echo $translator->trans('Hello World');
.. note::
@@ -182,7 +183,10 @@ variable with a "placeholder"::
public function indexAction($name)
{
- $t = $this->get('translator')->trans('Hello %name%', array('%name%' => $name));
+ $t = $this->get('translator')->trans(
+ 'Hello %name%',
+ array('%name%' => $name)
+ );
new Response($t);
}
@@ -584,7 +588,15 @@ Message pluralization is a tough topic as the rules can be quite complex. For
instance, here is the mathematic representation of the Russian pluralization
rules::
- (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2);
+ (($number % 10 == 1) && ($number % 100 != 11))
+ ? 0
+ : ((($number % 10 >= 2)
+ && ($number % 10 <= 4)
+ && (($number % 100 < 10)
+ || ($number % 100 >= 20)))
+ ? 1
+ : 2
+ );
As you can see, in Russian, you can have three different plural forms, each
given an index of 0, 1 or 2. For each form, the plural is different, and
diff --git a/book/validation.rst b/book/validation.rst
index bc0461cc407..fd013cd5f2c 100644
--- a/book/validation.rst
+++ b/book/validation.rst
@@ -8,10 +8,10 @@ Validation is a very common task in web applications. Data entered in forms
needs to be validated. Data also needs to be validated before it is written
into a database or passed to a web service.
-Symfony2 ships with a `Validator`_ component that makes this task easy and
-transparent. This component is based on the
-`JSR303 Bean Validation specification`_. What? A Java specification in PHP?
-You heard right, but it's not as bad as it sounds. Let's look at how it
+Symfony2 ships with a `Validator`_ component that makes this task easy and
+transparent. This component is based on the
+`JSR303 Bean Validation specification`_. What? A Java specification in PHP?
+You heard right, but it's not as bad as it sounds. Let's look at how it
can be used in PHP.
.. index::
@@ -450,7 +450,10 @@ options can be specified in this way.
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
- $metadata->addPropertyConstraint('gender', new Choice(array('male', 'female')));
+ $metadata->addPropertyConstraint(
+ 'gender',
+ new Choice(array('male', 'female'))
+ );
}
}
@@ -803,17 +806,20 @@ it looks like this::
$emailConstraint->message = 'Invalid email address';
// use the validator to validate the value
- $errorList = $this->get('validator')->validateValue($email, $emailConstraint);
+ $errorList = $this->get('validator')->validateValue(
+ $email,
+ $emailConstraint
+ );
if (count($errorList) == 0) {
// this IS a valid email address, do something
} else {
// this is *not* a valid email address
$errorMessage = $errorList[0]->getMessage()
-
+
// ... do something with the error
}
-
+
// ...
}