Symfony 2

4,942 views

Published on

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,942
On SlideShare
0
From Embeds
0
Number of Embeds
30
Actions
Shares
0
Downloads
38
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Symfony 2

  1. 1. Symfony 2 Kris Wallsmith @kriswallsmith April 20, 2010
  2. 2. An evolution of symfony 1.x • Same philosophy: • Full stack • Configurable • Testable • Components • Brand new foundation
  3. 3. Don’t reinvent the wheel • Doctrine • PHPUnit • SwiftMailer • Zend_Cache • Zend_Log
  4. 4. PHP 5.3 • Namespaces • Anonymous functions / closures • Late static binding
  5. 5. Symfony Components • Standalone libraries • Each with a specific scope • components.symfony-project.org
  6. 6. Symfony Components • BrowserKit • Process • Console • RequestHandler • CssSelector • Routing • DependencyInjection • Templating • DomCrawler • Yaml • EventDispatcher • OutputEscaper
  7. 7. Dependency Injection • A method of supplying an external dependency
  8. 8. Dependency Injection class User { protected $session; public function __construct(Session $session) { $this->session = $session; } }
  9. 9. DI Container • A method of organizing dependencies • Adds a configuration layer • Dependency injection does not require a container!
  10. 10. DI Container # in config.yml parameters: mailer.username: foo mailer.password: bar mailer.class: Zend_Mail mailer.transport.class: Zend_Mail_Transport_Smtp services: mail.transport: class: %mailer.transport.class% arguments: - smtp.gmail.com - { auth: login, username: %mailer.username%, password: %mailer.password%, ssl: ssl, port: 465 } shared: false mailer: class: %mailer.class% calls: - [setDefaultTransport, [@mail.transport]]
  11. 11. DI Container # in config_dev.yml imports: - config.yml parameters: mailer.transport.class: Zend_Mail_Transport_Null
  12. 12. DI Container use SymfonyComponentsDependencyInjection as DI; use SymfonyComponentsDependencyInjectionLoader; $container = new DIContainer(); $loader = new LoaderYamlFileLoader($container); $loader->load(‘config_dev.yml’); $mailer = $container->mailer;
  13. 13. Event Dispatcher • Implements the observer design pattern • Similar to events in JavaScript
  14. 14. 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); } }
  15. 15. Event Dispatcher class Thumbnailer { public function connect($dispatcher) { $dispatcher->connect(‘article.save’, array( $this, ‘generateArticleThumbnails’ )); } public function generateArticleThumbnails($event) { // ... } }
  16. 16. 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
  17. 17. The Symfony 2 sandbox
  18. 18. Live Demo
  19. 19. Follow us on GitHub • symfony • fabpot • jwage • kriswallsmith • bschussek • and 70+ other forks…
  20. 20. symfony-reloaded.org

×