Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Symfony

1,056 views

Published on

PHP framework overview

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Symfony

  1. 1. SYMFONY 2 FRAMEWORK INTRODUCTION Artjom Kurapov 5th April of 2013
  2. 2. Major PHP frameworks  Zend  Symfony 1  2  Code igniter  Kohana  CakePHP  Yii 2
  3. 3. Motivation  Singleton  Tight coupling  Untestable  Premature optimized  Indescriptive names  Duplication  Single responsibility  Open for extension, Closed for modification  LSP http://phpmaster.com/liskov-substitution-principle/  Interface segregation  Dependency inversion
  4. 4. Functional vs fast http://docs.phalconphp.com/en/latest/reference/benchmark/hello-world.html
  5. 5. Used with  Similar to Zend - a collection of components, which can be a full-stack framework  Drupal 8 is using only some of the components  eZ Publish 5 is using a full-stack  PHPUnit, Propel, Doctrine - use Yaml, Console  composer = package & dependency manager  PSR-0..3 standards affect autoloading
  6. 6. COMPONENTS As seen on the web
  7. 7. Components & Drupal 8
  8. 8. HttpFoundation Request
  9. 9. HttpFoundation Response
  10. 10. HttpFoundation Session
  11. 11. HttpKernel
  12. 12. Custom HttpKernel
  13. 13. FULL STACK
  14. 14. Setup  Download or install with composer: composer create-project symfony/framework-standard-edition symfony/ 2.2.0  Check for directory permissions & requirements php ./app/check.php  Open it in browser, get a 20mb wow effect http://localhost/symfony/web/app_dev.php/
  15. 15. Still, awesome profiler
  16. 16. Stylish error reports
  17. 17. Directory structure (Confusingasalways) appenvironmentconfiguration cache config logs bin src ourapplicationcode Exove CalendarBundle Controller Resourcesviews,css,imagesgohere vendor externallibraries,usuallyincompany/projectstructure symfony doctrine twig web publicwillseeonlythispart
  18. 18. IDE support
  19. 19. High-level request flow
  20. 20. Low-level request flow  Frontend bootstrap (web/app_dev.php) adds autoloader, boots kernel, creates Request  Kernel loads config, resolves URLto controller  Controller loads model & view, can make a subrequest and returns a Response  Views usually use twig  Models usually use doctrine
  21. 21. Routing with YAML  app/config/routing.yaml
  22. 22. Routing with PHP
  23. 23. Routing with annotations
  24. 24. Routing - URL generation AlsoaccessibleinviewsifyouuseTwig:
  25. 25. Controller You don’t have toinherit base Controller
  26. 26. VIEW
  27. 27. Controller + direct View
  28. 28. Controller + View @Template uses Controller name to figure out template path.. src/Exove/DemoBundle/Resources/views/Demo/hello.html.twig
  29. 29. Twig - variables
  30. 30. Twig - inheritance
  31. 31. Assetic - resource links Might not be a good idea if you use custom less / require.js
  32. 32. DATABASE
  33. 33. Doctrine  ORM - different headache (due to abstraction)  multiple db engine support  Mostly, no direct SQLs, instead - chaining  Alternative - DoctrineQL  Migration support  app/config/parameters.yml
  34. 34. Doctrine chained select
  35. 35. Entity An abstract object that gets extended with saving, retrieving, searching interfaces… It should not know how it is used or stored
  36. 36. Annotation type mapping
  37. 37. Getter/Setter generation
  38. 38. Schema generation
  39. 39. Controller + Model
  40. 40. DoctrineMigrationsBundle
  41. 41. Testing  Config@app/config/config_test.yml  Filesinsrc/*/*/Bundle/Tests  abstractclassWebTestCaseextendsPHPUnit_Framework_TestCase
  42. 42. Conclusion  Heavy and extensive  Twig / Doctrine  Functional with growing community

×