SlideShare a Scribd company logo
Integrating Doctrine
with Laravel
Mark Garratt - London Laravel Meetup - October 2015
Introduction
PHP Developer
DDD Student
Architecture Enthusiast
Metalhead
Archer
This Talk
What is Doctrine?
Installing Doctrine in Laravel
Replacing Eloquent
Using Doctrine
https://github.com/mgarratt/
laravel-doctrine-example
What is Doctrine?
• Doctrine is an ORM based on the Data Mapper Pattern
• Has it’s own underlying DBAL supporting MySQL,
PostgreSQL and MSSQL
• Uses a proprietary object oriented SQL dialect called
Doctrine Query Language (DQL)
• Store metadata as Annotations, XML, YAML or custom
implementations
• Uses Unit of Work Pattern to reduce database queries
How does it work?
• Models are Plain Old PHP Objects called Entities
• Entities are persisted through an EntityManager
• Entities are retrieved through a Repository
• Schema defined using Entity Metadata
LaravelDoctrine.org
• Preconfigured metadata,
connections and caching
• Annotations, yaml, xml, config
and static php meta data
mappings
• Pagination
• Extendable: extend or add your
own drivers for metadata,
connections or cache
• Change metadata, connection
or cache settings easy with a
resolved hook
LaravelDoctrine.org
• Multiple entity managers and
connections
• Simple authentication
implementation
• Password reminders
implementation
• Doctrine console commands
• DoctrineExtensions supported
• Timestamps, Softdeletes and
TablePrefix listeners
Replacing Eloquent with
Doctrine
• Remove extends model
• Replace Authenticatable
Trait and Contract
• Include ORM Mapping and
Timestamps
• Add fields, getters, setters
• Annotate everything
Replacing Eloquent with
Doctrine
• Update AuthController
validation to use Doctrine
unique syntax
• Replace AuthController
create with a version that uses
EntityManager
• Replace
PasswordController
resetPassword with a version
that uses EntityManager
Where are we now?
• Doctrine in use instead of Eloquent
• Separated persistence from entities
• Standard Authentication and Password Reset working
• Replaced save calls with global EntityManager
• Lost ability to query and save from entities
• Entities must be persisted and flushed to get an ID
• Also missing: Migrations & Seeds
Remove EntityManager Alias
• Begin using the Repository
Pattern
• EntityManger injected to
Repository
• Repository deals with storing
and retrieving entities only
Built in EntityRepository
• Repositories extend
EntityRepository
• Constructed with
EntityManager and
ClassMetaData
• Provides find() findAll()
findBy() and generic
matching() methods
FlushEntityManager
Middleware
• Calling persist on
EntityManager adds those
changes to the Unit of Work
• flush() must be called to
actually persist to the DB
• Add a Middleware to do this at
the end of every request
Application Generated IDs
• Use ramsey/uuid library -
RFC 4122 version 1, 3, 4, and
5 compliant
• Create global uuid() function
to return a UUID V4
• Use named constructors
• Update metadata so ID is a
string and Generator Strategy
is NONE
Migrations
• Provided by laravel-­‐doctrine/migrations
• No need to write yourself

php	
  artisan	
  doctrine:migrations:diff	
  
• Update your Entities then re-run diff to create a
new migration
• Run migrations using

php	
  artisan	
  doctrine:migrations:migrate
Seeds
• Work exactly the same
• Work directly with DBAL
• Create Entities and persist
• Model Factories do not work
(they’re part of Eloquent)
Switch to YAML Mapping
• Config doctrine.managers.default.path defines
where YAML files are stored
• Files named as fully qualified name with slashes
replaced by dots: App.User.dcm.yml

(dcm = Doctrine Mapping File)
• Also need a mapping for LaravelDoctrineORM
AuthPasswordsPasswordReminder
What has this achieved?
Gone from an application that depends on a SQL database to an
application that happens to be persisted on an SQL database
• Doctrine replaced with Eloquent
• Strong separation of concerns - Repositories deal with
persistence, Entities deal with business logic
• ID creation responsibility of the application
• Huge amount of Laravel functionality preserved
• Good foundation for DDD-style application
Moving Forward
• Build up methods in repository
• Take advantage of Laravel
Doctrine pagination
• Learn about Query Builder
and DQL
Obligatory Questions /
Contact Slide
Any Questions?
Mark Garratt

Twitter: @MGarratt88

GitHub: mgarratt
https://joind.in/15859

More Related Content

What's hot

Catedral de Lincoln(Lincoln Cathedral) Análise para História e Culturea das A...
Catedral de Lincoln(Lincoln Cathedral) Análise para História e Culturea das A...Catedral de Lincoln(Lincoln Cathedral) Análise para História e Culturea das A...
Catedral de Lincoln(Lincoln Cathedral) Análise para História e Culturea das A...
Tiago Loureiro
 
Detalle constructivo estructura mixta (metálica-hormigón)
Detalle constructivo estructura mixta (metálica-hormigón)Detalle constructivo estructura mixta (metálica-hormigón)
Detalle constructivo estructura mixta (metálica-hormigón)
Jose Antonio Fuentes
 
Ficha tecnica muro cortina 450 AD solucion estructural
Ficha tecnica muro cortina 450 AD solucion estructuralFicha tecnica muro cortina 450 AD solucion estructural
Ficha tecnica muro cortina 450 AD solucion estructural
CUPRUM
 
What Every Developer Should Know About Database Scalability
What Every Developer Should Know About Database ScalabilityWhat Every Developer Should Know About Database Scalability
What Every Developer Should Know About Database Scalability
jbellis
 
14.1. ARQUITECTURA DEL S.XIX. DEL NEOCLASICISMO AL MODERNISMO
14.1.  ARQUITECTURA DEL S.XIX. DEL NEOCLASICISMO AL MODERNISMO14.1.  ARQUITECTURA DEL S.XIX. DEL NEOCLASICISMO AL MODERNISMO
14.1. ARQUITECTURA DEL S.XIX. DEL NEOCLASICISMO AL MODERNISMO
manuel G. GUERRERO
 
Arquitectura barroca en italia
Arquitectura barroca en italiaArquitectura barroca en italia
Arquitectura barroca en italia
UJMD
 
Portafolio Guadua Bambu Colombia
Portafolio Guadua Bambu ColombiaPortafolio Guadua Bambu Colombia
Portafolio Guadua Bambu Colombia
Gustavo Teneche
 
Manierismo identificacion de los elementos
Manierismo identificacion de los elementosManierismo identificacion de los elementos
Manierismo identificacion de los elementos
patisosa
 
Plny12 galera-cluster-best-practices
Plny12 galera-cluster-best-practicesPlny12 galera-cluster-best-practices
Plny12 galera-cluster-best-practicesDimas Prasetyo
 
Revoques - Estuco.
Revoques - Estuco.Revoques - Estuco.
Revoques - Estuco.
Eduardo Calonge
 
El Renacimiento
El RenacimientoEl Renacimiento
El Renacimiento
Luis Godoy
 
Vidrios 2016
Vidrios 2016Vidrios 2016
Vidrios 2016
ramirix
 
MySQL GTID 시작하기
MySQL GTID 시작하기MySQL GTID 시작하기
MySQL GTID 시작하기
I Goo Lee
 

What's hot (13)

Catedral de Lincoln(Lincoln Cathedral) Análise para História e Culturea das A...
Catedral de Lincoln(Lincoln Cathedral) Análise para História e Culturea das A...Catedral de Lincoln(Lincoln Cathedral) Análise para História e Culturea das A...
Catedral de Lincoln(Lincoln Cathedral) Análise para História e Culturea das A...
 
Detalle constructivo estructura mixta (metálica-hormigón)
Detalle constructivo estructura mixta (metálica-hormigón)Detalle constructivo estructura mixta (metálica-hormigón)
Detalle constructivo estructura mixta (metálica-hormigón)
 
Ficha tecnica muro cortina 450 AD solucion estructural
Ficha tecnica muro cortina 450 AD solucion estructuralFicha tecnica muro cortina 450 AD solucion estructural
Ficha tecnica muro cortina 450 AD solucion estructural
 
What Every Developer Should Know About Database Scalability
What Every Developer Should Know About Database ScalabilityWhat Every Developer Should Know About Database Scalability
What Every Developer Should Know About Database Scalability
 
14.1. ARQUITECTURA DEL S.XIX. DEL NEOCLASICISMO AL MODERNISMO
14.1.  ARQUITECTURA DEL S.XIX. DEL NEOCLASICISMO AL MODERNISMO14.1.  ARQUITECTURA DEL S.XIX. DEL NEOCLASICISMO AL MODERNISMO
14.1. ARQUITECTURA DEL S.XIX. DEL NEOCLASICISMO AL MODERNISMO
 
Arquitectura barroca en italia
Arquitectura barroca en italiaArquitectura barroca en italia
Arquitectura barroca en italia
 
Portafolio Guadua Bambu Colombia
Portafolio Guadua Bambu ColombiaPortafolio Guadua Bambu Colombia
Portafolio Guadua Bambu Colombia
 
Manierismo identificacion de los elementos
Manierismo identificacion de los elementosManierismo identificacion de los elementos
Manierismo identificacion de los elementos
 
Plny12 galera-cluster-best-practices
Plny12 galera-cluster-best-practicesPlny12 galera-cluster-best-practices
Plny12 galera-cluster-best-practices
 
Revoques - Estuco.
Revoques - Estuco.Revoques - Estuco.
Revoques - Estuco.
 
El Renacimiento
El RenacimientoEl Renacimiento
El Renacimiento
 
Vidrios 2016
Vidrios 2016Vidrios 2016
Vidrios 2016
 
MySQL GTID 시작하기
MySQL GTID 시작하기MySQL GTID 시작하기
MySQL GTID 시작하기
 

Similar to Integrating Doctrine with Laravel

Hibernate in XPages
Hibernate in XPagesHibernate in XPages
Hibernate in XPagesToby Samples
 
They why behind php frameworks
They why behind php frameworksThey why behind php frameworks
They why behind php frameworks
Kirk Madera
 
New Persistence Features in Spring Roo 1.1
New Persistence Features in Spring Roo 1.1New Persistence Features in Spring Roo 1.1
New Persistence Features in Spring Roo 1.1
Stefan Schmidt
 
6 Months PHP internship in Noida
6 Months PHP internship in Noida6 Months PHP internship in Noida
6 Months PHP internship in Noida
Tech Mentro
 
Laravel ppt
Laravel pptLaravel ppt
Laravel ppt
Mayank Panchal
 
Talend big data online training
Talend big data online trainingTalend big data online training
Talend big data online training
GoLogica Technologies
 
Iterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternIterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design pattern
Nitin Bhide
 
LDP4j: A framework for the development of interoperable read-write Linked Da...
LDP4j: A framework for the development of interoperable read-write Linked Da...LDP4j: A framework for the development of interoperable read-write Linked Da...
LDP4j: A framework for the development of interoperable read-write Linked Da...
Nandana Mihindukulasooriya
 
Solr Recipes Workshop
Solr Recipes WorkshopSolr Recipes Workshop
Solr Recipes WorkshopErik Hatcher
 
Require.JS
Require.JSRequire.JS
Require.JS
Ivano Malavolta
 
Hibernate
HibernateHibernate
Drupal upgrades and migrations. BAD Camp 2013 version
Drupal upgrades and migrations. BAD Camp 2013 versionDrupal upgrades and migrations. BAD Camp 2013 version
Drupal upgrades and migrations. BAD Camp 2013 version
David Lanier
 
Integrating the Solr search engine
Integrating the Solr search engineIntegrating the Solr search engine
Integrating the Solr search engine
th0masr
 
70487.pdf
70487.pdf70487.pdf
70487.pdf
Karen Benoit
 
9780538745840 ppt ch10
9780538745840 ppt ch109780538745840 ppt ch10
9780538745840 ppt ch10
Terry Yoast
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
Krishnakanth Goud
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
Manav Prasad
 
Modules Building Presentation
Modules Building PresentationModules Building Presentation
Modules Building Presentationhtyson
 
Doctrine 2 - Enterprise Persistence Layer For PHP
Doctrine 2 - Enterprise Persistence Layer For PHPDoctrine 2 - Enterprise Persistence Layer For PHP
Doctrine 2 - Enterprise Persistence Layer For PHP
Jonathan Wage
 

Similar to Integrating Doctrine with Laravel (20)

Hibernate in XPages
Hibernate in XPagesHibernate in XPages
Hibernate in XPages
 
They why behind php frameworks
They why behind php frameworksThey why behind php frameworks
They why behind php frameworks
 
New Persistence Features in Spring Roo 1.1
New Persistence Features in Spring Roo 1.1New Persistence Features in Spring Roo 1.1
New Persistence Features in Spring Roo 1.1
 
6 Months PHP internship in Noida
6 Months PHP internship in Noida6 Months PHP internship in Noida
6 Months PHP internship in Noida
 
Laravel ppt
Laravel pptLaravel ppt
Laravel ppt
 
Talend big data online training
Talend big data online trainingTalend big data online training
Talend big data online training
 
Iterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternIterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design pattern
 
LDP4j: A framework for the development of interoperable read-write Linked Da...
LDP4j: A framework for the development of interoperable read-write Linked Da...LDP4j: A framework for the development of interoperable read-write Linked Da...
LDP4j: A framework for the development of interoperable read-write Linked Da...
 
Solr Recipes Workshop
Solr Recipes WorkshopSolr Recipes Workshop
Solr Recipes Workshop
 
Require.JS
Require.JSRequire.JS
Require.JS
 
Hibernate
HibernateHibernate
Hibernate
 
Drupal upgrades and migrations. BAD Camp 2013 version
Drupal upgrades and migrations. BAD Camp 2013 versionDrupal upgrades and migrations. BAD Camp 2013 version
Drupal upgrades and migrations. BAD Camp 2013 version
 
Integrating the Solr search engine
Integrating the Solr search engineIntegrating the Solr search engine
Integrating the Solr search engine
 
70487.pdf
70487.pdf70487.pdf
70487.pdf
 
9780538745840 ppt ch10
9780538745840 ppt ch109780538745840 ppt ch10
9780538745840 ppt ch10
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
 
Modules Building Presentation
Modules Building PresentationModules Building Presentation
Modules Building Presentation
 
Doctrine 2 - Enterprise Persistence Layer For PHP
Doctrine 2 - Enterprise Persistence Layer For PHPDoctrine 2 - Enterprise Persistence Layer For PHP
Doctrine 2 - Enterprise Persistence Layer For PHP
 
Doctrine2
Doctrine2Doctrine2
Doctrine2
 

Recently uploaded

Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Recently uploaded (20)

Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 

Integrating Doctrine with Laravel

  • 1. Integrating Doctrine with Laravel Mark Garratt - London Laravel Meetup - October 2015
  • 3. This Talk What is Doctrine? Installing Doctrine in Laravel Replacing Eloquent Using Doctrine https://github.com/mgarratt/ laravel-doctrine-example
  • 4. What is Doctrine? • Doctrine is an ORM based on the Data Mapper Pattern • Has it’s own underlying DBAL supporting MySQL, PostgreSQL and MSSQL • Uses a proprietary object oriented SQL dialect called Doctrine Query Language (DQL) • Store metadata as Annotations, XML, YAML or custom implementations • Uses Unit of Work Pattern to reduce database queries
  • 5. How does it work? • Models are Plain Old PHP Objects called Entities • Entities are persisted through an EntityManager • Entities are retrieved through a Repository • Schema defined using Entity Metadata
  • 6. LaravelDoctrine.org • Preconfigured metadata, connections and caching • Annotations, yaml, xml, config and static php meta data mappings • Pagination • Extendable: extend or add your own drivers for metadata, connections or cache • Change metadata, connection or cache settings easy with a resolved hook
  • 7. LaravelDoctrine.org • Multiple entity managers and connections • Simple authentication implementation • Password reminders implementation • Doctrine console commands • DoctrineExtensions supported • Timestamps, Softdeletes and TablePrefix listeners
  • 8.
  • 9.
  • 10.
  • 11. Replacing Eloquent with Doctrine • Remove extends model • Replace Authenticatable Trait and Contract • Include ORM Mapping and Timestamps • Add fields, getters, setters • Annotate everything
  • 12. Replacing Eloquent with Doctrine • Update AuthController validation to use Doctrine unique syntax • Replace AuthController create with a version that uses EntityManager • Replace PasswordController resetPassword with a version that uses EntityManager
  • 13. Where are we now? • Doctrine in use instead of Eloquent • Separated persistence from entities • Standard Authentication and Password Reset working • Replaced save calls with global EntityManager • Lost ability to query and save from entities • Entities must be persisted and flushed to get an ID • Also missing: Migrations & Seeds
  • 14. Remove EntityManager Alias • Begin using the Repository Pattern • EntityManger injected to Repository • Repository deals with storing and retrieving entities only
  • 15. Built in EntityRepository • Repositories extend EntityRepository • Constructed with EntityManager and ClassMetaData • Provides find() findAll() findBy() and generic matching() methods
  • 16. FlushEntityManager Middleware • Calling persist on EntityManager adds those changes to the Unit of Work • flush() must be called to actually persist to the DB • Add a Middleware to do this at the end of every request
  • 17. Application Generated IDs • Use ramsey/uuid library - RFC 4122 version 1, 3, 4, and 5 compliant • Create global uuid() function to return a UUID V4 • Use named constructors • Update metadata so ID is a string and Generator Strategy is NONE
  • 18. Migrations • Provided by laravel-­‐doctrine/migrations • No need to write yourself
 php  artisan  doctrine:migrations:diff   • Update your Entities then re-run diff to create a new migration • Run migrations using
 php  artisan  doctrine:migrations:migrate
  • 19. Seeds • Work exactly the same • Work directly with DBAL • Create Entities and persist • Model Factories do not work (they’re part of Eloquent)
  • 20. Switch to YAML Mapping • Config doctrine.managers.default.path defines where YAML files are stored • Files named as fully qualified name with slashes replaced by dots: App.User.dcm.yml
 (dcm = Doctrine Mapping File) • Also need a mapping for LaravelDoctrineORM AuthPasswordsPasswordReminder
  • 21.
  • 22. What has this achieved? Gone from an application that depends on a SQL database to an application that happens to be persisted on an SQL database • Doctrine replaced with Eloquent • Strong separation of concerns - Repositories deal with persistence, Entities deal with business logic • ID creation responsibility of the application • Huge amount of Laravel functionality preserved • Good foundation for DDD-style application
  • 23. Moving Forward • Build up methods in repository • Take advantage of Laravel Doctrine pagination • Learn about Query Builder and DQL
  • 24. Obligatory Questions / Contact Slide Any Questions? Mark Garratt
 Twitter: @MGarratt88
 GitHub: mgarratt https://joind.in/15859