Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Solutions avec Doctrine 2.0
Search
Anna Filina
May 05, 2011
Programming
44
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Solutions avec Doctrine 2.0
Anna Filina
May 05, 2011
Transcript
29 slides
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
More Decks by Anna Filina
See All by Anna Filina
Surviving a Symfony Upgrade
afilina
1
220
Upgrading Legacy to the Latest PHP Version
afilina
1
250
Better Code Design in PHP
afilina
0
340
Semi-Automated Refactoring and Upgrades with Rector
afilina
0
250
Better Code Design in PHP
afilina
1
500
Better Code Design in PHP
afilina
0
680
Adding Tests to Untestable Legacy Code
afilina
0
460
Upgrading Legacy to the Latest PHP Version
afilina
0
470
Semi-Automated Refactoring and Upgrades with Rector
afilina
0
370
Other Decks in Programming
See All in Programming
Promiseの向こう側へコンテキストを届ける ― proposal-async-context
seriseri
0
710
DroidKnights 2026 Android A2UI Jetpack Compose 기반의 안전한 AI UI 렌더링 - 박제창
itsmedreamwalker
1
270
LLM 101: Exploring LLMs, Starting with Tokens.
dalinaum
0
120
AIコーディング時代のKotest ユニットテストから APIレベルの仕様固定化テストへ
ooga04
0
340
Proxmox x Talos Linux x Terraform で実現するなんかいい感じの Kubernetes クラスタ / A Sleek Kubernetes Cluster Powered by Proxmox, Talos Linux, and Terraform
nnaka2992
0
320
コード生成時代のAPI定義を支えるRequest Spec移行
pvcresin
0
310
エラーチャンネルのボールを拾い続けて鍛えるエンジニアの地力 / phpcon-niigata2026
meihei3
1
520
RaspberryPi 5で軽くはじめるk3sとtailscaleを用いたホームサーバー構築 (1)
nasum
0
450
はじめてのPLATEAU
nokonoko1203
1
680
Spec-driven Development with AI
simas
PRO
0
2.3k
マルチプロダクトSaaSの アプリ一覧を速くする——複数プロダクトにまたがる「権限行脚」を減らすまで #techramen26conf
mktakuya
1
260
なぜ私たちは「現時点では」KMPの導入を見送ったのか
chigichan24
1
650
Featured
See All Featured
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
2
2.1k
Music & Morning Musume
bryan
48
7.5k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.7k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
A designer walks into a library…
pauljervisheath
211
25k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
2
540
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
590
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
380
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Scaling GitHub
holman
464
140k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.3k