13. DI Container
# in config_dev.yml
imports:
- config.yml
parameters:
mailer.transport.class: Zend_Mail_Transport_Null
14. DI Container
use SymfonyComponentsDependencyInjection as DI;
use SymfonyComponentsDependencyInjectionLoader;
$container = new DIContainer();
$loader = new LoaderYamlFileLoader($container);
$loader->load(‘config_dev.yml’);
$mailer = $container->mailer;
15. Event Dispatcher
• Implements the observer design pattern
• Similar to events in JavaScript
16. Event Dispatcher
use SymfonyComponentsEventDispatcherEvent;
class Article
{
protected $dispatcher;
public function __construct($dispatcher)
{
$this->dispatcher = $dispatcher;
}
public function save()
{
// ...
$event = new Event($this, ‘article.save’);
$this->dispatcher->notify($event);
}
}
17. Event Dispatcher
class Thumbnailer
{
public function connect($dispatcher)
{
$dispatcher->connect(‘article.save’, array(
$this,
‘generateArticleThumbnails’
));
}
public function generateArticleThumbnails($event)
{
// ...
}
}
18. The Symfony 2 sandbox
• curl -L http://bit.ly/sf2sbox > sandbox.tgz
• tar xzf sandbox.tgz
• cd sandbox
• chmod a+w hello/cache/ hello/logs
• chmod a+x hello/console