Doctrine is a PHP library that provides persistence services and related functionality. It includes an object relational mapper (ORM) for mapping database records to PHP objects, and a database abstraction layer (DBAL). Other libraries include an object document mapper (ODM) for NoSQL databases, common annotations, caching, data fixtures, and migrations. The presentation provides an overview of each library and how to use Doctrine for common tasks like mapping classes, saving and retrieving objects, and schema migrations. Help and contribution opportunities are available on Google Groups, IRC channels, and the project's GitHub page.
2. Eu!
● Daniel Lima
– @yourwebmaker
– fb.com/dlpinheiro
– Arquiteto de aplicações na
– Produtor musical & DJ
– Biker
– Skater
– Drunk
– ...
3. Agenda
● O que é o Doctrine na verdade?
– O projeto
– Libs:
● ORM
● ODM: MongoDB, CouchDB
● DBAL: Migrations
● Common: Annotations, Cache, Data Fixtures, Inflector
● Doctrine e outros projetos
5. O Projeto
● O que é o Doctrine na verdade?
– “The Doctrine Project is the home of a selected set
of PHP libraries primarily focused on providing
persistence services and related functionality. Its
prize projects are a Object Relational Mapper and
the Database Abstraction Layer it is built on top
of.” - http://www.doctrine-project.org/
8. Colaboradores
● Guilherme Blanco …. Éééééé do Brasilll!!!!
● Jonathan H. Wage
● Benjamin Eberlei
● Bulat Shakirzyanov
● Fabien Potencier
● Roman S. Borschel
● ….... Você!
10. ORM: Mapeador de Objeto Relacional
● É a lib mais conhecida pela comunidade
● Facilita o desenvolvimento voltado ao Domínio
(problema) da aplicação
● Aproxima o modelo entidade-relacionamento
ao modelo Orientado a Objetos
● Não é necessário escrever SQL
● Não é esse MONSTRO todo que pensam...
● RTFM!!!
11. ORM: Mapeador de Objeto Relacional
Passo a passo comum:
– Crie suas tabelas
– Crie suas classes
– Mapeie suas classes
– Instancie suas classes
– Salve seus objetos
– Traga seus objetos salvos
19. ODM: Mapeador para No-SQL
● Mesmo “Conceito” do ORM, mas trabalha
somente com bancos No-Sql
● Oferece funcionalidades extras que os Clients
No-Sql não oferecem:
– Event Manager
– EntityRepositories
– Herança
● MongoDB, CouchDB, OrientDB...
● O projeto DoctrineKeyValueStore pretende
padronizar o uso de bancos No-Sql.
20. DBAL: Data Base Abstraction & Access
Layer
● Camada de abstração de banco de dados
sobre a PDO
● Oferece funcionalidades extras à PDO
● ORM faz uso da DBAL
23. DBAL: Alguns Recursos extras à PDO
● Tipos
– CREATE DOMAIN MyMoney AS DECIMAL(18,3);
– Definindo um tipo:
https://gist.github.com/yourwebmaker/7a61f175c7
59cf00096d#file-moneytype-php
– Adicionando um tipo:
28. CommonAnnotations
● /**
* @var
* @todo
* @Entity(repositoryClass=”XRepository”)
* @ORMEntity
* @AssertNotBlank()
*/
● "Annotations provide data about a program that is
not part of the program itself. They have no direct
effect on the operation of the code they
annotate." Oracle
● São como arquivos de configuração
35. DBALMigrations
● “The Doctrine Migrations offer additional
functionality on top of the database abstraction
layer (DBAL) for versioning your database
schema and easily deploying changes to it. It
is a very easy to use and powerful tool.”
● Instale na munheca... ou... use o PHAR!
● 1000000x.... USE O PHAR!
38. DBALMigrations
● $ doctrine-migrations:generate
Generated new migration class to
"/path/to/migrations/classes/DoctrineMigrations/Ve
rsion20100416130422.php"
42. DBALMigrations
$ ./doctrine migrations:migrate --dry-run
Are you sure you wish to continue?
y
Executing dry run of migration up to 20100416130452
from 0
>> migrating 20100416130452
-> CREATE TABLE users (username VARCHAR(255) NOT
NULL, password VARCHAR(255) NOT NULL) ENGINE = InnoDB
43. DBALMigrations
$ ./doctrine migrations:migrate 0
Are you sure you wish to continue?
y
Migrating down to 0 from 20100416130422
-- reverting 20100416130422
-> DROP TABLE addresses
-- reverted
-- reverting 20100416130401
-> DROP TABLE users
-- reverted
45. Como obter ajuda?
● Google Groups:
– Doctrine-user
– Doctrine-dev
– Doctrine-BR
● IRC
– irc.freenode.net/doctrine
– irc.freenode.net/doctrine-dev
– irc.freenode.net/doctrine-mongodb-odm
● LEIA O MANUAL DE CABO A RABO!
46. Contribuindo com o Doctrine
● http://www.doctrine-project.org/contribute.html
● https://github.com/doctrine
– Há sempre projetos interessantes lá =)