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

Unglue All The Things! Symfony Live! London 2016

Beau Simensen
September 16, 2016

Unglue All The Things! Symfony Live! London 2016

Bundles. Packages. Modules. Plugins. So much code is locked up in framework-specific packages. With so may people talking about wanting to write framework agnostic packages, it can be easy to get stuck thinking that this is, and should always be, the end goal. Learn about one developer's experience trying to write truly framework agnostic code. See what worked, what didn't, and walk away having a better idea how you, too, can attempt to unglue all the things!

Beau Simensen

September 16, 2016
Tweet

More Decks by Beau Simensen

Other Decks in Programming

Transcript

  1. { "require": { "symfony/asset": "~2.8|~3.0", "symfony/cache": "~3.2", "symfony/class-loader": "~3.2", "symfony/dependency-injection":

    "~3.2", "symfony/config": "~2.8|~3.0", "symfony/event-dispatcher": "~2.8|~3.0", "symfony/http-foundation": "~3.1", "symfony/http-kernel": "~3.2", "symfony/polyfill-mbstring": "~1.0", "symfony/filesystem": "~2.8|~3.0", "symfony/finder": "~2.8|~3.0", "symfony/routing": "~3.0", "symfony/security-core": "~3.2", "symfony/security-csrf": "~2.8|~3.0", "symfony/stopwatch": "~2.8|~3.0", "symfony/templating": "~2.8|~3.0", "symfony/translation": "~2.8|~3.0", "doctrine/cache": "~1.0", "doctrine/annotations": "~1.0" } }
  2. # app/config/config.yml doctrine: orm: entity_managers: default: mappings: acme: type: annotation

    prefix: Acme\Entity dir: "%kernel.root_dir%/../vendor/acme/entity/src/Entity" is_bundle: false
  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. "autoload": { "psr-4": { "Monii\\Deal\\": "src" } } Monii\Deal\DealRepository =>

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

    classpath:Monii/Deal/resources/mapping.yml => resources/mapping.yml
  13. "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
  14. Problem: In many cases it is hard to write PSR-7

    code that is not tied to an implementation.
  15. Think about the code you write directly into a glue

    package It can lead to better design