SlideShare a Scribd company logo
1 of 20
PHP STARTER
APPLICATION
For Complex Business Logic
http://github.com/KimPrince/zf2-starter
Dealing with business complexity
General Requirements
• Means of organizing logic
• Flexible database interaction
• A clear API for client code
Solution
• MVC skeleton with a Model
• Model
• The Domain, with:
• Domain object factories
• Collection handling and logic
• Proxies
• Single-valued properties
• Multi-valued properties
• Identity map
• The Data Mapper
• The Service Layer
• View – OOTB
• Controller – OOTB
The code
• Zend Framework 2
• Easily ported to others
• Actively maintained
• Fork it on github
• Two modules
• Core
• Mapper (implementation)
• http://kimprince.com
• Detailed usage discussion
• Code examples
THE MVC ‘MODEL’
- An umbrella for a whole other structure
- The Domain, The Data Mapper, The Service Layer
The Domain: Domain objects
• Represent business objects
• Typically nouns such as ‘customer’, ‘product’
• Include data and behaviour
• Each implements its own interface
• Easily proxied or mocked
• Abstract parent
• Provides common features
• Encapsulation
• $allowed array
• Keys are property names
• Boolean values describe required/optional behaviour
• $data array stores real values
The Domain: Domain objects (cont)
• Construction
• Object factories do the heavy lifting
• Constructor expects an array of filtered values
• Checks that mandatory values have been supplied
• Sets any factories and finders which may have been injected
• Access
• Properties are ‘open for reading, closed for writing’
• __get() – assumes client code can read properties
• __set() – assumes client code can NOT write properties
• Override these with getPropertyName(), setPropertyName($value)
• Identity
• Abstract accessors: getId(), setId()
• For globally unique id: getShortType($object) . $object->getId()
• Value objects are handled differently
The Domain: Object proxies
• Most Domain objects have a proxy
• Factories may substitute proxies for real properties
• A proxy has a real object id and finder (Mapper)
• A proxy is realised if/when it is accessed
• Unless accessing the id only
The Domain: Collections
• One per Domain class (usually)
• Each implements own interface
• Easily proxied or mocked
• Iterable and countable
• Commonly returned by Mappers
• Contain a factory and an array of raw data
• May contain custom logic for the given type
• For sorting, filtering, adding members, removing, comparing, …
• Pass out a clone when filtering or sorting
The Domain: Collection proxies
• Most collections have a proxy
• Class diagram (over)
• Collections and their proxies inherit from a common hierarchy
• Key difference:
• A collection becomes an iterator
• A collection proxy becomes an iterator aggregate
• Iterator aggregate references the real iterator
• On construction, proxies receive
• A finder – for retrieving the collection
• A method name – which exists on the finder
• An array of arguments – which are passed to the finder method
• Collection proxies are used extensively by factories
• As a substitute for multi-valued properties
The Domain: Collection proxies (cont)
The Domain: Object factories
• Often long and complex classes
• Loaded via an abstract factory
• Use the factory method pattern
• Factories are service locator aware
• Include features related to N+1 selects handling (more later)
Method Responsibilities
New Object Defaults • Add defaults for new objects
• Override inputs where necessary
Type Conversion • Cast inputs to required types or proxies
Add Relations • Add collection proxies for multi-valued properties
Instantiation • Inject to constructor: $data, $finders, $factories
The Domain: Identity map
• A safety net
• Performance
• Model integrity
• Main clients: Object factories
• Check for existing before instantiating a Domain object
• Add newly instantiated Domain objects to the map
• Other clients: Data Mappers
• Check for existing before executing a ‘find’ query
• Add newly created entities to the map
• Following a db insert, since that’s when the id is assigned
The Mapper
• Translates between object world and the db
• Converts between under_score and camelCase
• Usually one Mapper class per Domain object
• A typical Mapper has:
• find($id) – returns a single Domain object
• Other single-object finders, such as findByName($name)
• Numerous collection finders, such as findByFoo($id)
• insert($object) – executes an sql insert
• update($object) – executes an sql update
• Mappers are loaded via an abstract factory
The Service Layer
• Highest layer of the Model
• Depends on Domain and Mapper
• Service-locator-aware
• Composes an event manager
• Loaded via an abstract factory
• Tasks
• “Whatever clients need…”
• Persisting changes
• Including database transactions
EVERYTHING ELSE
Non-Model considerations
Views, controllers, helpers
• Views
• OOTB
• Extensive use of helpers
• Forms – Consider hand-crafted for more control
• Confidence in performance, based on:
• Identity map means no fetching duplicates
• Object factories use collection proxies to avoid N+1 selects
• Controllers
• OOTB
• Service locator aware
• Helper trait
• Inserted into most supertypes
• getShortType() identifies a family of objects
• TheObject, TheObjectMapper, TheObjectFactory, TheObjectCollection
A note on filtering and validation
• May be located in Service Layer or Domain
• Option 1: Service Layer
• Easy to manage – i.e. audit, fix gaps
• Option 2: Domain (and Mapper)
• More difficult to manage, but a better fit with OO
• Three data contexts:
• Newly created entities – filter and validate in the object’s factory
• Updates to object properties – filter and validate in custom setters
• Finder parameters – filter and validate in Mappers themselves
The N+1 selects problem
• Occurs where a Domain object has a multi-valued property
• ‘First degree’ problems solved when factory used correctly, e.g.:
• If bars is multi-valued property of Foo…
• The Foo factory sets Foo->bars to a Bar collection proxy
• ‘Second degree’ problems require new factory ‘flavours’
• Flavours are stored in factories as class constants, e.g. FOO::BARS_WITH_BAZ
• Use setFlavour() and addFlavour() to configure factory
• In flavoured factories, collection proxies eagerly load navigable associations
• This affects Mappers too, e.g. Bar Mapper needs findByFooWithBaz($foo)
• See detailed usage discussion for more examples
Using the Starter Application
• See detailed usage discussion for notes on:
• Defining the business problem
• Building the Domain
• Building the Data Mapper
• Building the Service Layer
• Building the presentation layer (views, controllers)
• Iterating to completion
• Also in the usage discussion:
• Create your own Starter Application from Zend’s ZF2 Skeleton App.
www.kimprince.com
@Kim_Prince

More Related Content

What's hot

04 darwino concepts and utility classes
04   darwino concepts and utility classes04   darwino concepts and utility classes
04 darwino concepts and utility classesdarwinodb
 
Integrating Doctrine with Laravel
Integrating Doctrine with LaravelIntegrating Doctrine with Laravel
Integrating Doctrine with LaravelMark Garratt
 
Hibernate Tips ‘n’ Tricks - 15 Tips to solve common problems
Hibernate Tips ‘n’ Tricks - 15 Tips to solve common problemsHibernate Tips ‘n’ Tricks - 15 Tips to solve common problems
Hibernate Tips ‘n’ Tricks - 15 Tips to solve common problemsThorben Janssen
 
The Good, the Bad and the Ugly of Java API design
The Good, the Bad and the Ugly of Java API designThe Good, the Bad and the Ugly of Java API design
The Good, the Bad and the Ugly of Java API designMiro Cupak
 
iPhone dev intro
iPhone dev introiPhone dev intro
iPhone dev introVonbo
 
BGOUG 2012 - Drag & drop and other stuff - Using your database as a file server
BGOUG 2012 - Drag & drop and other stuff - Using your database as a file serverBGOUG 2012 - Drag & drop and other stuff - Using your database as a file server
BGOUG 2012 - Drag & drop and other stuff - Using your database as a file serverMarco Gralike
 
Spark real world use cases and optimizations
Spark real world use cases and optimizationsSpark real world use cases and optimizations
Spark real world use cases and optimizationsGal Marder
 
The good, the bad, and the ugly of Java API design
The good, the bad, and the ugly of Java API designThe good, the bad, and the ugly of Java API design
The good, the bad, and the ugly of Java API designMiro Cupak
 
/path/to/content - the Apache Jackrabbit content repository
/path/to/content - the Apache Jackrabbit content repository/path/to/content - the Apache Jackrabbit content repository
/path/to/content - the Apache Jackrabbit content repositoryJukka Zitting
 
Battle of the giants: Apache Solr vs ElasticSearch
Battle of the giants: Apache Solr vs ElasticSearchBattle of the giants: Apache Solr vs ElasticSearch
Battle of the giants: Apache Solr vs ElasticSearchRafał Kuć
 
Introduction to NHibernate
Introduction to NHibernateIntroduction to NHibernate
Introduction to NHibernateDublin Alt,Net
 

What's hot (11)

04 darwino concepts and utility classes
04   darwino concepts and utility classes04   darwino concepts and utility classes
04 darwino concepts and utility classes
 
Integrating Doctrine with Laravel
Integrating Doctrine with LaravelIntegrating Doctrine with Laravel
Integrating Doctrine with Laravel
 
Hibernate Tips ‘n’ Tricks - 15 Tips to solve common problems
Hibernate Tips ‘n’ Tricks - 15 Tips to solve common problemsHibernate Tips ‘n’ Tricks - 15 Tips to solve common problems
Hibernate Tips ‘n’ Tricks - 15 Tips to solve common problems
 
The Good, the Bad and the Ugly of Java API design
The Good, the Bad and the Ugly of Java API designThe Good, the Bad and the Ugly of Java API design
The Good, the Bad and the Ugly of Java API design
 
iPhone dev intro
iPhone dev introiPhone dev intro
iPhone dev intro
 
BGOUG 2012 - Drag & drop and other stuff - Using your database as a file server
BGOUG 2012 - Drag & drop and other stuff - Using your database as a file serverBGOUG 2012 - Drag & drop and other stuff - Using your database as a file server
BGOUG 2012 - Drag & drop and other stuff - Using your database as a file server
 
Spark real world use cases and optimizations
Spark real world use cases and optimizationsSpark real world use cases and optimizations
Spark real world use cases and optimizations
 
The good, the bad, and the ugly of Java API design
The good, the bad, and the ugly of Java API designThe good, the bad, and the ugly of Java API design
The good, the bad, and the ugly of Java API design
 
/path/to/content - the Apache Jackrabbit content repository
/path/to/content - the Apache Jackrabbit content repository/path/to/content - the Apache Jackrabbit content repository
/path/to/content - the Apache Jackrabbit content repository
 
Battle of the giants: Apache Solr vs ElasticSearch
Battle of the giants: Apache Solr vs ElasticSearchBattle of the giants: Apache Solr vs ElasticSearch
Battle of the giants: Apache Solr vs ElasticSearch
 
Introduction to NHibernate
Introduction to NHibernateIntroduction to NHibernate
Introduction to NHibernate
 

Viewers also liked (7)

9.4 Group 6
9.4 Group 69.4 Group 6
9.4 Group 6
 
RestaurantFinder
RestaurantFinderRestaurantFinder
RestaurantFinder
 
My restaurant finder hci
My restaurant finder hciMy restaurant finder hci
My restaurant finder hci
 
Restaurant management
Restaurant managementRestaurant management
Restaurant management
 
Android Application Seminar_Usman
Android Application Seminar_UsmanAndroid Application Seminar_Usman
Android Application Seminar_Usman
 
Computer Based Ordering System
Computer Based Ordering SystemComputer Based Ordering System
Computer Based Ordering System
 
Customer ordering system
Customer ordering systemCustomer ordering system
Customer ordering system
 

Similar to PHP Starter Application

Software design with Domain-driven design
Software design with Domain-driven design Software design with Domain-driven design
Software design with Domain-driven design Allan Mangune
 
SE2016 - Java EE revisits design patterns 2016
SE2016 - Java EE revisits design patterns 2016SE2016 - Java EE revisits design patterns 2016
SE2016 - Java EE revisits design patterns 2016Alex Theedom
 
Integrating the Solr search engine
Integrating the Solr search engineIntegrating the Solr search engine
Integrating the Solr search engineth0masr
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoFu Cheng
 
Java EE revisits design patterns
Java EE revisits design patternsJava EE revisits design patterns
Java EE revisits design patternsAlex Theedom
 
Java EE revisits design patterns
Java EE revisits design patterns Java EE revisits design patterns
Java EE revisits design patterns Alex Theedom
 
hibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdfhibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdfPatiento Del Mar
 
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and CapabilitiesNot Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and CapabilitiesBrett Meyer
 
Java EE Revisits Design Patterns
Java EE Revisits Design PatternsJava EE Revisits Design Patterns
Java EE Revisits Design PatternsAlex Theedom
 
OrigoDB - take the red pill
OrigoDB - take the red pillOrigoDB - take the red pill
OrigoDB - take the red pillRobert Friberg
 
Full Text Search with Lucene
Full Text Search with LuceneFull Text Search with Lucene
Full Text Search with LuceneWO Community
 
Apache Solr crash course
Apache Solr crash courseApache Solr crash course
Apache Solr crash courseTommaso Teofili
 
Informatica power center online training
Informatica power center online trainingInformatica power center online training
Informatica power center online trainingSmartittrainings
 
Informatica power center 8.x course content
Informatica power center 8.x course contentInformatica power center 8.x course content
Informatica power center 8.x course contentSmartittrainings
 
Informatica online training from inida
Informatica online training from inidaInformatica online training from inida
Informatica online training from inidaQualitytrainings
 
Informatica online training from inida
Informatica online training from inidaInformatica online training from inida
Informatica online training from inidaQualitytrainings
 
Informatica online training from inida
Informatica online training from inidaInformatica online training from inida
Informatica online training from inidaQualitytrainings
 
Informatica online training from inida
Informatica online training from inidaInformatica online training from inida
Informatica online training from inidaQualitytrainings
 

Similar to PHP Starter Application (20)

Software design with Domain-driven design
Software design with Domain-driven design Software design with Domain-driven design
Software design with Domain-driven design
 
SE2016 - Java EE revisits design patterns 2016
SE2016 - Java EE revisits design patterns 2016SE2016 - Java EE revisits design patterns 2016
SE2016 - Java EE revisits design patterns 2016
 
Integrating the Solr search engine
Integrating the Solr search engineIntegrating the Solr search engine
Integrating the Solr search engine
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
 
Java EE revisits design patterns
Java EE revisits design patternsJava EE revisits design patterns
Java EE revisits design patterns
 
Java EE revisits design patterns
Java EE revisits design patterns Java EE revisits design patterns
Java EE revisits design patterns
 
hibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdfhibernateormfeatures-140223193044-phpapp02.pdf
hibernateormfeatures-140223193044-phpapp02.pdf
 
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and CapabilitiesNot Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
 
Java EE Revisits Design Patterns
Java EE Revisits Design PatternsJava EE Revisits Design Patterns
Java EE Revisits Design Patterns
 
OrigoDB - take the red pill
OrigoDB - take the red pillOrigoDB - take the red pill
OrigoDB - take the red pill
 
Full Text Search with Lucene
Full Text Search with LuceneFull Text Search with Lucene
Full Text Search with Lucene
 
06.1 .Net memory management
06.1 .Net memory management06.1 .Net memory management
06.1 .Net memory management
 
Apache Solr crash course
Apache Solr crash courseApache Solr crash course
Apache Solr crash course
 
Informatica power center online training
Informatica power center online trainingInformatica power center online training
Informatica power center online training
 
Fedora4
Fedora4Fedora4
Fedora4
 
Informatica power center 8.x course content
Informatica power center 8.x course contentInformatica power center 8.x course content
Informatica power center 8.x course content
 
Informatica online training from inida
Informatica online training from inidaInformatica online training from inida
Informatica online training from inida
 
Informatica online training from inida
Informatica online training from inidaInformatica online training from inida
Informatica online training from inida
 
Informatica online training from inida
Informatica online training from inidaInformatica online training from inida
Informatica online training from inida
 
Informatica online training from inida
Informatica online training from inidaInformatica online training from inida
Informatica online training from inida
 

Recently uploaded

SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhimiss dipika
 
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Sonam Pathan
 
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一Fs
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书rnrncn29
 
Intellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptxIntellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptxBipin Adhikari
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一Fs
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一z xss
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITMgdsc13
 
Elevate Your Business with Our IT Expertise in New Orleans
Elevate Your Business with Our IT Expertise in New OrleansElevate Your Business with Our IT Expertise in New Orleans
Elevate Your Business with Our IT Expertise in New Orleanscorenetworkseo
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Paul Calvano
 
Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Excelmac1
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Dana Luther
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作ys8omjxb
 

Recently uploaded (20)

SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhi
 
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
 
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
 
Intellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptxIntellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptx
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
 
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
Elevate Your Business with Our IT Expertise in New Orleans
Elevate Your Business with Our IT Expertise in New OrleansElevate Your Business with Our IT Expertise in New Orleans
Elevate Your Business with Our IT Expertise in New Orleans
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24
 
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
 
Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...
 
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
 

PHP Starter Application

  • 1. PHP STARTER APPLICATION For Complex Business Logic http://github.com/KimPrince/zf2-starter
  • 2. Dealing with business complexity General Requirements • Means of organizing logic • Flexible database interaction • A clear API for client code Solution • MVC skeleton with a Model • Model • The Domain, with: • Domain object factories • Collection handling and logic • Proxies • Single-valued properties • Multi-valued properties • Identity map • The Data Mapper • The Service Layer • View – OOTB • Controller – OOTB
  • 3. The code • Zend Framework 2 • Easily ported to others • Actively maintained • Fork it on github • Two modules • Core • Mapper (implementation) • http://kimprince.com • Detailed usage discussion • Code examples
  • 4. THE MVC ‘MODEL’ - An umbrella for a whole other structure - The Domain, The Data Mapper, The Service Layer
  • 5. The Domain: Domain objects • Represent business objects • Typically nouns such as ‘customer’, ‘product’ • Include data and behaviour • Each implements its own interface • Easily proxied or mocked • Abstract parent • Provides common features • Encapsulation • $allowed array • Keys are property names • Boolean values describe required/optional behaviour • $data array stores real values
  • 6. The Domain: Domain objects (cont) • Construction • Object factories do the heavy lifting • Constructor expects an array of filtered values • Checks that mandatory values have been supplied • Sets any factories and finders which may have been injected • Access • Properties are ‘open for reading, closed for writing’ • __get() – assumes client code can read properties • __set() – assumes client code can NOT write properties • Override these with getPropertyName(), setPropertyName($value) • Identity • Abstract accessors: getId(), setId() • For globally unique id: getShortType($object) . $object->getId() • Value objects are handled differently
  • 7. The Domain: Object proxies • Most Domain objects have a proxy • Factories may substitute proxies for real properties • A proxy has a real object id and finder (Mapper) • A proxy is realised if/when it is accessed • Unless accessing the id only
  • 8. The Domain: Collections • One per Domain class (usually) • Each implements own interface • Easily proxied or mocked • Iterable and countable • Commonly returned by Mappers • Contain a factory and an array of raw data • May contain custom logic for the given type • For sorting, filtering, adding members, removing, comparing, … • Pass out a clone when filtering or sorting
  • 9. The Domain: Collection proxies • Most collections have a proxy • Class diagram (over) • Collections and their proxies inherit from a common hierarchy • Key difference: • A collection becomes an iterator • A collection proxy becomes an iterator aggregate • Iterator aggregate references the real iterator • On construction, proxies receive • A finder – for retrieving the collection • A method name – which exists on the finder • An array of arguments – which are passed to the finder method • Collection proxies are used extensively by factories • As a substitute for multi-valued properties
  • 10. The Domain: Collection proxies (cont)
  • 11. The Domain: Object factories • Often long and complex classes • Loaded via an abstract factory • Use the factory method pattern • Factories are service locator aware • Include features related to N+1 selects handling (more later) Method Responsibilities New Object Defaults • Add defaults for new objects • Override inputs where necessary Type Conversion • Cast inputs to required types or proxies Add Relations • Add collection proxies for multi-valued properties Instantiation • Inject to constructor: $data, $finders, $factories
  • 12. The Domain: Identity map • A safety net • Performance • Model integrity • Main clients: Object factories • Check for existing before instantiating a Domain object • Add newly instantiated Domain objects to the map • Other clients: Data Mappers • Check for existing before executing a ‘find’ query • Add newly created entities to the map • Following a db insert, since that’s when the id is assigned
  • 13. The Mapper • Translates between object world and the db • Converts between under_score and camelCase • Usually one Mapper class per Domain object • A typical Mapper has: • find($id) – returns a single Domain object • Other single-object finders, such as findByName($name) • Numerous collection finders, such as findByFoo($id) • insert($object) – executes an sql insert • update($object) – executes an sql update • Mappers are loaded via an abstract factory
  • 14. The Service Layer • Highest layer of the Model • Depends on Domain and Mapper • Service-locator-aware • Composes an event manager • Loaded via an abstract factory • Tasks • “Whatever clients need…” • Persisting changes • Including database transactions
  • 16. Views, controllers, helpers • Views • OOTB • Extensive use of helpers • Forms – Consider hand-crafted for more control • Confidence in performance, based on: • Identity map means no fetching duplicates • Object factories use collection proxies to avoid N+1 selects • Controllers • OOTB • Service locator aware • Helper trait • Inserted into most supertypes • getShortType() identifies a family of objects • TheObject, TheObjectMapper, TheObjectFactory, TheObjectCollection
  • 17. A note on filtering and validation • May be located in Service Layer or Domain • Option 1: Service Layer • Easy to manage – i.e. audit, fix gaps • Option 2: Domain (and Mapper) • More difficult to manage, but a better fit with OO • Three data contexts: • Newly created entities – filter and validate in the object’s factory • Updates to object properties – filter and validate in custom setters • Finder parameters – filter and validate in Mappers themselves
  • 18. The N+1 selects problem • Occurs where a Domain object has a multi-valued property • ‘First degree’ problems solved when factory used correctly, e.g.: • If bars is multi-valued property of Foo… • The Foo factory sets Foo->bars to a Bar collection proxy • ‘Second degree’ problems require new factory ‘flavours’ • Flavours are stored in factories as class constants, e.g. FOO::BARS_WITH_BAZ • Use setFlavour() and addFlavour() to configure factory • In flavoured factories, collection proxies eagerly load navigable associations • This affects Mappers too, e.g. Bar Mapper needs findByFooWithBaz($foo) • See detailed usage discussion for more examples
  • 19. Using the Starter Application • See detailed usage discussion for notes on: • Defining the business problem • Building the Domain • Building the Data Mapper • Building the Service Layer • Building the presentation layer (views, controllers) • Iterating to completion • Also in the usage discussion: • Create your own Starter Application from Zend’s ZF2 Skeleton App.