симфони это не страшно

2,612 views
2,507 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,612
On SlideShare
0
From Embeds
0
Number of Embeds
670
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

симфони это не страшно

  1. 1. Symfony is not scary
  2. 2. Is it scary?..
  3. 3. Is it scary?.. No! Let me try it!!!- Interior- Driving- Engine- Assembly- Service- etc
  4. 4. Symfony is not scary → Why I love Symfony2
  5. 5. Just try it!$ curl -s http://getcomposer.org/installer | php$ php composer.phar create-projectsymfony/framework-standard-edition/var/www/symfony/$ cd /var/www/symfony/$ php app/check.php (PHP >= 5.3.2, etc)
  6. 6. Get Symfony using Composer
  7. 7. Composer — dependency managerfor PHP
  8. 8. Composer.json{autoload: {psr-0: {}}name: My Projectdescription: Very cool onerequire: {php: >=5.3.3,symfony/class-loader: 2.2.*,}}
  9. 9. Composer: run your PHP script
  10. 10. Time to look what weve got
  11. 11. Some demo included
  12. 12. Symfony is both:Full-stack frameworkSet of decoupled and standalone components
  13. 13. What are the Symfony components?Symfony components are:– Set of independent components– Each can be used separately– High quality coded, tested and documentedSymfony components are just bricks but yourecompletely responsible to glue them
  14. 14. The list of Symfony2 componentsClass loaderConfigConsoleCssSelectorDependency InjectionFormEvent DispatcherHttp FoundationHttp KernelRoutingSecurityYaml
  15. 15. What is bundleBundle — set of files which implement singlefeatureGenerate bundle skeleton$ php app/console generate:bundle--namespace=BundleFolder/NameBundle--format=annotation
  16. 16. What is bundleTemplates go thereDatabase mappersRequest → Response
  17. 17. Controller: all together
  18. 18. Controller: routeURL and name of route
  19. 19. Controller: templateLook for template in:./Resources/views/Account/index.html.twig
  20. 20. Controller: get data from DBFetch Doctrinedata managerGet data from repository
  21. 21. TwigSyntax is very simple:{{ something }} - «Print something»{% something %} - «Do something»
  22. 22. TwigPrint var:{{ var }}«var» can be even an object. With __toString() methodpublic function __toString(){return $this->name;}
  23. 23. TwigConcise:<?php echo $var ?> → {{ var }}<?php echo htmlspecialchars($var, ENT_QUOTES, UTF-8 ?>{{ var |e }}
  24. 24. Twig: documentation
  25. 25. Twig: base template example
  26. 26. Twig: inheritance
  27. 27. Need smth Twig doesnt provide?Just do it!
  28. 28. Symfony and inspirationHow to rescue your PHP project with Symfony2componentshttp://habrahabr.ru/post/146521/http://www.slideshare.net/xavierlacot/symfony2-components-to-the-rescue-of-your-php-projects
  29. 29. Create your own framework on topof Symfony componentsRecipe from Fabien Potencierhttp://fabien.potencier.org/article/50/create-your-own-framework-on-top-of-the-symfony2-components-part-1
  30. 30. Symfony2 components: ConsoleSome examples of usage$ php app/console doctrine:generate:entitiesName/MyBundle/Entity/SomeEntity- generates getters and setters for SomeEntity$ php app/console container:debuglist of all available services
  31. 31. Symfony2 components: Console
  32. 32. Http FoundationRequest Response
  33. 33. Http Foundation: Request
  34. 34. Http Foundation: Response
  35. 35. Routing component
  36. 36. Services: Dependency Injection
  37. 37. Benefits:Only one instance of Mailer which can be usedin entire applicationCentralized configuration of MailerIt can be replaced by another service
  38. 38. Services container (DIC)Step 1: Create classStep 2: Register it as service by adding to theservice containerStep 3 ... n: Use it
  39. 39. Create class
  40. 40. Register as service
  41. 41. Lets make example more complicatedStep 1: Create one more classStep 2: Inject service to itStep 3: Register it as service as well
  42. 42. Create class and inject service
  43. 43. Register new class as service
  44. 44. Use it
  45. 45. Lets improve it. Load services from file
  46. 46. Service.yml become a config file
  47. 47. Http Kernel
  48. 48. Request → Response flow
  49. 49. Events and listenersEvent 1 in HttpKernel->handle(): kernel.requestI.e. Security listener can throw Response objectwith 403 Access denied response
  50. 50. Symfony2 is very kind:For visitorsFor developers
  51. 51. Symfony2 is very fastResponse class to manage HTTP cache:$response = new Response();$response->setMaxAge(600);$date = new DateTime();$date->modify(+600 seconds);$response->setExpires($date);
  52. 52. Symfony2 dev mode
  53. 53. Symfony2 dev mode
  54. 54. Symfony2 dev mode
  55. 55. Symfony2 follows standards...Autoloading standard: PSR-0Basic coding style: PSR-1Coding style: PSR-2http://www.php-fig.org/
  56. 56. … which means:It heavily uses namespaces, OOP, SOA, designpatterns, etchttp://php.net/manual/en/language.namespaces.phphttp://en.wikipedia.org/wiki/Software_design_patternhttp://en.wikipedia.org/wiki/Service-oriented_architecture
  57. 57. Im almost finishedYellow: developmentBlue: stableGreen: maintenanceSince 3 June 2013 –long time supportfor v. 2.3
  58. 58. Symfony2 bundles
  59. 59. Try Symfony2But be careful — it can becomeaddictive from the very firstencounter :)
  60. 60. Questionsvaleriy.tuz@gmail.com +380 67 505 42 76

×