Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Preparing for Doctrine 3

Preparing for Doctrine 3

Doctrine ORM is probably the most used database abstraction in PHP. With Doctrine 3 on the horizon it's a perfect time to look at how Doctrine has changed and will change and what this means for you as users. This talk looks at some of the already merged features for Doctrine 3 that could have an impact on your code and why the might prevent you from upgrading. I will show approaches for tackling these changes and how your projects might benefit from introducing them already.

Denis Brumann

November 12, 2020
Tweet

More Decks by Denis Brumann

Other Decks in Programming

Transcript

  1. PREPARING FOR DOCTRINE 3 Denis Brumann [email protected]

  2. ABOUT ME Denis Brumann [email protected] @dbrumann @dbrumann [email protected] 1

  3. @dbrumann [email protected] 2

  4. @dbrumann [email protected] 3

  5. @dbrumann [email protected] 4

  6. @dbrumann [email protected] 5

  7. MAPPING UUID GENERATOR NAMED QUERIES NAMESPACE ALIASES CLASS METADATA ENTITY

    MANAGER SECOND LEVEL CACHE @dbrumann [email protected] 6
  8. @dbrumann [email protected] 7

  9. MAPPING use Doctrine\ORM\Mapping as ORM; @dbrumann [email protected] 8

  10. MAPPING use Doctrine\ORM\Annotation as ORM; @dbrumann [email protected] 9

  11. MAPPING UUID GENERATOR NAMED QUERIES NAMESPACE ALIASES CLASS METADATA ENTITY

    MANAGER SECOND LEVEL CACHE @dbrumann [email protected] 10
  12. /** @ORM\Entity */ class Customer { /** * @ORM\Id *

    @ORM\Column(type="guid") * @ORM\GeneratedValue(strategy="UUID") */ private $id; … @dbrumann [email protected] 11
  13. /** @ORM\Entity */ class Customer { /** * @ORM\Id *

    @ORM\Column(type="guid") * @ORM\GeneratedValue(strategy="UUID") */ private $id; … @dbrumann [email protected] 12
  14. UUID GENERATOR composer require ramsey/uuid-doctrine @dbrumann [email protected] 13

  15. /** @ORM\Entity */ class Customer { /** * @ORM\Id *

    @ORM\Column(type="uuid") * @ORM\GeneratedValue(strategy="NONE") */ private $id; public function __construct() { $this->id = Uuid::uuid4(); } public function getId(): string { return (string) $this->id; } @dbrumann [email protected] 14
  16. MAPPING UUID GENERATOR NAMED QUERIES NAMESPACE ALIASES CLASS METADATA ENTITY

    MANAGER SECOND LEVEL CACHE @dbrumann [email protected] 15
  17. 16

  18. Doctrine\ORM\Mapping\ NamedQueries NamedQuery NamedNativeQuery ColumnResult FieldResult EntityResult SqlResultSetMappings SqlResultSetMapping @dbrumann

    [email protected] 17
  19. Doctrine\ORM\EntityManager:: createNamedQuery createNamedNativeQuery @dbrumann [email protected] 18

  20. Doctrine\ORM\EntityRepository:: createNamedQuery createNamedNativeQuery @dbrumann [email protected] 19

  21. MAPPING UUID GENERATOR NAMED QUERIES NAMESPACE ALIASES CLASS METADATA ENTITY

    MANAGER SECOND LEVEL CACHE @dbrumann [email protected] 20
  22. @dbrumann [email protected] 21 SELECT p FROM AppBundle:Product p WHERE p.price

    > :price
  23. @dbrumann [email protected] 22 SELECT p FROM AppBundle:Product p WHERE p.price

    > :price
  24. @dbrumann [email protected] 23 SELECT p FROM AppBundle\Entity\Product p WHERE p.price

    > :price
  25. @dbrumann [email protected] 24 SELECT p FROM Product::class p WHERE p.price

    > :price
  26. @dbrumann [email protected] 25

  27. MAPPING UUID GENERATOR NAMED QUERIES NAMESPACE ALIASES CLASS METADATA ENTITY

    MANAGER SECOND LEVEL CACHE @dbrumann [email protected] 26
  28. Doctrine\ORM\Mapping\ClassMetadata:: getQuotedColumnName getQuotedTableName getQuotedJoinTableName getQuotedIdentifierColumnNames @dbrumann [email protected] 27

  29. /** @ORM\Entity */ class Customer { /** * @ORM\Id *

    @ORM\Column(name="number", type=“integer") */ private $number; … @dbrumann [email protected] 28
  30. /** @ORM\Entity */ class Customer { /** * @ORM\Id *

    @ORM\Column(name="number", type=“integer") */ private $number; … @dbrumann [email protected] 29
  31. @dbrumann [email protected] 30

  32. @dbrumann [email protected] 31

  33. @dbrumann [email protected] 32

  34. @dbrumann [email protected] 33

  35. @dbrumann [email protected] 34

  36. @dbrumann [email protected] 35

  37. @dbrumann [email protected] 36

  38. @dbrumann [email protected] 37

  39. @dbrumann [email protected] 38

  40. @dbrumann [email protected] 39

  41. MAPPING UUID GENERATOR NAMED QUERIES NAMESPACE ALIASES CLASS METADATA ENTITY

    MANAGER SECOND LEVEL CACHE @dbrumann [email protected] 40
  42. @dbrumann [email protected] 41

  43. Doctrine\ORM\EntityManagerInterface:: copy($entity, $deep = false) merge($object) detach($object) @dbrumann [email protected] 42

  44. @dbrumann [email protected] 43

  45. Doctrine\ORM\EntityManagerInterface:: flush($entity = null) clear($entityName = null) @dbrumann [email protected] 44

  46. Doctrine\ORM\EntityManagerInterface:: flush($entity = null) clear($entityName = null) @dbrumann [email protected] 45

  47. @dbrumann [email protected] 46

  48. @dbrumann [email protected] 47

  49. @dbrumann [email protected] 48

  50. MAPPING UUID GENERATOR NAMED QUERIES NAMESPACE ALIASES CLASS METADATA ENTITY

    MANAGER SECOND LEVEL CACHE @dbrumann [email protected] 49
  51. @dbrumann [email protected] 50

  52. @dbrumann [email protected] 51

  53. @dbrumann [email protected] 52 RECAP MAPPING UUID GENERATOR NAMED QUERIES NAMESPACE

    ALIASES CLASS METADATA ENTITY MANAGER SECOND LEVEL CACHE
  54. @dbrumann [email protected] 53

  55. @dbrumann [email protected] 54

  56. @dbrumann [email protected] 55 Thank You! Have a good evening.