If you liked what you've learned so far, dive in!
Subscribe to get access to this tutorial plus
video, code and script downloads.
With the base Controller, we can give ourselves shortcuts to develop faster and faster.
Inside RegisterController, my IDE recognizes the setToken method on the security context automatically. Actually, this only works because I’m using an awesome Symfony2 plugin for PHPStorm. The getSecurityContext method doesn’t have any PHPDoc, so any other editor will have no idea what type of object this method returns.
To fix this, and because PHPDoc is a good practice, let’s add some to our new method:
// src/Yoda/EventBundle/Controller/Controller.php
// ...
/**
* @return \Symfony\Component\Security\Core\SecurityContext
*/
public function getSecurityContext()
{
return $this->container->get('security.context');
}
Because of the Symfony2 plugin, the @return tag was filled in automatically. That’s awesome! But if it hadn’t, we could figure out what type of object security.context is by using the container:debug console command:
php app/console container:debug security.context
If you use PHPStorm, install the Symfony Plugin. If not, rely on this console command to help you find out more about a service.
It’s like you read my mind! Now is a prefect time to re-run the test suite to make sure we haven’t broken anything. I know I know, we’re missing tests for some important parts, like event creation, but it’s better than nothing.
But first, update your test database for our latest schema changes:
php app/console doctrine:schema:update --force --env=test
We need this because we configured our project in episode 2 to use an entirely different database for testing.
./bin/phpunit -c app/
"Houston: no signs of life"
Start the conversation!
// composer.json
{
"require": {
"php": ">=5.3.3",
"symfony/symfony": "~2.4", // v2.4.2
"doctrine/orm": "~2.2,>=2.2.3", // v2.4.2
"doctrine/doctrine-bundle": "~1.2", // v1.2.0
"twig/extensions": "~1.0", // v1.0.1
"symfony/assetic-bundle": "~2.3", // v2.3.0
"symfony/swiftmailer-bundle": "~2.3", // v2.3.5
"symfony/monolog-bundle": "~2.4", // v2.5.0
"sensio/distribution-bundle": "~2.3", // v2.3.4
"sensio/framework-extra-bundle": "~3.0", // v3.0.0
"sensio/generator-bundle": "~2.3", // v2.3.4
"incenteev/composer-parameter-handler": "~2.0", // v2.1.0
"doctrine/doctrine-fixtures-bundle": "~2.2.0", // v2.2.0
"ircmaxell/password-compat": "~1.0.3", // 1.0.3
"phpunit/phpunit": "~4.1", // 4.1.0
"stof/doctrine-extensions-bundle": "~1.1.0" // v1.1.0
}
}