Package best practices                              April 20, 2013Saturday 20 April 13 / CW:
April 20, 2013                     Flow package best practices                                               About me     ...
April 20, 2013                     Flow package best practices                                        My Flow experience  ...
April 20, 2013                   Flow package best practices                                  45 best practices for ...   ...
April 20, 2013                           Flow package best practices                                               Best pr...
April 20, 2013                                   Flow package best practices                                        A deep...
April 20, 2013                   Flow package best practices             Architecture                                     ...
April 20, 2013                            Flow package best practices             Architecture                            ...
April 20, 2013                        Flow package best practices             Architecture                                ...
April 20, 2013               Flow package best practices             Architecture                                         ...
April 20, 2013                      Flow package best practices             Architecture                                  ...
April 20, 2013               Flow package best practices             Architecture                                         ...
April 20, 2013               Flow package best practices             Architecture                                         ...
April 20, 2013               Flow package best practices             Architecture                                         ...
April 20, 2013               Flow package best practices             Architecture                                         ...
April 20, 2013                                     Flow package best practices             Architecture                   ...
April 20, 2013                                     Flow package best practices             Architecture                   ...
April 20, 2013                             Flow package best practices             Architecture                           ...
April 20, 2013                             Flow package best practices             Architecture                           ...
April 20, 2013               Flow package best practices             Architecture                                         ...
April 20, 2013                                         Flow package best practices             Architecture               ...
April 20, 2013                                         Flow package best practices             Architecture               ...
April 20, 2013                           Flow package best practices                                               Best pr...
April 20, 2013                           Flow package best practices                                               Post-ki...
April 20, 2013                        Flow package best practices                Coding:              Post-kickstart      ...
April 20, 2013                      Flow package best practices                Coding:              Post-kickstart        ...
April 20, 2013                         Flow package best practices                Coding:              Post-kickstart     ...
April 20, 2013                          Flow package best practices                Coding:              Post-kickstart    ...
April 20, 2013                      Flow package best practices                                               Debugging   ...
April 20, 2013                         Flow package best practices                    Coding:                   Debugging ...
April 20, 2013                Flow package best practices                    Coding:                   Debugging          ...
April 20, 2013                Flow package best practices                    Coding:                   Debugging          ...
April 20, 2013                     Flow package best practices                                               Composer     ...
April 20, 2013                   Flow package best practices                   Coding:                  Composer          ...
April 20, 2013                         Flow package best practices                                               Configurat...
April 20, 2013                       Flow package best practices                Coding:              Configuration         ...
April 20, 2013                         Flow package best practices                Coding:              Configuration       ...
April 20, 2013                   Flow package best practices                Coding:              Configuration             ...
April 20, 2013                Flow package best practices                                               MVC            Pan...
April 20, 2013                 Flow package best practices                      Coding:                       MVC         ...
April 20, 2013                                        Flow package best practices                      Coding:            ...
April 20, 2013                        Flow package best practices                      Coding:                       MVC  ...
April 20, 2013                Flow package best practices                      Coding:                       MVC          ...
April 20, 2013                    Flow package best practices                      Coding:                       MVC      ...
April 20, 2013                Flow package best practices                      Coding:                       MVC          ...
April 20, 2013                    Flow package best practices                                               Session       ...
April 20, 2013                Flow package best practices                      Coding:                      Session       ...
April 20, 2013                Flow package best practices                                   Dependency Injection          ...
April 20, 2013                  Flow package best practices                  Coding:                Dependency            ...
April 20, 2013                                      Flow package best practices                  Coding:                De...
April 20, 2013                        Flow package best practices                                               Persistenc...
April 20, 2013                        Flow package best practices                  Coding:                 Persistence    ...
April 20, 2013                   Flow package best practices                  Coding:                 Persistence         ...
April 20, 2013                     Flow package best practices                  Coding:                 Persistence       ...
April 20, 2013                            Flow package best practices                  Coding:                 Persistence...
April 20, 2013                   Flow package best practices                  Coding:                 Persistence         ...
April 20, 2013                      Flow package best practices                  Coding:                 Persistence      ...
April 20, 2013                       Flow package best practices                  Coding:                 Persistence     ...
April 20, 2013                Flow package best practices                  Coding:                 Persistence            ...
April 20, 2013                Flow package best practices                  Coding:                 Persistence            ...
April 20, 2013                      Flow package best practices                                               Resources   ...
April 20, 2013                  Flow package best practices                   Coding:                  Resources          ...
April 20, 2013           Flow package best practices                             Development Environment            Pankaj...
April 20, 2013                         Flow package best practices                Coding:              Development        ...
April 20, 2013                      Flow package best practices                Coding:              Development           ...
April 20, 2013                          Flow package best practices                                               Error Pr...
April 20, 2013                Flow package best practices                Coding:             Error proofing                ...
April 20, 2013                       Flow package best practices                                           Error Handling ...
April 20, 2013                       Flow package best practices                Coding:             Error handling        ...
April 20, 2013                      Flow package best practices                                               Utilities   ...
April 20, 2013                        Flow package best practices                      Coding:                      Utilit...
April 20, 2013                      Flow package best practices                                               Bootstrap   ...
April 20, 2013                Flow package best practices                    Coding:                   Bootstrap          ...
April 20, 2013                      Flow package best practices                                         Troubleshooting   ...
April 20, 2013                Flow package best practices                 Coding:             Troubleshooting             ...
April 20, 2013                    Flow package best practices                                               Testing       ...
April 20, 2013                Flow package best practices                        Coding:                        Testing   ...
April 20, 2013                  Flow package best practices                        Coding:                        Testing ...
April 20, 2013                        Flow package best practices                                               Performanc...
April 20, 2013                Flow package best practices                   Coding:                 Performance           ...
April 20, 2013                Flow package best practices                   Coding:                 Performance           ...
April 20, 2013                       Flow package best practices                                               Thank you! ...
April 20, 2013                       Flow package best practices                                               Questions? ...
Upcoming SlideShare
Loading in …5
×

TYPO3 Flow package best practices

5,658 views

Published on

Talk at Inspiring Flow 2013

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

No Downloads
Views
Total views
5,658
On SlideShare
0
From Embeds
0
Number of Embeds
14
Actions
Shares
0
Downloads
38
Comments
0
Likes
9
Embeds 0
No embeds

No notes for slide

TYPO3 Flow package best practices

  1. 1. Package best practices April 20, 2013Saturday 20 April 13 / CW:
  2. 2. April 20, 2013 Flow package best practices About me • Pankaj Lele • Live in Goa, India • Lelesys Founder Director and CTO (10+ years) • @pankajlele Pankaj Lele - pankaj@lelesys.com 2Saturday 20 April 13 / CW:
  3. 3. April 20, 2013 Flow package best practices My Flow experience • Large scale enterprise project • Full agile development with 7 teams, 3 countries, 20+ developers • Start with FLOW3 1.0 Nov. 2011 • First public version March 2012 Pankaj Lele - pankaj@lelesys.com 3Saturday 20 April 13 / CW:
  4. 4. April 20, 2013 Flow package best practices 45 best practices for ... • Efficiency • Assuring quality • Avoiding common errors • Flexibility Pankaj Lele - pankaj@lelesys.com 4Saturday 20 April 13 / CW:
  5. 5. April 20, 2013 Flow package best practices Best practices Architecture Coding Pankaj Lele - pankaj@lelesys.com 5Saturday 20 April 13 / CW:
  6. 6. April 20, 2013 Flow package best practices A deep thinking architect ... Pankaj Lele - pankaj@lelesys.com 6Saturday 20 April 13 / CW:
  7. 7. April 20, 2013 Flow package best practices Architecture #1 • Good to define full class design with UML Pankaj Lele - pankaj@lelesys.com 7Saturday 20 April 13 / CW:
  8. 8. April 20, 2013 Flow package best practices Architecture #1 ArgoUML (all platforms) Pankaj Lele - pankaj@lelesys.com 8Saturday 20 April 13 / CW:
  9. 9. April 20, 2013 Flow package best practices Architecture #2 • Avoid unnecessary bi-directional associations in your domain model Pankaj Lele - pankaj@lelesys.com 9Saturday 20 April 13 / CW:
  10. 10. April 20, 2013 Flow package best practices Architecture #3 • Always good to define interfaces • defaults - Objects.yaml • ReflectionService Pankaj Lele - pankaj@lelesys.com 10Saturday 20 April 13 / CW:
  11. 11. April 20, 2013 Flow package best practices Architecture #3 For example, PaymentHandlerInterface Pankaj Lele - pankaj@lelesys.com 11Saturday 20 April 13 / CW:
  12. 12. April 20, 2013 Flow package best practices Architecture #4 • Avoid defining static functions • PhpUnit limitations for mocks Pankaj Lele - pankaj@lelesys.com 12Saturday 20 April 13 / CW:
  13. 13. April 20, 2013 Flow package best practices Architecture #5 • Good to define domain services Pankaj Lele - pankaj@lelesys.com 13Saturday 20 April 13 / CW:
  14. 14. April 20, 2013 Flow package best practices Architecture #5 Pankaj Lele - pankaj@lelesys.com 14Saturday 20 April 13 / CW:
  15. 15. April 20, 2013 Flow package best practices Architecture #6 • Good to use doctrine inheritance mapping if possible Pankaj Lele - pankaj@lelesys.com 15Saturday 20 April 13 / CW:
  16. 16. April 20, 2013 Flow package best practices Architecture #6 BAD class Media { /** * The title of media * @var string */ protected $title; /** * The type one of audio or video * @var string */ protected $type; } Pankaj Lele - pankaj@lelesys.com 16Saturday 20 April 13 / CW:
  17. 17. April 20, 2013 Flow package best practices Architecture #6 BAD class Media { /** * The title of media * @var string */ protected $title; /** * The type one of audio or video * @var string */ protected $type; } Pankaj Lele - pankaj@lelesys.com 16Saturday 20 April 13 / CW:
  18. 18. April 20, 2013 Flow package best practices Architecture #6 GOOD class Audio extends class AbstractMedia { AbstractMedia { /** } * The title of media * @var string class Video extends */ AbstractMedia { protected $title; } } Pankaj Lele - pankaj@lelesys.com 17Saturday 20 April 13 / CW:
  19. 19. April 20, 2013 Flow package best practices Architecture #6 GOOD class Audio extends class AbstractMedia { AbstractMedia { /** } * The title of media * @var string class Video extends */ AbstractMedia { protected $title; } } Pankaj Lele - pankaj@lelesys.com 17Saturday 20 April 13 / CW:
  20. 20. April 20, 2013 Flow package best practices Architecture #7 • Good to define class constants • no need to remember values Pankaj Lele - pankaj@lelesys.com 18Saturday 20 April 13 / CW:
  21. 21. April 20, 2013 Flow package best practices Architecture #7 GOOD class ElectronicAddress { const TYPE_AIM = Aim; const TYPE_EMAIL = Email; const TYPE_ICQ = Icq; const TYPE_JABBER = Jabber; } $electronicAddress = new ElectronicAddress(); $electronicAddress->setType(ElectronicAddress::TYPE_EMAIL); Pankaj Lele - pankaj@lelesys.com 19Saturday 20 April 13 / CW:
  22. 22. April 20, 2013 Flow package best practices Architecture #7 GOOD class ElectronicAddress { const TYPE_AIM = Aim; const TYPE_EMAIL = Email; const TYPE_ICQ = Icq; const TYPE_JABBER = Jabber; } $electronicAddress = new ElectronicAddress(); $electronicAddress->setType(ElectronicAddress::TYPE_EMAIL); Pankaj Lele - pankaj@lelesys.com 19Saturday 20 April 13 / CW:
  23. 23. April 20, 2013 Flow package best practices Best practices Architecture Coding Pankaj Lele - pankaj@lelesys.com 20Saturday 20 April 13 / CW:
  24. 24. April 20, 2013 Flow package best practices Post-kickstart Pankaj Lele - pankaj@lelesys.com 21Saturday 20 April 13 / CW:
  25. 25. April 20, 2013 Flow package best practices Coding: Post-kickstart #8 • Good to define methods addX(), removeX() and getXs() for collections • example: TYPO3PartyDomainModel AbstractParty Pankaj Lele - pankaj@lelesys.com 22Saturday 20 April 13 / CW:
  26. 26. April 20, 2013 Flow package best practices Coding: Post-kickstart #9 • Always good to initialize collections in entity class constructor • recommended by Doctrine Pankaj Lele - pankaj@lelesys.com 23Saturday 20 April 13 / CW:
  27. 27. April 20, 2013 Flow package best practices Coding: Post-kickstart #10 • Always annotate properties with validators right away after kickstart Pankaj Lele - pankaj@lelesys.com 24Saturday 20 April 13 / CW:
  28. 28. April 20, 2013 Flow package best practices Coding: Post-kickstart #11 • Always remove unused controller actions created by kick-starter Pankaj Lele - pankaj@lelesys.com 25Saturday 20 April 13 / CW:
  29. 29. April 20, 2013 Flow package best practices Debugging Pankaj Lele - pankaj@lelesys.com 26Saturday 20 April 13 / CW:
  30. 30. April 20, 2013 Flow package best practices Coding: Debugging #12 • Always use TYPO3Flow var_dump() for debugging variables • no more memory full errors • object information Pankaj Lele - pankaj@lelesys.com 27Saturday 20 April 13 / CW:
  31. 31. April 20, 2013 Flow package best practices Coding: Debugging #12 Pankaj Lele - pankaj@lelesys.com 28Saturday 20 April 13 / CW:
  32. 32. April 20, 2013 Flow package best practices Coding: Debugging #13 • Best to use package debug/toolbar • queries executed • functions called Pankaj Lele - pankaj@lelesys.com 29Saturday 20 April 13 / CW:
  33. 33. April 20, 2013 Flow package best practices Composer Pankaj Lele - pankaj@lelesys.com 30Saturday 20 April 13 / CW:
  34. 34. April 20, 2013 Flow package best practices Coding: Composer #14 • Always maintain composer.json right away • document what you used • ext-zip or ext-imagick Pankaj Lele - pankaj@lelesys.com 31Saturday 20 April 13 / CW:
  35. 35. April 20, 2013 Flow package best practices Configuration Pankaj Lele - pankaj@lelesys.com 32Saturday 20 April 13 / CW:
  36. 36. April 20, 2013 Flow package best practices Coding: Configuration #15 • Good to set defaultLocale setting • application’s default language • helps formatting numbers and currencies automatically Pankaj Lele - pankaj@lelesys.com 33Saturday 20 April 13 / CW:
  37. 37. April 20, 2013 Flow package best practices Coding: Configuration #16 • Always run ./flow configuration:validate to check whether package *.yaml files are valid Pankaj Lele - pankaj@lelesys.com 34Saturday 20 April 13 / CW:
  38. 38. April 20, 2013 Flow package best practices Coding: Configuration #17 • Always crosscheck package configuration using ./flow configuration:show Pankaj Lele - pankaj@lelesys.com 35Saturday 20 April 13 / CW:
  39. 39. April 20, 2013 Flow package best practices MVC Pankaj Lele - pankaj@lelesys.com 36Saturday 20 April 13 / CW:
  40. 40. April 20, 2013 Flow package best practices Coding: MVC #18 • Always map all GET/POST variables as action arguments Pankaj Lele - pankaj@lelesys.com 37Saturday 20 April 13 / CW:
  41. 41. April 20, 2013 Flow package best practices Coding: MVC #18 BAD /** * Create action * * @return void */ public function createAction() { $newVideo = $this->request->getHttpRequest()->getArgument(newVideo); // .... } Pankaj Lele - pankaj@lelesys.com 38Saturday 20 April 13 / CW:
  42. 42. April 20, 2013 Flow package best practices Coding: MVC #18 Good /** * Create action * * @param Video $newVideo The video * @return void */ public function createAction(Video $newVideo) { // .... } Pankaj Lele - pankaj@lelesys.com 39Saturday 20 April 13 / CW:
  43. 43. April 20, 2013 Flow package best practices Coding: MVC #19 • Good to have an AbstractController • assign logged in user to the view • inject common dependencies Pankaj Lele - pankaj@lelesys.com 40Saturday 20 April 13 / CW:
  44. 44. April 20, 2013 Flow package best practices Coding: MVC #20 • Avoid exit() call inside controller action • StopActionException() is what you want Pankaj Lele - pankaj@lelesys.com 41Saturday 20 April 13 / CW:
  45. 45. April 20, 2013 Flow package best practices Coding: MVC #21 • Good to use StandAloneView • render e-mail templates Pankaj Lele - pankaj@lelesys.com 42Saturday 20 April 13 / CW:
  46. 46. April 20, 2013 Flow package best practices Session Pankaj Lele - pankaj@lelesys.com 43Saturday 20 April 13 / CW:
  47. 47. April 20, 2013 Flow package best practices Coding: Session #22 • Avoid using direct session API • encapsulate • session scoped class • example: ShoppingCart Pankaj Lele - pankaj@lelesys.com 44Saturday 20 April 13 / CW:
  48. 48. April 20, 2013 Flow package best practices Dependency Injection Pankaj Lele - pankaj@lelesys.com 45Saturday 20 April 13 / CW:
  49. 49. April 20, 2013 Flow package best practices Coding: Dependency #23 Injection • Always inject interfaces • proper factory object is used • change implementation via Objects.yaml Pankaj Lele - pankaj@lelesys.com 46Saturday 20 April 13 / CW:
  50. 50. April 20, 2013 Flow package best practices Coding: Dependency #24 Injection If you really want to ... • inject TYPO3FlowSessionSessionInterface • current active session • inject TYPO3FlowSessionSession • completely new session Pankaj Lele - pankaj@lelesys.com 47Saturday 20 April 13 / CW:
  51. 51. April 20, 2013 Flow package best practices Persistence Pankaj Lele - pankaj@lelesys.com 48Saturday 20 April 13 / CW:
  52. 52. April 20, 2013 Flow package best practices Coding: Persistence #25 • Frequently call ./flow doctrine:validate • after kickstart + modifications • after each change in domain model Pankaj Lele - pankaj@lelesys.com 49Saturday 20 April 13 / CW:
  53. 53. April 20, 2013 Flow package best practices Coding: Persistence #26 • Always use doctrine migrations for database update • doctrine:update/create not good for serious projects Pankaj Lele - pankaj@lelesys.com 50Saturday 20 April 13 / CW:
  54. 54. April 20, 2013 Flow package best practices Coding: Persistence #27 • Always test “down” doctrine migrations • good for change rollback Pankaj Lele - pankaj@lelesys.com 51Saturday 20 April 13 / CW:
  55. 55. April 20, 2013 Flow package best practices Coding: Persistence #28 • Always separate out doctrine migrations of respective packages Pankaj Lele - pankaj@lelesys.com 52Saturday 20 April 13 / CW:
  56. 56. April 20, 2013 Flow package best practices Coding: Persistence #29 • Good to use doctrine migrations also for migrating data • $this->connection Pankaj Lele - pankaj@lelesys.com 53Saturday 20 April 13 / CW:
  57. 57. April 20, 2013 Flow package best practices Coding: Persistence #30 • Good do not mention any collation or use utf8_unicode_ci in doctrine migrations • my.cnf "collation-server" Pankaj Lele - pankaj@lelesys.com 54Saturday 20 April 13 / CW:
  58. 58. April 20, 2013 Flow package best practices Coding: Persistence #31 • Do not delete/modify doctrine migration files once committed • always generate new migration on each domain model change Pankaj Lele - pankaj@lelesys.com 55Saturday 20 April 13 / CW:
  59. 59. April 20, 2013 Flow package best practices Coding: Persistence #32 • Always pull upstream code changes • doctrine:migrate • doctrine:migrationgenerate Pankaj Lele - pankaj@lelesys.com 56Saturday 20 April 13 / CW:
  60. 60. April 20, 2013 Flow package best practices Coding: Persistence #33 • Good to use DQL at some places • aggregations • joins • avoid nested foreach loops • warning: QOM based widgets Pankaj Lele - pankaj@lelesys.com 57Saturday 20 April 13 / CW:
  61. 61. April 20, 2013 Flow package best practices Resources Pankaj Lele - pankaj@lelesys.com 58Saturday 20 April 13 / CW:
  62. 62. April 20, 2013 Flow package best practices Coding: Resources #34 • If needed, good to write files in /Data • Persistent • Temporary • UtilityEnvironment Pankaj Lele - pankaj@lelesys.com 59Saturday 20 April 13 / CW:
  63. 63. April 20, 2013 Flow package best practices Development Environment Pankaj Lele - pankaj@lelesys.com 60Saturday 20 April 13 / CW:
  64. 64. April 20, 2013 Flow package best practices Coding: Development #35 Environment • Good to ignore directories in your favorite IDE • Data/Temporary, Logs, Persistent • speeds up the IDE • proxy classes ignored Pankaj Lele - pankaj@lelesys.com 61Saturday 20 April 13 / CW:
  65. 65. April 20, 2013 Flow package best practices Coding: Development #36 Environment • Good to freeze packages not changed so often • freeze framework packages • ./flow package:freeze Pankaj Lele - pankaj@lelesys.com 62Saturday 20 April 13 / CW:
  66. 66. April 20, 2013 Flow package best practices Error Proofing Pankaj Lele - pankaj@lelesys.com 63Saturday 20 April 13 / CW:
  67. 67. April 20, 2013 Flow package best practices Coding: Error proofing #37 • Always type-hint method arguments • strict expectations Pankaj Lele - pankaj@lelesys.com 64Saturday 20 April 13 / CW:
  68. 68. April 20, 2013 Flow package best practices Error Handling Pankaj Lele - pankaj@lelesys.com 65Saturday 20 April 13 / CW:
  69. 69. April 20, 2013 Flow package best practices Coding: Error handling #38 • Always throw exceptions from domain services • catch in controllers • better error reporting to the user Pankaj Lele - pankaj@lelesys.com 66Saturday 20 April 13 / CW:
  70. 70. April 20, 2013 Flow package best practices Utilities Pankaj Lele - pankaj@lelesys.com 67Saturday 20 April 13 / CW:
  71. 71. April 20, 2013 Flow package best practices Coding: Utilities #39 • Always look for available TYPO3Flow Utility • get things done the way framework likes • environment, files, algorithms, array Pankaj Lele - pankaj@lelesys.com 68Saturday 20 April 13 / CW:
  72. 72. April 20, 2013 Flow package best practices Bootstrap Pankaj Lele - pankaj@lelesys.com 69Saturday 20 April 13 / CW:
  73. 73. April 20, 2013 Flow package best practices Coding: Bootstrap #40 • Good to rely on FLOW_* constants • paths Pankaj Lele - pankaj@lelesys.com 70Saturday 20 April 13 / CW:
  74. 74. April 20, 2013 Flow package best practices Troubleshooting Pankaj Lele - pankaj@lelesys.com 71Saturday 20 April 13 / CW:
  75. 75. April 20, 2013 Flow package best practices Coding: Troubleshooting #41 • Always find exact database error • SHOW INNODB STATUS Pankaj Lele - pankaj@lelesys.com 72Saturday 20 April 13 / CW:
  76. 76. April 20, 2013 Flow package best practices Testing Pankaj Lele - pankaj@lelesys.com 73Saturday 20 April 13 / CW:
  77. 77. April 20, 2013 Flow package best practices Coding: Testing #42 • Unit tests which test business logic • usually test domain services • persistence mocked Pankaj Lele - pankaj@lelesys.com 74Saturday 20 April 13 / CW:
  78. 78. April 20, 2013 Flow package best practices Coding: Testing #43 • Functional tests which test user stories • test controllers • virtual browser • in-memory persistence Pankaj Lele - pankaj@lelesys.com 75Saturday 20 April 13 / CW:
  79. 79. April 20, 2013 Flow package best practices Performance Pankaj Lele - pankaj@lelesys.com 76Saturday 20 April 13 / CW:
  80. 80. April 20, 2013 Flow package best practices Coding: Performance #44 • Good to analyze performance • sandstorm/plumber • xhprof just profiler • inclusive/exclusive timing • no code changes Pankaj Lele - pankaj@lelesys.com 77Saturday 20 April 13 / CW:
  81. 81. April 20, 2013 Flow package best practices Coding: Performance #45 • Always good to cache stuff • caching framework • front-ends • backends Pankaj Lele - pankaj@lelesys.com 78Saturday 20 April 13 / CW:
  82. 82. April 20, 2013 Flow package best practices Thank you! Pankaj Lele - pankaj@lelesys.com 79Saturday 20 April 13 / CW:
  83. 83. April 20, 2013 Flow package best practices Questions? Pankaj Lele - pankaj@lelesys.com 80Saturday 20 April 13 / CW:

×