doctrine 2.0 enterprise persistence layer for php

Post on 10-May-2015

5.164 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

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

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

What is Doctrine?

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

and ActiveRecord (Ruby)

Doctrine Roadmap

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

Doctrine Integration & Support

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

• Supports all drivers supported by PDO

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!

Doctrine 2.0

Challenges

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)

Doctrine 2.0 - Challenges

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

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

Doctrine 2.0 - Challenges

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

connections

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…

Doctrine 2.0 - Challenges

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

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

Doctrine 2.0 - Challenges

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

Doctrine 2.0 - Challenges

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

Doctrine 2.0 - Challenges

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

Doctrine 2.0

Almost 95% of codebase rewrittenRequires PHP 5.3

Doctrine 2.0

Simplified public APISmaller footprint

Doctrine 2.0

Un-necessary clutter removedNo more cyclic references

Doctrine 2.0

Code heavily decoupledExtremely extendable

Doctrine 2.0

• Three main packages:– Common– DBAL– ORM

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

Doctrine 2.0 - Common

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

Doctrine 2.0 - Common

• Class loaders:– GlobalClassLoader

– IsolatedClassLoader

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

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

Doctrine 2.0 - DBAL

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

Doctrine 2.0 - DBAL

Doctrine 2.0 - DBAL

Doctrine 2.0 - ORM

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

• Multigraph– Unidirectional– Bidirectional

Doctrine 2.0 - ORM

• Simplified bootstrap code

Doctrine 2.0 - ORM

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

Doctrine 2.0 - ORM

Doctrine 2.0 - ORM

Doctrine 2.0 - ORM

Doctrine 2.0 - ORM

Doctrine 2.0 - ORM

• Working with objects

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

Doctrine 2.0 - ORM

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

Doctrine 2.0 - ORM

Doctrine 2.0 - ORM

Doctrine 2.0 - ORM

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

Doctrine 2.0 - CLI

Questions?

Thanks!!!

Guilherme Blancoguilhermeblanco gmail com

+55 16 9215.8480

http://www.doctrine-project.org

top related