+ All Categories
Home > Technology > PHP Frameworks, or how I learnt to stop worrying and love the code

PHP Frameworks, or how I learnt to stop worrying and love the code

Date post: 09-Feb-2017
Category:
Upload: michal-juhas
View: 1,180 times
Download: 0 times
Share this document with a friend
63
THPUG & HotelQuickly Meetup PHP Frameworks, or how I learned to stop worrying and love the code .
Transcript
Page 1: PHP Frameworks, or how I learnt to stop worrying and love the code

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

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

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

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

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

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

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

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

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

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

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

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

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
Page 15: PHP Frameworks, or how I learnt to stop worrying and love the code

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

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
Page 18: PHP Frameworks, or how I learnt to stop worrying and love the code

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

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
Page 21: PHP Frameworks, or how I learnt to stop worrying and love the code
Page 22: PHP Frameworks, or how I learnt to stop worrying and love the code

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

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
Page 25: PHP Frameworks, or how I learnt to stop worrying and love the code

Profiling and Debug Tools

Page 26: PHP Frameworks, or how I learnt to stop worrying and love the code

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
Page 28: PHP Frameworks, or how I learnt to stop worrying and love the code

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

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
Page 31: PHP Frameworks, or how I learnt to stop worrying and love the code

Tracy - Debugging and Errors

Page 32: PHP Frameworks, or how I learnt to stop worrying and love the code

Latte - Templating EngineTemplate InheritanceContext aware Escaping

Page 33: PHP Frameworks, or how I learnt to stop worrying and love the code

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

Macros & FiltersMacros Surrounding HTML

Macros Inline HTML

Page 35: PHP Frameworks, or how I learnt to stop worrying and love the code

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

Latte vs Blade Dependencies

Page 37: PHP Frameworks, or how I learnt to stop worrying and love the code
Page 38: PHP Frameworks, or how I learnt to stop worrying and love the code

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

Stack Overflow Tag Popularity

Page 40: PHP Frameworks, or how I learnt to stop worrying and love the code

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

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
Page 43: PHP Frameworks, or how I learnt to stop worrying and love the code

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

LumenFrom the Laravel TeamProvides a structure for your project

Page 45: PHP Frameworks, or how I learnt to stop worrying and love the code
Page 46: PHP Frameworks, or how I learnt to stop worrying and love the code

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

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

PHP 5.6

Page 49: PHP Frameworks, or how I learnt to stop worrying and love the code

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

PHP 7 Beta

Page 51: PHP Frameworks, or how I learnt to stop worrying and love the code

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

“What do you use?”

Page 53: PHP Frameworks, or how I learnt to stop worrying and love the code

“What should I use?”

Page 54: PHP Frameworks, or how I learnt to stop worrying and love the code

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

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

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

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

Hexagonal Architecture

Page 59: PHP Frameworks, or how I learnt to stop worrying and love the code

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
Page 61: PHP Frameworks, or how I learnt to stop worrying and love the code
Page 62: PHP Frameworks, or how I learnt to stop worrying and love the code

Referenceshttps://goo.gl/59Sgko

Page 63: PHP Frameworks, or how I learnt to stop worrying and love the code

PHP Conf 2015

http://phpconf.asia

Discount Code: sgphp2015


Recommended