Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Usnadněte si soužití s Doctrine
Filip Procházka
October 27, 2013
Technology
0
23
Usnadněte si soužití s Doctrine
Filip Procházka
October 27, 2013
Tweet
Share
More Decks by Filip Procházka
See All by Filip Procházka
Evolving architecture
fprochazka
0
52
Value objects in PHP
fprochazka
1
130
Jak psát testy na REST API
fprochazka
0
39
V gitu se nic neztratí
fprochazka
0
180
Co se PHP programátor může naučit od Javy?
fprochazka
1
52
4 roky remote
fprochazka
1
39
Před čím tě Nette ani Symfony neochrání
fprochazka
0
85
Nejlepší cache je žádná cache
fprochazka
0
53
Doctrine: co dělat, když entity nestačí
fprochazka
0
30
Other Decks in Technology
See All in Technology
2年で10→70人へ! スタートアップの 情報セキュリティ課題と施策
miekobayashi
1
200
GitHub Codespaces が拡げる開発環境、いつでもどこでも Visual Studio Code で!
dzeyelid
0
150
もし本番ネットワークをまるごと仮想環境に”コピー”できたらうれしいですか? / janog51
corestate55
0
120
230125 古いタブレットの活用 かーでぃさん
comucal
PRO
0
1k
OCI DevOps 概要 / OCI DevOps overview
oracle4engineer
PRO
0
470
CUEとKubernetesカスタムオペレータを用いた新しいネットワークコントローラをつくってみた
hrk091
0
240
ステート管理を超えるRecoil運用の考え方
uhyo
7
5.4k
ERC3525 Semi-Fungible token
sbtechnight
0
330
マネーフォワードクラウドを支える事業者基盤
machisuke
0
320
Akiba-dot-SaaS-ExtraHop
sakaitakeshi
1
110
目指せCoverage100%! AutoScale環境におけるSavings Plans購入戦略 / JAWS-UG_SRE_Coverage
taishin
0
350
Cloudflare Workersで動くOG画像生成器
aiji42
1
460
Featured
See All Featured
WebSockets: Embracing the real-time Web
robhawkes
58
6k
Thoughts on Productivity
jonyablonski
49
2.7k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
24
4.5k
KATA
mclloyd
12
9.7k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
38
3.6k
Learning to Love Humans: Emotional Interface Design
aarron
263
38k
Side Projects
sachag
451
37k
Designing for Performance
lara
600
65k
Stop Working from a Prison Cell
hatefulcrawdad
263
18k
Support Driven Design
roundedbygravity
88
8.9k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
29
7.8k
GitHub's CSS Performance
jonrohan
1020
430k
Transcript
Usnadněte si soužití s Doctrine Filip Procházka
Co si ukážeme? + Kdyby/Doctrine + Kdyby/Console + Kdyby/Events
Proč Kdyby? - Doctrine má spoustu skvělých vlastností - Doctrine
má spoustu otravných vlastností - Kdyby je plug&play (convention over configuration), tedy konfigurace na pár řádků a hned můžete pracovat
Instalace $ composer require \ kdyby/doctrine $ composer create-project \
hosiplan/project
Konfigurace extensions: annotations: Kdyby\Annotations\DI\AnnotationsExtension console: Kdyby\Console\DI\ConsoleExtension events: Kdyby\Events\DI\EventsExtension doctrine: Kdyby\Doctrine\DI\OrmExtension
Konfigurace doctrine: user: foo password: bar dbname: sandbox metadata: App:
%appDir%
Entita use Doctrine\ORM\Mapping as ORM; /** @ORM\Entity() */ class Article
extends \Kdyby\Doctrine\Entities\IdentifiedEntity { /** @ORM\Column(type="string") */ protected $title; }
BaseEntity? Ta je přece fuj! class Article extends BaseEntity {
private $one; protected $two; public $three; }
Skvělé na prototypování $article->getOne(); $article->one; $article->getTwo(); $article->two; $article->getThree(); $article->three; $article->addComment($comment);
$article->removeComment($comment);
Striktní validace schématu $ php www/index.php \ orm:validate
Entity potřebují tabulky... $ php www/index.php \ orm:schema:up --dump-sql
Proxy třídy kvůli lazy loadingu $ php www/index.php \ orm:generate:proxies
Repository DAO $articles = $entityManager ->getDao(App\Article::getClassName()); $articles = $entityManager ->getDao(App\Article::class);
Ne, repository nestačí... $article = new Article(); $article->title = "The
Tigger Movie"; $articles->save($article); $article = $articles->find(1); echo $article->title; // "The Tigger Movie"
Repozitář umí hezky nabobtnat class ArticlesDao extends EntityDao { function
findByTitle($title); function findByStepmothersBrothersEyeColor(); function findBy...(); }
Hlavně žádné další dědění! class ArticlesDao extends EntityDao { function
findByTitle($title); function findByStepmothersBrothersEyeColor(); function findBy...(); }
Krocení repozitářů http://www.whitewashing.de http://www.whitewashing.de/2013/03/04/doctrine_repositories.html http://filip-prochazka.com/blog/doctrine-a-service-vrstva-aneb-takto-mi-to-dava-smysl
Tak třeba objednávky... OrderModel - Order\UserOpening - Order\Dispatching - Order\Delivery
- ….
Eventy: systémové listenery class EditLogger implements Kdyby\Events\Subscriber { function getSubscribedEvents()
{ return array('postUpdate'); } function postUpdate() { } }
Eventy: systémové listenery services: something: class: App\EditLogger tags: [kdyby.subscriber]
ResultSet $dql = $articles->createQuery("SELECT a FROM Articles a"); $articles =
new Kdyby\Doctrine\ResultSet($dql); $articles->applyPaginator($this['vp']->paginator);
Utilitky Helpers::loadFromFile() Tools\NonLockingUniqueInserter
Dotazy?
Filip Procházka http://filip-prochazka.com http://www.kdyby.org