Slide 1

Slide 1 text

ACTIONBUNDLE SYMFONY CONTROLLERS, REDESIGNED

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

SYMFONY CONTROLLERS, NOWADAYS

Slide 6

Slide 6 text

SYMFONY CONTROLLERS TYPICAL CONTROLLER

Slide 7

Slide 7 text

SYMFONY CONTROLLERS FUNCTION AS CONTROLLER

Slide 8

Slide 8 text

SYMFONY CONTROLLERS INVOKABLE CLASS AS CONTROLLER

Slide 9

Slide 9 text

SYMFONY CONTROLLERS INVOKABLE CLASS: HOW DOES IT WORK?

Slide 10

Slide 10 text

SYMFONY CONTROLLERS CONTAINER AWARE CONTROLLER (E.G. FRAMEWORKBUNDLE’S CONTROLLER)

Slide 11

Slide 11 text

SYMFONY CONTROLLERS CONTROLLER AS A SERVICE

Slide 12

Slide 12 text

SYMFONY CONTROLLERS CONTROLLER AS A SERVICE

Slide 13

Slide 13 text

SYMFONY CONTROLLERS INVOKABLE CONTROLLER AS A SERVICE

Slide 14

Slide 14 text

AUTOWIRED SERVICES

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

AUTOWIRED SERVICES EXAMPLE

Slide 17

Slide 17 text

DUNGLAS ACTION BUNDLE

Slide 18

Slide 18 text

DUNGLASACTIONBUNDLE ALLOWS TO CREATE REUSABLE, FRAMEWORK AGNOSTIC AND EASY TO UNIT TEST ACTION CLASSES. github.com/dunglas/DunglasActionBundle TEXTE

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

DUNGLASACTIONBUNDLE INSTALL composer require dunglas/action-bundle

Slide 21

Slide 21 text

DUNGLASACTIONBUNDLE USAGE (CONTROLLER)

Slide 22

Slide 22 text

NO CONFIGURATION REQUIRED TO INJECT DEPENDENCIES! TEXTE

Slide 23

Slide 23 text

AUTOWIRED SERVICES EXAMPLE

Slide 24

Slide 24 text

DUNGLASACTIONBUNDLE USAGE (COMMAND)

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

THE ADR PATTERN

Slide 27

Slide 27 text

THE ADR PATTERN INTRODUCTION ▸ Stand for Action-Domain-Responder ▸ Web-specific refinement of Model-View-Controller https://github.com/pmjones/adr

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

AN ADR IMPLEMENTATION USING DUNGLASACTIONBUNDLE

Slide 30

Slide 30 text

AN ADR IMPLEMENTATION USING DUNGLASACTIONBUNDLE ACTION

Slide 31

Slide 31 text

AN ADR IMPLEMENTATION USING DUNGLASACTIONBUNDLE RESPONDER

Slide 32

Slide 32 text

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)

Slide 33

Slide 33 text

DUNGLASACTIONBUNDLE GIVE IT A STAR ON GITHUB https://github.com/dunglas/DunglasActionBundle

Slide 34

Slide 34 text

QUESTIONS?