Enterprise Persistence Layer for PHP
• Frontend web developer since 1998
• Moved to backend programming in 2002
• Currently employee of MIH – SWAT team
• Commi...
Doctrine is an Object Relational Modeling tool
for PHP, mostly inspired by Hibernate (Java)
and ActiveRecord (Ruby)
• Very active community
• Monthly releases
• Current work branches:
– 1.0 (LTS), 1.1, 1.2 (LTS), 2.0 (LTS)
• Integrates with many different frameworks:
– Zend Framework
– Symfony
– CodeIgniter
– Kohana
– …
• Supports all drivers ...
• Based on JSR-317 a.k.a. JPA v2.0 (~80%)
• Java…. What?!? #$&*@!
• PHP still lacks of standards
• PHP Standards Group to ...
Challenges
• No need to extend base class
• New Reflection support
• Benchmarks (˜50000 iterations):
– Setter:
• $o->prop set: 0.3587...
• Optimize hydration of entities
• Garbage Collector – Identity Map
• spl_object_hash
• SplObjectStorage vs. ArrayAccess
• Optimize hydration of Entities
• Benchmarks:
– Doctrine 1.1
• 4.3435637950897 for 5000 records
– Doctrine 2.0
• 1.431444...
• Replication support
• Internal mindset change
• No more weird DSN constructions
• No more shared Identity Maps across mu...
• Huge API of public methods
• Lambdas and Closures
• Centralized entry points of methods
• No singleton nightmares!
- I h...
• RDBMS <-> PHP differences
• Clean separation of Platforms via Dialects
• Separation between DB value and PHP value
• Ext...
• String processing for DQL
• Implemented a LL(*) parser
• Constructs AST nodes
• TreeWalkers to do compilation DQL -> SQL...
• Metadata Mapping
• Extendable mapping drivers
• Should not mess Entities code – VOs
• Cache support to prevent overhead
• Real Native SQL support
• Introduction of ResultsetMapping support
• Allow custom columns to be mapped into VOs
• Specif...
• Commit ordering
• True multigraph implementation
• Topological Sorting
• Prevents cycles
• F*cking incredible fast!
Almost 95% of codebase rewritten
Requires PHP 5.3
Simplified public API
Smaller footprint
Un-necessary clutter removed
No more cyclic references
Code heavily decoupled
Extremely extendable
• Three main packages:
– Common
– DBAL
– ORM
– Maybe in the future ODM…
• Anyone interested to contribute?
• Class Loaders
• Annotations support
• Collection
• Cache
• Event System
• Common LL(*) classes
• Class loaders:
– GlobalClassLoader
– IsolatedClassLoader
• Annotations EBNF – Yeah baby!
Annotation ::= "@" AnnotationName ["(" [Values] ")”]
AnnotationName ::= QualifiedName | Si...
• Use DBAL independent of ORM
• Powerful Database Abstraction Layer
• Always existed, but it wasn’t advertised
• Can be a ...
• Platforms, Drivers and SchemaManagers
• Nested transactions
• Fully supports:
– Schemas
– Sequences
– Catalogs
• Supports:
– One-to-one
– One-to-many
– Many-to-many
• Multigraph
– Unidirectional
– Bidirectional
• Simplified bootstrap code
• Driver based Metadata
– Annotations
– PHP
– XML
– YAML
– … your own?!
• Working with objects
• Doctrine Query Language
– Similar do HQL or JPQL
– Automatically makes join restrictions
– Supports inheritance natively...
• Querying
– DQL string
– QueryBuilder object (Criteria)
– Native SQL query
• Directed Acyclic Graphs
• Easily extendable
• Several handy tasks to help development
– Schema-tool
– Generate-proxies
–...
Guilherme Blanco
guilhermeblanco gmail com
+55 16 9215.8480
http://www.doctrine-project.org
Doctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHP
Doctrine 2.0 Enterprise Persistence Layer for PHP
Upcoming SlideShare
Loading in …5
×

Doctrine 2.0 Enterprise Persistence Layer for PHP

7,388 views

Published on

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.

Published in: Technology
0 Comments
13 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
7,388
On SlideShare
0
From Embeds
0
Number of Embeds
141
Actions
Shares
0
Downloads
122
Comments
0
Likes
13
Embeds 0
No embeds

No notes for slide
  • 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
  • Criteria: Fluent vs. Programmatically API
  • Doctrine 2.0 Enterprise Persistence Layer for PHP

    1. Enterprise Persistence Layer for PHP
    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!
    7. Challenges
    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
    17. • Commit ordering • True multigraph implementation • Topological Sorting • Prevents cycles • F*cking incredible fast!
    18. Almost 95% of codebase rewritten Requires PHP 5.3
    19. Simplified public API Smaller footprint
    20. Un-necessary clutter removed No more cyclic references
    21. Code heavily decoupled Extremely extendable
    22. • Three main packages: – Common – DBAL – ORM – Maybe in the future ODM… • Anyone interested to contribute?
    23. • Class Loaders • Annotations support • Collection • Cache • Event System • Common LL(*) classes
    24. • Class loaders: – GlobalClassLoader – IsolatedClassLoader
    25. • Annotations EBNF – Yeah baby! Annotation ::= "@" AnnotationName ["(" [Values] ")”] AnnotationName ::= QualifiedName | SimpleName QualifiedName ::= NameSpacePart "" {NameSpacePart ""}* SimpleName NameSpacePart ::= identifier SimpleName ::= identifier Values ::= Array | Value {"," Value}* Value ::= PlainValue | FieldAssignment PlainValue ::= integer | string | float | boolean | Array | Annotation FieldAssignment ::= FieldName "=" PlainValue FieldName ::= identifier Array ::= "{" ArrayEntry {"," ArrayEntry}* "}” ArrayEntry ::= Value | KeyValuePair KeyValuePair ::= Key "=" PlainValue Key ::= string | integer
    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
    27. • Platforms, Drivers and SchemaManagers • Nested transactions • Fully supports: – Schemas – Sequences – Catalogs
    28. • Supports: – One-to-one – One-to-many – Many-to-many • Multigraph – Unidirectional – Bidirectional
    29. • Simplified bootstrap code
    30. • Driver based Metadata – Annotations – PHP – XML – YAML – … your own?!
    31. • Working with objects
    32. • 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
    33. • Querying – DQL string – QueryBuilder object (Criteria) – Native SQL query
    34. • Directed Acyclic Graphs • Easily extendable • Several handy tasks to help development – Schema-tool – Generate-proxies – Convert-mapping – Run-sql – Run-dql
    35. Guilherme Blanco guilhermeblanco gmail com +55 16 9215.8480 http://www.doctrine-project.org

    ×