From 05cd9f5ba45e37ac6fc5c24b569ae01b4e4bfba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brikou=20Carr=C3=A9?= Date: Fri, 6 Jul 2012 16:58:14 +0200 Subject: [PATCH] fixed php code against 2.0 branch --- book/controller.rst | 6 +++--- book/doctrine.rst | 8 ++++---- book/forms.rst | 1 - book/from_flat_php_to_symfony2.rst | 2 +- book/page_creation.rst | 8 ++++---- book/routing.rst | 4 ++-- book/testing.rst | 2 +- cookbook/bundles/inheritance.rst | 4 ++-- .../doctrine/event_listeners_subscribers.rst | 6 +++--- cookbook/form/create_custom_field_type.rst | 6 +++--- cookbook/form/data_transformers.rst | 1 - cookbook/form/dynamic_form_generation.rst | 12 ++++++------ cookbook/form/form_collections.rst | 18 +++++++++--------- cookbook/form/use_virtuals_forms.rst | 2 +- .../custom_authentication_provider.rst | 8 ++++---- cookbook/security/custom_provider.rst | 4 ++-- cookbook/security/entity_provider.rst | 5 ----- cookbook/service_container/event_listener.rst | 4 ++-- cookbook/templating/twig_extension.rst | 6 ++---- cookbook/testing/doctrine.rst | 1 - 20 files changed, 49 insertions(+), 59 deletions(-) diff --git a/book/controller.rst b/book/controller.rst index ba82c671f09..d2f8e893f43 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -94,8 +94,8 @@ a controller object. Controllers are also called *actions*. :linenos: // src/Acme/HelloBundle/Controller/HelloController.php - namespace Acme\HelloBundle\Controller; + use Symfony\Component\HttpFoundation\Response; class HelloController @@ -208,8 +208,8 @@ passed to that method: getEntityManager() @@ -1067,7 +1067,7 @@ following method to the ``ProductRepository`` class:: JOIN p.category c WHERE p.id = :id' )->setParameter('id', $id); - + try { return $query->getSingleResult(); } catch (\Doctrine\ORM\NoResultException $e) { diff --git a/book/forms.rst b/book/forms.rst index 5d669574dad..338aa3216e7 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -754,7 +754,6 @@ that will house the logic for building the task form: .. code-block:: php // src/Acme/TaskBundle/Form/Type/TaskType.php - namespace Acme\TaskBundle\Form\Type; use Symfony\Component\Form\AbstractType; diff --git a/book/from_flat_php_to_symfony2.rst b/book/from_flat_php_to_symfony2.rst index 289f4aacd63..a020fe9eb1b 100644 --- a/book/from_flat_php_to_symfony2.rst +++ b/book/from_flat_php_to_symfony2.rst @@ -543,8 +543,8 @@ them for you. Here's the same sample application, now built in Symfony2: getEntity(); $entityManager = $args->getEntityManager(); - + // perhaps you only want to act on some "Product" entity if ($entity instanceof Product) { // do something with the Product diff --git a/cookbook/form/create_custom_field_type.rst b/cookbook/form/create_custom_field_type.rst index 9ff61aa3eed..ca0fd20a4d2 100644 --- a/cookbook/form/create_custom_field_type.rst +++ b/cookbook/form/create_custom_field_type.rst @@ -20,7 +20,7 @@ will be called `GenderType` and the file will be stored in the default location for form fields, which is ``\Form\Type``. Make sure the field extends :class:`Symfony\\Component\\Form\\AbstractType`:: - # src/Acme/DemoBundle/Form/Type/GenderType.php + // src/Acme/DemoBundle/Form/Type/GenderType.php namespace Acme\DemoBundle\Form\Type; use Symfony\Component\Form\AbstractType; @@ -153,7 +153,7 @@ new instance of the type in one of your forms:: use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; - + class AuthorType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) @@ -231,7 +231,7 @@ returned by the ``getName`` method defined earlier. We'll see the importance of this in a moment when we use the custom field type. But first, add a ``__construct`` argument to ``GenderType``, which receives the gender configuration:: - # src/Acme/DemoBundle/Form/Type/GenderType.php + // src/Acme/DemoBundle/Form/Type/GenderType.php namespace Acme\DemoBundle\Form\Type; // ... diff --git a/cookbook/form/data_transformers.rst b/cookbook/form/data_transformers.rst index c5a13de1c2c..68d40389f02 100644 --- a/cookbook/form/data_transformers.rst +++ b/cookbook/form/data_transformers.rst @@ -193,7 +193,6 @@ manager can be automatically injected: You can now add the type to your form by its alias as follows:: // src/Acme/TaskBundle/Form/Type/TaskType.php - namespace Acme\TaskBundle\Form\Type; use Symfony\Component\Form\AbstractType; diff --git a/cookbook/form/dynamic_form_generation.rst b/cookbook/form/dynamic_form_generation.rst index c9d781a13da..429ec72facc 100644 --- a/cookbook/form/dynamic_form_generation.rst +++ b/cookbook/form/dynamic_form_generation.rst @@ -99,12 +99,12 @@ might look like the following:: class AddNameFieldSubscriber implements EventSubscriberInterface { private $factory; - + public function __construct(FormFactoryInterface $factory) { $this->factory = $factory; } - + public static function getSubscribedEvents() { // Tells the dispatcher that we want to listen on the form.pre_set_data @@ -116,11 +116,11 @@ might look like the following:: { $data = $event->getData(); $form = $event->getForm(); - - // During form creation setData() is called with null as an argument - // by the FormBuilder constructor. We're only concerned with when + + // During form creation setData() is called with null as an argument + // by the FormBuilder constructor. We're only concerned with when // setData is called with an actual Entity object in it (whether new, - // or fetched with Doctrine). This if statement let's us skip right + // or fetched with Doctrine). This if statement let's us skip right // over the null condition. if (null === $data) { return; diff --git a/cookbook/form/form_collections.rst b/cookbook/form/form_collections.rst index 4cbe247170e..79dc743bc49 100755 --- a/cookbook/form/form_collections.rst +++ b/cookbook/form/form_collections.rst @@ -24,7 +24,7 @@ objects. Start by creating a simple ``Task`` class:: // src/Acme/TaskBundle/Entity/Task.php namespace Acme\TaskBundle\Entity; - + use Doctrine\Common\Collections\ArrayCollection; class Task @@ -37,7 +37,7 @@ objects. Start by creating a simple ``Task`` class:: { $this->tags = new ArrayCollection(); } - + public function getDescription() { return $this->description; @@ -149,13 +149,13 @@ In your controller, you'll now initialize a new instance of ``TaskType``:: // src/Acme/TaskBundle/Controller/TaskController.php namespace Acme\TaskBundle\Controller; - + use Acme\TaskBundle\Entity\Task; use Acme\TaskBundle\Entity\Tag; use Acme\TaskBundle\Form\Type\TaskType; use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\Controller; - + class TaskController extends Controller { public function newAction(Request $request) @@ -171,9 +171,9 @@ In your controller, you'll now initialize a new instance of ``TaskType``:: $tag2->name = 'tag2'; $task->getTags()->add($tag2); // end dummy code - + $form = $this->createForm(new TaskType(), $task); - + // process the form on POST if ('POST' === $request->getMethod()) { $form->bindRequest($request); @@ -181,7 +181,7 @@ In your controller, you'll now initialize a new instance of ``TaskType``:: // maybe do some form processing, like saving the Task and Tag objects } } - + return $this->render('AcmeTaskBundle:Task:new.html.twig', array( 'form' => $form->createView(), )); @@ -280,7 +280,7 @@ add the ``allow_add`` option to our collection field:: // src/Acme/TaskBundle/Form/Type/TaskType.php // ... - + public function buildForm(FormBuilder $builder, array $options) { $builder->add('description'); @@ -491,7 +491,7 @@ Start by adding the ``allow_delete`` option in the form Type:: // src/Acme/TaskBundle/Form/Type/TaskType.php // ... - + public function buildForm(FormBuilder $builder, array $options) { $builder->add('description'); diff --git a/cookbook/form/use_virtuals_forms.rst b/cookbook/form/use_virtuals_forms.rst index 588da319117..3c57ecfc2fa 100644 --- a/cookbook/form/use_virtuals_forms.rst +++ b/cookbook/form/use_virtuals_forms.rst @@ -25,7 +25,7 @@ For example, imagine you have two entities, a ``Company`` and a ``Customer``:: .. code-block:: php - // src/Acme/HelloBundle/Entity/Company.php + // src/Acme/HelloBundle/Entity/Customer.php namespace Acme\HelloBundle\Entity; class Customer diff --git a/cookbook/security/custom_authentication_provider.rst b/cookbook/security/custom_authentication_provider.rst index f0d27e0fcf7..5712d4177df 100644 --- a/cookbook/security/custom_authentication_provider.rst +++ b/cookbook/security/custom_authentication_provider.rst @@ -61,11 +61,11 @@ provider. public $created; public $digest; public $nonce; - + public function __construct(array $roles = array()) { parent::__construct($roles); - + // If the user has roles, consider it authenticated $this->setAuthenticated(count($roles) > 0); } @@ -141,7 +141,7 @@ set an authenticated token in the security context if successful. if ($returnValue instanceof TokenInterface) { return $this->securityContext->setToken($returnValue); - } else if ($returnValue instanceof Response) { + } elseif ($returnValue instanceof Response) { return $event->setResponse($returnValue); } } catch (AuthenticationException $e) { @@ -208,7 +208,7 @@ the ``PasswordDigest`` header value matches with the user's password. { $user = $this->userProvider->loadUserByUsername($token->getUsername()); - if ($user && $this->validateDigest($token->digest, $token->nonce, $token->created, $user->getPassword())) { + if ($user && $this->validateDigest($token->digest, $token->nonce, $token->created, $user->getPassword())) { $authenticatedToken = new WsseUserToken($user->getRoles()); $authenticatedToken->setUser($user); diff --git a/cookbook/security/custom_provider.rst b/cookbook/security/custom_provider.rst index 3f9753d939f..68e859ae8c8 100644 --- a/cookbook/security/custom_provider.rst +++ b/cookbook/security/custom_provider.rst @@ -27,7 +27,7 @@ class: ``getRoles()``, ``getPassword()``, ``getSalt()``, ``getUsername()``, Let's see this in action:: - // src/Acme/WebserviceUserBundle/Security/User.php + // src/Acme/WebserviceUserBundle/Security/User/WebserviceUser.php namespace Acme\WebserviceUserBundle\Security\User; use Symfony\Component\Security\Core\User\UserInterface; @@ -65,7 +65,7 @@ Let's see this in action:: public function getUsername() { return $this->username; - } + } public function eraseCredentials() { diff --git a/cookbook/security/entity_provider.rst b/cookbook/security/entity_provider.rst index 72eb027646d..a0fa64c8ac7 100644 --- a/cookbook/security/entity_provider.rst +++ b/cookbook/security/entity_provider.rst @@ -43,7 +43,6 @@ focus on the most important methods that come from the .. code-block:: php // src/Acme/UserBundle/Entity/User.php - namespace Acme\UserBundle\Entity; use Doctrine\ORM\Mapping as ORM; @@ -267,7 +266,6 @@ For this example, the first three methods will return ``true`` whereas the .. code-block:: php // src/Acme/UserBundle/Entity/User.php - namespace Acme\Bundle\UserBundle\Entity; // ... @@ -325,7 +323,6 @@ The code below shows the implementation of the ``UserRepository`` class:: // src/Acme/UserBundle/Entity/UserRepository.php - namespace Acme\UserBundle\Entity; use Symfony\Component\Security\Core\User\UserInterface; @@ -421,7 +418,6 @@ more users. As a group is also a role, the previous ``getRoles()`` method now returns the list of related groups:: // src/Acme/UserBundle/Entity/User.php - namespace Acme\Bundle\UserBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; @@ -511,7 +507,6 @@ relationship in the ``UserRepository::loadUserByUsername()`` method. This will fetch the user and his associated roles / groups with a single query:: // src/Acme/UserBundle/Entity/UserRepository.php - namespace Acme\Bundle\UserBundle\Entity; // ... diff --git a/cookbook/service_container/event_listener.rst b/cookbook/service_container/event_listener.rst index 9f3463738c6..4484f7ce8c9 100644 --- a/cookbook/service_container/event_listener.rst +++ b/cookbook/service_container/event_listener.rst @@ -27,12 +27,12 @@ event is just one of the core kernel events:: // We get the exception object from the received event $exception = $event->getException(); $message = 'My Error says: ' . $exception->getMessage(); - + // Customize our response object to display our exception details $response = new Response(); $response->setContent($message); $response->setStatusCode($exception->getStatusCode()); - + // Send our modified response object to the event $event->setResponse($response); } diff --git a/cookbook/templating/twig_extension.rst b/cookbook/templating/twig_extension.rst index 5addd8f8f6e..3175d828e0c 100644 --- a/cookbook/templating/twig_extension.rst +++ b/cookbook/templating/twig_extension.rst @@ -24,12 +24,10 @@ To get your custom functionality you must first create a Twig Extension class. As an example we will create a price filter to format a given number into price:: // src/Acme/DemoBundle/Twig/AcmeExtension.php - namespace Acme\DemoBundle\Twig; use Twig_Extension; use Twig_Filter_Method; - use Twig_Function_Method; class AcmeExtension extends Twig_Extension { @@ -39,7 +37,7 @@ As an example we will create a price filter to format a given number into price: 'price' => new Twig_Filter_Method($this, 'priceFilter'), ); } - + public function priceFilter($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',') { $price = number_format($number, $decimals, $decPoint, $thousandsSep); @@ -53,7 +51,7 @@ As an example we will create a price filter to format a given number into price: return 'acme_extension'; } } - + .. tip:: Along with custom filters, you can also add custom `functions` and register `global variables`. diff --git a/cookbook/testing/doctrine.rst b/cookbook/testing/doctrine.rst index b8ea7f59d4b..a321e821199 100644 --- a/cookbook/testing/doctrine.rst +++ b/cookbook/testing/doctrine.rst @@ -21,7 +21,6 @@ to get a valid connection. In this case, you'll extend the ``WebTestCase``, which makes all of this quite easy:: // src/Acme/StoreBundle/Tests/Entity/ProductRepositoryFunctionalTest.php - namespace Acme\StoreBundle\Tests\Entity; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;