#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
#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
#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
#phpday
Migrating up executes up() methods
Migrating down executes down() methods
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#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
#phpday
New Data
Hydration
Types
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Scalar
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Flat, rectangular
result set
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Faster to execute
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Harder to work with
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Can contain
duplicate data
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Like normal SQL
result set
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#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
#phpday
Single Scalar
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Sub-type of Scalar
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Returns single
scalar value
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Useful for retrieving
single value for
aggregate/calculated
results
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Very fast
No need to hydrate
objects
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#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
#phpday
Doctrine 2.0
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
PHP 5.3
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Performance increases
from 5.3
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Test suite runs
20% faster
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
And uses 30%
less memory
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Re-Design
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Simplified the
public API
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Heavily influenced
by JPA, Java Hibernate
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Smaller footprint
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Un-necessary
clutter removed
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Removed
Limitations
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
No need to extend
Doctrine 1 Doctrine 2
/**
class User extends Doctrine_Record * @DoctrineEntity
{ * @DoctrineTable(name=\"user\")
public function setTableDefinition() */
{ class User
$this->hasColumn('id', 'integer', null, array( {
'primary' => true, /**
'auto_increment' => true * @DoctrineId
)); * @DoctrineColumn(type=\"integer\")
* @DoctrineGeneratedValue(strategy=\"auto\")
$this->hasColumn('username', 'string', 255); */
} public $id;
}
/**
* @DoctrineColumn(type=\"varchar\", length=255)
*/
public $username;
}
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
No more crazy cyclic
references
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#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
#phpday
Positive effects of
removing the base
class all around
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
No more shared identity
map across connections
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
General
Improvements
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Code de-coupled
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
3 Main Packages
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Common
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
DBAL
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
ORM
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Use Doctrine DBAL
separate from the ORM
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Easier to extend and
override things
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Better support for
multiple databases
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Sequences, schemas
and catalogs
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Simplified connection
information
$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’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
No more DSN
nightmares
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Connection information
specified as arrays
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Removed old
attribute system
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Replaced with simpler
string based system
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Real Native SQL support
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Driver Based
Meta Data
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
PHP Annotations
/**
* @DoctrineEntity
* @DoctrineTable(name=\"user\")
*/
class User
{
/**
* @DoctrineId
* @DoctrineColumn(type=\"integer\")
* @DoctrineGeneratedValue(strategy=\"auto\")
*/
public $id;
/**
* @DoctrineColumn(type=\"varchar\", length=255)
*/
public $username;
}
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#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
#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
#phpday
Write your own driver
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Cache
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Query Cache
Cache final SQL that is parsed from DQL
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Metadata Cache
Cache the parsing of meta data
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Result Cache
Cache the results of your queries
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Inheritance
Mapping
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Single Table
One table per hierarchy
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Class Table
One table per class
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Concrete Table
One table per concrete class
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Testing
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Switched to phpUnit
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Better mock testing
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Easy to run tests against
multiple DBMS
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Code de-coupled so
it is easier to test
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
New Features
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
New DQL Parser
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Hand written
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Recursive-descent
parser
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Constructs AST
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
PHP Class names
directly represent
DQL language
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Every DQL feature
has a class to handle
parsing
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Easy to maintain
Easy to add new features
Easy to use
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Performance?
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Final SQL can be
easily and effectively
cached
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Not practical to parse
every time
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Custom
Column Types
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Add your own data types
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Types are OOP classes
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Easy to extend
or add new types
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Extend DQL
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
DQL parser can
be extended
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Add your own
DQL functions
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
When?
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
First release
in September
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
ALPHA
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
BETA
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
RC
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Stable - 2010’ ?
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
What is next?
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Publishing of first
Doctrine book
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Write more
documentation
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Publish more books
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Doctrine community
extension repository
Symfony has Plugins
and
Doctrine has Extensions
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
Default DBAL
and ORM in PEAR2?
De-facto standard?
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#phpday
It is up to you! :)
What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
#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
0 comments
Post a comment