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
Dependency injection v Nette 2.1 prakticky
Search
Filip Procházka
January 27, 2014
Technology
0
50
Dependency injection v Nette 2.1 prakticky
Filip Procházka
January 27, 2014
Tweet
Share
More Decks by Filip Procházka
See All by Filip Procházka
Evolving architecture
fprochazka
0
230
Value objects in PHP
fprochazka
1
220
Jak psát testy na REST API
fprochazka
0
110
V gitu se nic neztratí
fprochazka
0
400
Co se PHP programátor může naučit od Javy?
fprochazka
1
130
4 roky remote
fprochazka
1
88
Před čím tě Nette ani Symfony neochrání
fprochazka
0
150
Nejlepší cache je žádná cache
fprochazka
0
130
Doctrine: co dělat, když entity nestačí
fprochazka
0
75
Other Decks in Technology
See All in Technology
LLM活用の壁を超える:リクルートR&Dの戦略と打ち手
recruitengineers
PRO
1
240
Introduction to Sansan, inc / Sansan Global Development Center, Inc.
sansan33
PRO
0
3k
GitLab Duo Agent Platform + Local LLMサービングで幸せになりたい
jyoshise
0
110
AI時代にエンジニアはどう成長すれば良いのか?
recruitengineers
PRO
1
140
OpenClawで回す組織運営
jacopen
2
390
管理者向けGitHub Enterpriseの運用Tips紹介: 人にもAIにも優しいプラットフォームづくり
yuriemori
0
110
OSSで構築するIT基盤管理実践事例: NetBox・Snipe-IT・FreeRADIUS+PrivacyIDEA / Practical Case Studies of IT Infrastructure Management Using OSS
nttcom
0
200
LINE Messengerの次世代ストレージ選定
lycorptech_jp
PRO
19
7.3k
Datadog Cloud Cost Management で実現するFinOps
taiponrock
PRO
0
140
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
15
95k
生成AIの利用とセキュリティ /gen-ai-and-security
mizutani
1
1.2k
ブラックボックス観測に基づくAI支援のプロトコルのリバースエンジニアリングと再現~AIを用いたリバースエンジニアリング~ @ SECCON 14 電脳会議 / Reverse Engineering and Reproduction of an AI-Assisted Protocol Based on Black-Box Observation @ SECCON 14 DENNO-KAIGI
chibiegg
0
140
Featured
See All Featured
Speed Design
sergeychernyshev
33
1.6k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.2k
Six Lessons from altMBA
skipperchong
29
4.2k
The Limits of Empathy - UXLibs8
cassininazir
1
240
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.4k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
80
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Exploring anti-patterns in Rails
aemeredith
2
280
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
130
Agile that works and the tools we love
rasmusluckow
331
21k
Unsuck your backbone
ammeep
672
58k
Transcript
Nette ❤ DI @ProchazkaFilip - @Damejidlo
Co si povíme? - rychle prolítneme teorii DI - jak
to funguje v Nette - jak napsat použitelné rozšíření
Teorie: typy injekce - konstruktor - setter - property -
magie
Konstruktor injection class Cart extends Nette\Object { private $entityManager; public
function __construct(EntityManager $em) { $this->entityManager = $em; } http://wbab.suffolk.lib.ny.us/wp-content/uploads/2013/12/medals.jpg
Setter injection class Cart extends Nette\Object { private $entityManager; public
function setEntityManager(EntityManager $em) { $this->entityManager = $em; } http://wbab.suffolk.lib.ny.us/wp-content/uploads/2013/12/medals.jpg
Property injection class Cart extends Nette\Object { /** @var EntityManager
*/ public $entityManager; http://wbab.suffolk.lib.ny.us/wp-content/uploads/2013/12/medals.jpg
Magic injection class Cart extends Nette\Object { /** @var EntityManager
*/ private $entityManager; http://www.wyatt-lorenz.com/images/biohazard_warnings.jpg
Teorie: slovníček - DI Container (composition root) - služby -
implementace / abstrakce
Praxe: konfigurace - služby - rozšíření
Registrace služby services: - Damejidlo\Cart()
Konfigurace rozšíření nette: latte: macros: - Assets\CssMacro
Bacha na zanoření parameters: services: nette:
Praxe: typy služeb - modely - presentery - komponenty
Modely - konstruktor (99.99%) - setter (když jsi v úzkých)
- property (ehm?)
Presentery - konstruktor (myslím že ne Time) - setter inject*()
(přihořívá) - property @inject (vítěz!) /** @var Damejidlo\Cart @inject */ public $cart;
Presentery services: productListPresenter: class: ShopModule\ProductsPresenter() setup: - $tempPath(%tempPath%) # nebo
- BlogModule\ArticlePresenter()
Komponenty - konstruktor (ano prosím!) - setter (meh?) - property
(bleh)
Komponenty v presenterech protected function createComponentForm() { return new OrderForm($entityManager???)
}
Ruční továrničky class OrderFormFactory { private $em; function __construct(EntityManager $em)
{ … } /** @return OrderForm */ public function create() { return new OrderForm($this->em); }
Generované továrničky interface IOrderFormFactory { /** @return OrderForm */ function
create(); }
Generované továrničky services: orderFormFactory: implement: IOrderFormFactory # nebo - {implement:
IOrderFormFactory}
Generované továrničky /** @var IOrderFormFactory @inject */ public $orderFormFactory; protected
function createComponentOrderForm() { $form = $this->orderFormFactory->create(); $form->onSuccess[] = ...; return $form }
Rozšíření class OrmExtension extends CompilerExtension { # vytvori služby public
function loadConfiguration() { } # upravuje své a jiné služby public function beforeCompile() { } # hackuje DI container public function afterCompile() { }
Dobré rozšíření - Composer - MUST HAVE - Jednoduchá registrace
- Convention over Configuration - validujte
Dotazy?