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
160
Upgrading Legacy to the Latest PHP Version
afilina
1
180
Better Code Design in PHP
afilina
0
290
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
610
Adding Tests to Untestable Legacy Code
afilina
0
390
Upgrading Legacy to the Latest PHP Version
afilina
0
410
Semi-Automated Refactoring and Upgrades with Rector
afilina
0
320
Other Decks in Programming
See All in Programming
AI Assistants for YourAngular Solutions @Angular Graz, March 2026
manfredsteyer
PRO
0
140
Laravel Nightwatchの裏側 - Laravel公式Observabilityツールを支える設計と実装
avosalmon
1
300
PHP でエミュレータを自作して Ubuntu を動かそう
m3m0r7
PRO
2
160
メッセージングを利用して時間的結合を分離しよう #phperkaigi
kajitack
3
540
飯MCP
yusukebe
0
460
Agentic AI: Evolution oder Revolution
mobilelarson
PRO
0
230
The free-lunch guide to idea circularity
hollycummins
0
400
Xdebug と IDE による デバッグ実行の仕組みを見る / Exploring-How-Debugging-Works-with-Xdebug-and-an-IDE
shin1x1
0
310
Mastering Event Sourcing: Your Parents Holidayed in Yugoslavia
super_marek
0
130
Claude Codeログ基盤の構築
giginet
PRO
7
3.8k
Coding as Prompting Since 2025
ragingwind
0
640
見せてもらおうか、 OpenSearchの性能とやらを!
shunta27
1
170
Featured
See All Featured
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.5k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
300
Speed Design
sergeychernyshev
33
1.6k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
510
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
320
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.1k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
170
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.4k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.1k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.9k
Docker and Python
trallard
47
3.8k
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