Sf2 wtf

2,653 views

Published on

Symfony2 è sicuramente uno dei framework migliori in circolazione, ma non sono tutte rose e fiori, soprattutto per chi inizia a sviluppare ed è alle prime armi. In questa presentazione vorrei condividere la mie esperienza di apprendimento ed utilizzo del framework, cercando di mettere in evidenza i miei momenti wtf e alcune linee guida per sviluppare applicazioni manutenibili

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,653
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
13
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Sf2 wtf

  1. 1. My Symfony WTF
  2. 2. Michele Orselli CTO@Ideato @_orso_ mo@ideato.it Who am I?
  3. 3. Why a talk on WTF? why a talk on WTF?
  4. 4. I♥ why a talk on WTF?
  5. 5. but... why a talk on WTF?
  6. 6. why a talk on WTF?
  7. 7. why a talk on WTF?
  8. 8. why a talk on WTF?
  9. 9. why a talk on WTF?
  10. 10. symfony 1 was focused on Rapid Application Development the (old) times?
  11. 11. Symfony2 is focused on Application Development the shiny new thing
  12. 12. the shiny new thing
  13. 13. the shiny new thing
  14. 14. the shiny new thing
  15. 15. speed as selling point
  16. 16. create-project symfony/framework-standard-edition ./foo 2.3.0 installation
  17. 17. cache/log permissions
  18. 18. cache/log permissions
  19. 19. php app/console cache:clear cache/log permissions
  20. 20. cache/log permissions
  21. 21. cache all the things (in dev too)!
  22. 22. http://symfony.com/doc/current/book/templating.html cache all the things (in dev too)!
  23. 23. config.yml: twig: cache: false user session in cache!
  24. 24. uhm, wait a minute...
  25. 25. user session in cache!
  26. 26. capifony? idephix? :-P user session in cache!
  27. 27. config.yml: framework: session: save_path: "%kernel.root_dir%/sessions/" user session in cache!
  28. 28. sf2 in da cloud
  29. 29. sf2 in da cloud
  30. 30. http:/ /www.ideato.it/planet-ideato/symfony2-su-google-app-engine/ symfony2 needs a writable filesystem symfony2 uses some restricted functions you can warmup cache, but paths are absolute the problem is not only limited to symfony (eg: assetic) sf2 in da cloud
  31. 31. sf2 in da cloud
  32. 32. /** * @ORMEntity(repositoryClass="IdeatoOfferBundleRepositoryCityRepository") * @ORMTable(name="city") */ class City { /** * @ORMId * @ORMColumn(type="integer") * @ORMGeneratedValue(strategy="AUTO") */ private $id; /** * @ORMColumn(type="string", length=255) * @AssertNotBlank() */ private $name; annotations
  33. 33. use DoctrineORMMapping as ORM; use SymfonyComponentValidatorConstraints as Assert; /** * @ORMEntity(repositoryClass="IdeatoOfferBundleRepositoryCityRepository") * @ORMTable(name="city") */ class City { /** * @ORMId * @ORMColumn(type="integer") * @ORMGeneratedValue(strategy="AUTO") */ private $id; /** * @ORMColumn(type="string", length=255) * @AssertNotBlank() */ private $name; annotations
  34. 34. @ParamConverter do you need everything?
  35. 35. /** * @ParamConverter("post", class="SensioBlogBundle:Post") */ public function showAction(Post $post) { ... } do you need everything?
  36. 36. /** * @ParamConverter("post", class="SensioBlogBundle:Post") */ public function showAction(Post $post) { ... } public function showAction(Post $post) { ... } do you need everything?
  37. 37. /** * @ParamConverter("post", class="SensioBlogBundle:Post") */ public function showAction(Post $post) { ... } public function showAction(Post $post) { ... } public function showAction(Post $post, Comment $comment) { ... } do you need everything?
  38. 38. /** * @ParamConverter("post", class="SensioBlogBundle:Post") */ public function showAction(Post $post) { ... } public function showAction(Post $post) { ... } public function showAction(Post $post, Comment $comment) { ... } kill the magic?
  39. 39. public function showAction($post_id) { $post = $this->getRepository(‘Posts’) ->findOneById($post_id); } explicit vs implicit
  40. 40. use DoctrineDBALTypesType; use DoctrineDBALPlatformsAbstractPlatform;   /** * NewObject datatype */ class NewObjectType extends Type { public function convertToPHPValue($value, AbstractPlatform $platform) { $listeners = $platform -> getEventManager() -> getListeners('getContainer');   $listener = array_shift($listeners); $container = $listener -> getContainer();   return $container -> get('service'); } } if u can it doesn’t mean you have to
  41. 41. class A { protected $first_service; protected $second_service; public function __construct(ContainerInterface $container) { $this->first_service = $container->get(‘firstService’); $this->second_service = $container->get(‘secondService’); } } passing around the DIC is bad
  42. 42. class A { protected $first_service; protected $second_service; public function __construct(FirstService $first, SecondService $second) { $this->first_service = $first; $this->second_service = $second; } } in services.yml: services: my.service: arguments: - "@first_service" - "@second_service" class: MyClassA passing around the DIC is bad
  43. 43. everything is a bundle
  44. 44. mopa_bootstrap: version: ~ form: templating: MopaBootstrapBundle:Form:fields.html.twig horizontal_label_class: col-lg-3 horizontal_input_wrapper_class: col-lg-9 row_wrapper_class: form-group render_fieldset: true render_collection_item: true show_legend: true show_child_legend: false checkbox_label: both render_optional_text: true render_required_asterisk: false error_type: ~ tooltip: icon: icon-info-sign placement: top tabs: class: nav nav-tabs popover: icon: icon-info-sign placement: top collection: widget_remove_btn: attr: class: btn icon: ~ icon_color: ~ widget_add_btn: attr: class: btn icon: ~ icon_color: ~ navbar: template: MopaBootstrapBundle:Navbar:navbar.html.twig initializr: meta: title: MopaBootstrapBundle description: MopaBootstrapBundle keywords: MopaBootstrapBundle, Twitter Bootstrap, HTML5 Boilerplate author_name: My name author_url: # feed_atom: ~ feed_rss: ~ sitemap: ~ nofollow: false noindex: false dns_prefetch: # Default: - //ajax.googleapis.com google: wt: ~ analytics: ~ diagnostic_mode: false configuration (Mopa)...
  45. 45. fos_user: db_driver: ~ # Required user_class: ~ # Required firewall_name: ~ # Required model_manager_name: ~ use_listener: true use_username_form_type: true from_email: address: webmaster@example.com sender_name: webmaster profile: form: type: fos_user_profile name: fos_user_profile_form validation_groups: # Defaults: - Profile - Default change_password: form: type: name: validation_groups: # Defaults: - ChangePassword - Default registration: confirmation: enabled: template: from_email: address: sender_name: form: type: name: validation_groups: fos_user_change_password fos_user_change_password_form false FOSUserBundle:Registration:email.txt.twig ~ # Required ~ # Required resetting: token_ttl: 86400 email: template: FOSUserBundle:Resetting:email.txt.twig from_email: address: ~ # Required sender_name: ~ # Required form: type: fos_user_resetting name: fos_user_resetting_form validation_groups: # Defaults: - ResetPassword - Default service: mailer: fos_user.mailer.default email_canonicalizer: fos_user.util.canonicalizer.default token_generator: fos_user.util.token_generator.default username_canonicalizer: fos_user.util.canonicalizer.default user_manager: fos_user.user_manager.default template: engine: twig group: group_class: ~ # Required group_manager: fos_user.group_manager.default form: type: fos_user_group name: fos_user_group_form validation_groups: # Defaults: - Registration - Default fos_user_registration fos_user_registration_form # Defaults: - Registration - Default configuration (FosUserBundle)...
  46. 46. configuration is just another way of programming configuration...
  47. 47. is there a way to create decoupled, maintainable code? configuration...
  48. 48. libraries configuration...
  49. 49. src !"" Acme #"" CoreDomain $ !"" User $ #"" User.php $ #"" UserId.php $ !"" UserRepository.php !"" CoreDomainBundle #"" Repository $   !"" InMemoryUserRepository.php !"" AcmeCoreDomainBundle.php http:/ /williamdurand.fr/2013/08/07 /ddd-with-symfony2-folder-structure-and-code-first/ http:/ /whitewashing.de ddd, code first, ...
  50. 50. wrap up Wrap up
  51. 51. after all Symfony2 is just a framework Wrap up
  52. 52. framework != architecture Wrap up
  53. 53. do you need that feature? Wrap up
  54. 54. think in advance Wrap up
  55. 55. keep things decoupled Wrap up
  56. 56. Thank you! @_orso_ that’s all folks! mo@ideato.it
  57. 57. Pics Credits wtf per minute: http://www.codinghorror.com/blog/2009/02/whos-your-coding-buddy.html pills: http://www.daygame.com/2013/blog/swallowing-the-red-pill/ umarell: http://www.informarexresistere.fr/ clouds: http://www.flickr.com/photos/uncle_jerry/49341110/ gae: http://venturebeat.files.wordpress.com/2013/05/google-app-engine-php-zend.jpg that’s all folks!

×