Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Mission (Im)possible: Quality Decoupled Code with Drupal 7 (Singapore PHP user group meetup)

Mission (Im)possible: Quality Decoupled Code with Drupal 7 (Singapore PHP user group meetup)

We're all excited about Drupal 8 coming up soon and we want to be ready for it! How can we make sure our code is ready for it? How can we build modules that are backwards compatible with D7 and future proofed for D8?

Learn how to build code decoupled from your platform and use it with Drupal or any other framework.

Presented at Singapore PHP User Group meetup.

2bd48651cd01e0ca2e0a255a63da77aa?s=128

Marek Matulka

March 08, 2016
Tweet

Transcript

  1. Marek Matulka

  2. at @super_marek

  3. None
  4. None
  5. None
  6. None
  7. http://photobucket.com/user/marcrobinsone/media/Drupal%20Comics/marcrobinsonegmailcom__drupalNinja.png.html

  8. None
  9. None
  10. In order to create a good software, you have to

    know what the software is all about. – Eric Evans
  11. How do we learn?

  12. Stakeholders

  13. Ask for examples... ...write stories!

  14. Vocabulary

  15. Ubiquitous Language Ubiquitous Language

  16. Ubiquitous Language Ubiquitous Language Domain Expert Analyst Tester Developer Developer

  17. Ubiquitous Language Ubiquitous Language Domain Expert Analyst Tester Developer Developer

    Application Code Acceptance Criteria Specs and documentation
  18. Example?

  19. Example

  20. Example

  21. Domain

  22. Implementation

  23. why interface?

  24. Layered Architecture “High level modules should not depend on lower

    level implementation” – Robert C. Martin User Interface Application Domain Infrastructure
  25. Dependency Inversion Policy Layer <interface> Policy Service Mechanism Layer <interface>

    Mechanism Service Utility Layer
  26. Layered Architecture User Interface Application Domain Infrastructure

  27. Layered Architecture User Interface Application Domain Infrastructure

  28. Clean Architecture Entities Use Cases Controllers Web

  29. Clean Architecture Entities Use Cases Controllers Web Framework Drivers Interface

    Adapters Application Business Rules Enterprise Business Rules
  30. Hexagonal Architecture UI Adapter Log Adapter Data Storage Adapter External

    Data Adapter Application Domain
  31. Hexagonal Architecture Acme\Depot\DepotLocator Acme\MagentoAdapter\MagentoDepotLocator

  32. Hexagonal Architecture Acme\Depot\DepotLocator Acme\MagentoAdapter\MagentoDepotLocator port adapter

  33. Why clean architecture?

  34. Why clean architecture? - your code is clean(er)

  35. Why clean architecture? - your code is clean(er) - decoupled

    from framework
  36. Why clean architecture? - your code is clean(er) - decoupled

    from framework - reusable
  37. Why clean architecture? - your code is clean(er) - decoupled

    from framework - reusable - easy to test
  38. Why clean architecture? - your code is clean(er) - decoupled

    from framework - reusable - easy to test - easy to maintain
  39. Why clean architecture? - your code is clean(er) - decoupled

    from framework - reusable - easy to test - easy to maintain - easy to change
  40. None
  41. None
  42. dependency injection

  43. Dependency Injection - a standardised and centralised way of constructing

    objects in our application
  44. Kernel

  45. Kernel

  46. Kernel

  47. Kernel

  48. Kernel

  49. Kernel

  50. Kernel

  51. parameters.yml

  52. services.xml

  53. console commands

  54. Import Handler

  55. Console command

  56. app/console

  57. persisting products

  58. XML Writer

  59. Why write XML? - fetching data from Magento and dumping

    it into xml file is quick - xml can be imported by Drupal’s feed importer
  60. Why it didn’t work? - Feed importer was damn slow

    - 10k products imported in 4.5h - Scheduling import with Elysia Cron module was flaky - Scheduled feed importer would add products all over again - resources hungry!
  61. Direct save to the db

  62. Why direct save to the db? - Drupal promises data

    structure won’t ever change - It’s fast - 40k products in 2 minutes - It works!
  63. composer.json

  64. container.php

  65. database.php

  66. settings.php

  67. depot_locator.module

  68. Project folder structure

  69. None
  70. None
  71. as a CMS platform Drupal is great!

  72. Cherry pick what you need! Symfony Components

  73. Try it yourself! Decoupled code

  74. Right tool Choose wisely!

  75. @super_marek