170 likes | 324 Views
Rapid Web Development (for libraries!) with Symfony 2. Justin Clark Junior Web Developer Berkman Center. So many questions. What is it? Why use it? How's it designed? What's it do? What else does it do?. What is Symfony 2?. Symfony 2 is a PHP Framework for web development
E N D
Rapid Web Development (for libraries!) with Symfony 2 Justin Clark Junior Web Developer Berkman Center
So many questions • What is it? • Why use it? • How's it designed? • What's it do? • What else does it do?
What is Symfony 2? • Symfony 2 is a PHP Framework for web development • Symfony 2 is MVC • Symfony 2 is OOP • Symfony 2 is probably a bunch more acronyms • Symfony 2 is not Symfony 1 (>=PHP 5.3) • Symfony 2 is HTTP-centric • Symfony 2 is like bits of Rails and like bits of Java http://symfony.com Released July 28, 2011 after ~2.5 years development
Why Symfony 2? PHP was a given Contenders in the area: • Zend is old and huge and scary. • Yii is new and small and one guy. • CakePHP is old and hacky. • CodeIgniter is small and hacky. Symfony 2 is new hotness. Who uses it? Dailymotion, Yahoo! Answers, Drupal, phpBB
"New hotness" is a stupid phrase.Really, why Symfony 2? Non-technical: • Very modular (standard distro is 21 standalone modules) • Very flexible (dependency injection, service container) • Targeted at serious apps (stable API) • Backed by a company (software as service - take it or leave it) • Very little magic • Kinda, sorta portable • MIT License • Good docs for beginners • Really good code commenting • Responsive community (response from core dev in 4 minutes) • External security audit • On Github (most forked and most watched in PHP, 13th and 24th overall)
I want CODE Technical: • Includes good ORM (and ODM, but I haven't used it) • Includes very good templating language (safe and expressive) • Includes good asset manager (auto combining, filtering [closure, pngcrush, etc.]) • Includes very good debugging tools (web debug toolbar, linked exceptions, stack traces) • Includes very good caching (includes reverse-proxy, speaks ESI) • Includes good security tools (basic auth through X.509, ACLs) • Includes very good testing tools (PHPUnit and functional testing) • Includes very good generators (models, views, controllers, forms, tests, bundles) • Includes handy autoloading (namespaces)
Not so awesome things • Learning curve • API Docs are complete but so-so • Few advanced docs • Few advanced best-practices docs • It's still PHP
Architecture Request-Response Model Modularity is big selling point. Three main constructs for modularity: • Bundles • Services • Events
Modularity - Bundles • Apps are composed of "bundles" • Bundles are basically packages • They includes models, views, controllers, and whatever else • Bundles can inherit (child bundles) • Zend libraries can be bundles • Apps can override any part of any bundle • New package manager in the works
Modularity - Services • Bundles can provide services • Services are externally configurable (constructor injection, setter injection, property injection, optional config interface) • Services can require or include other services • Services get registered with the service container • Every controller has access to the service container • It's dependency injection
Modularity - Events • Every controller has access to the event dispatcher • It's a hook system to modify any part of any controller
Handy Bundles • Doctrine2 • Twig • Debugging
Debugging • Pretty web toolbar • Lots of info pages • Pretty exception handling http://dev5.berkmancenter.org/app.php
What I didn't talk about • Console Tasks • Session-handling • Form validation • Model constraints • Routing • User Bundle (and symfony2bundles.org) • YML, XML, Annotation options • Emailing • Environments • Logging • i18n • Git integration • etc.
Takeaways • Good for little things, good for big things • Learning curve fairly shallow for little things, steep for big things • Little things can be done really quickly • Big things take more time • It's PHP - but modern, solid, secure PHP