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.

6a1345d8e6dd15b2c78eff0c331963b1?s=128

Denis Brumann

November 12, 2020
Tweet

Transcript

  1. PREPARING FOR DOCTRINE 3 Denis Brumann denis.brumann@sensiolabs.de

  2. ABOUT ME Denis Brumann denis.brumann@sensiolabs.de @dbrumann @dbrumann denis.brumann@sensiolabs.de 1

  3. @dbrumann denis.brumann@sensiolabs.de 2

  4. @dbrumann denis.brumann@sensiolabs.de 3

  5. @dbrumann denis.brumann@sensiolabs.de 4

  6. @dbrumann denis.brumann@sensiolabs.de 5

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

    MANAGER SECOND LEVEL CACHE @dbrumann denis.brumann@sensiolabs.de 6
  8. @dbrumann denis.brumann@sensiolabs.de 7

  9. MAPPING use Doctrine\ORM\Mapping as ORM; @dbrumann denis.brumann@sensiolabs.de 8

  10. MAPPING use Doctrine\ORM\Annotation as ORM; @dbrumann denis.brumann@sensiolabs.de 9

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

    MANAGER SECOND LEVEL CACHE @dbrumann denis.brumann@sensiolabs.de 10
  12. /** @ORM\Entity */ class Customer { /** * @ORM\Id *

    @ORM\Column(type="guid") * @ORM\GeneratedValue(strategy="UUID") */ private $id; … @dbrumann denis.brumann@sensiolabs.de 11
  13. /** @ORM\Entity */ class Customer { /** * @ORM\Id *

    @ORM\Column(type="guid") * @ORM\GeneratedValue(strategy="UUID") */ private $id; … @dbrumann denis.brumann@sensiolabs.de 12
  14. UUID GENERATOR composer require ramsey/uuid-doctrine @dbrumann denis.brumann@sensiolabs.de 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 denis.brumann@sensiolabs.de 14
  16. MAPPING UUID GENERATOR NAMED QUERIES NAMESPACE ALIASES CLASS METADATA ENTITY

    MANAGER SECOND LEVEL CACHE @dbrumann denis.brumann@sensiolabs.de 15
  17. 16

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

    denis.brumann@sensiolabs.de 17
  19. Doctrine\ORM\EntityManager:: createNamedQuery createNamedNativeQuery @dbrumann denis.brumann@sensiolabs.de 18

  20. Doctrine\ORM\EntityRepository:: createNamedQuery createNamedNativeQuery @dbrumann denis.brumann@sensiolabs.de 19

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

    MANAGER SECOND LEVEL CACHE @dbrumann denis.brumann@sensiolabs.de 20
  22. @dbrumann denis.brumann@sensiolabs.de 21 SELECT p FROM AppBundle:Product p WHERE p.price

    > :price
  23. @dbrumann denis.brumann@sensiolabs.de 22 SELECT p FROM AppBundle:Product p WHERE p.price

    > :price
  24. @dbrumann denis.brumann@sensiolabs.de 23 SELECT p FROM AppBundle\Entity\Product p WHERE p.price

    > :price
  25. @dbrumann denis.brumann@sensiolabs.de 24 SELECT p FROM Product::class p WHERE p.price

    > :price
  26. @dbrumann denis.brumann@sensiolabs.de 25

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

    MANAGER SECOND LEVEL CACHE @dbrumann denis.brumann@sensiolabs.de 26
  28. Doctrine\ORM\Mapping\ClassMetadata:: getQuotedColumnName getQuotedTableName getQuotedJoinTableName getQuotedIdentifierColumnNames @dbrumann denis.brumann@sensiolabs.de 27

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

    @ORM\Column(name="number", type=“integer") */ private $number; … @dbrumann denis.brumann@sensiolabs.de 28
  30. /** @ORM\Entity */ class Customer { /** * @ORM\Id *

    @ORM\Column(name="number", type=“integer") */ private $number; … @dbrumann denis.brumann@sensiolabs.de 29
  31. @dbrumann denis.brumann@sensiolabs.de 30

  32. @dbrumann denis.brumann@sensiolabs.de 31

  33. @dbrumann denis.brumann@sensiolabs.de 32

  34. @dbrumann denis.brumann@sensiolabs.de 33

  35. @dbrumann denis.brumann@sensiolabs.de 34

  36. @dbrumann denis.brumann@sensiolabs.de 35

  37. @dbrumann denis.brumann@sensiolabs.de 36

  38. @dbrumann denis.brumann@sensiolabs.de 37

  39. @dbrumann denis.brumann@sensiolabs.de 38

  40. @dbrumann denis.brumann@sensiolabs.de 39

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

    MANAGER SECOND LEVEL CACHE @dbrumann denis.brumann@sensiolabs.de 40
  42. @dbrumann denis.brumann@sensiolabs.de 41

  43. Doctrine\ORM\EntityManagerInterface:: copy($entity, $deep = false) merge($object) detach($object) @dbrumann denis.brumann@sensiolabs.de 42

  44. @dbrumann denis.brumann@sensiolabs.de 43

  45. Doctrine\ORM\EntityManagerInterface:: flush($entity = null) clear($entityName = null) @dbrumann denis.brumann@sensiolabs.de 44

  46. Doctrine\ORM\EntityManagerInterface:: flush($entity = null) clear($entityName = null) @dbrumann denis.brumann@sensiolabs.de 45

  47. @dbrumann denis.brumann@sensiolabs.de 46

  48. @dbrumann denis.brumann@sensiolabs.de 47

  49. @dbrumann denis.brumann@sensiolabs.de 48

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

    MANAGER SECOND LEVEL CACHE @dbrumann denis.brumann@sensiolabs.de 49
  51. @dbrumann denis.brumann@sensiolabs.de 50

  52. @dbrumann denis.brumann@sensiolabs.de 51

  53. @dbrumann denis.brumann@sensiolabs.de 52 RECAP MAPPING UUID GENERATOR NAMED QUERIES NAMESPACE

    ALIASES CLASS METADATA ENTITY MANAGER SECOND LEVEL CACHE
  54. @dbrumann denis.brumann@sensiolabs.de 53

  55. @dbrumann denis.brumann@sensiolabs.de 54

  56. @dbrumann denis.brumann@sensiolabs.de 55 Thank You! Have a good evening.