One area that was mostly abandoned in applications is the Model layer. Doctrine is a project that brings enterprise support this layer through a powerful ORM implementation.
Allied with new support introduced in PHP 5.3, Doctrine 2.0 brings the concept of ORM in PHP to the next level. It introduces a couple of concepts known from other languages and areas, like Annotations, Object Query Languages and Parsers. This talk will introduce these new concepts as well as explain most of its architecture.
2. • Frontend web developer since 1998
• Moved to backend programming in 2002
• Currently employee of MIH – SWAT team
• Committer of many O.S. projects, including
Zend Framework, Symfony and Doctrine
• Enjoys to play Age of Empires
3. Doctrine is an Object Relational Modeling tool
for PHP, mostly inspired by Hibernate (Java)
and ActiveRecord (Ruby)
4. • Very active community
• Monthly releases
• Current work branches:
– 1.0 (LTS), 1.1, 1.2 (LTS), 2.0 (LTS)
5. • Integrates with many different frameworks:
– Zend Framework
– Symfony
– CodeIgniter
– Kohana
– …
• Supports all drivers supported by PDO
6. • Based on JSR-317 a.k.a. JPA v2.0 (~80%)
• Java…. What?!? #$&*@!
• PHP still lacks of standards
• PHP Standards Group to the rescue!
8. • No need to extend base class
• New Reflection support
• Benchmarks (˜50000 iterations):
– Setter:
• $o->prop set: 0.35872411727905
• $o->setProp: 0.61513090133667 (71% slower)
• $reflProp->setValue: 0.67149507522583 (87% slower)
– Getter:
• $o->prop get: 0.25784397125244
• $o->getProp: 0.46534395217896 (80% slower)
• $reflProp->getValue: 0.64541401863098 (150% slower)
9. • Optimize hydration of entities
• Garbage Collector – Identity Map
• spl_object_hash
• SplObjectStorage vs. ArrayAccess
10. • Optimize hydration of Entities
• Benchmarks:
– Doctrine 1.1
• 4.3435637950897 for 5000 records
– Doctrine 2.0
• 1.4314442552312 for 5000 records
• 3.4690098762528 for 10000 records
11. • Replication support
• Internal mindset change
• No more weird DSN constructions
• No more shared Identity Maps across multiple
connections
12. • Huge API of public methods
• Lambdas and Closures
• Centralized entry points of methods
• No singleton nightmares!
- I have a problem!
- You can fix it with a singleton.
- Now I have 2 problems…
13. • RDBMS <-> PHP differences
• Clean separation of Platforms via Dialects
• Separation between DB value and PHP value
• Extendable to user land
14. • String processing for DQL
• Implemented a LL(*) parser
• Constructs AST nodes
• TreeWalkers to do compilation DQL -> SQL
• Cache support to prevent overhead
15. • Metadata Mapping
• Extendable mapping drivers
• Should not mess Entities code – VOs
• Cache support to prevent overhead
16. • Real Native SQL support
• Introduction of ResultsetMapping support
• Allow custom columns to be mapped into VOs
• Specific DBMS SQL supported
26. • Use DBAL independent of ORM
• Powerful Database Abstraction Layer
• Always existed, but it wasn’t advertised
• Can be a separate package in the future
38. • Doctrine Query Language
– Similar do HQL or JPQL
– Automatically makes join restrictions
– Supports inheritance natively
– Can be boosted by usage of a Query Cache
– Easily extendable
Project started in 2005/2006 by Konsta
Currently maintained by Jonathan Wage, Roman Borschel and Guilherme Blanco
Active community:
IRC, Mailing List, Cookbook, etc
1.0 LTS (support ends in March 2010)
1.1 (supports ends in November 2009)
1.2 LTS (support ends in March 2011)
2.0 LTS (support ends in March 2011)
Doctrine team follows all functional specs
Wants to contribute to PHP Standards Group
Optimize Reflection even more!
Hydration start/end: memory remains almost the same amount (thanks to GC!)
EntityManagers for the rescue!
Sharding in the future? Maybe in 2.X!
Dialects reuse methods of Platforms
SchemaManagers are responsible for complex tasks (CREATE TABLE, INDEX, UPDATE TABLE, etc)
Top-down recursive descent parser
AST class names follows EBNF grammar rules
Reuses Platform to support SQL differences
Annotations support is a LL(*) parser too =D
OTHER STUFF!!!
CLI Tasks - DAGs to control options dependencies and exclusions TBF!
Reverse engineering (DB -> VOs + Mappings)
Mapping conversion between drivers
Schema Generation Tool (create, drop & update)
Proxy Objects (for Lazy-Loading)
Event System
Centralized Configuration
Multi-level Caching support (APC, Memcache, Xcache)
Self referencing, one-to-one, one-to-many, many-to-many
Owning side and inverse side. Owning side determines updates to Database
DQL: Looks like SQL, but it isn’t!
Supports SELECT, UPDATE and DELETE