Advertisement
Advertisement

More Related Content

Advertisement
Advertisement

How Symfony Changed My Life

  1. Matthias Noback Lelystad, September 1st 2015 10 years! How Symfony changed my life
  2. Pre-symfony
  3. From ASP using VBScript and a MS Access database To PHP with a MySQL database "You should try PHP!"
  4. From include('script.php') To proper function calls
  5. From PHP 4 and one mega Page class To PHP 5 with proper scoping for methods and properties, and autoloading
  6. From PHP & HTML in the same file To PHP classes and Smarty template files
  7. From copying snippets from the Internet To downloading single-purpose libraries
  8. Feeling mighty fine SQL injection Register globals Session hijacking Magic quotes CSRF XSS
  9. Basically...
  10. But... performance was very good ;)
  11. Driebit (2008)
  12. symfony (1) with a lower-case s
  13. Symfony Camp (2007) Stefan Koopmanschap
  14. The Book (back then) François Zaninotto (Propel) symfony 1.1
  15. Working with symfony 1 meant... MVC Fat controllers Fat models (Zend devs wrote fat services as well)
  16. Not in the controller or the model? Put it in: A "peer" class A utility class Or: create a global singleton for it
  17. What's a singleton? Static Global Single instance class Singleton
 {
 private static $instance;
 
 private function __construct()
 {
 }
 
 public static function getInstance()
 {
 if (self::$instance === null) {
 self::$instance = new self();
 }
 
 return self::$instance;
 }
 }
  18. God object sfContext::getInstance() getUser(), getResponse(), getRequest(), getLogger(), getI18N(), ...
  19. Just reach out
  20. Why bad? Testability Isolation Side-effects Configuration No separation of concerns
  21. CTO at SensioLabs DE
  22. Pushing the limits
  23. Tweaking symfony Event listeners: add missing methods on the fly (!) Filters: chain of responsibility factories.yml and other config files
  24. Switch to Doctrine It was... new version 1.0
  25. Develop some Plugins
  26. Learn about advanced topics Emails Forms Doctrine Internals
  27. SymfonyLive Paris 2010 Revealing Symfony2
  28. SymfonyLive Paris 2011 Almost releasing Symfony 2.0 Excitement all over the place
  29. Start using 2.0? No backwards compatibility No best practices No CMS
  30. Not even... ... an admin generator only for scaffolding ;)
  31. Migrating to 2.0? Company owners didn't dare to take the step (I agree with them now!) I left the company :)
  32. Symfony2 capital "S" no space, for Google
  33. Infrastructure 1. Git for version control 2. Install script or Git submodules for vendor code 3. At some point: composer started handling dependencies
  34. Templating Twig: Own syntax No PHP code "Auto-safe" Fast (the engine that is) "Templating engines in PHP" by Fabien Potencier
  35. Dependency injection container Major improvement: everything can be configured No runtime resolvers anymore
  36. What's dependency injection? class Foo
 {
 private $bar;
 
 public function __construct(Bar $bar)
 {
 $this->bar = $bar;
 }
 }
  37. What's a DI container? class Container
 {
 public function createFoo()
 {
 return new Foo($this->getBar());
 }
 
 private function createBar()
 {
 return new Bar();
 }
 }
  38. What does DI give us? Single responsibility Testability Dependency inversion Speed Flexibility
  39. Active record -> data mapper Doctrine 1/Propel Doctrine 2/...
  40. Active record sample class Invoice extends Record
 {
 }
 
 $invoice = new Invoice();
 $invoice->save();
  41. Data mapper sample class Invoice
 {
 }
 
 $invoice = new Invoice();
 $entityManager->persist($invoice); POPO
  42. Why is that better? Isolation Model first Decoupling (not always a good reason)
  43. Bundle ~= Plugin
  44. First-class citizens
  45. A bundle for each feature
  46. Framework coupling Libraries are framework- independent Bundles are explicitly meant to couple code to the framework
  47. Bundles: service definitions Service definition files Bundle extension Bundle configuration Compiler pass
  48. Bundle: root for resources @MyBundle/Resources/views/ template.html.twig
  49. Resources Expose: Templates Translations ...
  50. Assets Assetic Separate tools (non-PHP based)
  51. Security So very hard Documented in many different ways It's really good though Simplified at code level now
  52. Symfony is an early adopter PHP-FIG PSR-0, PSR-1, PSR-2, PSR-3, PSR-7 - very quickly adopted
  53. Extensive documentation High quality Friendly Good- looking Well maintained
  54. "The Book"?
  55. Excellent BC promise @api
  56. A Year With Symfony
  57. Struggling with framework coupling
  58. The fight against CRUD
  59. Hexagonal architecture
  60. phparchitecturetour.com
  61. Conclusion
  62. Symfony - The biggest change Dependency injection (container) Which is an enabler for better code Because: maintainable and testable
  63. My personal development: 1. I love symfony 2. I love Symfony2 3. I want to decouple from it 4. I want to fully embrace it whenever that's okay
  64. For me it's about Knowing your framework Being fast with it Not being totally dependent on it
  65. Long live PolderPHP!
Advertisement