Introducing 

Prezi AI.

Your new presentation assistant.

Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.

Loading…
Transcript

Let the developer get focused on objects interaction, so that it is possible to make database matters to be pushed into the background.

Highly reusable components, which do not have any other dependency than PHP.

Namespace: Doctrine\Common

DataBase Abstraction Layer based on PDO. Interaction with databases since this layer is transparent.

Namespace: Doctrine\DBAL

Contains a toolkit necessary to map plain PHP classes absolutely decoupled.

Namespace: Doctrine\ORM

Examples

Via composer

Get an instance of EntityManager:

Updating the local environment during development:

Regular PHP class representing a domain object:

Using the entity

Instantiation, update and persistence:

Questions?

Gracias

Thank you

Vielen Dank

Grazie

Mercí

Obrigado

спасибо

Architecture

UnitOfWork

  • Design Pattern
  • Keeps a list of affected objects by business transactions and manages changes persistance. Also looks after concurrency problems.

Architecture

EntityManager

Proxies

  • Created automatically. Developers must NEVER touch them.
  • They extend the entities. Each one has got a proxy.
  • Utilised by Doctrine when execute partial queries which don't fill up entity properties.
  • Implement Lazy Loading logic.
  • Load automatically from the database any property not loaded before.
  • Main ORM access point provided by Doctrine 2.
  • Provides an API used to manage persistance and persistent objects query.

Find

  • Tries to find an entity data by id.

Persist / Remove

  • Adds managed objects to the UnitOfWork's queue mantaining the coherence between relations without access the database.

Flush (Unit Of Work pattern)

  • Executes the queue indeed in the database.

Introduction

Goal

Packages

Common

DBAL

ORM

Architecture

Repository

Entities

  • Provides methods to make queries to the database (find, findAll, findBy, etc)
  • Can be extended for each entity (whenever it is necessary).
  • It should not implement methods to execute INSERT, REPLACE, UPDATE o DELETE, but only SELECT.

Light domain object

Can be a simple PHP class

Constraints:

  • Can not be a "final" class
  • Properties must be private or protected. Otherwise, lazy loading and serialisation will not work properly.
  • Magic methods __clone y __wakeup should not be implemented (can be done with special care)
  • If entity A extends B both can not have a mapped field with the same name.
  • An entity can not use func_get_args() to get parameters. Generated proxies do not support them due to performance reasons and will fail if this constraint is violated.

Doctrine 2

Workshop

Setup

Bootstrap

Doctrine CLI Console

Entity

davidvartanian@gmail.com

Learn more about creating dynamic, engaging presentations with Prezi