Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Plongée dans l'injection de dépendances de Symfony
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Titouan Galopin
April 27, 2019
Programming
1.3k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Plongée dans l'injection de dépendances de Symfony
Titouan Galopin
April 27, 2019
More Decks by Titouan Galopin
See All by Titouan Galopin
Concevoir son API pour le futur
tgalopin
2
1.8k
Content editing in Symfony
tgalopin
3
1.2k
Symfony UX: a new JavaScript ecosystem for Symfony
tgalopin
4
4.2k
[SymfonyLive Paris 2020] Pragmatic frontend for Symfony developers
tgalopin
2
1.2k
SymfonyInsight: How to setup quality processes in Symfony apps
tgalopin
2
440
Symfony 5 - AFUP Day Lille 2020
tgalopin
1
1k
Pragmatic frontend for Symfony developers
tgalopin
2
1.4k
Demystifying React for Symfony developers
tgalopin
2
860
Symfony 5
tgalopin
1
750
Other Decks in Programming
See All in Programming
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
540
Oxcを導入して開発体験が向上した話
yug1224
4
310
Vite+ Unified Toolchain for the Web
naokihaba
0
300
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
7
4.4k
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.4k
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
540
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
2
340
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
21
6.6k
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
230
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
130
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
300
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
280
How to build a perfect <img>
jonoalderson
1
5.6k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
330
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
230
A Soul's Torment
seathinner
6
2.9k
sira's awesome portfolio website redesign presentation
elsirapls
0
280
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
140
Transcript
Plongée dans l'injection de dépendances de Symfony Avril 2019 SymfonyLive
Tunis
Titouan Galopin @tgalopin 2 insight.symfony.com
3 Une question m’obnubile …
4 Pourquoi l’architecture logicielle est-elle importante ?
5 Qu’est-ce qui différencie du code bien conçu et du
code mal conçu ?
6 La gestion du changement
7 Une architecture logicielle de qualité, c’est une architecture qui
accompagne le changement
8 Changement ... Dans le temps Dans l’environnement
9 Comment concevoir une architecture qui accompagne le changement ?
10 Créer des classes qui se partagent les responsabilités
11 Elles interagissent pour constituer l’application
12 Elles sont modifiables indépendamment les unes des autres
13 Mailer Persister RegistrationManager Swiftmailer Twig Doctrine
14 Mailer Persister RegistrationManager Swiftmailer Twig Doctrine
15 Mailer Persister RegistrationManager Swiftmailer Twig Doctrine Contrats (= Interfaces)
16 interface PersisterInterface { /* ... */ } interface MailerInterface
{ /* ... */ } class RegistrationManager { private $persister; private $mailer; public function __construct( PersisterInterface $persister, MailerInterface $mailer ) { $this->persister = $persister; $this->mailer = $mailer; } public function register() {/* ... */} }
17 C’est l’injection de dépendances
18 Encapsuler des objets dans d’autres pour créer des comportements
complexes
19 Faciliter le changement par l’utilisation de contrats
20 Mais créer un objet devient plus compliqué
21 $manager = new RegistrationManager( new Persister( new Doctrine(/* ...
*/) ), new Mailer( new Twig(/* ... */), new SwiftMailer(/* ... */) ) );
22 Symfony DependencyInjection
23 Objectif : permettre la création aisé d’instances de classes
24 Configurer ce graphe de dépendances entre classes
25 interface PersisterInterface { /* ... */ } interface MailerInterface
{ /* ... */ } class RegistrationManager { private $persister; private $mailer; public function __construct( PersisterInterface $persister, MailerInterface $mailer ) { $this->persister = $persister; $this->mailer = $mailer; } public function register() {/* ... */} }
26 $manager = new RegistrationManager( new Persister( new Doctrine(/* ...
*/) ), new Mailer( new Twig(/* ... */), new SwiftMailer(/* ... */) ) ); Objectif
27 Fonctionnement général 1 Configuration 2 Compilation 3 Utilisation
28 1. Configuration services.yaml
29 Mailer Persister RegistrationManager Swiftmailer Twig Doctrine
30 services: # ... App\Persister: arguments: ['@doctrine'] App\Mailer: arguments: ['@twig',
'@swiftmailer] App\RegistrationManager: arguments: ['@App\Persister', '@App\Mailer']
31 Depuis Symfony 4 : Autodiscovery Autowiring
32 services: _defaults: autowire: true App\: resource: '../src/*'
33 services: _defaults: autowire: true App\: resource: '../src/*' Autodiscovery :
importe toutes les classes dans src/ en tant que noeuds du graphe
34 services: _defaults: autowire: true App\: resource: '../src/*' Autodiscovery :
importe toutes les classes dans src/ en tant que noeuds du graphe Autowiring : créé les liens entre les noeuds du graphe automatiquement
35 Mailer Persister RegistrationManager Swiftmailer Twig Doctrine Autodiscovery Autowiring
36 2. Compilation
37 On a maintenant un graphe de dépendances
38 On sait donc créer une instance de classe
39 Mais passer par le graphe directement, c’est lent
40 Compiler le graphe de dépendances = Le transformer en
PHP
41
42 Nouvelle possibilité : modifier le graphe entre la configuration
et l’utilisation
43 CompilerPass = Modification du graphe au moment de la
compilation
44 3. Utilisation
45 Transparente !
46 Les points d’entrée de votre application (contrôleurs, commandes, …)
font partie du graphe !
47 class RegistrationController extends AbstractController { /** * @Route("/register", name="register")
*/ public function register(RegistrationManager $manager) { // ... $manager->register($user); // ... } }
48 Mailer Persister RegistrationManager Swiftmailer Twig Doctrine RegistrationController
49 Beaucoup d’autres fonctionnalités Tags, bindings, named autowiring aliases, autoconfiguration,
factories, decorators, ...
50 Contribuez ! symfony.com/support => Slack Pinguez Nicolas Grekas
51 Merci ! Venez me voir au stand SymfonyInsight !
▪ Twitter : @titouangalopin ▪ Github : @tgalopin ▪
[email protected]