Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

What's New In Doctrine

2,583 views

Published on

Presentation on the Doctrine ORM from phpDay 2009 in Verona, Italy

Published in: Technology
  • Be the first to comment

What's New In Doctrine

  1. 1. #phpday What’s new in Doctrine What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  2. 2. #phpday Doctrine Book What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  3. 3. #phpday First official published Doctrine documentation What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  4. 4. #phpday Doctrine 1.1 What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  5. 5. #phpday Doctrine 2.0 What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  6. 6. #phpday Doctrine 1.1 What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  7. 7. #phpday 1.x Evolution What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  8. 8. #phpday Stability, bugs, features What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  9. 9. #phpday Zero failing test cases What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  10. 10. #phpday Dozens of new test cases adding more code coverage What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  11. 11. #phpday Fine tuned API What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  12. 12. #phpday Improved Hydration Performance What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  13. 13. #phpday Hydrate larger result sets in less time What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  14. 14. #phpday Re-written documentation What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  15. 15. #phpday Misc. Features What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  16. 16. #phpday New configuration options What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  17. 17. #phpday Better custom mutator and accessor support What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  18. 18. #phpday Enhanced fromArray() and synchronizeWithArray() What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  19. 19. #phpday Handles Relationships What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  20. 20. #phpday $userData = array( 'username' => 'jwage', 'password' => 'changeme', 'Groups' => array( array( '_identifier' => 1, ), array( '_identifier' => 2 ), array( 'name' => 'New Group' ) ) ); $user = new User(); $user->fromArray($userData); What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  21. 21. #phpday Generate phpDoc property tags What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  22. 22. #phpday /** * BaseUser * * This class has been auto-generated by the Doctrine ORM Framework * * @property string $username * @property string $password * * @package ##PACKAGE## * @subpackage ##SUBPACKAGE## * @author ##NAME## <##EMAIL##> * @version SVN: $Id: Builder.php 5441 2009-01-30 22:58:43Z jwage $ */ abstract class BaseUser extends Doctrine_Record { public function setTableDefinition() { $this->setTableName('user'); $this->hasColumn('username', 'string', 255, array('type' => 'string', 'length' => '255')); $this->hasColumn('password', 'string', 255, array('type' => 'string', 'length' => '255')); } } What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  23. 23. #phpday Used for IDE autocomplete, etc. What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  24. 24. #phpday Migrations What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  25. 25. #phpday General improvements all around to make things more intuitive What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  26. 26. #phpday Brand New Diff tool What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  27. 27. #phpday Generate migration classes What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  28. 28. #phpday By comparing two Doctrine schemas What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  29. 29. #phpday Automate deployment of database changes What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  30. 30. #phpday From Schema User: columns: username: string(255) password: string(255) What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  31. 31. #phpday To Schema User: columns: username: string(255) password: string(255) email_address: string(255) What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  32. 32. #phpday Generating Changes $from = 'schema/from.yml'; $to = 'schema/to.yml'; $migrationsDir = 'migrations'; $diff = new Doctrine_Migration_Diff($from, $to, $migrationsDir); $changes = $diff->generateChanges(); print_r($changes); Array ( [created_columns] => Array ( [user] => Array ( [email_address] => Array ( [type] => string [length] => 255 ) ) ) ) What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  33. 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. 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. 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. 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. 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. 38. #phpday New Data Hydration Types What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  39. 39. #phpday Scalar What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  40. 40. #phpday Flat, rectangular result set What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  41. 41. #phpday Faster to execute What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  42. 42. #phpday Harder to work with What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  43. 43. #phpday Can contain duplicate data What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  44. 44. #phpday Like normal SQL result set What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  45. 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
  46. 46. #phpday Scalar Example Array ( [0] => Array ( [u_id] => 1 [u_username] => jwage [u_password] => changeme [u_email_address] => jonwage@gmail.com [p_id] => 1 [p_user_id] => 1 [p_phonenumber] => 16155139185 ) [1] => Array ( [u_id] => 1 [u_username] => jwage [u_password] => changeme [u_email_address] => jonwage@gmail.com [p_id] => 2 [p_user_id] => 1 [p_phonenumber] => 14159925468 ) ) What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  47. 47. #phpday Single Scalar What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  48. 48. #phpday Sub-type of Scalar What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  49. 49. #phpday Returns single scalar value What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  50. 50. #phpday Useful for retrieving single value for aggregate/calculated results What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  51. 51. #phpday Very fast No need to hydrate objects What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  52. 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. 53. #phpday Doctrine 2.0 What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  54. 54. #phpday PHP 5.3 What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  55. 55. #phpday Performance increases from 5.3 What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  56. 56. #phpday Test suite runs 20% faster What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  57. 57. #phpday And uses 30% less memory What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  58. 58. #phpday Re-Design What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  59. 59. #phpday Simplified the public API What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  60. 60. #phpday Heavily influenced by JPA, Java Hibernate What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  61. 61. #phpday Smaller footprint What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  62. 62. #phpday Un-necessary clutter removed What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  63. 63. #phpday Removed Limitations What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  64. 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. 65. #phpday No more crazy cyclic references What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  66. 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. 67. #phpday Positive effects of removing the base class all around What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  68. 68. #phpday No more shared identity map across connections What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  69. 69. #phpday General Improvements What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  70. 70. #phpday Code de-coupled What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  71. 71. #phpday 3 Main Packages What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  72. 72. #phpday Common What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  73. 73. #phpday DBAL What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  74. 74. #phpday ORM What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  75. 75. #phpday Use Doctrine DBAL separate from the ORM What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  76. 76. #phpday Easier to extend and override things What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  77. 77. #phpday Better support for multiple databases What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  78. 78. #phpday Sequences, schemas and catalogs What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  79. 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. 80. #phpday No more DSN nightmares What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  81. 81. #phpday Connection information specified as arrays What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  82. 82. #phpday Removed old attribute system What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  83. 83. #phpday Replaced with simpler string based system What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  84. 84. #phpday Real Native SQL support What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  85. 85. #phpday Driver Based Meta Data What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  86. 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. 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. 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. 89. #phpday Write your own driver What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  90. 90. #phpday Cache What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  91. 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. 92. #phpday Metadata Cache Cache the parsing of meta data What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  93. 93. #phpday Result Cache Cache the results of your queries What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  94. 94. #phpday Inheritance Mapping What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  95. 95. #phpday Single Table One table per hierarchy What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  96. 96. #phpday Class Table One table per class What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  97. 97. #phpday Concrete Table One table per concrete class What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  98. 98. #phpday Testing What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  99. 99. #phpday Switched to phpUnit What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  100. 100. #phpday Better mock testing What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  101. 101. #phpday Easy to run tests against multiple DBMS What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  102. 102. #phpday Code de-coupled so it is easier to test What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  103. 103. #phpday New Features What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  104. 104. #phpday New DQL Parser What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  105. 105. #phpday Hand written What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  106. 106. #phpday Recursive-descent parser What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  107. 107. #phpday Constructs AST What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  108. 108. #phpday PHP Class names directly represent DQL language What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  109. 109. #phpday Every DQL feature has a class to handle parsing What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  110. 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. 111. #phpday Performance? What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  112. 112. #phpday Final SQL can be easily and effectively cached What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  113. 113. #phpday Not practical to parse every time What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  114. 114. #phpday Custom Column Types What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  115. 115. #phpday Add your own data types What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  116. 116. #phpday Types are OOP classes What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  117. 117. #phpday Easy to extend or add new types What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  118. 118. #phpday Extend DQL What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  119. 119. #phpday DQL parser can be extended What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  120. 120. #phpday Add your own DQL functions What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  121. 121. #phpday When? What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  122. 122. #phpday First release in September What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  123. 123. #phpday ALPHA What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  124. 124. #phpday BETA What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  125. 125. #phpday RC What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  126. 126. #phpday Stable - 2010’ ? What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  127. 127. #phpday What is next? What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  128. 128. #phpday Publishing of first Doctrine book What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  129. 129. #phpday Write more documentation What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  130. 130. #phpday Publish more books What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  131. 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. 132. #phpday Default DBAL and ORM in PEAR2? De-facto standard? What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  133. 133. #phpday It is up to you! :) What’s new in Doctrine www.doctrine-project.org www.sensiolabs.com
  134. 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

×