$30 off During Our Annual Pro Sale. View Details »

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]

    View Slide

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

    View Slide

  3. @dbrumann [email protected] 2

    View Slide

  4. @dbrumann [email protected] 3

    View Slide

  5. @dbrumann [email protected] 4

    View Slide

  6. @dbrumann [email protected] 5

    View Slide

  7. MAPPING
    UUID GENERATOR
    NAMED QUERIES
    NAMESPACE ALIASES
    CLASS METADATA
    ENTITY MANAGER
    SECOND LEVEL CACHE
    @dbrumann [email protected] 6

    View Slide

  8. @dbrumann [email protected] 7

    View Slide

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

    View Slide

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

    View Slide

  11. MAPPING
    UUID GENERATOR
    NAMED QUERIES
    NAMESPACE ALIASES
    CLASS METADATA
    ENTITY MANAGER
    SECOND LEVEL CACHE
    @dbrumann [email protected] 10

    View Slide

  12. /** @ORM\Entity */
    class Customer
    {
    /**
    * @ORM\Id
    * @ORM\Column(type="guid")
    * @ORM\GeneratedValue(strategy="UUID")
    */
    private $id;

    @dbrumann [email protected] 11

    View Slide

  13. /** @ORM\Entity */
    class Customer
    {
    /**
    * @ORM\Id
    * @ORM\Column(type="guid")
    * @ORM\GeneratedValue(strategy="UUID")
    */
    private $id;

    @dbrumann [email protected] 12

    View Slide

  14. UUID GENERATOR
    composer require ramsey/uuid-doctrine
    @dbrumann [email protected] 13

    View Slide

  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

    View Slide

  16. MAPPING
    UUID GENERATOR
    NAMED QUERIES
    NAMESPACE ALIASES
    CLASS METADATA
    ENTITY MANAGER
    SECOND LEVEL CACHE
    @dbrumann [email protected] 15

    View Slide

  17. 16

    View Slide

  18. Doctrine\ORM\Mapping\
    NamedQueries NamedQuery
    NamedNativeQuery ColumnResult
    FieldResult EntityResult
    SqlResultSetMappings SqlResultSetMapping
    @dbrumann [email protected] 17

    View Slide

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

    View Slide

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

    View Slide

  21. MAPPING
    UUID GENERATOR
    NAMED QUERIES
    NAMESPACE ALIASES
    CLASS METADATA
    ENTITY MANAGER
    SECOND LEVEL CACHE
    @dbrumann [email protected] 20

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  26. @dbrumann [email protected] 25

    View Slide

  27. MAPPING
    UUID GENERATOR
    NAMED QUERIES
    NAMESPACE ALIASES
    CLASS METADATA
    ENTITY MANAGER
    SECOND LEVEL CACHE
    @dbrumann [email protected] 26

    View Slide

  28. Doctrine\ORM\Mapping\ClassMetadata::
    getQuotedColumnName
    getQuotedTableName
    getQuotedJoinTableName
    getQuotedIdentifierColumnNames
    @dbrumann [email protected] 27

    View Slide

  29. /** @ORM\Entity */
    class Customer
    {
    /**
    * @ORM\Id
    * @ORM\Column(name="number", type=“integer")
    */
    private $number;

    @dbrumann [email protected] 28

    View Slide

  30. /** @ORM\Entity */
    class Customer
    {
    /**
    * @ORM\Id
    * @ORM\Column(name="number", type=“integer")
    */
    private $number;

    @dbrumann [email protected] 29

    View Slide

  31. @dbrumann [email protected] 30

    View Slide

  32. @dbrumann [email protected] 31

    View Slide

  33. @dbrumann [email protected] 32

    View Slide

  34. @dbrumann [email protected] 33

    View Slide

  35. @dbrumann [email protected] 34

    View Slide

  36. @dbrumann [email protected] 35

    View Slide

  37. @dbrumann [email protected] 36

    View Slide

  38. @dbrumann [email protected] 37

    View Slide

  39. @dbrumann [email protected] 38

    View Slide

  40. @dbrumann [email protected] 39

    View Slide

  41. MAPPING
    UUID GENERATOR
    NAMED QUERIES
    NAMESPACE ALIASES
    CLASS METADATA
    ENTITY MANAGER
    SECOND LEVEL CACHE
    @dbrumann [email protected] 40

    View Slide

  42. @dbrumann [email protected] 41

    View Slide

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

    View Slide

  44. @dbrumann [email protected] 43

    View Slide

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

    View Slide

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

    View Slide

  47. @dbrumann [email protected] 46

    View Slide

  48. @dbrumann [email protected] 47

    View Slide

  49. @dbrumann [email protected] 48

    View Slide

  50. MAPPING
    UUID GENERATOR
    NAMED QUERIES
    NAMESPACE ALIASES
    CLASS METADATA
    ENTITY MANAGER
    SECOND LEVEL CACHE
    @dbrumann [email protected] 49

    View Slide

  51. @dbrumann [email protected] 50

    View Slide

  52. @dbrumann [email protected] 51

    View Slide

  53. @dbrumann [email protected] 52
    RECAP
    MAPPING
    UUID GENERATOR
    NAMED QUERIES
    NAMESPACE ALIASES
    CLASS METADATA
    ENTITY MANAGER
    SECOND LEVEL CACHE

    View Slide

  54. @dbrumann [email protected] 53

    View Slide

  55. @dbrumann [email protected] 54

    View Slide

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

    View Slide