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

ADR pattern, autowiring, DunglasActionBundle: S...

ADR pattern, autowiring, DunglasActionBundle: Symfony controllers redesigned

Presentation of the controller system of Symfony and one of is refinement using the ADR pattern and services autowiring: DunglasActionBundle.

https://github.com/dunglas/DunglasActionBundle

Kévin Dunglas

June 16, 2016
Tweet

More Decks by Kévin Dunglas

Other Decks in Programming

Transcript

  1. ABOUT ME KÉVIN DUNGLAS ▸ Founder of Les-Tilleuls.coop ▸ Symfony

    Core Team Member ▸ API Platform Creator ▸ Teacher at Lille 1 University Twitter / GitHub : @dunglas dunglas.fr
  2. ABOUT US LES-TILLEULS.COOP ▸ 15+ consultants and developers ▸ Symfony

    / Angular 1 & 2 / React / Amazon AWS / Docker / SCRUM / … ▸ 100% owned by his employees ▸ 1 person = 1 vote, all benefits are equally distributed ▸ We are hiring! Twitter / GitHub : @coopTilleuls les-tilleuls.coop
  3. A CONTROLLER IS A PHP CALLABLE YOU CREATE THAT TAKES

    INFORMATION FROM THE HTTP REQUEST AND CREATES AND RETURNS AN HTTP RESPONSE (AS A SYMFONY RESPONSE OBJECT). The Symfony Book SYMFONY CONTROLLERS
  4. AUTOWIRING ALLOWS TO REGISTER SERVICES IN THE CONTAINER WITH MINIMAL

    CONFIGURATION. IT AUTOMATICALLY RESOLVES THE SERVICE DEPENDENCIES BASED ON THE CONSTRUCTOR'S TYPEHINT WHICH IS USEFUL IN THE FIELD OF RAPID APPLICATION DEVELOPMENT, WHEN DESIGNING PROTOTYPES IN EARLY STAGES OF LARGE PROJECTS. IT MAKES IT EASY TO REGISTER A SERVICE GRAPH AND EASES REFACTORING. The Symfony Book AUTOWIRED SERVICES
  5. DUNGLASACTIONBUNDLE ALLOWS TO CREATE REUSABLE, FRAMEWORK AGNOSTIC AND EASY TO

    UNIT TEST ACTION CLASSES. github.com/dunglas/DunglasActionBundle TEXTE
  6. DUNGLASACTIONBUNDLE INTRODUCTION ▸ Replacement for the controller layer (controllers, commands,

    event listeners…) of Symfony ▸ Controllers and commands automatically registered as services ▸ Autowiring enabled: their dependencies are explicitly injected - you don’t need to configure your services anymore!! ▸ Only 209 lines of code (+ some patches to Symfony) ▸ 150+ stars on GitHub
  7. DUNGLASACTIONBUNDLE MORE? ▸ Also support Event Listeners ▸ Configuration to

    register your own types of classes ▸ Can automatically add tags to registered classes ▸ 100% compatible with existing libraries and bundles (including SensioFrameworkExtraBundle) ▸ Will be included in API Platform v2
  8. THE ADR PATTERN INTRODUCTION ▸ Stand for Action-Domain-Responder ▸ Web-specific

    refinement of Model-View-Controller https://github.com/pmjones/adr
  9. THE ADR PATTERN DETAILS ▸ Action: logic that connects the

    Domain and Responder. Uses the request input to interact with the Domain, and passes the Domain output to the Responder. ▸ Domain: logic to manipulate the domain, session, application, and environment data, modifying state and persistence as needed. ▸ Responder: logic to build an HTTP response or response description. It deals with body content, templates and views, headers and cookies, status codes, and so on. Source: https://github.com/pmjones/adr
  10. DUNGLASACTIONBUNDLE THE ROAD TO REUSABLE AND CROSS FRAMEWORK ACTIONS ▸

    Don’t depend of FrameworkBundle features ▸ Use PSR-7 instead of HttpFoundation: https:// dunglas.fr/2015/07/slides-using-psr-7-with- symfony/ ▸ Don’t use annotations (prefer XML or YAML for routing)