php frameworks, or how i learnt to stop worrying and love the code
TRANSCRIPT
![Page 1: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/1.jpg)
THPUG & HotelQuickly Meetup
PHP Frameworks, or how I learned to stop worrying and love the code.
![Page 2: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/2.jpg)
Who are we?Thailand PHP User Group - A group for bringing together PHP users in Thailand
HotelQuickly - The Number 1 last minute booking app in Asia Pacific
Alex Stansfield - Software Development Manager at Gomeeki, 12 years PHP developer
![Page 3: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/3.jpg)
Topics for the eveningWhat is a Framework?Why would I want to use one?What kind of Frameworks are there?Full Stack Top Three (Laravel, Symfony, Nette)Micro Frameworks (Silex, Slim3, Lumen)BenchmarksHQ Talk: Writing Framework Independent CodeQuestions and Discussion
![Page 4: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/4.jpg)
What is a Framework?“Standard Solution to Common problems”
All the code you used to write or pull from your other projects packaged up for you
Provides a structure to your codeCommunity
![Page 5: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/5.jpg)
Why would you want to use one?Saves you from reinventing the wheelCommunity Resources (plugins, tutorials)Open Source
Some of the best minds involvedMany eyes to review the codeContribute
Keep code consistent between developers
![Page 6: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/6.jpg)
What kind of frameworks are there?Frameworks mostly fall into three groups:
Micro FrameworksFull Stack FrameworksContent Management Frameworks
![Page 7: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/7.jpg)
What is a Micro Framework?Minimal frameworks giving you a fast shell for your code
Dependency Injection Container
RoutingMiddleware SupportRequest and Response
HandlingBasic Error Handling
![Page 8: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/8.jpg)
Routinghttp://example.com/my/bloghttp://example.com/my/blog/edit
In the Past/var/www/site/my/blog/index.php/var/www/site/my/blog/edit/index.php
Now/var/www/site/public/index.php
![Page 9: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/9.jpg)
RequestEverything from the Request wrapped up in easy to access Object.
$_POST[‘this’], $_GET[‘that’], $_SERVER[‘REQUEST_METHOD’]
$request->has(‘this’);$request->get(‘that’);$request->getMethod();$request->getHeader(‘Content-Type’);
![Page 10: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/10.jpg)
Routing & Requesthttp://example.com/blog/2015/08/29
Route - /blog/{year}/{month}/{day}
Request Populated With:year: 2015month: 08day: 29
![Page 11: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/11.jpg)
Example$app->get('/hello[/{name}]', function ($request, $response) { $response->write("Hello, " . $request->get('name')); return $response;})->setArgument('name', 'World!');
GET /helloHello, World!
GET /hello/alexHello, alex
![Page 12: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/12.jpg)
What is a Full Stack Framework?Contains many components to help you rapidly develop large applications
DBAL and ORMMultiple configuration filesCachingLoggingDetailed Error HandlingConsole CommandsEventsTemplating EngineForms and validationSecurity
![Page 13: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/13.jpg)
Full Stack Top Three
Sitepoint Survey into PHP Framework popularity from March 2015
![Page 14: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/14.jpg)
![Page 15: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/15.jpg)
The Full Stack Big ThreeSitepoint Survey into PHP Framework popularity from March 2015
1.Laravel2.Symfony23.Nette
![Page 16: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/16.jpg)
LaravelAiming to make web development easierBuilds upon third party componentsFacade provides easy access to services More components than other frameworksHomestead Vagrant boxSuited to all sizes of project
![Page 17: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/17.jpg)
![Page 18: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/18.jpg)
IlluminateIlluminate wraps a number of 3rd party
libraries and framework componentsProvides more features (Queues, Cloud)Provides more choice with ContractsFairly tight coupling
![Page 19: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/19.jpg)
FacadesStatic interface to classes that are in service
containerFacades for existing Illuminate servicesCan create your own facades to access your
servicesSeen by some as promoting bad practiseInjecting Services is still available
![Page 20: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/20.jpg)
![Page 21: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/21.jpg)
![Page 22: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/22.jpg)
Laravel - Round UpLarge community and user baseVery easy to pick up and configureIlluminate provides more out of the boxHomestead helps you get developingDocumentation focuses more on FacadeGood for projects of any sizeQuite Tightly coupled so harder to leave
![Page 23: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/23.jpg)
Symfony2Heavy Inspiration from Ruby on RailsBuilding Robust Enterprise ApplicationsHighly CustomisablePowerful Profiling and Debug toolsIncludes popular 3rd party componentsMany useful Bundles availableLearning curve can be steep
![Page 24: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/24.jpg)
![Page 25: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/25.jpg)
Profiling and Debug Tools
![Page 26: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/26.jpg)
Third Party BundlesUser Registration, Login and ProfileOAuth Interface to many social loginsAutomatic Rest HandlingWeb Service Api DocumentationImage ManipulationEasy Access to Third Party Libraries
![Page 27: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/27.jpg)
![Page 28: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/28.jpg)
Symfony2 - Round UpLarge community and user basePowerful Profiling and Debugging ToolsLoosely Coupled and 3rd party ComponentsVery configurable (a pro and a con)Can be daunting to new users and steeper
learning curveBetter for larger projects
![Page 29: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/29.jpg)
NetteMature but little known outside CzechDesigned around MVP over MVCTracy debugger and profilerDetailed Error ReportingLatte templating componentQuite loosely coupled components
![Page 30: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/30.jpg)
![Page 31: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/31.jpg)
Tracy - Debugging and Errors
![Page 32: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/32.jpg)
Latte - Templating EngineTemplate InheritanceContext aware Escaping
![Page 33: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/33.jpg)
Context Aware Escaping
Value of $movie is 'Amarcord & 8 1/2'
![Page 34: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/34.jpg)
Macros & FiltersMacros Surrounding HTML
Macros Inline HTML
![Page 35: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/35.jpg)
Latte - Templating EngineTemplate InheritanceContext aware EscapingMacros inline in HTML tags (like AngularJS)Filters for content manipulationUser defined Filters and MacrosCompiles templates to PHP so very fastNo dependencies on other libraries
![Page 36: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/36.jpg)
Latte vs Blade Dependencies
![Page 37: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/37.jpg)
![Page 38: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/38.jpg)
Nette - Round UpEasy learning curveUseful debugger and profilerGreat Error reporting in dev modeFantastic Templating EngineSmall community outside Czech RepublicPlacement on Sitepoint survey will bring it
more attention
![Page 39: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/39.jpg)
Stack Overflow Tag Popularity
![Page 40: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/40.jpg)
Micro FrameworksVery minimal installNo path structure (most of the time)Much faster than Full Stack FrameworksIdeal for small projects, quick micro services
or command line applications
![Page 41: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/41.jpg)
SilexClosely related to Symfony2Uses Pimple v1 and Symfony2 ComponentsWide range of Official and Third Party Service
ProvidersVersion 2 under development
![Page 42: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/42.jpg)
![Page 43: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/43.jpg)
Slim 3Still in BetaFollow up to the very fast Slim 2Embraces Standards
container-interop interfacePSR-7 Requests and Responses
Routing with Nickc’s FastRouteAimed at Web Applications
![Page 44: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/44.jpg)
LumenFrom the Laravel TeamProvides a structure for your project
![Page 45: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/45.jpg)
![Page 46: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/46.jpg)
LumenFrom the Laravel TeamProvides a structure for your projectIncludes Artisan helper commandConsole command support out of the boxEmbraces Laravel’s aim of being easy to learn
and useSupport for PSR-7 requests and responses
![Page 47: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/47.jpg)
BenchmarksSetup:
Default install of the frameworkUsing recommended way to output textPrints “Hello World!”Run on PHP 5.6 and 7 betaApacheBench over 10 seconds
Don’t hate me, just for guidance
![Page 48: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/48.jpg)
PHP 5.6
![Page 49: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/49.jpg)
PHP 5.6_______________________________________________________________________|framework |requests per second|relative|peak memory|relative||-------------------|------------------:|-------:|----------:|-------:||slim-3 | 1,928.82| 7.3| 0.75| 1.0||silex-1.3 | 1,148.48| 4.3| 1.00| 1.3||lumen-5.1 | 1,292.36| 4.9| 1.00| 1.3||nette-2.3 | 815.80| 3.1| 1.50| 2.0||symfony-2.7 | 400.95| 1.5| 3.00| 4.0||laravel-5.1 | 265.66| 1.0| 2.50| 3.3|---------------------------------------------------------------
![Page 50: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/50.jpg)
PHP 7 Beta
![Page 51: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/51.jpg)
PHP 7.0 vs 5.6|framework | RPS 7.0 | RPS 5.6 ||-------------------|----------:|----------:||slim-3 | 3,072.28 | 1,928.82 ||silex-1.3 | 1,689.54 | 1,148.48 ||lumen-5.1 | 1,968.67 | 1,292.36 ||nette-2.3 | 1,449.96 | 815.80 ||symfony-2.7 | 842.56 | 400.95 ||laravel-5.1 | 487.74 | 265.66 |
![Page 52: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/52.jpg)
“What do you use?”
![Page 53: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/53.jpg)
“What should I use?”
![Page 54: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/54.jpg)
Framework Independent Codea.k.a Framework Agnostic
What is it about?
![Page 55: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/55.jpg)
Architectures/Patterns●DDD (Domain-Driven Design)●Ports & Adapters (Hexagonal Architecture)●Dependency Inversion/Injection Principle
![Page 56: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/56.jpg)
Domain-Driven Design“Domain-driven design is not a
technology or a methodology. DDD provides a structure of practices and
terminology for making design decisions that focus and accelerate
software projects.” Eric Evans
![Page 57: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/57.jpg)
Hexagonal Architecture“Allow an application to equally be driven by users,
programs, automated test or batch scripts, and to be developed and tested in isolation from its eventual run-time
devices and databases” - Alistair Cockburn
![Page 58: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/58.jpg)
Hexagonal Architecture
![Page 59: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/59.jpg)
High-level modules should not depend on low-level modules. Both should depend on abstractions.
A code is worth a thousand words!
Dependency Inversion Principle
![Page 60: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/60.jpg)
![Page 61: PHP Frameworks, or how I learnt to stop worrying and love the code](https://reader030.vdocuments.mx/reader030/viewer/2022021506/589c73661a28abe96c8b6b93/html5/thumbnails/61.jpg)