What Is Doctrine?
-
Upload
jonathan-wage -
Category
Technology
-
view
7.395 -
download
2
description
Transcript of What Is Doctrine?
![Page 1: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/1.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
What is Doctrine?
![Page 2: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/2.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Doctrine is a ORMwritten in PHP
![Page 3: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/3.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
What is an ORM?
![Page 4: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/4.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
ORM stands forObject Relational Mapper
![Page 5: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/5.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Manipulate RDBMSas a set of PHP objects
![Page 6: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/6.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Easy to get started
![Page 7: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/7.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Doctrine Sandbox
![Page 8: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/8.jpg)
$ svn co http://svn.doctrine-project.org/branches/1.1 lamp_doctrine$ cd lamp_doctrine/tools/sandbox$ php doctrine.php
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Doctrine Sandbox
Command Line
![Page 9: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/9.jpg)
Phonenumber: columns: phonenumber: type: string(55) notnull: true user_id: type: integer notnull: true relations: User: foreignAlias: Phonenumbers onDelete: CASCADE
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Test SchemaUser: columns: first_name: type: string(255) notnull: true last_name: type: string(255) notnull: true username: type: string(255) unique: true notnull: true password: type: string(255) notnull: true email_address: type: string(255) notnull: true email: true unique: true
lamp_doctrine/tools/sandbox/schema/schema.yml
![Page 10: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/10.jpg)
User: jwage: first_name: Jonathan last_name: Wage username: jwage password: changeme email_address: [email protected] Phonenumbers: cell: phonenumber: 6155139185 office: phonenumber: 4159925468
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Test Datalamp_doctrine/tools/sandbox/data/fixtures/data.yml
![Page 11: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/11.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Build All Reload
$ php doctrine.php build-all-reload
![Page 12: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/12.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Running Tests• First DQL Query• Working with objects• Writing DQL Queries
– SELECT queries– UPDATE queries– DELETE queries
• Custom Accessors/Mutators• Using Migrations
![Page 13: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/13.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
First DQL Query$ php doctrine.php dql "FROM User u, u.Phonenumbers p"
![Page 14: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/14.jpg)
$user = new User();$user->first_name = 'Fabien';$user->last_name = 'Potencier';$user->username = 'fabpot';$user->password = 'changeme';$user->email_address = '[email protected]';$user->save();
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Working with Objects
Insert new User
$ php index.php
lamp_doctrine/tools/sandbox/index.php
![Page 15: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/15.jpg)
$userTable = Doctrine::getTable('User');
$user = $userTable->findOneByUsername('jwage');$user->password = 'newpassword';$user->save();
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Working with Objects
Edit existing User
lamp_doctrine/tools/sandbox/index.php
$ php index.php
![Page 16: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/16.jpg)
$userTable = Doctrine::getTable('User');
$user = $userTable->findOneByUsername('fabpot');
$user->Phonenumbers[]->phonenumber = '1233451234';$user->Phonenumbers[]->phonenumber = '9875674543';
$user->save();
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Working with Objects
Adding Phonenumbers
lamp_doctrine/tools/sandbox/index.php
$ php index.php
![Page 17: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/17.jpg)
$userTable = Doctrine::getTable('User');
$user = $userTable->findOneByUsername('fabpot');$user->Phonenumbers[0]->delete();
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Working with Objects
Deleting Objects
lamp_doctrine/tools/sandbox/index.php
$ php index.php
![Page 18: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/18.jpg)
$userTable = Doctrine::getTable('User');
$user = $userTable->findOneByUsername('fabpot');$user->Phonenumbers->delete();
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Working with Objects
Deleting Collections
lamp_doctrine/tools/sandbox/index.php
$ php index.php
![Page 19: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/19.jpg)
$q = Doctrine::getTable('User') ->createQuery('u');
$users = $q->execute();
print_r($users->toArray());
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Writing DQL Queries
SELECT Queries
lamp_doctrine/tools/sandbox/index.php
$ php index.php
![Page 20: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/20.jpg)
Array( [0] => Array ( [id] => 1 [first_name] => Jonathan [last_name] => Wage [username] => jwage [password] => changeme [email_address] => [email protected] )
[1] => Array ( [id] => 2 [first_name] => Fabien [last_name] => Potencier [username] => fabpot [password] => changeme [email_address] => [email protected] )
) What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Writing DQL Queries
![Page 21: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/21.jpg)
$q = Doctrine::getTable('User') ->createQuery('u') ->leftJoin('u.Phonenumbers p') ->andWhere('u.username = ?', 'jwage');
$users = $q->execute();
print_r($users->toArray(true));
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Writing DQL Queries
SELECT Queries
lamp_doctrine/tools/sandbox/index.php
$ php index.php
![Page 22: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/22.jpg)
Array( [0] => Array ( [id] => 1 [first_name] => Jonathan [last_name] => Wage [username] => jwage [password] => changeme [email_address] => [email protected] [Phonenumbers] => Array ( [0] => Array ( [id] => 1 [phonenumber] => 6155139185 [user_id] => 1 [User] => )
[1] => Array ( [id] => 2 [phonenumber] => 4159925468 [user_id] => 1 [User] => )
)
)
)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Writing DQL Queries
![Page 23: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/23.jpg)
$q = Doctrine::getTable('User') ->createQuery('u') ->update() ->set('email_address', '?', '[email protected]') ->andWhere('username = ?', 'jwage');
$affectedRows = $q->execute();
echo $affectedRows; // 1
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Writing DQL Queries
UPDATE Queries
lamp_doctrine/tools/sandbox/index.php
$ php index.php
![Page 24: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/24.jpg)
$q = Doctrine::getTable('User') ->createQuery('u') ->delete() ->andWhere('username = ?', 'jwage');
$affectedRows = $q->execute();
echo $affectedRows; // 1
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Writing DQL Queries
DELETE Queries
lamp_doctrine/tools/sandbox/index.php
$ php index.php
![Page 25: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/25.jpg)
// ...$manager = Doctrine_Manager::getInstance();$manager->setAttribute('auto_accessor_override', true);
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Custom AccessorsEnable Auto Accessor Override
lamp_doctrine/tools/sandbox/config.php
![Page 26: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/26.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Custom Accessors
Custom `name` accessor
![Page 27: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/27.jpg)
class User extends BaseUser{ public function getName() { return trim($this->first_name.' '.$this->last_name); }}
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Custom Accessorslamp_doctrine/tools/sandbox/models/User.php
![Page 28: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/28.jpg)
$q = Doctrine::getTable('User') ->createQuery('u') ->andWhere('username = ?', 'jwage');
$user = $q->fetchOne();
echo $user->name; // Jonathan Wage
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Custom Accessorslamp_doctrine/tools/sandbox/index.php
$ php index.php
![Page 29: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/29.jpg)
class User extends BaseUser{ // ...
public function setPassword($password) { $this->_set('password', md5($password)); }}
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Custom Mutator
MD5 encrypt passwords
![Page 30: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/30.jpg)
$q = Doctrine::getTable('User') ->createQuery('u') ->andWhere('username = ?', 'jwage');
$user = $q->fetchOne();
$user->password = 'changeme';$user->save();
echo $user->password; // 4cb9c8a8048fd02294477fcb1a41191a
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Custom Mutator
MD5 encrypt passwords
![Page 31: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/31.jpg)
echo $user->name;echo $user->get('name');echo $user['name'];
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Accessor/Mutator SyntaxObject property, function, array access
![Page 32: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/32.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Database Migrations
![Page 33: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/33.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Deploy schema changes
![Page 34: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/34.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Maintain production data
![Page 35: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/35.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Programmatic interfacefor issuing DDL statements
![Page 36: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/36.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Versions your database
![Page 37: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/37.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Upgrade your database to new versionsDowngrade to previous versions
![Page 38: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/38.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Database Migrations
Add new status column to users
![Page 39: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/39.jpg)
User: columns:# ... status: type: enum values: [Pending, Active, Inactive]
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Database Migrations
![Page 40: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/40.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Database Migrations
Generate migration class
$ php doctrine generate-migrations-diff
![Page 41: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/41.jpg)
class Version1 extends Doctrine_Migration_Base{ public function up() { $this->addColumn('user', 'status', 'enum', '', array('values' => array(0 => 'Pending', 1 => 'Active', 2 => 'Inactive'))); }
public function down() { $this->removeColumn('user', 'status'); }}
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Database MigrationsGenerate migration class
![Page 42: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/42.jpg)
class Version1 extends Doctrine_Migration_Base{ public function postUp() { Doctrine::loadModels(realpath(dirname(__FILE__).'/../models'));
Doctrine::getTable('User') ->createQuery('u') ->update() ->set('status', '?', 'Active') ->execute(); }
// ...}
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Database MigrationsCustomize migration class
![Page 43: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/43.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Database MigrationsExecuting migration
$ php doctrine migratemigrate - migrated successfully to version #1
![Page 44: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/44.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Database MigrationsUpdate models from YAML
$ php doctrine generate-models-yaml
![Page 45: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/45.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Database MigrationsInspect migration was
successful or not
New status column existsDefault `Active` value
![Page 46: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/46.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Future of Doctrine?
![Page 47: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/47.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
New Versions
![Page 48: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/48.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Doctrine 1.2
![Page 49: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/49.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Continued evolutionof the 1.x codebase
![Page 50: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/50.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Doctrine 2.0
![Page 51: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/51.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Almost complete re-rewrite
![Page 52: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/52.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Major version
![Page 53: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/53.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Requires PHP 5.3
![Page 54: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/54.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Performance increases from 5.3
![Page 55: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/55.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Test suite runs20% faster
![Page 56: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/56.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
And uses 30%less memory
![Page 57: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/57.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Hydration performanceimprovements
![Page 58: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/58.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Doctrine 1.14.3435637950897 for 5000 records
Doctrine 2.01.4314442552312 for 5000 records
Doctrine 2.03.4690098762512 for 10000 records
Hydration Performance
![Page 59: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/59.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Removed Major Limitation
class User extends Doctrine_Record{ public function setTableDefinition() { $this->hasColumn('id', 'integer', null, array( 'primary' => true, 'auto_increment' => true ));
$this->hasColumn('username', 'string', 255); }}
No need to extend a base class
/** * @DoctrineEntity * @DoctrineTable(name="user") */class User{ /** * @DoctrineId * @DoctrineColumn(type="integer") * @DoctrineGeneratedValue(strategy="auto") */ public $id;
/** * @DoctrineColumn(type="varchar", length=255) */ public $username;}
![Page 60: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/60.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
No more crazy cyclic references
![Page 61: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/61.jpg)
User Object( [id] => [username] => jwage)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
print_r() your objects
$user = new User();$user->username = 'jwage';print_r($user);
![Page 62: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/62.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Positive effects of removing the base
class all around
![Page 63: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/63.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
GeneralImprovements
![Page 64: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/64.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Code de-coupled
![Page 65: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/65.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
3 Main Packages
![Page 66: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/66.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Common
![Page 67: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/67.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
DBAL
![Page 68: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/68.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
ORM
![Page 69: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/69.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Use Doctrine DBALseparate from the ORM
![Page 70: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/70.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Easier to extend and override things
![Page 71: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/71.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Better support formultiple databases
![Page 72: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/72.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Sequences, schemasand catalogs
![Page 73: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/73.jpg)
$config = new \Doctrine\ORM\Configuration();$eventManager = new \Doctrine\Common\EventManager();$connectionOptions = array( 'driver' => 'pdo_sqlite', 'path' => 'database.sqlite');$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config, $eventManager);
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Simplified connectioninformation
![Page 74: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/74.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
No more DSN nightmares
![Page 75: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/75.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Connection informationspecified as arrays
![Page 76: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/76.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Removed oldattribute system
![Page 77: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/77.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Replaced with simplerstring based system
![Page 78: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/78.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Real Native SQL support
![Page 79: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/79.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Driver BasedMeta Data
![Page 80: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/80.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
/** * @DoctrineEntity * @DoctrineTable(name="user") */class User{ /** * @DoctrineId * @DoctrineColumn(type="integer") * @DoctrineGeneratedValue(strategy="auto") */ public $id;
/** * @DoctrineColumn(type="varchar", length=255) */ public $username;}
PHP Annotations
![Page 81: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/81.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
PHP Codeclass User{ public $id, $username;}
$metadata = new ClassMetadata('User');
$metadata->mapField(array( 'fieldName' => 'id', 'type' => 'integer', 'id' => true));
$metadata->setIdGeneratorType('auto');
$metadata->mapField(array( 'fieldName' => 'username', 'type' => 'varchar', 'length' => 255));
![Page 82: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/82.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
YAML
User: properties: id: id: true type: integer idGenerator: auto username: type: varchar length: 255
class User{ public $id, $username;}
![Page 83: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/83.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Write your own driver
![Page 84: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/84.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Cache
![Page 85: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/85.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Query CacheCache final SQL that is parsed from DQL
![Page 86: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/86.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Metadata CacheCache the parsing of meta data
![Page 87: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/87.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Result CacheCache the results of your queries
![Page 88: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/88.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
InheritanceMapping
![Page 89: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/89.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Single TableOne table per hierarchy
![Page 90: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/90.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Class TableOne table per class
![Page 91: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/91.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Concrete TableOne table per concrete class
![Page 92: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/92.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Testing
![Page 93: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/93.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Switched to phpUnit
![Page 94: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/94.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Better mock testing
![Page 95: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/95.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Easy to run tests against multiple DBMS
![Page 96: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/96.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Code de-coupled soit is easier to test
![Page 97: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/97.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
New Features
![Page 98: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/98.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
New DQL Parser
![Page 99: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/99.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Hand written
![Page 100: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/100.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Recursive-descentparser
![Page 101: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/101.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Constructs AST
![Page 102: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/102.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
PHP Class namesdirectly represent
DQL language
![Page 103: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/103.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Every DQL featurehas a class to handle
parsing
![Page 104: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/104.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Easy to maintainEasy to add new features
Easy to use
![Page 105: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/105.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Performance?
![Page 106: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/106.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Final SQL can beeasily and effectively cached
![Page 107: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/107.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Not practical to parseevery time
![Page 108: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/108.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
CustomColumn Types
![Page 109: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/109.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Add your own data types
![Page 110: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/110.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Types are OOP classes
![Page 111: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/111.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Easy to extendor add new types
![Page 112: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/112.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Extend DQL
![Page 113: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/113.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
DQL parser canbe extended
![Page 114: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/114.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Add your ownDQL functions
![Page 115: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/115.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
When?
![Page 116: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/116.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
First releasein September 09`
![Page 117: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/117.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
ALPHA
![Page 118: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/118.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
BETA
![Page 119: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/119.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
RC
![Page 120: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/120.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Stable - 2010’ ?
![Page 121: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/121.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
What is next?
![Page 122: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/122.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Publishing of firstDoctrine book
![Page 123: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/123.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Write more documentation
![Page 124: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/124.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Publish more books
![Page 125: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/125.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Doctrine communityextension repository
Symfony has Plugins
and
Doctrine has Extensions
![Page 126: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/126.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Default DBALand ORM in PEAR2?
De-facto standard?
![Page 127: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/127.jpg)
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
It is up to you! :)
![Page 128: What Is Doctrine?](https://reader036.fdocuments.net/reader036/viewer/2022062312/5552df08b4c905014c8b4c97/html5/thumbnails/128.jpg)
You can contact Jonathan about Doctrine and Open-Source or for training, consulting, application development, or business related
questions at [email protected]
What is Doctrine? www.doctrine-project.org www.sensiolabs.com
Nashville LAMP
Jonathan H. [email protected]+1 415 992 5468
sensiolabs.com | doctrine-project.org | sympalphp.org | jwage.com
Questions?