doctrine 2

Download Doctrine 2

If you can't read please download the document

Upload: rym9pnfekfxrnln2n2ipm5gqu

Post on 22-May-2015

244 views

Category:

Technology


3 download

TRANSCRIPT

2. Doctrine 2 Common , /DBAL ORM - 3. Doctrine Common , DocBlock PHP : ApcCache, ArrayCache, FilesystemCache, FilesystemCache, MemcachedCache, PhpFileCache, RedisCache, WinCacheCache, XcacheCache, ZendDataCache 4. namespace Entities; /** * @Entity @Table(name="users") */ class User { /** @Id @Column(type="integer") @GeneratedValue */ private $id; /** @Column(length=50) */ private $name; /** @OneToOne(targetEntity="Address") */ private $address; } 5. Doctrine DBAL ( sql-) 6. Doctrine ORM PHP , XML YAML , DQL(Doctrine Query Language) 7. / // 8. /, / XML YAML PHP 9. /** @MappedSuperclass */ class MappedSuperclassBase { /** @Column(type="integer") */ private $mapped1; /** @Column(type="string") */ private $mapped2; /** * @OneToOne(targetEntity="SuperclassRelated1") * @JoinColumn(name="related1_id", referencedColumnName="id") */ private $mappedRelated1; // ... more fields and methods } 10. /** @Entity */ class EntitySubClass extends MappedSuperclassBase { /** @Id @Column(type="integer") */ private $id; /** @Column(type="string") */ private $name; // ... more fields and methods } 11. /** * @Entity * @InheritanceType("SINGLE_TABLE") * @DiscriminatorColumn(name="discr", type="string") * @DiscriminatorMap({"person" = "Person", "employee" = "Employee"}) */ class Person { // ... } /** * @Entity */ class Employee extends Person { // ... } 12. DQL SQL ORM 13. Doctrinefor ($i = 0; $i < 20; ++$i) { $user = new User; $user->name = ' ..'; $em->persist($user); } $s = microtime(true); $em->flush(); $e = microtime(true); echo $e - $s; 14. PHP$s = microtime(true); for ($i = 0; $i < 20; ++$i) { mysql_query("INSERT INTO users (name) VALUES (' ..')"); } $e = microtime(true); echo $e - $s; 15. Doctrine 2 0.0094 mysql_query 0.0165 16. PHP v2$s = microtime(true); mysql_query('START TRANSACTION'); for ($i = 0; $i < 20; ++$i) { mysql_query("INSERT INTO users (name) VALUES (' ..')"); } mysql_query('COMMIT'); $e = microtime(true); echo $e - $s; 0.0028 17. preRemove postRemove prePersist postPersist preUpdate postUpdate postLoad loadClassMetadata 18. /** @Entity @HasLifecycleCallbacks */ class User { /** * @Column(type="string", length=255) */ public $value; /** @PrePersist */ public function doStuffOnPrePersist() { $this->value = date('Y-m-d H:m:s'); } /** @PrePersist */ public function doOtherStuffOnPrePersist() { $this->value = 'changed from prePersist callback!'; } /** @PostLoad */ public function doStuffOnPostLoad() { $this->value = 'changed from postLoad callback!'; } } 19. ! ?