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

Unglue all the things! (DPC 2016)

Unglue all the things! (DPC 2016)

Bundles. Packages. Modules. Plugins. So much code is locked up in framework-specific packages. Integration packages are not bad, but losing the ability to reuse code that has nothing to do with a specific framework's implementation is! Don't let reusable code get locked into framework-specific glue packages! Come see practical strategies for writing framework agnostic code and walk away having a better idea how you, too, can unglue all the things!

Beau Simensen

June 25, 2016
Tweet

More Decks by Beau Simensen

Other Decks in Programming

Transcript

  1. Symfony handled this by convention (this is one reason why

    so many projects ship everything as a bundle)
  2. Won't work if the mappings live in a project other

    than a bundle* * Nasty __DIR__ hacks don't count.
  3. "autoload": { "psr-0": { "Monii\\Deal\\": "src" } } Monii\Deal\DealRepository =>

    src/Monii/Deal/DealRepository.php Monii\Deal\DealRepository => vendor/monii/deal/src/Monii/Deal/DealRepository.php
  4. What if we used PSR-0 mappings and rules to locate

    other types of files than just classes?
  5. "autoload": { "psr-0": { "Monii\\Deal\\": "src" } } Monii\Deal\DealRepository =>

    src/Monii/Deal/DealRepository.php classpath:Monii/Deal/resources/mapping.yml => src/Monii/Deal/resources/mapping.yml
  6. "autoload": { "psr-0": { "Monii\\Deal\\": "src" } } Monii\Deal\DealRepository =>

    src/Monii/Deal/DealRepository.php classpath:Monii/Deal/resources/mapping.yml => src/Monii/Deal/resources/mapping.yml classpath:Monii/Deal/resources/mapping.yml => vendor/monii/deal/src/Monii/Deal/resources/mapping.yml
  7. $container["orm.em.options"] = [ "mappings" => [ [ "type" => "xml",

    "namespace" => "Monii\Deal", "resources_namespace" => "Monii\Deal\mappings", ], ], ];
  8. $container["orm.em.options"] = [ "mappings" => [ [ "type" => "xml",

    "namespace" => "Monii\Deal", "resources_namespace" => "Monii\Deal\mappings", ], ], ]; Monii\Deal\Deal
  9. $container["orm.em.options"] = [ "mappings" => [ [ "type" => "xml",

    "namespace" => "Monii\Deal", "resources_namespace" => "Monii\Deal\mappings", ], ], ]; Monii\Deal\Deal => classpath:Monii/Deal/mappings/Deal.xml
  10. $container["orm.em.options"] = [ "mappings" => [ [ "type" => "xml",

    "namespace" => "Monii\Deal", "resources_namespace" => "Monii\Deal\mappings", ], ], ]; Monii\Deal\Deal => classpath:Monii/Deal/mappings/Deal.xml => vendor/monii/deal/src/Monii/Deal/mappings/Deal.xml
  11. Updating the Symfony Bundle would have required a lot of

    work (and buy-in from the Doctrine team...)
  12. "autoload": { "psr-4": { "Monii\\Deal\\": "src" } } Monii\Deal\DealRepository =>

    src/DealRepository.php Monii\Deal\DealRepository => vendor/monii/deal/src/DealRepository.php
  13. "autoload": { "psr-4": { "Monii\\Deal\\": "src", "Monii\\Deal\\resources": "resources" } }

    classpath:Monii/Deal/resources/mapping.yml => resources/mapping.yml
  14. "autoload": { "psr-4": { "Monii\\Deal\\": "src", "Monii\\Deal\\resources": "resources" } }

    classpath:Monii/Deal/resources/mapping.yml => resources/mapping.yml classpath:Monii/Deal/resources/mapping.yml => vendor/monii/deal/resources/mapping.yml
  15. Symfony controllers as services can be used as-is in Silex,

    Drupal, Laravel, and Symfony full stack
  16. :)

  17. :(

  18. Hey! I'm trying to decide if Glide should use PSR-7

    for it's next release. — Jonathan Reinink, June 2015
  19. Problem: In many cases it is hard to write PSR-7

    code that is not tied to an implementation.
  20. With PSR-7, PSR-15 and PSR-17 combined we can truly start

    writing Framework Agnostic HTTP applications.
  21. Think about the code you write directly into a glue

    package (It can lead to better design)