Date post: | 09-Feb-2017 |
Category: |
Technology |
Upload: | michal-juhas |
View: | 1,180 times |
Download: | 0 times |
THPUG & HotelQuickly Meetup
PHP Frameworks, or how I learned to stop worrying and love the code.
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
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
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
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
What kind of frameworks are there?Frameworks mostly fall into three groups:
Micro FrameworksFull Stack FrameworksContent Management Frameworks
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
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
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’);
Routing & Requesthttp://example.com/blog/2015/08/29
Route - /blog/{year}/{month}/{day}
Request Populated With:year: 2015month: 08day: 29
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
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
Full Stack Top Three
Sitepoint Survey into PHP Framework popularity from March 2015
The Full Stack Big ThreeSitepoint Survey into PHP Framework popularity from March 2015
1.Laravel2.Symfony23.Nette
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
IlluminateIlluminate wraps a number of 3rd party
libraries and framework componentsProvides more features (Queues, Cloud)Provides more choice with ContractsFairly tight coupling
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
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
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
Profiling and Debug Tools
Third Party BundlesUser Registration, Login and ProfileOAuth Interface to many social loginsAutomatic Rest HandlingWeb Service Api DocumentationImage ManipulationEasy Access to Third Party Libraries
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
NetteMature but little known outside CzechDesigned around MVP over MVCTracy debugger and profilerDetailed Error ReportingLatte templating componentQuite loosely coupled components
Tracy - Debugging and Errors
Latte - Templating EngineTemplate InheritanceContext aware Escaping
Context Aware Escaping
Value of $movie is 'Amarcord & 8 1/2'
Macros & FiltersMacros Surrounding HTML
Macros Inline HTML
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
Latte vs Blade Dependencies
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
Stack Overflow Tag Popularity
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
SilexClosely related to Symfony2Uses Pimple v1 and Symfony2 ComponentsWide range of Official and Third Party Service
ProvidersVersion 2 under development
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
LumenFrom the Laravel TeamProvides a structure for your project
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
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
PHP 5.6
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|---------------------------------------------------------------
PHP 7 Beta
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 |
“What do you use?”
“What should I use?”
Framework Independent Codea.k.a Framework Agnostic
What is it about?
Architectures/Patterns●DDD (Domain-Driven Design)●Ports & Adapters (Hexagonal Architecture)●Dependency Inversion/Injection Principle
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
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
Hexagonal Architecture
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