SlideShare a Scribd company logo
Standards in
PHP world
About me
Michael Morozov
PHP-developer @ Binary Studio
Coach @ Binary Studio Academy
World Of Tanks Standards
Standards in PHP
➔ RFC (Requests For Comments)
➔ PSR (PHP Standard Recommendations)
RFC Lifecycle
Internet
Draft
Proposed
Draft
Draft
Standard
Internet
Standard
What about PSR?
PHP Standard Recommendations
➔ Set of conventions aimed to improve collaboration
between different projects in PHP-ecosystem
➔ Established and maintained by
https://github.com/php-fig/fig-standards
PSRs Classification
➔ Accepted
➔ Review
➔ Draft
➔ Deprecated
Deprecated PSR-0
➔ Autoloading Standard
➔ Provided SplClassLoader implementation which is able to load PHP 5.3
classes
'ZendMailMessage' =>
'/path/to/project/lib/vendor/Zend/Mail/Message.php',
'Zend_Config_Json' =>
'/path/to/project/lib/vendor/Zend/Config/Json.php'
Accepted PSRs
Accepted PSR-d+
➔ PSR-1: Basic Coding Standard
➔ PSR-2: Coding Style Guide
➔ PSR-3: Logger Interface
➔ PSR-4: Autoloading Standard
➔ PSR-6: Caching Interface
➔ PSR-7: HTTP Message Interface
Coding
Style
Code Style Holy Wars. Indentation
Code Style Holy Wars. Case
Code Style Holy Wars. Line Feeds
n or r or rn
Code Style Holy Wars. Right margin
80? 120?
3 screens?
80? 120?
Code Style Holy Wars. Eto translit, detka
$koli4estvo = 10;
$privet = 'Medved';
$Beschleunigung = 9.8;
PSR-1 & PSR-2 Intention
Reduce the cognitive friction when reading code
from other authors by standardized formatting.”
Coding Style Tools
➔ Ourselves
➔ PHP-CS-Fixer (https://github.com/FriendsOfPHP/PHP-CS-Fixer)
➔ PHP_CodeSniffer (https://github.com/squizlabs/PHP_CodeSniffer)
➔ PHP Mess Detector (https://phpmd.org/)
➔ phpcf (https://github.com/badoo/phpcf)
➔ StyleCI (https://styleci.io/)
➔ Our own implementation
PHP-CS-Fixer
➔ CLI utility
➔ Easy to integrate with code editor or CI
➔ Default fixers preset (psr1, psr2, symfony)
➔ Dry-run
➔ Extendability
How about to refine this ?
<?php namespace Submit; class DirtyClass {
private $privacy; protected $data;
public function __construct() {} public function getPrivacy()
{ return $this->privacy;}
}
OK, Let’s run:
$ php php-cs-fixer.phar fix /path/to/dir
<?php namespace Submit;
class FixMe
{
private $privacy;
protected $data;
public function __construct()
{
}
public function getPrivacy()
{
return $this->privacy;
}
}
PHP-CS-Fixer
Custom config
(.php_cs)
$finder = SymfonyCSFinderDefaultFinder::create()
->in('src')
->notPath('tests');
$config = SymfonyCSConfigConfig::create();
$config->level(null);
$config->fixers(
array(
'line_after_namespace',
'linefeed',
'php_closing_tag',
'short_array_syntax',
'unused_use'
)
);
$config->finder($finder);
return $config;
PHP-CS-Fixer as a separate CI ?
https://styleci.io/
What about legacy?
Code style in legacy code
➔ Skip vendor and legacy libs in code style tools
➔ Request single codebase re-formatting
➔ Force every team member using the same style
PSR-3: The “Right” Logging
PSR-3 Logger Interface
namespace PsrLog;
interface LoggerInterface
{
public function emergency($message, array $context = array());
public function alert($message, array $context = array());
public function critical($message, array $context = array());
public function error($message, array $context = array());
public function warning($message, array $context = array());
public function notice($message, array $context = array());
public function info($message, array $context = array());
public function debug($message, array $context = array());
public function log($level, $message, array $context = array());
}
Log All The Things with Monolog
$ composer require monolog/monolog
➔ Fully PSR-3 Compatible
➔ Write to files, sockets, chats, databases, web-services, mails
➔ Customize log format
➔ 42.3 M downloads. Just give it a try.
Monolog
Example
$bindings = [
'slack.handler' => function($app) {
return new MonologHandlerSlackHandler(
getenv('SLACK_TOKEN'),
getenv('SLACK_ROOM')
);
},
'slack.logger' => function($app) {
return new MonologLogger('slack', [$app['slack.handler']]);
}
];
$container = new PimpleContainer($bindings);
$container['slack.logger']->info('Hey, guys!');
$container['slack.logger']->emergency('Website is down!');
PSR-3 Based Loggers
➔ Monolog (https://github.com/Seldaek/monolog)
➔ zend-log (https://github.com/zendframework/zend-log)
➔ KLogger (https://github.com/katzgrau/klogger)
➔ Your logger implementation
➔ Oh, cmon. Just use Monolog
PSR-4 Auto
PSR-4 Autoloading
➔ Autoloading takes care about classes with fully-qualified class names
(FQCN)
➔ Classes, interfaces, traits considers as “class” (FooInterface::class)
<NamespaceName>(<SubNamespaceNames>)*<ClassName>
FQCN Namespace
prefix
Base directory Resulting file path
SymfonyCoreRequest SymfonyCore ./vendor/Symfony/Core/ ./vendor/Symfony/Core/Request.php
AuraWebResponseStatus AuraWeb /path/to/aura-web/src/ /path/to/aura-web/src/Response/Status.php
PSR-4 Autoloading via Composer
{
"autoload": {
"psr-4": {
"Monolog": "src/",
"VendorNamespace": ""
}
}
}
{
"autoload": {
"psr-4": { "": "src/" }
}
}
HTTP
Message
Interface
PSR-7 Main Concept
HTTP Requests and Responses
are abstracted in form of HTTP
messages
PSR-7 Interfaces schema
PSR-7 Component features
➔ Request, ServerRequest, Response, Uri are immutable
➔ Response Body is stream (like php://temp)
PSR-7 Known Implementations
➔ guzzlehttp/psr7 (https://packagist.org/packages/guzzlehttp/psr7)
➔ slim/http (https://packagist.org/packages/slim/http)
➔ zendframework/diactorous
(https://packagist.org/packages/zendframework/zend-diactoros)
➔ wandu/http (https://packagist.org/packages/wandu/http)
➔ symfony/psr-http-message-bridge
(https://packagist.org/packages/symfony/psr-http-message-bridge)
➔ zendframework/zend-psr7-bridge
(https://packagist.org/packages/zendframework/zend-psr7bridge)
PSR-7 examples
$app = new SlimApp;
$app->get('/foo', function ($req, $res, $args) {
return $res->withHeader(
'Content-Type',
'application/json'
);
});
$app->run();
PSR-7 examples
$response = new ZendDiactorosResponse();
$response->getBody()->write("Hellon");
$response->getBody()->write("worldn");
$response = $response
->withHeader('Content-Type', 'text/plain')
->withAddedHeader('X-Show-Something', 'something');
Caching with PSR-6
PSR-6: Caching interface
CacheItemPool
CacheItem
Caching examples using Stash (tedivm/stash)
$driver = new StashDriverFileSystem();
$pool = new StashPool($driver);
$item = $pool->getItem('path/to/data');
$info = $item->get();
if ($item->isMiss()) {
$info = loadInfo($id);
$item->set($userInfo, 120);
}
return $info;
Cache implementations
https://packagist.org/providers/psr/cache-implementation
Interesting Draft
PSRs
Draft PSRs
➔ PSR-12: Extended Coding Style Guide
➔ PSR-14: Event Manager
➔ PSR-15: HTTP Middlewares
Current Stage and Future of PHP-FIG
➔ Some members complained that they are forced to use or support
PSRs in their projects
➔ As a results they would like to have some “re-branding”
➔ This led to PHP Community-driven Standards and HTTP Interop
appearing
Summary
➔ Following coding standards disciplines & improves readability
➔ Sometimes usage of “code-smell” tools is beneficial and not routine
➔ Autoloading via Composer nowadays rocks
➔ There are some well-grounded techniques that can be a problem solution
(logging, caching, containers, etc.)
➔ Having abstraction layer in HTTP is more convenient than raw access to
superglobals
➔ PHP becomes more mature and more standardized
Questions ?
Thanks for
watching

More Related Content

What's hot

typemap in Perl/XS
typemap in Perl/XS  typemap in Perl/XS
typemap in Perl/XS
charsbar
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life better
ZendCon
 
30 Minutes To CPAN
30 Minutes To CPAN30 Minutes To CPAN
30 Minutes To CPAN
daoswald
 
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
ZFConf Conference
 
On UnQLite
On UnQLiteOn UnQLite
On UnQLite
charsbar
 
Php 7 hhvm and co
Php 7 hhvm and coPhp 7 hhvm and co
Php 7 hhvm and co
Pierre Joye
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)
julien pauli
 
Composer - Package Management for PHP. Silver Bullet?
Composer - Package Management for PHP. Silver Bullet?Composer - Package Management for PHP. Silver Bullet?
Composer - Package Management for PHP. Silver Bullet?
Kirill Chebunin
 
Continuous Quality Assurance
Continuous Quality AssuranceContinuous Quality Assurance
Continuous Quality Assurance
Michelangelo van Dam
 
Debugging on rails
Debugging on railsDebugging on rails
Debugging on rails
Mykhaylo Sorochan
 
Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!
Jeff Jones
 
Lecture8
Lecture8Lecture8
Lecture8
Majid Taghiloo
 
Shellcode Analysis - Basic and Concept
Shellcode Analysis - Basic and ConceptShellcode Analysis - Basic and Concept
Shellcode Analysis - Basic and Concept
Julia Yu-Chin Cheng
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course Deck
rICh morrow
 
Deploying Perl apps on dotCloud
Deploying Perl apps on dotCloudDeploying Perl apps on dotCloud
Deploying Perl apps on dotCloud
daoswald
 
PHP Function
PHP Function PHP Function
PHP Function
Reber Novanta
 
PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015
Colin O'Dell
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extension
julien pauli
 
Gradle in a Polyglot World
Gradle in a Polyglot WorldGradle in a Polyglot World
Gradle in a Polyglot World
Schalk Cronjé
 
How DSL works on Ruby
How DSL works on RubyHow DSL works on Ruby
How DSL works on Ruby
Hiroshi SHIBATA
 

What's hot (20)

typemap in Perl/XS
typemap in Perl/XS  typemap in Perl/XS
typemap in Perl/XS
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life better
 
30 Minutes To CPAN
30 Minutes To CPAN30 Minutes To CPAN
30 Minutes To CPAN
 
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
 
On UnQLite
On UnQLiteOn UnQLite
On UnQLite
 
Php 7 hhvm and co
Php 7 hhvm and coPhp 7 hhvm and co
Php 7 hhvm and co
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)
 
Composer - Package Management for PHP. Silver Bullet?
Composer - Package Management for PHP. Silver Bullet?Composer - Package Management for PHP. Silver Bullet?
Composer - Package Management for PHP. Silver Bullet?
 
Continuous Quality Assurance
Continuous Quality AssuranceContinuous Quality Assurance
Continuous Quality Assurance
 
Debugging on rails
Debugging on railsDebugging on rails
Debugging on rails
 
Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!
 
Lecture8
Lecture8Lecture8
Lecture8
 
Shellcode Analysis - Basic and Concept
Shellcode Analysis - Basic and ConceptShellcode Analysis - Basic and Concept
Shellcode Analysis - Basic and Concept
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course Deck
 
Deploying Perl apps on dotCloud
Deploying Perl apps on dotCloudDeploying Perl apps on dotCloud
Deploying Perl apps on dotCloud
 
PHP Function
PHP Function PHP Function
PHP Function
 
PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015PHP 7 Crash Course - php[world] 2015
PHP 7 Crash Course - php[world] 2015
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extension
 
Gradle in a Polyglot World
Gradle in a Polyglot WorldGradle in a Polyglot World
Gradle in a Polyglot World
 
How DSL works on Ruby
How DSL works on RubyHow DSL works on Ruby
How DSL works on Ruby
 

Similar to Submit PHP: Standards in PHP world. Михайло Морозов

Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018
Adam Tomat
 
Zend Expressive 3 e PSR-15
Zend Expressive 3 e PSR-15Zend Expressive 3 e PSR-15
Zend Expressive 3 e PSR-15
Juciellen Cabrera
 
The Solar Framework for PHP 5 (2010 Confoo)
The Solar Framework for PHP 5 (2010 Confoo)The Solar Framework for PHP 5 (2010 Confoo)
The Solar Framework for PHP 5 (2010 Confoo)
Paul Jones
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
Rowan Merewood
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
Hisateru Tanaka
 
Tips
TipsTips
Tipsmclee
 
MidwestPHP Symfony2 Internals
MidwestPHP Symfony2 InternalsMidwestPHP Symfony2 Internals
MidwestPHP Symfony2 InternalsRaul Fraile
 
PHP Development Tools
PHP  Development ToolsPHP  Development Tools
PHP Development Tools
Antony Abramchenko
 
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
James Titcumb
 
PHP. Trends, implementations, frameworks and solutions
PHP. Trends, implementations, frameworks and solutionsPHP. Trends, implementations, frameworks and solutions
PHP. Trends, implementations, frameworks and solutionsOleg Zinchenko
 
Automatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themesAutomatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themes
Otto Kekäläinen
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
Darren Craig
 
PSR: Standards in PHP by Alex Simanovich
PSR: Standards in PHP by Alex SimanovichPSR: Standards in PHP by Alex Simanovich
PSR: Standards in PHP by Alex Simanovich
Minsk PHP User Group
 
Prepare for PHP Test Fest 2009
Prepare for PHP Test Fest 2009Prepare for PHP Test Fest 2009
Prepare for PHP Test Fest 2009
PHPBelgium
 
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
Wong Hoi Sing Edison
 
Basics PHP
Basics PHPBasics PHP
Namespaces and Autoloading
Namespaces and AutoloadingNamespaces and Autoloading
Namespaces and Autoloading
Vic Metcalfe
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
Francois Zaninotto
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207patter
 
New PHP Exploitation Techniques
New PHP Exploitation TechniquesNew PHP Exploitation Techniques
New PHP Exploitation Techniques
RIPS Technologies GmbH
 

Similar to Submit PHP: Standards in PHP world. Михайло Морозов (20)

Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018
 
Zend Expressive 3 e PSR-15
Zend Expressive 3 e PSR-15Zend Expressive 3 e PSR-15
Zend Expressive 3 e PSR-15
 
The Solar Framework for PHP 5 (2010 Confoo)
The Solar Framework for PHP 5 (2010 Confoo)The Solar Framework for PHP 5 (2010 Confoo)
The Solar Framework for PHP 5 (2010 Confoo)
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Tips
TipsTips
Tips
 
MidwestPHP Symfony2 Internals
MidwestPHP Symfony2 InternalsMidwestPHP Symfony2 Internals
MidwestPHP Symfony2 Internals
 
PHP Development Tools
PHP  Development ToolsPHP  Development Tools
PHP Development Tools
 
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
 
PHP. Trends, implementations, frameworks and solutions
PHP. Trends, implementations, frameworks and solutionsPHP. Trends, implementations, frameworks and solutions
PHP. Trends, implementations, frameworks and solutions
 
Automatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themesAutomatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themes
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
PSR: Standards in PHP by Alex Simanovich
PSR: Standards in PHP by Alex SimanovichPSR: Standards in PHP by Alex Simanovich
PSR: Standards in PHP by Alex Simanovich
 
Prepare for PHP Test Fest 2009
Prepare for PHP Test Fest 2009Prepare for PHP Test Fest 2009
Prepare for PHP Test Fest 2009
 
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
[HKDUG] #20161210 - BarCamp Hong Kong 2016 - What's News in PHP?
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Namespaces and Autoloading
Namespaces and AutoloadingNamespaces and Autoloading
Namespaces and Autoloading
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
 
New PHP Exploitation Techniques
New PHP Exploitation TechniquesNew PHP Exploitation Techniques
New PHP Exploitation Techniques
 

More from Binary Studio

Academy PRO: D3, part 3
Academy PRO: D3, part 3Academy PRO: D3, part 3
Academy PRO: D3, part 3
Binary Studio
 
Academy PRO: D3, part 1
Academy PRO: D3, part 1Academy PRO: D3, part 1
Academy PRO: D3, part 1
Binary Studio
 
Academy PRO: Cryptography 3
Academy PRO: Cryptography 3Academy PRO: Cryptography 3
Academy PRO: Cryptography 3
Binary Studio
 
Academy PRO: Cryptography 1
Academy PRO: Cryptography 1Academy PRO: Cryptography 1
Academy PRO: Cryptography 1
Binary Studio
 
Academy PRO: Advanced React Ecosystem. MobX
Academy PRO: Advanced React Ecosystem. MobXAcademy PRO: Advanced React Ecosystem. MobX
Academy PRO: Advanced React Ecosystem. MobX
Binary Studio
 
Academy PRO: Docker. Part 4
Academy PRO: Docker. Part 4Academy PRO: Docker. Part 4
Academy PRO: Docker. Part 4
Binary Studio
 
Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 2Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 2
Binary Studio
 
Academy PRO: Docker. Part 1
Academy PRO: Docker. Part 1Academy PRO: Docker. Part 1
Academy PRO: Docker. Part 1
Binary Studio
 
Binary Studio Academy 2017: JS team project - Orderly
Binary Studio Academy 2017: JS team project - OrderlyBinary Studio Academy 2017: JS team project - Orderly
Binary Studio Academy 2017: JS team project - Orderly
Binary Studio
 
Binary Studio Academy 2017: .NET team project - Unicorn
Binary Studio Academy 2017: .NET team project - UnicornBinary Studio Academy 2017: .NET team project - Unicorn
Binary Studio Academy 2017: .NET team project - Unicorn
Binary Studio
 
Academy PRO: React native - miscellaneous
Academy PRO: React native - miscellaneousAcademy PRO: React native - miscellaneous
Academy PRO: React native - miscellaneous
Binary Studio
 
Academy PRO: React native - publish
Academy PRO: React native - publishAcademy PRO: React native - publish
Academy PRO: React native - publish
Binary Studio
 
Academy PRO: React native - navigation
Academy PRO: React native - navigationAcademy PRO: React native - navigation
Academy PRO: React native - navigation
Binary Studio
 
Academy PRO: React native - building first scenes
Academy PRO: React native - building first scenesAcademy PRO: React native - building first scenes
Academy PRO: React native - building first scenes
Binary Studio
 
Academy PRO: React Native - introduction
Academy PRO: React Native - introductionAcademy PRO: React Native - introduction
Academy PRO: React Native - introduction
Binary Studio
 
Academy PRO: Push notifications. Denis Beketsky
Academy PRO: Push notifications. Denis BeketskyAcademy PRO: Push notifications. Denis Beketsky
Academy PRO: Push notifications. Denis Beketsky
Binary Studio
 
Academy PRO: Docker. Lecture 4
Academy PRO: Docker. Lecture 4Academy PRO: Docker. Lecture 4
Academy PRO: Docker. Lecture 4
Binary Studio
 
Academy PRO: Docker. Lecture 3
Academy PRO: Docker. Lecture 3Academy PRO: Docker. Lecture 3
Academy PRO: Docker. Lecture 3
Binary Studio
 
Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 2Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 2
Binary Studio
 
Academy PRO: Docker. Lecture 1
Academy PRO: Docker. Lecture 1Academy PRO: Docker. Lecture 1
Academy PRO: Docker. Lecture 1
Binary Studio
 

More from Binary Studio (20)

Academy PRO: D3, part 3
Academy PRO: D3, part 3Academy PRO: D3, part 3
Academy PRO: D3, part 3
 
Academy PRO: D3, part 1
Academy PRO: D3, part 1Academy PRO: D3, part 1
Academy PRO: D3, part 1
 
Academy PRO: Cryptography 3
Academy PRO: Cryptography 3Academy PRO: Cryptography 3
Academy PRO: Cryptography 3
 
Academy PRO: Cryptography 1
Academy PRO: Cryptography 1Academy PRO: Cryptography 1
Academy PRO: Cryptography 1
 
Academy PRO: Advanced React Ecosystem. MobX
Academy PRO: Advanced React Ecosystem. MobXAcademy PRO: Advanced React Ecosystem. MobX
Academy PRO: Advanced React Ecosystem. MobX
 
Academy PRO: Docker. Part 4
Academy PRO: Docker. Part 4Academy PRO: Docker. Part 4
Academy PRO: Docker. Part 4
 
Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 2Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 2
 
Academy PRO: Docker. Part 1
Academy PRO: Docker. Part 1Academy PRO: Docker. Part 1
Academy PRO: Docker. Part 1
 
Binary Studio Academy 2017: JS team project - Orderly
Binary Studio Academy 2017: JS team project - OrderlyBinary Studio Academy 2017: JS team project - Orderly
Binary Studio Academy 2017: JS team project - Orderly
 
Binary Studio Academy 2017: .NET team project - Unicorn
Binary Studio Academy 2017: .NET team project - UnicornBinary Studio Academy 2017: .NET team project - Unicorn
Binary Studio Academy 2017: .NET team project - Unicorn
 
Academy PRO: React native - miscellaneous
Academy PRO: React native - miscellaneousAcademy PRO: React native - miscellaneous
Academy PRO: React native - miscellaneous
 
Academy PRO: React native - publish
Academy PRO: React native - publishAcademy PRO: React native - publish
Academy PRO: React native - publish
 
Academy PRO: React native - navigation
Academy PRO: React native - navigationAcademy PRO: React native - navigation
Academy PRO: React native - navigation
 
Academy PRO: React native - building first scenes
Academy PRO: React native - building first scenesAcademy PRO: React native - building first scenes
Academy PRO: React native - building first scenes
 
Academy PRO: React Native - introduction
Academy PRO: React Native - introductionAcademy PRO: React Native - introduction
Academy PRO: React Native - introduction
 
Academy PRO: Push notifications. Denis Beketsky
Academy PRO: Push notifications. Denis BeketskyAcademy PRO: Push notifications. Denis Beketsky
Academy PRO: Push notifications. Denis Beketsky
 
Academy PRO: Docker. Lecture 4
Academy PRO: Docker. Lecture 4Academy PRO: Docker. Lecture 4
Academy PRO: Docker. Lecture 4
 
Academy PRO: Docker. Lecture 3
Academy PRO: Docker. Lecture 3Academy PRO: Docker. Lecture 3
Academy PRO: Docker. Lecture 3
 
Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 2Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 2
 
Academy PRO: Docker. Lecture 1
Academy PRO: Docker. Lecture 1Academy PRO: Docker. Lecture 1
Academy PRO: Docker. Lecture 1
 

Recently uploaded

Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
Roshan Dwivedi
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
kalichargn70th171
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
mz5nrf0n
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 

Recently uploaded (20)

Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 

Submit PHP: Standards in PHP world. Михайло Морозов

  • 2. About me Michael Morozov PHP-developer @ Binary Studio Coach @ Binary Studio Academy
  • 3.
  • 4. World Of Tanks Standards
  • 5. Standards in PHP ➔ RFC (Requests For Comments) ➔ PSR (PHP Standard Recommendations)
  • 8. PHP Standard Recommendations ➔ Set of conventions aimed to improve collaboration between different projects in PHP-ecosystem ➔ Established and maintained by https://github.com/php-fig/fig-standards
  • 9. PSRs Classification ➔ Accepted ➔ Review ➔ Draft ➔ Deprecated
  • 10. Deprecated PSR-0 ➔ Autoloading Standard ➔ Provided SplClassLoader implementation which is able to load PHP 5.3 classes 'ZendMailMessage' => '/path/to/project/lib/vendor/Zend/Mail/Message.php', 'Zend_Config_Json' => '/path/to/project/lib/vendor/Zend/Config/Json.php'
  • 12. Accepted PSR-d+ ➔ PSR-1: Basic Coding Standard ➔ PSR-2: Coding Style Guide ➔ PSR-3: Logger Interface ➔ PSR-4: Autoloading Standard ➔ PSR-6: Caching Interface ➔ PSR-7: HTTP Message Interface
  • 14.
  • 15. Code Style Holy Wars. Indentation
  • 16. Code Style Holy Wars. Case
  • 17. Code Style Holy Wars. Line Feeds n or r or rn
  • 18. Code Style Holy Wars. Right margin 80? 120? 3 screens? 80? 120?
  • 19. Code Style Holy Wars. Eto translit, detka $koli4estvo = 10; $privet = 'Medved'; $Beschleunigung = 9.8;
  • 20. PSR-1 & PSR-2 Intention Reduce the cognitive friction when reading code from other authors by standardized formatting.”
  • 21. Coding Style Tools ➔ Ourselves ➔ PHP-CS-Fixer (https://github.com/FriendsOfPHP/PHP-CS-Fixer) ➔ PHP_CodeSniffer (https://github.com/squizlabs/PHP_CodeSniffer) ➔ PHP Mess Detector (https://phpmd.org/) ➔ phpcf (https://github.com/badoo/phpcf) ➔ StyleCI (https://styleci.io/) ➔ Our own implementation
  • 22. PHP-CS-Fixer ➔ CLI utility ➔ Easy to integrate with code editor or CI ➔ Default fixers preset (psr1, psr2, symfony) ➔ Dry-run ➔ Extendability
  • 23. How about to refine this ? <?php namespace Submit; class DirtyClass { private $privacy; protected $data; public function __construct() {} public function getPrivacy() { return $this->privacy;} } OK, Let’s run: $ php php-cs-fixer.phar fix /path/to/dir
  • 24. <?php namespace Submit; class FixMe { private $privacy; protected $data; public function __construct() { } public function getPrivacy() { return $this->privacy; } }
  • 25. PHP-CS-Fixer Custom config (.php_cs) $finder = SymfonyCSFinderDefaultFinder::create() ->in('src') ->notPath('tests'); $config = SymfonyCSConfigConfig::create(); $config->level(null); $config->fixers( array( 'line_after_namespace', 'linefeed', 'php_closing_tag', 'short_array_syntax', 'unused_use' ) ); $config->finder($finder); return $config;
  • 26. PHP-CS-Fixer as a separate CI ? https://styleci.io/
  • 28. Code style in legacy code ➔ Skip vendor and legacy libs in code style tools ➔ Request single codebase re-formatting ➔ Force every team member using the same style
  • 30. PSR-3 Logger Interface namespace PsrLog; interface LoggerInterface { public function emergency($message, array $context = array()); public function alert($message, array $context = array()); public function critical($message, array $context = array()); public function error($message, array $context = array()); public function warning($message, array $context = array()); public function notice($message, array $context = array()); public function info($message, array $context = array()); public function debug($message, array $context = array()); public function log($level, $message, array $context = array()); }
  • 31. Log All The Things with Monolog $ composer require monolog/monolog ➔ Fully PSR-3 Compatible ➔ Write to files, sockets, chats, databases, web-services, mails ➔ Customize log format ➔ 42.3 M downloads. Just give it a try.
  • 32. Monolog Example $bindings = [ 'slack.handler' => function($app) { return new MonologHandlerSlackHandler( getenv('SLACK_TOKEN'), getenv('SLACK_ROOM') ); }, 'slack.logger' => function($app) { return new MonologLogger('slack', [$app['slack.handler']]); } ]; $container = new PimpleContainer($bindings); $container['slack.logger']->info('Hey, guys!'); $container['slack.logger']->emergency('Website is down!');
  • 33. PSR-3 Based Loggers ➔ Monolog (https://github.com/Seldaek/monolog) ➔ zend-log (https://github.com/zendframework/zend-log) ➔ KLogger (https://github.com/katzgrau/klogger) ➔ Your logger implementation ➔ Oh, cmon. Just use Monolog
  • 35. PSR-4 Autoloading ➔ Autoloading takes care about classes with fully-qualified class names (FQCN) ➔ Classes, interfaces, traits considers as “class” (FooInterface::class) <NamespaceName>(<SubNamespaceNames>)*<ClassName> FQCN Namespace prefix Base directory Resulting file path SymfonyCoreRequest SymfonyCore ./vendor/Symfony/Core/ ./vendor/Symfony/Core/Request.php AuraWebResponseStatus AuraWeb /path/to/aura-web/src/ /path/to/aura-web/src/Response/Status.php
  • 36. PSR-4 Autoloading via Composer { "autoload": { "psr-4": { "Monolog": "src/", "VendorNamespace": "" } } } { "autoload": { "psr-4": { "": "src/" } } }
  • 38. PSR-7 Main Concept HTTP Requests and Responses are abstracted in form of HTTP messages
  • 40. PSR-7 Component features ➔ Request, ServerRequest, Response, Uri are immutable ➔ Response Body is stream (like php://temp)
  • 41. PSR-7 Known Implementations ➔ guzzlehttp/psr7 (https://packagist.org/packages/guzzlehttp/psr7) ➔ slim/http (https://packagist.org/packages/slim/http) ➔ zendframework/diactorous (https://packagist.org/packages/zendframework/zend-diactoros) ➔ wandu/http (https://packagist.org/packages/wandu/http) ➔ symfony/psr-http-message-bridge (https://packagist.org/packages/symfony/psr-http-message-bridge) ➔ zendframework/zend-psr7-bridge (https://packagist.org/packages/zendframework/zend-psr7bridge)
  • 42. PSR-7 examples $app = new SlimApp; $app->get('/foo', function ($req, $res, $args) { return $res->withHeader( 'Content-Type', 'application/json' ); }); $app->run();
  • 43. PSR-7 examples $response = new ZendDiactorosResponse(); $response->getBody()->write("Hellon"); $response->getBody()->write("worldn"); $response = $response ->withHeader('Content-Type', 'text/plain') ->withAddedHeader('X-Show-Something', 'something');
  • 45.
  • 47. Caching examples using Stash (tedivm/stash) $driver = new StashDriverFileSystem(); $pool = new StashPool($driver); $item = $pool->getItem('path/to/data'); $info = $item->get(); if ($item->isMiss()) { $info = loadInfo($id); $item->set($userInfo, 120); } return $info;
  • 50. Draft PSRs ➔ PSR-12: Extended Coding Style Guide ➔ PSR-14: Event Manager ➔ PSR-15: HTTP Middlewares
  • 51. Current Stage and Future of PHP-FIG ➔ Some members complained that they are forced to use or support PSRs in their projects ➔ As a results they would like to have some “re-branding” ➔ This led to PHP Community-driven Standards and HTTP Interop appearing
  • 52. Summary ➔ Following coding standards disciplines & improves readability ➔ Sometimes usage of “code-smell” tools is beneficial and not routine ➔ Autoloading via Composer nowadays rocks ➔ There are some well-grounded techniques that can be a problem solution (logging, caching, containers, etc.) ➔ Having abstraction layer in HTTP is more convenient than raw access to superglobals ➔ PHP becomes more mature and more standardized