SlideShare una empresa de Scribd logo
1 de 31
The Why Behind PHP
Frameworks
Kirk Madera
Director, Technology @ Robofirm
About Me
• Zend Framemwork 2 Certified
• Magento Certified Plus
• Zend PHP 5.5 Certified Engineer
• Married with two kids
• Metalhead
• Coding experience rooted in C++
• Writing PHP for 10+ years
Objective
Start with a simple HTML site and transform it by solving one problem
at a time into something that resembles a modern day framework.
Overview
• Distribute virtual machines (Virtual Box or VMWare)
• Hands on coding with explanations at each step
• Git tags that map to each step
(Use “git clean -xf; git reset --hard {tagname}” if you get behind)
• Ticket sales site is used as our test site
• Don’t judge my design work
Let’s get started!
1.0: Review plain HTML and discuss issues
• What if you ran a plain HTML site?
• Every artist and show would require a new html file
• A rescheduled show requires multiple file edits
• Duplication causes human error
• Dynamic lists like “Most Popular” maintained in HTML
2.0: Reduce duplication through require statements
• So we need php. Skip to git tag 2.0 to get all files converted to PHP.
• require() for head, header, footer, and before body end
• How to deal with title since it’s dynamic? Global variable?
• Problems with global variables.
• Referring to templates from diff directories (e.g. artists/ vs. /)
• How to deal with links in title?
3.0 Encapsulation – Fixing the global variable problem
• Encapsulation is a big word for containing all logic and data for
something in a single place
• We need classes for this
• We’ll start off simple by making a single class in index.php
3.1 Encapsulation – Apply to shows.php and artists.php
• We’ll apply the same idea to shows.php and artists.php
• What if we had to keep going to all php files in artists and shows?
• And wait a second… duplication is back…
3.2 Encapsulation - Reusing classes
• We need index.php, shows.php, artists.php and all other pages to use
the same TemplateRenderer class
• Start by moving it to it’s own file
4.0 Bootstrapping
• Notice the code at the top of each file is growing
• All pages need a lot of the same things to happen
• Additional examples:
• Set error reporting
• Set a BASE_PATH constant
• Set the cwd() to make working with files easier
• Set an environment based variable like DEVELOPER_MODE
• Create bootstrap.php
• Also add BASE_PATH
4.1 Bootstrapping - Autoloader
• require() needs to be called on every page for TemplateRenderer
• What about when we have more classes?
• Requiring every class would be slow
• Lazy requiring classes with require_once() is also slow
• We can avoid thinking about requires altogether with an autoloader
5.0 Separate Logic from View
• Data/Logic should not live in the view
• Things to separate:
• “Popular” artists/shows list
• All artists/shows lists
• Single artist/show data
• Start by moving data to arrays
5.1 Separate Logic From View - Classes
• Move arrays out of templates and into classes
• We’ll call these Mapper classes since
• We will use static arrays within the Mapper classes
• In the next step, we will make this data dynamic
6.0 Dynamic data
• Work entirely within the Mapper classes for now
• Use built in PDO class
• All mappers need database access.
• Where to put credentials?
• Should I make this connection separately for each mapper?
7.0 Routing and Controllers
• Routing lets us have pretty URLs
• E.g. “/shows/metallica-gexa-pavilion-2016-05-04” instead of
“/shows.php?id=1”
• Front Controller Pattern – All requests go to index.php. Router routes
to the right controller
• Make these URLs functional “/”, “/shows”, “/artists”
• Delete shows.php and artists.php
7.1 Routing and Controllers - Artist and show pages
• Repeat previous step but for view pages
• How to deal with ids in URL?
• We have ugly URLs now… like “artist.php?id=4”
7.2 Routing and Controllers – Pretty URLs
• Change URLs from “artist.php?id=1” to “artist/metallica”
• URL alias mapper
8.0 Move all views into templates – Clean up TemplateRenderer
• Remove the need to specify full template path and file extension
8.1 Move all views into templates
• Move all views into controllers for now
• The old separate PHP top level files are the equivalent of controllers
9.0 App class – Encapsulate bootstrap and run
• This makes it easier to have multiple entry points to your app
• For example, a shell script entry point or an API
10.0 Service Locator - Invokables
• Shh.. This is Dependency Injection
• This is just an easier way to understand it
• We are improving reusability and testability here
10.1 Service Locator - Factories
• Creating dependencies which have their own dependencies
10.2 ReflectionFactory
• Doing it automatically
• Avoid making factories for everything
• Reflection in PHP 7 is fast enough that this is viable
• A production strategy of caching a compiled factory built by reflection
works also. (Magento 2 does something similar)
11.0 File Security – Making a public directory
• All files in the project are currently within the web root
• That means the are web accessible
• Save yourself a security headache and move the document root to a
subdirectory called “public”
• Update Nginx
sudo sed -i
's|/var/www/local.tickets.com|/var/www/local.tickets.com/public|g'
/etc/nginx/sites-available/local.tickets.com;
sudo service nginx restart;
12.0 Config
• Configuration should be separate from code
• Move configuration from public/index.php to config/app.php
• Many strategies could be used for collecting configuration
• This is especially important when you get to more complicated
modular code
13.0 Blocks
• Move logic related to grabbing the data for the view into Block classes
• Thins out the controllers
Compare to Other Frameworks
• Zend Framework 2:
https://github.com/zendframework/ZendSkeletonApplication
• Symfony:
https://github.com/symfony/symfony-standard
• Laravel:
https://github.com/hyfn/laravel-skeleton/tree/master/public
Why use a framework?
• Don’t reinvent the wheel
• Benefit from others’ experience
• Spend time on the core purpose of your site
Resources
• Code:
https://bitbucket.org/robofirm/tickets.com-tutorial
• Site URL:
http://local.tickets.com/
• VM:
https://robofirm.box.com/s/ip0xg5gw2gjomu4nr64col7rjiwnx760
• This Slideshow:
http://www.slideshare.net/KirkMadera/they-why-behind-php-
frameworks

Más contenido relacionado

La actualidad más candente

NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...
NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...
NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...Frank van der Linden
 
Developing PHP Applications Faster
Developing PHP Applications FasterDeveloping PHP Applications Faster
Developing PHP Applications FasterAdam Culp
 
Getting Started with ASP.net Core 1.0
Getting Started with ASP.net Core 1.0Getting Started with ASP.net Core 1.0
Getting Started with ASP.net Core 1.0joescars
 
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20Michael Lihs
 
Conquering AngularJS Limitations
Conquering AngularJS LimitationsConquering AngularJS Limitations
Conquering AngularJS LimitationsValeri Karpov
 
RESTFul Tools For Lazy Experts - CFSummit 2016
RESTFul Tools For Lazy Experts - CFSummit 2016RESTFul Tools For Lazy Experts - CFSummit 2016
RESTFul Tools For Lazy Experts - CFSummit 2016Ortus Solutions, Corp
 
Ship It ! with Ruby/ Rails Ecosystem
Ship It ! with Ruby/ Rails EcosystemShip It ! with Ruby/ Rails Ecosystem
Ship It ! with Ruby/ Rails EcosystemYi-Ting Cheng
 
Building Web Apps in Ratpack
Building Web Apps in RatpackBuilding Web Apps in Ratpack
Building Web Apps in RatpackDaniel Woods
 
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)daylerees
 
Practical PHP Deployment with Jenkins
Practical PHP Deployment with JenkinsPractical PHP Deployment with Jenkins
Practical PHP Deployment with JenkinsAdam Culp
 
Asp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework CoreAsp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework Coremohamed elshafey
 
Intro to Ratpack (CDJDN 2015-01-22)
Intro to Ratpack (CDJDN 2015-01-22)Intro to Ratpack (CDJDN 2015-01-22)
Intro to Ratpack (CDJDN 2015-01-22)David Carr
 
Dev objective2015 lets git together
Dev objective2015 lets git togetherDev objective2015 lets git together
Dev objective2015 lets git togetherColdFusionConference
 
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember DataIn The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember DataStacy London
 

La actualidad más candente (20)

NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...
NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...
NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...
 
Command box
Command boxCommand box
Command box
 
Agile sites @ telmore
Agile sites @ telmore Agile sites @ telmore
Agile sites @ telmore
 
Agile sites2
Agile sites2Agile sites2
Agile sites2
 
Developing PHP Applications Faster
Developing PHP Applications FasterDeveloping PHP Applications Faster
Developing PHP Applications Faster
 
Getting Started with ASP.net Core 1.0
Getting Started with ASP.net Core 1.0Getting Started with ASP.net Core 1.0
Getting Started with ASP.net Core 1.0
 
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
 
Conquering AngularJS Limitations
Conquering AngularJS LimitationsConquering AngularJS Limitations
Conquering AngularJS Limitations
 
RESTFul Tools For Lazy Experts - CFSummit 2016
RESTFul Tools For Lazy Experts - CFSummit 2016RESTFul Tools For Lazy Experts - CFSummit 2016
RESTFul Tools For Lazy Experts - CFSummit 2016
 
Ship It ! with Ruby/ Rails Ecosystem
Ship It ! with Ruby/ Rails EcosystemShip It ! with Ruby/ Rails Ecosystem
Ship It ! with Ruby/ Rails Ecosystem
 
Building Web Apps in Ratpack
Building Web Apps in RatpackBuilding Web Apps in Ratpack
Building Web Apps in Ratpack
 
Instant ColdFusion with Vagrant
Instant ColdFusion with VagrantInstant ColdFusion with Vagrant
Instant ColdFusion with Vagrant
 
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
 
Practical PHP Deployment with Jenkins
Practical PHP Deployment with JenkinsPractical PHP Deployment with Jenkins
Practical PHP Deployment with Jenkins
 
Hidden gems in cf2016
Hidden gems in cf2016Hidden gems in cf2016
Hidden gems in cf2016
 
Keep Applications Online
Keep Applications OnlineKeep Applications Online
Keep Applications Online
 
Asp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework CoreAsp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework Core
 
Intro to Ratpack (CDJDN 2015-01-22)
Intro to Ratpack (CDJDN 2015-01-22)Intro to Ratpack (CDJDN 2015-01-22)
Intro to Ratpack (CDJDN 2015-01-22)
 
Dev objective2015 lets git together
Dev objective2015 lets git togetherDev objective2015 lets git together
Dev objective2015 lets git together
 
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember DataIn The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
 

Destacado

Flat 4-animated powerpoint jjd
Flat 4-animated powerpoint jjdFlat 4-animated powerpoint jjd
Flat 4-animated powerpoint jjdhaverstockmedia
 
Kunci dan Perangkat PENJASKES SMP kelas 8
Kunci dan Perangkat PENJASKES SMP kelas 8Kunci dan Perangkat PENJASKES SMP kelas 8
Kunci dan Perangkat PENJASKES SMP kelas 8Sulistiyo Wibowo
 
Selenium course syllabus
Selenium course syllabusSelenium course syllabus
Selenium course syllabuslakshmipriyaaka
 
Reklamos prekybos centruose apžvalga
Reklamos prekybos centruose apžvalgaReklamos prekybos centruose apžvalga
Reklamos prekybos centruose apžvalgaKarolis Rimkus
 
Kunci dan Perangkat PENJASKES SMP kelas 9
Kunci dan Perangkat PENJASKES SMP kelas 9Kunci dan Perangkat PENJASKES SMP kelas 9
Kunci dan Perangkat PENJASKES SMP kelas 9Sulistiyo Wibowo
 
(Eft)emotional freedom technique cici
(Eft)emotional  freedom technique cici(Eft)emotional  freedom technique cici
(Eft)emotional freedom technique ciciYan Eshad
 
ルイヴィトンのバッグは
ルイヴィトンのバッグはルイヴィトンのバッグは
ルイヴィトンのバッグはyixing152
 

Destacado (8)

Flat 4-animated powerpoint jjd
Flat 4-animated powerpoint jjdFlat 4-animated powerpoint jjd
Flat 4-animated powerpoint jjd
 
Kunci dan Perangkat PENJASKES SMP kelas 8
Kunci dan Perangkat PENJASKES SMP kelas 8Kunci dan Perangkat PENJASKES SMP kelas 8
Kunci dan Perangkat PENJASKES SMP kelas 8
 
Selenium course syllabus
Selenium course syllabusSelenium course syllabus
Selenium course syllabus
 
Sesiones de la conferencia
Sesiones de la conferenciaSesiones de la conferencia
Sesiones de la conferencia
 
Reklamos prekybos centruose apžvalga
Reklamos prekybos centruose apžvalgaReklamos prekybos centruose apžvalga
Reklamos prekybos centruose apžvalga
 
Kunci dan Perangkat PENJASKES SMP kelas 9
Kunci dan Perangkat PENJASKES SMP kelas 9Kunci dan Perangkat PENJASKES SMP kelas 9
Kunci dan Perangkat PENJASKES SMP kelas 9
 
(Eft)emotional freedom technique cici
(Eft)emotional  freedom technique cici(Eft)emotional  freedom technique cici
(Eft)emotional freedom technique cici
 
ルイヴィトンのバッグは
ルイヴィトンのバッグはルイヴィトンのバッグは
ルイヴィトンのバッグは
 

Similar a The Why Behind PHP Frameworks: From Plain HTML to MVC Framework

Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsTaylor Lovett
 
Symfony2 for legacy app rejuvenation: the eZ Publish case study
Symfony2 for legacy app rejuvenation: the eZ Publish case studySymfony2 for legacy app rejuvenation: the eZ Publish case study
Symfony2 for legacy app rejuvenation: the eZ Publish case studyGaetano Giunta
 
Porting Projects to .NET 5
Porting Projects to .NET 5Porting Projects to .NET 5
Porting Projects to .NET 5Immo Landwerth
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Henry S
 
Git Going w/ Git
Git Going w/ GitGit Going w/ Git
Git Going w/ GitheyMP
 
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Mack Hardy
 
Continuous Integration at Mollie
Continuous Integration at MollieContinuous Integration at Mollie
Continuous Integration at Molliewillemstuursma
 
Migration from ASP.NET MVC to ASP.NET Core
Migration from ASP.NET MVC to ASP.NET CoreMigration from ASP.NET MVC to ASP.NET Core
Migration from ASP.NET MVC to ASP.NET CoreMiroslav Popovic
 
Symfony under control. Continuous Integration and Automated Deployments in Sy...
Symfony under control. Continuous Integration and Automated Deployments in Sy...Symfony under control. Continuous Integration and Automated Deployments in Sy...
Symfony under control. Continuous Integration and Automated Deployments in Sy...Max Romanovsky
 
Symfony Under Control by Maxim Romanovsky
Symfony Under Control by Maxim RomanovskySymfony Under Control by Maxim Romanovsky
Symfony Under Control by Maxim Romanovskyphp-user-group-minsk
 
Sitecore development approach evolution – destination helix
Sitecore development approach evolution – destination helixSitecore development approach evolution – destination helix
Sitecore development approach evolution – destination helixPeter Nazarov
 
Zend Framework 2, What's new, Confoo 2011
Zend Framework 2, What's new, Confoo 2011Zend Framework 2, What's new, Confoo 2011
Zend Framework 2, What's new, Confoo 2011Bachkoutou Toutou
 
Writing Services with ZF2
Writing Services with ZF2Writing Services with ZF2
Writing Services with ZF2Mike Willbanks
 
Stress Free Deployment - Confoo 2011
Stress Free Deployment  - Confoo 2011Stress Free Deployment  - Confoo 2011
Stress Free Deployment - Confoo 2011Bachkoutou Toutou
 
SOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class LibrariesSOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class LibrariesVagif Abilov
 
CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...
CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...
CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...E. Camden Fisher
 
Headless cms architecture
Headless cms architectureHeadless cms architecture
Headless cms architectureKevin Wenger
 
Drupal 8 deeper dive
Drupal 8 deeper diveDrupal 8 deeper dive
Drupal 8 deeper diveAmazee Labs
 

Similar a The Why Behind PHP Frameworks: From Plain HTML to MVC Framework (20)

Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress Applications
 
Symfony2 for legacy app rejuvenation: the eZ Publish case study
Symfony2 for legacy app rejuvenation: the eZ Publish case studySymfony2 for legacy app rejuvenation: the eZ Publish case study
Symfony2 for legacy app rejuvenation: the eZ Publish case study
 
Codeigniter framework
Codeigniter framework Codeigniter framework
Codeigniter framework
 
Porting Projects to .NET 5
Porting Projects to .NET 5Porting Projects to .NET 5
Porting Projects to .NET 5
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1
 
Git Going w/ Git
Git Going w/ GitGit Going w/ Git
Git Going w/ Git
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
 
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
 
Continuous Integration at Mollie
Continuous Integration at MollieContinuous Integration at Mollie
Continuous Integration at Mollie
 
Migration from ASP.NET MVC to ASP.NET Core
Migration from ASP.NET MVC to ASP.NET CoreMigration from ASP.NET MVC to ASP.NET Core
Migration from ASP.NET MVC to ASP.NET Core
 
Symfony under control. Continuous Integration and Automated Deployments in Sy...
Symfony under control. Continuous Integration and Automated Deployments in Sy...Symfony under control. Continuous Integration and Automated Deployments in Sy...
Symfony under control. Continuous Integration and Automated Deployments in Sy...
 
Symfony Under Control by Maxim Romanovsky
Symfony Under Control by Maxim RomanovskySymfony Under Control by Maxim Romanovsky
Symfony Under Control by Maxim Romanovsky
 
Sitecore development approach evolution – destination helix
Sitecore development approach evolution – destination helixSitecore development approach evolution – destination helix
Sitecore development approach evolution – destination helix
 
Zend Framework 2, What's new, Confoo 2011
Zend Framework 2, What's new, Confoo 2011Zend Framework 2, What's new, Confoo 2011
Zend Framework 2, What's new, Confoo 2011
 
Writing Services with ZF2
Writing Services with ZF2Writing Services with ZF2
Writing Services with ZF2
 
Stress Free Deployment - Confoo 2011
Stress Free Deployment  - Confoo 2011Stress Free Deployment  - Confoo 2011
Stress Free Deployment - Confoo 2011
 
SOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class LibrariesSOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class Libraries
 
CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...
CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...
CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...
 
Headless cms architecture
Headless cms architectureHeadless cms architecture
Headless cms architecture
 
Drupal 8 deeper dive
Drupal 8 deeper diveDrupal 8 deeper dive
Drupal 8 deeper dive
 

Último

Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 

Último (20)

Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 

The Why Behind PHP Frameworks: From Plain HTML to MVC Framework

  • 1. The Why Behind PHP Frameworks Kirk Madera Director, Technology @ Robofirm
  • 2. About Me • Zend Framemwork 2 Certified • Magento Certified Plus • Zend PHP 5.5 Certified Engineer • Married with two kids • Metalhead • Coding experience rooted in C++ • Writing PHP for 10+ years
  • 3. Objective Start with a simple HTML site and transform it by solving one problem at a time into something that resembles a modern day framework.
  • 4. Overview • Distribute virtual machines (Virtual Box or VMWare) • Hands on coding with explanations at each step • Git tags that map to each step (Use “git clean -xf; git reset --hard {tagname}” if you get behind) • Ticket sales site is used as our test site • Don’t judge my design work
  • 6. 1.0: Review plain HTML and discuss issues • What if you ran a plain HTML site? • Every artist and show would require a new html file • A rescheduled show requires multiple file edits • Duplication causes human error • Dynamic lists like “Most Popular” maintained in HTML
  • 7. 2.0: Reduce duplication through require statements • So we need php. Skip to git tag 2.0 to get all files converted to PHP. • require() for head, header, footer, and before body end • How to deal with title since it’s dynamic? Global variable? • Problems with global variables. • Referring to templates from diff directories (e.g. artists/ vs. /) • How to deal with links in title?
  • 8. 3.0 Encapsulation – Fixing the global variable problem • Encapsulation is a big word for containing all logic and data for something in a single place • We need classes for this • We’ll start off simple by making a single class in index.php
  • 9. 3.1 Encapsulation – Apply to shows.php and artists.php • We’ll apply the same idea to shows.php and artists.php • What if we had to keep going to all php files in artists and shows? • And wait a second… duplication is back…
  • 10. 3.2 Encapsulation - Reusing classes • We need index.php, shows.php, artists.php and all other pages to use the same TemplateRenderer class • Start by moving it to it’s own file
  • 11.
  • 12. 4.0 Bootstrapping • Notice the code at the top of each file is growing • All pages need a lot of the same things to happen • Additional examples: • Set error reporting • Set a BASE_PATH constant • Set the cwd() to make working with files easier • Set an environment based variable like DEVELOPER_MODE • Create bootstrap.php • Also add BASE_PATH
  • 13. 4.1 Bootstrapping - Autoloader • require() needs to be called on every page for TemplateRenderer • What about when we have more classes? • Requiring every class would be slow • Lazy requiring classes with require_once() is also slow • We can avoid thinking about requires altogether with an autoloader
  • 14. 5.0 Separate Logic from View • Data/Logic should not live in the view • Things to separate: • “Popular” artists/shows list • All artists/shows lists • Single artist/show data • Start by moving data to arrays
  • 15. 5.1 Separate Logic From View - Classes • Move arrays out of templates and into classes • We’ll call these Mapper classes since • We will use static arrays within the Mapper classes • In the next step, we will make this data dynamic
  • 16. 6.0 Dynamic data • Work entirely within the Mapper classes for now • Use built in PDO class • All mappers need database access. • Where to put credentials? • Should I make this connection separately for each mapper?
  • 17. 7.0 Routing and Controllers • Routing lets us have pretty URLs • E.g. “/shows/metallica-gexa-pavilion-2016-05-04” instead of “/shows.php?id=1” • Front Controller Pattern – All requests go to index.php. Router routes to the right controller • Make these URLs functional “/”, “/shows”, “/artists” • Delete shows.php and artists.php
  • 18. 7.1 Routing and Controllers - Artist and show pages • Repeat previous step but for view pages • How to deal with ids in URL? • We have ugly URLs now… like “artist.php?id=4”
  • 19. 7.2 Routing and Controllers – Pretty URLs • Change URLs from “artist.php?id=1” to “artist/metallica” • URL alias mapper
  • 20. 8.0 Move all views into templates – Clean up TemplateRenderer • Remove the need to specify full template path and file extension
  • 21. 8.1 Move all views into templates • Move all views into controllers for now • The old separate PHP top level files are the equivalent of controllers
  • 22. 9.0 App class – Encapsulate bootstrap and run • This makes it easier to have multiple entry points to your app • For example, a shell script entry point or an API
  • 23. 10.0 Service Locator - Invokables • Shh.. This is Dependency Injection • This is just an easier way to understand it • We are improving reusability and testability here
  • 24. 10.1 Service Locator - Factories • Creating dependencies which have their own dependencies
  • 25. 10.2 ReflectionFactory • Doing it automatically • Avoid making factories for everything • Reflection in PHP 7 is fast enough that this is viable • A production strategy of caching a compiled factory built by reflection works also. (Magento 2 does something similar)
  • 26. 11.0 File Security – Making a public directory • All files in the project are currently within the web root • That means the are web accessible • Save yourself a security headache and move the document root to a subdirectory called “public” • Update Nginx sudo sed -i 's|/var/www/local.tickets.com|/var/www/local.tickets.com/public|g' /etc/nginx/sites-available/local.tickets.com; sudo service nginx restart;
  • 27. 12.0 Config • Configuration should be separate from code • Move configuration from public/index.php to config/app.php • Many strategies could be used for collecting configuration • This is especially important when you get to more complicated modular code
  • 28. 13.0 Blocks • Move logic related to grabbing the data for the view into Block classes • Thins out the controllers
  • 29. Compare to Other Frameworks • Zend Framework 2: https://github.com/zendframework/ZendSkeletonApplication • Symfony: https://github.com/symfony/symfony-standard • Laravel: https://github.com/hyfn/laravel-skeleton/tree/master/public
  • 30. Why use a framework? • Don’t reinvent the wheel • Benefit from others’ experience • Spend time on the core purpose of your site
  • 31. Resources • Code: https://bitbucket.org/robofirm/tickets.com-tutorial • Site URL: http://local.tickets.com/ • VM: https://robofirm.box.com/s/ip0xg5gw2gjomu4nr64col7rjiwnx760 • This Slideshow: http://www.slideshare.net/KirkMadera/they-why-behind-php- frameworks