doctrine 2.0 enterprise persistence layer for php

46
Doctrine 2.0 Enterprise Persistence Layer for PHP

Upload: guilherme-blanco

Post on 10-May-2015

5.162 views

Category:

Technology


3 download

DESCRIPTION

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.

TRANSCRIPT

Page 1: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0

Enterprise Persistence Layer for PHP

Page 2: Doctrine 2.0 Enterprise Persistence Layer for PHP

Who am I?

• 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

Page 3: Doctrine 2.0 Enterprise Persistence Layer for PHP

What is Doctrine?

Doctrine is an Object Relational Modeling tool for PHP, mostly inspired by Hibernate (Java)

and ActiveRecord (Ruby)

Page 4: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine Roadmap

• Very active community• Monthly releases• Current work branches: – 1.0 (LTS), 1.1, 1.2 (LTS), 2.0 (LTS)

Page 5: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine Integration & Support

• Integrates with many different frameworks:– Zend Framework– Symfony– CodeIgniter– Kohana– …

• Supports all drivers supported by PDO

Page 6: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - Architecture

• Based on JSR-317 a.k.a. JPA v2.0 (~80%)• Java…. What?!? #$&*@!• PHP still lacks of standards• PHP Standards Group to the rescue!

Page 7: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0

Challenges

Page 8: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - Challenges

• 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)

Page 9: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - Challenges

• Optimize hydration of entities• Garbage Collector – Identity Map• spl_object_hash• SplObjectStorage vs. ArrayAccess

Page 10: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - Challenges

• 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

Page 11: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - Challenges

• Replication support• Internal mindset change• No more weird DSN constructions• No more shared Identity Maps across multiple

connections

Page 12: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - Challenges

• 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…

Page 13: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - Challenges

• RDBMS <-> PHP differences• Clean separation of Platforms via Dialects• Separation between DB value and PHP value• Extendable to user land

Page 14: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - Challenges

• String processing for DQL• Implemented a LL(*) parser• Constructs AST nodes• TreeWalkers to do compilation DQL -> SQL• Cache support to prevent overhead

Page 15: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - Challenges

• Metadata Mapping• Extendable mapping drivers• Should not mess Entities code – VOs• Cache support to prevent overhead

Page 16: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - Challenges

• Real Native SQL support• Introduction of ResultsetMapping support• Allow custom columns to be mapped into VOs• Specific DBMS SQL supported

Page 17: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - Challenges

• Commit ordering• True multigraph implementation• Topological Sorting• Prevents cycles• F*cking incredible fast!

Page 18: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0

Almost 95% of codebase rewrittenRequires PHP 5.3

Page 19: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0

Simplified public APISmaller footprint

Page 20: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0

Un-necessary clutter removedNo more cyclic references

Page 21: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0

Code heavily decoupledExtremely extendable

Page 22: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0

• Three main packages:– Common– DBAL– ORM

– Maybe in the future ODM…• Anyone interested to contribute?

Page 23: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - Common

• Class Loaders• Annotations support• Collection• Cache• Event System• Common LL(*) classes

Page 24: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - Common

• Class loaders:– GlobalClassLoader

– IsolatedClassLoader

Page 25: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - Common• Annotations EBNF – Yeah baby!

Annotation ::= "@" AnnotationName ["(" [Values] ")”]AnnotationName ::= QualifiedName | SimpleNameQualifiedName ::= NameSpacePart "\" {NameSpacePart "\"}*

SimpleNameNameSpacePart ::= identifierSimpleName ::= identifierValues ::= Array | Value {"," Value}*Value ::= PlainValue | FieldAssignmentPlainValue ::= integer | string | float | boolean | Array |

AnnotationFieldAssignment ::= FieldName "=" PlainValueFieldName ::= identifierArray ::= "{" ArrayEntry {"," ArrayEntry}* "}”ArrayEntry ::= Value | KeyValuePairKeyValuePair ::= Key "=" PlainValueKey ::= string | integer

Page 26: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - DBAL

• Use DBAL independent of ORM• Powerful Database Abstraction Layer• Always existed, but it wasn’t advertised• Can be a separate package in the future

Page 27: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - DBAL

• Platforms, Drivers and SchemaManagers• Nested transactions• Fully supports:– Schemas– Sequences– Catalogs

Page 28: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - DBAL

Page 29: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - DBAL

Page 30: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - ORM

• Supports:– One-to-one– One-to-many– Many-to-many

• Multigraph– Unidirectional– Bidirectional

Page 31: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - ORM

• Simplified bootstrap code

Page 32: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - ORM

• Driver based Metadata– Annotations– PHP– XML– YAML– … your own?!

Page 33: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - ORM

Page 34: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - ORM

Page 35: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - ORM

Page 36: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - ORM

Page 37: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - ORM

• Working with objects

Page 38: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - ORM

• 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

Page 39: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - ORM

• Querying– DQL string– QueryBuilder object (Criteria)– Native SQL query

Page 40: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - ORM

Page 41: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - ORM

Page 42: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - ORM

Page 43: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - CLI

• Directed Acyclic Graphs• Easily extendable• Several handy tasks to help development– Schema-tool– Generate-proxies– Convert-mapping– Run-sql– Run-dql

Page 44: Doctrine 2.0 Enterprise Persistence Layer for PHP

Doctrine 2.0 - CLI

Page 45: Doctrine 2.0 Enterprise Persistence Layer for PHP

Questions?

Page 46: Doctrine 2.0 Enterprise Persistence Layer for PHP

Thanks!!!

Guilherme Blancoguilhermeblanco gmail com

+55 16 9215.8480

http://www.doctrine-project.org