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
Solutions avec Doctrine 2.0
Search
Anna Filina
May 05, 2011
Programming
38
0
Share
Solutions avec Doctrine 2.0
Anna Filina
May 05, 2011
More Decks by Anna Filina
See All by Anna Filina
Surviving a Symfony Upgrade
afilina
1
170
Upgrading Legacy to the Latest PHP Version
afilina
1
180
Better Code Design in PHP
afilina
0
300
Semi-Automated Refactoring and Upgrades with Rector
afilina
0
190
Better Code Design in PHP
afilina
1
450
Better Code Design in PHP
afilina
0
620
Adding Tests to Untestable Legacy Code
afilina
0
390
Upgrading Legacy to the Latest PHP Version
afilina
0
420
Semi-Automated Refactoring and Upgrades with Rector
afilina
0
320
Other Decks in Programming
See All in Programming
ついに来た!本格的なマルチクラウド時代の Google Cloud
maroon1st
0
220
iOS機能開発のAI環境と起きた変化
ryunakayama
0
190
AWS re:Invent 2025の少し振り返り + DevOps AgentとBacklogを連携させてみた
satoshi256kbyte
3
170
Cache-moi si tu peux : patterns et pièges du cache en production - Devoxx France 2026 - Conférence
slecache
0
280
Running Swift without an OS
kishikawakatsumi
0
850
AIベース静的検査器の偽陽性率を抑える工夫3選
orgachem
PRO
3
350
CursorとClaudeCodeとCodexとOpenCodeを実際に比較してみた
terisuke
1
490
Spec Driven Development | AI Summit Vilnius
danielsogl
PRO
1
110
年間50登壇、単著出版、雑誌寄稿、Podcast出演、YouTube、CM、カンファレンス主催……全部やってみたので面白さ等を比較してみよう / I’ve tried them all, so let’s compare how interesting they are.
nrslib
4
800
ふりがな Deep Dive try! Swift Tokyo 2026
watura
0
230
AIと共に生きる技術選定 2026
sgash708
0
100
Making the RBS Parser Faster
soutaro
0
500
Featured
See All Featured
Skip the Path - Find Your Career Trail
mkilby
1
110
Designing Powerful Visuals for Engaging Learning
tmiket
1
350
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.2k
Being A Developer After 40
akosma
91
590k
Color Theory Basics | Prateek | Gurzu
gurzu
0
290
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
900
How to build a perfect <img>
jonoalderson
1
5.4k
A better future with KSS
kneath
240
18k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
680
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.2k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Transcript
Solutions avec Doctrine 2.0 PHP Québec, 5 mai 2011
Anna Filina PHP Québec - groupe d’utilisateurs ConFoo - conférence
sans but lucratif FooLab - solution TI pour entreprises
Étendue ORM... De Kessé??? Setup Commandes de base Cas d’utilisation
en entreprise Gestion de rôles API
Pourquoi un ORM? Abstraction du SQL Standardiser Simplifier Réutilisation et
extensibilité
Setup
Entités class Invoice { public $id; public $items; public $total;
}
Entités: table /** * @Entity * @Table(name="invoice") */ class Invoice
{
Entités: colonne /** * @Id * @Column(type="integer") * @GeneratedValue */
public $id;
Bootstrap: driver $connectionOptions = array( 'driver' => 'pdo_sqlite', 'path' =>
'database.sqlite' );
Schéma >./doctrine orm:schema-tool:create
Commandes de base
Persistance $entityManager = EntityManager::create($conn, $config); $invoice = new Invoice(); $invoice->total
= 35.00; $entityManager->persist($invoice); $entityManager->flush();
Persistance avec relations $invoice = new Invoice(); $item = new
Item(); $item->name = 'Unicorn'; $invoice->items[] = $item; $entityManager->persist($invoice); $entityManager->flush();
Relation dans l’entité /** * @ManyToMany(targetEntity="Item", * cascade={"persist"}) */ public
$items;
Requêtes $query = $entityManager->createQuery( 'SELECT inv FROM Invoice inv'); $invoices
= $query->getResult();
Requêtes: left join $query = $entityManager->createQuery( 'SELECT inv, item FROM
Invoice inv LEFT JOIN inv.items item'); $invoices = $query->getResult();
Requêtes: left join array 'id' => 284 'total' => 0
'items' => array 0 => array 'id' => 279 'name' => 'Rainbow' 'price' => 10 'quantity' => 3 1 => array 'id' => 280 'name' => 'Unicorn' 'price' => 15 'quantity' => 2
Cas d’utilisation: Gestion de rôles
Rôles Admin: modifier tout Author: modifier projets de la compagnie
Reader: voir projets publiés seulement
Filtres Admin: * Author: WHERE project.organisation_id = ? Reader: WHERE
project.organisation_id = ? AND project.status = “Published”
Author class Author implements Role { public function filterQuery(&$q) {
$a = $q->getRootAlias(); $q->add('where', $a.'.organisation_id = :org_id'); $q->setParameter('org_id', $this->org_id); } }
Reader class Reader implements Role { public function filterQuery(&$q) {
$a = $q->getRootAlias(); $q->add('where', $a.'.organisation_id = :org_id'); $q->setParameter('org_id', $this->org_id); $q->add('where', $a.'.status = "Published"'); } }
Cas d’utilisation: API
API But: via AJAX, récupérer des données du serveur et
injecter dans une page Input: critères de recherche pour une liste Output: liste filtrée et paginée
Javascript $.ajax({ url: '/project.json', data: { page: 0, pageSize: 10
} success: function(json) { refreshHtmlTable(json); } });
PHP class API { public function process($entity, $filters) { $q
= $entity->getBaseQuery(); $q->setMaxResults($filters['pageSize']); $q->setFirstResult( $filters['pageSize'] * $filters['page']); $result = $q->getQuery() ->getResult(Query::HYDRATE_ARRAY); return json_encode($result); } }
Bonus Level!
Combinaisons class API { public function process($entity, $filters) { //
[...] $this->user->role->filterQuery($q); $q->getQuery()->useResultCache(true, 3600, 'uid'); // [...] } }
http://www.doctrine-project.org http://annafilina.com