STANDARDS A PHP DEVELOPER SHOULD KNOW
@movetodevnullsebastianfeldmann
Sebastian Feldmann
T E N
STANDARDS ARE
EVERYWHERE
The web is build on standards
💩 encodingUTF8
UTF16
ISO8859-1
ANSI
CP1252
ASCIIEBCDIC273
w w w . p h p - f i g . o r gPHP-FIG
•Composer
•Drupal
• Joomla
•Magento
•ReactPHP
• Slim
• Symfony
• Zend Framework
•…
PSR vs. RFC
PSR2 PSR12PSR1
Coding Standards
<?php namespace Vendor\Package;
use FooInterface; use BarClass as Bar; use OtherVendor\OtherPackage\BazClass;
class Foo extends Bar implements FooInterface { public function sampleMethod($a, $b = null) { if ($a === $b) { bar(); } elseif ($a > $b) { $foo->bar($arg1); } else { BazClass::bar($arg2, $arg3); } }
final public static function bar() { // method body } }
<?php namespace Vendor\Package;
class Foo extends Bar implements FooInterface { public function sampleMethod($a, $b = null) { if ($this->someImportantProperty === $this->someEvenMoreImportantProperty && $this->currentState !== self::SOME_STATE_YOU_DONT_WANT) { throw new \RuntimeException('Something went wrong!'); }
... }
...
<?php namespace Vendor\Package;
class Foo extends Bar implements FooInterface { public function sampleMethod($a, $b = null) { if ( $this->someImportantProperty === $this->someEvenMoreImportantProperty && $this->currentState !== self::SOME_STATE_YOU_DONT_WANT ) { throw new \RuntimeException('Something went wrong!'); }
... }
...
<?php namespace Vendor\Package;
class Foo extends Bar implements FooInterface { public function sampleMethod($a, $b = null) { $foo = 'some super string';$bar = 'some other stuff';
... }
...
<?php namespace Vendor\Package;
class Foo extends Bar implements FooInterface { public function sampleMethod($a, $b = null) { $foo = 'some super string’; $bar = 'some other stuff';
... }
...
PHP Code Sniffer
PHP Coding Standard Fixer
PSR4PSR0
Autoloading
Namespace
<NamespaceName>(_<SubNamespaceNames>)*_<ClassName>
PHPUnit_Framework_TestCase
PHPUnit
Framework
TestCase.php
\PHPUnit\Framework\TestCase
\<NamespaceName>(\<SubNamespaceNames>)*\<ClassName>
src PHPUnit=>
PSR0
<NamespaceName>(_<SubNamespaceNames>)*_<ClassName>
PHPUnit_Framework_TestCase
Framework
TestCase.php
\PHPUnit\Framework\TestCase
\<NamespaceName>(\<SubNamespaceNames>)*\<ClassName>
src
PHPUnit PHPUnit=> Framework
TestCase.php
src PHPUnit=>
PSR4
{
...
"autoload": { "psr-4": { "MyNamespace\\": "src/", }, "psr-0": { "OldLib_Lib1_": "libs/lib1", "SomeLib\\Lib2": "libs/lib2" } }
...
}
composer.json
PSR3
Logging
<?php
namespace Psr\Log;
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()); }
<?php
namespace Psr\Log;
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()); }
<?php
namespace Psr\Log;
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()); }
<?php
namespace Psr\Log;
interface LoggerAwareInterface { public function setLogger(LoggerInterface $logger); }
<?php
namespace Psr\Log;
class LogLevel { const EMERGENCY = 'emergency'; const ALERT = 'alert'; const CRITICAL = 'critical'; const ERROR = 'error'; const WARNING = 'warning'; const NOTICE = 'notice'; const INFO = 'info'; const DEBUG = 'debug'; }
<?php declare(strict_types=1);
namespace Monolog;
...
class Logger implements LoggerInterface { ...
}
PSR16PSR6
Caching
<?php
namespace Psr\Cache;
interface CacheItemInterface { public function getKey();
public function get();
public function isHit(); public function set($value); public function expiresAt($expiration); public function expiresAfter($time); }
PSR6
<?php
namespace Psr\Cache;
interface CacheItemInterface { public function getKey();
public function get();
public function isHit(); public function set($value); public function expiresAt($expiration); public function expiresAfter($time); }
PSR6
<?php
namespace Psr\Cache;
interface CacheItemInterface { public function getKey();
public function get();
public function isHit(); public function set($value); public function expiresAt($expiration); public function expiresAfter($time); }
PSR6
<?php
namespace Psr\Cache;
interface CacheItemInterface { public function getKey();
public function get();
public function isHit(); public function set($value); public function expiresAt($expiration); public function expiresAfter($time); }
PSR6
<?php
namespace Psr\Cache;
interface CacheItemInterface { public function getKey();
public function get();
public function isHit(); public function set($value); public function expiresAt($expiration); public function expiresAfter($time); }
PSR6
<?php
namespace Psr\Cache;
interface CacheItemPoolInterface { public function getItem($key);
public function getItems(array $keys = array());
public function hasItem($key);
public function clear(); public function deleteItem($key);
public function deleteItems(array $keys);
public function save(CacheItemInterface $item);
public function saveDeferred(CacheItemInterface $item);
public function commit(); }
PSR6
<?php
namespace Psr\Cache;
interface CacheItemPoolInterface { public function getItem($key);
public function getItems(array $keys = array());
public function hasItem($key);
public function clear(); public function deleteItem($key);
public function deleteItems(array $keys);
public function save(CacheItemInterface $item);
public function saveDeferred(CacheItemInterface $item);
public function commit(); }
PSR6
<?php
namespace Psr\Cache;
interface CacheItemPoolInterface { public function getItem($key);
public function getItems(array $keys = array());
public function hasItem($key);
public function clear(); public function deleteItem($key);
public function deleteItems(array $keys);
public function save(CacheItemInterface $item);
public function saveDeferred(CacheItemInterface $item);
public function commit(); }
PSR6
<?php
namespace Psr\Cache;
interface CacheItemPoolInterface { public function getItem($key);
public function getItems(array $keys = array());
public function hasItem($key);
public function clear(); public function deleteItem($key);
public function deleteItems(array $keys);
public function save(CacheItemInterface $item);
public function saveDeferred(CacheItemInterface $item);
public function commit(); }
PSR6
stop
stop
that’s too much
<?php
namespace Psr\SimpleCache;
interface CacheInterface { public function get($key, $default = null);
public function set($key, $value, $ttl = null); public function delete($key); public function clear();
public function getMultiple($keys, $default = null); public function setMultiple($values, $ttl = null); public function deleteMultiple($keys);
public function has($key); }
PSR16
<?php
namespace Psr\SimpleCache;
interface CacheInterface { public function get($key, $default = null);
public function set($key, $value, $ttl = null); public function delete($key); public function clear();
public function getMultiple($keys, $default = null); public function setMultiple($values, $ttl = null); public function deleteMultiple($keys);
public function has($key); }
PSR16
<?php
namespace Psr\SimpleCache;
interface CacheInterface { public function get($key, $default = null);
public function set($key, $value, $ttl = null); public function delete($key); public function clear();
public function getMultiple($keys, $default = null); public function setMultiple($values, $ttl = null); public function deleteMultiple($keys);
public function has($key); }
PSR16
PSR11
Container Interface
aka Container Interop
<?php
namespace Psr\Container;
interface ContainerInterface { public function get($id);
public function has($id); }
PSR11
Dependency Injection
<?php
class Foo { public function __construct() { $handler = new Bar(); $handler->handleInternalStuff($this->value); ... } }
<?php
class Foo { public function __construct() { $handler = new Bar(); $handler->handleInternalStuff($this->value); ... } }
<?php
class Foo { public function __construct() { $handler = new Bar(); $handler->handleInternalStuff($this->value); ... } }
<?php
class Foo { public function __construct() { $handler = new Bar(); $handler->handleInternalStuff($this->value); ... } }
<?php
class Foo { public function __construct() {
$handler->handleInternalStuff($this->value); ... } }
<?php
class Foo { public function __construct( ) {
$handler->handleInternalStuff($this->value); ... } }
<?php
class Foo { public function __construct(Bar $handler) {
$handler->handleInternalStuff($this->value); ... } }
<?php
class Foo { public function __construct(Bar $handler) { $handler->handleInternalStuff($this->value); ... } }
Dependency Injection
• loose coupling
• more flexibility
• easier testing
• better code
• complex object creation
+ -
<?php
$someComplexObject = $container->get('MyComplexObject');
• Disco
• League/Container
• Pimple
• Zend/ServiceManager
PSR11 - Container
• Slim
• zend-expressive
PSR11 - Frameworks
PSR7
HTTP Message
Request
$_GET
$_POST
$_FILES
http_get_request_body()
$_COOKIE
http_get_request_headers()
Response
print()
setcookie()
echo
http_response_code()
header()
http_redirect()
Request
<?php namespace Psr\Http\Message;
interface MessageInterface { public function getProtocolVersion();
public function withProtocolVersion($version);
public function getHeaders();
public function hasHeader($name);
public function getHeader($name);
public function getHeaderLine($name);
public function withHeader($name, $value);
public function withAddedHeader($name, $value);
public function withoutHeader($name);
public function getBody();
public function withBody(StreamInterface $body); }
<?php namespace Psr\Http\Message;
interface RequestInterface extends MessageInterface { public function getRequestTarget();
public function withRequestTarget($requestTarget);
public function getMethod();
public function withMethod($method);
public function getUri();
public function withUri(UriInterface $uri, $preserveHost = false); }
<?php namespace Psr\Http\Message;
interface ServerRequestInterface extends RequestInterface { public function getServerParams();
public function getCookieParams();
public function withCookieParams(array $cookies);
public function getQueryParams();
public function withQueryParams(array $query);
public function getUploadedFiles();
public function withUploadedFiles(array $uploadedFiles);
public function getParsedBody();
public function withParsedBody($data);
public function getAttributes();
public function getAttribute($name, $default = null);
public function withAttribute($name, $value);
public function withoutAttribute($name); }
<?php namespace Psr\Http\Message;
interface MessageInterface { public function getProtocolVersion();
public function withProtocolVersion($version);
public function getHeaders();
public function hasHeader($name);
public function getHeader($name);
public function getHeaderLine($name);
public function withHeader($name, $value);
public function withAddedHeader($name, $value);
public function withoutHeader($name);
public function getBody();
public function withBody(StreamInterface $body); }
<?php namespace Psr\Http\Message;
interface MessageInterface { public function getProtocolVersion();
public function withProtocolVersion($version);
public function getHeaders();
public function hasHeader($name);
public function getHeader($name);
public function getHeaderLine($name);
public function withHeader($name, $value);
public function withAddedHeader($name, $value);
public function withoutHeader($name);
public function getBody();
public function withBody(StreamInterface $body); }
<?php namespace Psr\Http\Message;
interface MessageInterface { public function getProtocolVersion();
public function withProtocolVersion($version);
public function getHeaders();
public function hasHeader($name);
public function getHeader($name);
public function getHeaderLine($name);
public function withHeader($name, $value);
public function withAddedHeader($name, $value);
public function withoutHeader($name);
public function getBody();
public function withBody(StreamInterface $body); }
<?php namespace Psr\Http\Message;
interface RequestInterface extends MessageInterface { public function getRequestTarget();
public function withRequestTarget($requestTarget);
public function getMethod();
public function withMethod($method);
public function getUri();
public function withUri(UriInterface $uri, $preserveHost = false); }
<?php namespace Psr\Http\Message;
interface RequestInterface extends MessageInterface { public function getRequestTarget();
public function withRequestTarget($requestTarget);
public function getMethod();
public function withMethod($method);
public function getUri();
public function withUri(UriInterface $uri, $preserveHost = false); }
<?php namespace Psr\Http\Message;
interface ServerRequestInterface extends RequestInterface { public function getServerParams();
public function getCookieParams();
public function withCookieParams(array $cookies);
public function getQueryParams();
public function withQueryParams(array $query);
public function getUploadedFiles();
public function withUploadedFiles(array $uploadedFiles);
public function getParsedBody();
public function withParsedBody($data);
public function getAttributes();
public function getAttribute($name, $default = null);
public function withAttribute($name, $value);
public function withoutAttribute($name); }
<?php namespace Psr\Http\Message;
interface ServerRequestInterface extends RequestInterface { public function getServerParams();
public function getCookieParams();
public function withCookieParams(array $cookies);
public function getQueryParams();
public function withQueryParams(array $query);
public function getUploadedFiles();
public function withUploadedFiles(array $uploadedFiles);
public function getParsedBody();
public function withParsedBody($data);
public function getAttributes();
public function getAttribute($name, $default = null);
public function withAttribute($name, $value);
public function withoutAttribute($name); }
<?php namespace Psr\Http\Message;
interface ServerRequestInterface extends RequestInterface { public function getServerParams();
public function getCookieParams();
public function withCookieParams(array $cookies);
public function getQueryParams();
public function withQueryParams(array $query);
public function getUploadedFiles();
public function withUploadedFiles(array $uploadedFiles);
public function getParsedBody();
public function withParsedBody($data);
public function getAttributes();
public function getAttribute($name, $default = null);
public function withAttribute($name, $value);
public function withoutAttribute($name); }
<?php namespace Psr\Http\Message;
interface ServerRequestInterface extends RequestInterface { public function getServerParams();
public function getCookieParams();
public function withCookieParams(array $cookies);
public function getQueryParams();
public function withQueryParams(array $query);
public function getUploadedFiles();
public function withUploadedFiles(array $uploadedFiles);
public function getParsedBody();
public function withParsedBody($data);
public function getAttributes();
public function getAttribute($name, $default = null);
public function withAttribute($name, $value);
public function withoutAttribute($name); }
<?php namespace Psr\Http\Message;
interface ServerRequestInterface extends RequestInterface { public function getServerParams();
public function getCookieParams();
public function withCookieParams(array $cookies);
public function getQueryParams();
public function withQueryParams(array $query);
public function getUploadedFiles();
public function withUploadedFiles(array $uploadedFiles);
public function getParsedBody();
public function withParsedBody($data);
public function getAttributes();
public function getAttribute($name, $default = null);
public function withAttribute($name, $value);
public function withoutAttribute($name); }
<?php namespace Psr\Http\Message;
interface ServerRequestInterface extends RequestInterface { public function getServerParams();
public function getCookieParams();
public function withCookieParams(array $cookies);
public function getQueryParams();
public function withQueryParams(array $query);
public function getUploadedFiles();
public function withUploadedFiles(array $uploadedFiles);
public function getParsedBody();
public function withParsedBody($data);
public function getAttributes();
public function getAttribute($name, $default = null);
public function withAttribute($name, $value);
public function withoutAttribute($name); }
[ 'files' => [ 'name' => [ 0 => 'file0.txt', 1 => 'file1.html', ], 'type' => [ 0 => 'text/plain', 1 => 'text/html', ],
...
], ]
[ 'files' => [ 0 => [ 'name' => 'file0.txt', 'type' => ‚text/plain',
...
], 1 => [ 'name' => 'file1.html', 'type' => ‚text/html',
...
], ], ];
[ 'files' => [
0 => /* UploadedFileInterface instance */
1 => /* UploadedFileInterface instance */
] ];
<?php namespace Psr\Http\Message;
interface UploadedFileInterface { public function getStream();
public function moveTo($targetPath);
public function getSize();
public function getError();
public function getClientFilename();
public function getClientMediaType(); }
<?php namespace Psr\Http\Message;
interface UploadedFileInterface { public function getStream();
public function moveTo($targetPath);
public function getSize();
public function getError();
public function getClientFilename();
public function getClientMediaType(); }
<?php namespace Psr\Http\Message;
interface UploadedFileInterface { public function getStream();
public function moveTo($targetPath);
public function getSize();
public function getError();
public function getClientFilename();
public function getClientMediaType(); }
<?php namespace Psr\Http\Message;
interface UploadedFileInterface { public function getStream();
public function moveTo($targetPath);
public function getSize();
public function getError();
public function getClientFilename();
public function getClientMediaType(); }
<?php namespace Psr\Http\Message;
interface UploadedFileInterface { public function getStream();
public function moveTo($targetPath);
public function getSize();
public function getError();
public function getClientFilename();
public function getClientMediaType(); }
<?php namespace Psr\Http\Message;
interface UriInterface { public function getScheme();
public function getAuthority();
public function getUserInfo();
public function getHost();
public function getPort();
public function getPath();
public function getQuery();
public function getFragment();
public function withScheme($scheme);
public function withUserInfo($user, $password = null);
public function withHost($host);
public function withPort($port);
public function withPath($path);
public function withQuery($query);
public function withFragment($fragment);
public function __toString(); }
<?php namespace Psr\Http\Message;
interface UriInterface { public function getScheme();
public function getAuthority();
public function getUserInfo();
public function getHost();
public function getPort();
public function getPath();
public function getQuery();
public function getFragment();
public function withScheme($scheme);
public function withUserInfo($user, $password = null);
public function withHost($host);
public function withPort($port);
public function withPath($path);
public function withQuery($query);
public function withFragment($fragment);
public function __toString(); }
<?php namespace Psr\Http\Message;
interface UriInterface { public function getScheme();
public function getAuthority();
public function getUserInfo();
public function getHost();
public function getPort();
public function getPath();
public function getQuery();
public function getFragment();
public function withScheme($scheme);
public function withUserInfo($user, $password = null);
public function withHost($host);
public function withPort($port);
public function withPath($path);
public function withQuery($query);
public function withFragment($fragment);
public function __toString(); }
<?php namespace Psr\Http\Message;
interface UriInterface { public function getScheme();
public function getAuthority();
public function getUserInfo();
public function getHost();
public function getPort();
public function getPath();
public function getQuery();
public function getFragment();
public function withScheme($scheme);
public function withUserInfo($user, $password = null);
public function withHost($host);
public function withPort($port);
public function withPath($path);
public function withQuery($query);
public function withFragment($fragment);
public function __toString(); }
<?php namespace Psr\Http\Message;
interface UriInterface { public function getScheme();
public function getAuthority();
public function getUserInfo();
public function getHost();
public function getPort();
public function getPath();
public function getQuery();
public function getFragment();
public function withScheme($scheme);
public function withUserInfo($user, $password = null);
public function withHost($host);
public function withPort($port);
public function withPath($path);
public function withQuery($query);
public function withFragment($fragment);
public function __toString(); }
<?php namespace Psr\Http\Message;
interface UriInterface { public function getScheme();
public function getAuthority();
public function getUserInfo();
public function getHost();
public function getPort();
public function getPath();
public function getQuery();
public function getFragment();
public function withScheme($scheme);
public function withUserInfo($user, $password = null);
public function withHost($host);
public function withPort($port);
public function withPath($path);
public function withQuery($query);
public function withFragment($fragment);
public function __toString(); }
Request
• Query data
• POST data
• Cookie data
• Uploaded files
• URI information
• Stream data
Response
<?php namespace Psr\Http\Message;
interface MessageInterface { public function getProtocolVersion();
public function withProtocolVersion($version);
public function getHeaders();
public function hasHeader($name);
public function getHeader($name);
public function getHeaderLine($name);
public function withHeader($name, $value);
public function withAddedHeader($name, $value);
public function withoutHeader($name);
public function getBody();
public function withBody(StreamInterface $body); }
<?php namespace Psr\Http\Message;
interface MessageInterface { public function getProtocolVersion();
public function withProtocolVersion($version);
public function getHeaders();
public function hasHeader($name);
public function getHeader($name);
public function getHeaderLine($name);
public function withHeader($name, $value);
public function withAddedHeader($name, $value);
public function withoutHeader($name);
public function getBody();
public function withBody(StreamInterface $body); }
<?php namespace Psr\Http\Message;
interface ResponseInterface extends MessageInterface { public function getStatusCode();
public function withStatus($code, $reasonPhrase = '');
public function getReasonPhrase(); }
<?php namespace Psr\Http\Message;
interface ResponseInterface extends MessageInterface { public function getStatusCode();
public function withStatus($code, $reasonPhrase = '');
public function getReasonPhrase(); }
<?php namespace Psr\Http\Message;
interface ResponseInterface extends MessageInterface { public function getStatusCode();
public function withStatus($code, $reasonPhrase = '');
public function getReasonPhrase(); }
PSR7
Request
Response
Request
Request
Response
• Slim
• zend-expressive
• Laravel
• Symfony (PSR-7-Bridge)
PSR7 - Frameworks
PSR17 PSR18
PSR17HTTP Factory
<?php
namespace Psr\Http\Message;
<?php
namespace Psr\Http\Message;
interface RequestFactoryInterface
<?php
namespace Psr\Http\Message;
interface RequestFactoryInterface
interface ServerRequestFactoryInterface
<?php
namespace Psr\Http\Message;
interface RequestFactoryInterface
interface ServerRequestFactoryInterface
interface ResponseFactoryInterface
<?php
namespace Psr\Http\Message;
interface RequestFactoryInterface
interface ServerRequestFactoryInterface
interface ResponseFactoryInterface
interface UploadedFileFactoryInterface
<?php
namespace Psr\Http\Message;
interface RequestFactoryInterface
interface ServerRequestFactoryInterface
interface ResponseFactoryInterface
interface UploadedFileFactoryInterface
interface UriFactoryInterface
<?php
namespace Psr\Http\Message;
interface RequestFactoryInterface
interface ServerRequestFactoryInterface
interface ResponseFactoryInterface
interface UploadedFileFactoryInterface
interface UriFactoryInterface
interface StreamFactoryInterface
PSR18HTTP Client
<?php
namespace Psr\Http\Client;
use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface;
interface ClientInterface { public function sendRequest(RequestInterface $request): ResponseInterface; }
<?php
namespace Psr\Http\Client;
use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface;
interface ClientInterface { public function sendRequest(RequestInterface $request): ResponseInterface; }
Guzzle
PSR15HTTP Handler
<?php
namespace Psr\Http\Server;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface;
interface RequestHandlerInterface { public function handle(ServerRequestInterface $request): ResponseInterface; }
<?php
namespace Psr\Http\Server;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface;
interface MiddlewareInterface { public function process( ServerRequestInterface $request, RequestHandlerInterface $handler ): ResponseInterface; }
Middleware examples
• Authentication
• Authorization
• Redirecting / Social Routing
• Output Formatting
<?php
use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface;
class FinalResponder implements MiddlewareInterface { public function process( ServerRequestInterface $request, RequestHandlerInterface $handler ): ResponseInterface { try { return $handler->handle($request); } catch (\Exception $e) { return ErrorPage::createResponse($e); } } }
<?php
use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface;
class FinalResponder implements MiddlewareInterface { public function process( ServerRequestInterface $request, RequestHandlerInterface $handler ): ResponseInterface { try { return $handler->handle($request); } catch (\Exception $e) { return ErrorPage::createResponse($e); } } }
<?php
use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface;
class FinalResponder implements MiddlewareInterface { public function process( ServerRequestInterface $request, RequestHandlerInterface $handler ): ResponseInterface { try { return $handler->handle($request); } catch (\Exception $e) { return ErrorPage::createResponse($e); } } }
<?php
use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface;
class FinalResponder implements MiddlewareInterface { public function process( ServerRequestInterface $request, RequestHandlerInterface $handler ): ResponseInterface { try { return $handler->handle($request); } catch (\Exception $e) { return ErrorPage::createResponse($e); } } }
<?php
use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface;
class FinalResponder implements MiddlewareInterface { public function process( ServerRequestInterface $request, RequestHandlerInterface $handler ): ResponseInterface { try { return $handler->handle($request); } catch (\Exception $e) { return ErrorPage::createResponse($e); } } }
• Single Responsibility
• Tiny testable peaces
• Defined data flow
PSR15 - Middleware
PSR14
Event ManagerDRAFT
• Events
• Tasks
• Emitter
• EventLister
• Processor
PSR14
• Security framework that handles access permissions
• Common full page caching system
• Logging package to track all actions
PSR14
PSR8
Huggable Interface
<?php namespace Psr\Hug;
/** * Defines a huggable object. * * A huggable object expresses mutual affection with another huggable object. */ interface Huggable {
/** * Hugs this object. * * All hugs are mutual. An object that is hugged MUST in turn hug the other * object back by calling hug() on the first parameter. All objects MUST * implement a mechanism to prevent an infinite loop of hugging. * * @param Huggable $h * The object that is hugging this object. */ public function hug(Huggable $h); }
💩
PSR8
PSR15 PSR7
PSR18
PSR2
PSR6
PSR8PSR12
PSR4
PSR11
Deadpool loves standards
Sebastian Feldmann
@movetodevnull
https://phpbu.de
sebastianfeldmann
Captain Hook