SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
33.
#phpday
Generating Classes
$from = 'schema/from.yml';
$to = 'schema/to.yml';
$migrationsDir = 'migrations';
$diff = new Doctrine_Migration_Diff($from, $to, $migrationsDir);
$diff->generateMigrationClasses();
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
34.
#phpday
Generating Classes
// migrations/1239913213_version1.php
class Version1 extends Doctrine_Migration_Base
{
public function up()
{
$this->addColumn('user', 'email_address', 'string', '255', array('email' =>
'1'));
}
public function down()
{
$this->removeColumn('user', 'email_address');
}
}
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
35.
#phpday
Migrating Changes
Migrate from version 0 to version 1
$migration = new Doctrine_Migration('migrations');
$migration->migrate();
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
36.
#phpday
Migrating up executes up() methods
Migrating down executes down() methods
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
37.
#phpday
Reversing Changes
Migrate from version 1 to version 0
$migration = new Doctrine_Migration('migrations');
$migration->migrate(0);
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
38.
#phpday
New Data
Hydration
Types
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
39.
#phpday
Scalar
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
40.
#phpday
Flat, rectangular
result set
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
41.
#phpday
Faster to execute
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
42.
#phpday
Harder to work with
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
43.
#phpday
Can contain
duplicate data
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
44.
#phpday
Like normal SQL
result set
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
45.
#phpday
Scalar Example
$q = Doctrine::getTable('User')
->createQuery('u')
->leftJoin('u.Phonenumbers p');
$results = $q->execute(array(), Doctrine::HYDRATE_SCALAR);
print_r($results);
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
47.
#phpday
Single Scalar
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
48.
#phpday
Sub-type of Scalar
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
49.
#phpday
Returns single
scalar value
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
50.
#phpday
Useful for retrieving
single value for
aggregate/calculated
results
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
51.
#phpday
Very fast
No need to hydrate
objects
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
52.
#phpday
Single Scalar Example
$q = Doctrine::getTable('User')
->createQuery('u')
->select('COUNT(p.id) as num_phonenumbers')
->leftJoin('u.Phonenumbers p');
$results = $q->execute(array(), Doctrine::HYDRATE_SINGLE_SCALAR);
echo $results; // 2
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
53.
#phpday
Doctrine 2.0
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
54.
#phpday
PHP 5.3
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
55.
#phpday
Performance increases
from 5.3
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
56.
#phpday
Test suite runs
20% faster
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
57.
#phpday
And uses 30%
less memory
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
58.
#phpday
Re-Design
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
59.
#phpday
Simplified the
public API
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
60.
#phpday
Heavily influenced
by JPA, Java Hibernate
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
61.
#phpday
Smaller footprint
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
62.
#phpday
Un-necessary
clutter removed
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
63.
#phpday
Removed
Limitations
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
64.
#phpday
No need to extend
Doctrine 1 Doctrine 2
/**
class User extends Doctrine_Record * @DoctrineEntity
{ * @DoctrineTable(name=quot;userquot;)
public function setTableDefinition() */
{ class User
$this->hasColumn('id', 'integer', null, array( {
'primary' => true, /**
'auto_increment' => true * @DoctrineId
)); * @DoctrineColumn(type=quot;integerquot;)
* @DoctrineGeneratedValue(strategy=quot;autoquot;)
$this->hasColumn('username', 'string', 255); */
} public $id;
}
/**
* @DoctrineColumn(type=quot;varcharquot;, length=255)
*/
public $username;
}
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
65.
#phpday
No more crazy cyclic
references
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
66.
#phpday
print_r() your objects
$user = new User();
$user->username = 'jwage';
print_r($user);
User Object
(
[id] =>
[username] => jwage
)
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
67.
#phpday
Positive effects of
removing the base
class all around
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
68.
#phpday
No more shared identity
map across connections
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
69.
#phpday
General
Improvements
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
70.
#phpday
Code de-coupled
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
71.
#phpday
3 Main Packages
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
72.
#phpday
Common
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
73.
#phpday
DBAL
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
74.
#phpday
ORM
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
75.
#phpday
Use Doctrine DBAL
separate from the ORM
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
76.
#phpday
Easier to extend and
override things
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
77.
#phpday
Better support for
multiple databases
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
78.
#phpday
Sequences, schemas
and catalogs
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
79.
#phpday
Simplified connection
information
$config = new DoctrineORMConfiguration();
$eventManager = new DoctrineCommonEventManager();
$connectionOptions = array(
'driver' => 'pdo_sqlite',
'path' => 'database.sqlite'
);
$em = DoctrineORMEntityManager::create($connectionOptions, $config, $eventManager);
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
80.
#phpday
No more DSN
nightmares
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
81.
#phpday
Connection information
specified as arrays
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
82.
#phpday
Removed old
attribute system
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
83.
#phpday
Replaced with simpler
string based system
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
84.
#phpday
Real Native SQL support
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
85.
#phpday
Driver Based
Meta Data
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
86.
#phpday
PHP Annotations
/**
* @DoctrineEntity
* @DoctrineTable(name=quot;userquot;)
*/
class User
{
/**
* @DoctrineId
* @DoctrineColumn(type=quot;integerquot;)
* @DoctrineGeneratedValue(strategy=quot;autoquot;)
*/
public $id;
/**
* @DoctrineColumn(type=quot;varcharquot;, length=255)
*/
public $username;
}
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
87.
#phpday
PHP Code
class 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
));
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
88.
#phpday
YAML
class User
{
public
$id,
$username;
}
User:
properties:
id:
id: true
type: integer
idGenerator: auto
username:
type: varchar
length: 255
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
89.
#phpday
Write your own driver
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
90.
#phpday
Cache
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
91.
#phpday
Query Cache
Cache final SQL that is parsed from DQL
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
92.
#phpday
Metadata Cache
Cache the parsing of meta data
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
93.
#phpday
Result Cache
Cache the results of your queries
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
94.
#phpday
Inheritance
Mapping
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
95.
#phpday
Single Table
One table per hierarchy
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
96.
#phpday
Class Table
One table per class
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
97.
#phpday
Concrete Table
One table per concrete class
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
98.
#phpday
Testing
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
99.
#phpday
Switched to phpUnit
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
100.
#phpday
Better mock testing
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
101.
#phpday
Easy to run tests against
multiple DBMS
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
102.
#phpday
Code de-coupled so
it is easier to test
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
103.
#phpday
New Features
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
104.
#phpday
New DQL Parser
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
105.
#phpday
Hand written
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
106.
#phpday
Recursive-descent
parser
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
107.
#phpday
Constructs AST
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
108.
#phpday
PHP Class names
directly represent
DQL language
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
109.
#phpday
Every DQL feature
has a class to handle
parsing
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
110.
#phpday
Easy to maintain
Easy to add new features
Easy to use
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
111.
#phpday
Performance?
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
112.
#phpday
Final SQL can be
easily and effectively
cached
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
113.
#phpday
Not practical to parse
every time
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
114.
#phpday
Custom
Column Types
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
115.
#phpday
Add your own data types
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
116.
#phpday
Types are OOP classes
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
117.
#phpday
Easy to extend
or add new types
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
118.
#phpday
Extend DQL
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
119.
#phpday
DQL parser can
be extended
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
120.
#phpday
Add your own
DQL functions
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
121.
#phpday
When?
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
122.
#phpday
First release
in September
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
123.
#phpday
ALPHA
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
124.
#phpday
BETA
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
125.
#phpday
RC
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
126.
#phpday
Stable - 2010’ ?
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
127.
#phpday
What is next?
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
128.
#phpday
Publishing of first
Doctrine book
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
129.
#phpday
Write more
documentation
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
130.
#phpday
Publish more books
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
131.
#phpday
Doctrine community
extension repository
Symfony has Plugins
and
Doctrine has Extensions
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
132.
#phpday
Default DBAL
and ORM in PEAR2?
De-facto standard?
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
133.
#phpday
It is up to you! :)
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
134.
#phpday
Questions?
Jonathan H. Wage
jonathan.wage@sensio.com
+1 415 992 5468
sensiolabs.com | doctrine-project.org | sympalphp.org | jwage.com
You can contact Jonathan about Doctrine and Open-Source or for
training, consulting, application development, or business related
questions at jonathan.wage@sensio.com
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com