SlideShare a Scribd company logo
PSR7
interoperabilità HTTP
Massimiliano Arione
PUG Roma
24 aprile 2018
PSR?
PHP
Standard
Recommendations
FIG
https://www.php-fig.org/
Status # Title Status # Title
X 0 Autoloading Standard B 10 Security Reporting Process
A 1 Basic Coding Standard A 11 Container Interface
A 2 Coding Style Guide R 12 Extended Coding Style Guide
A 3 Logger Interface A 13 Hypermedia Links
A 4 Autoloading Standard B 14 Event Manager
B 5 PHPDoc Standard A 15 HTTP Handlers
A 6 Caching Interface A 16 Simple Cache
A 7 HTTP Message Interface D 17 HTTP Factories
B 8 Huggable Interface D 18 HTTP Client
B 9 Security Advisories
Status # Title Status # Title
X 0 Autoloading Standard B 10 Security Reporting Process
A 1 Basic Coding Standard A 11 Container Interface
A 2 Coding Style Guide R 12 Extended Coding Style Guide
A 3 Logger Interface A 13 Hypermedia Links
A 4 Autoloading Standard B 14 Event Manager
B 5 PHPDoc Standard A 15 HTTP Handlers
A 6 Caching Interface A 16 Simple Cache
A 7 HTTP Message Interface D 17 HTTP Factories
B 8 Huggable Interface D 18 HTTP Client
B 9 Security Advisories
Interfacce
<?php
namespace DoctrineCommonPersistence;
interface ObjectManager
{
public function find($className, $id);
public function persist($object);
public function remove($object);
/* … */
}
<?php
namespace DoctrineORM;
use DoctrineCommonPersistenceObjectManager;
interface EntityManagerInterface extends ObjectManager
{
public function getCache();
public function getConnection();
public function beginTransaction();
public function commit();
public function rollback();
/* ... */
}
<?php
namespace PUGRoma;
use DoctrineORMEntityManagerInterface;
class Pippo implements EntityManagerInterface, ArrayAccess
{
/* tutti i metodi delle interfacce implementate ... */
}
interfacce predefinite
● Traversable
● Iterator
● IteratorAggregate
● Throwable
● ArrayAccess
● Serializable
●
● Countable
● OuterIterator
● RecursiveIterator
● SeekableIterator
●
● DateTimeInterface
● JsonSerializable
S.O.L.I.D.
Single responsibility
Open/closed
Liskov substitution
Interface segregation
Dependency inversion
http://wall-skills.com/wp-content/uploads/2013/12/solid-OOP_wall-skills.pdf
Interfacce PSR
● PSR3 Logging
● PSR6 Caching
● PSR7 HTTP Message
● PSR11 Container
● PSR13 Hypermedia links
● PSR15 HTTP Handlers
● PSR16 SimpleCache
HTTP
HTTP
PSR7
PsrHttpMessageRequestInterface
PsrHttpMessageResponseInterface
PSR7 gerarchia
MessageInterface
RequestInterface ResponseInterface
ServerRequestInterface
PSR7 altre interfacce
● StreamInterface
● UploadedFileInterface
● UriInterface
<?php
namespace AppController;
use ApplicationCommandCreaElementoCommand;
use PsrHttpMessageServerRequestInterface;
use SimpleBusMessageBusMessageBus;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpFoundationResponse;
use SymfonyBundleFrameworkBundleControllerAbstractController
final class PippoController extends AbstractController
{
public function creaElemento(MessageBus $bus, Request $request): Response
{
$command = CreaElementoCommand::fromRequest($request);
$bus->handle($command);
return $this->json([], Response::HTTP_CREATED);
}
}
<?php
namespace ApplicationCommand;
use SymfonyComponentHttpFoundationRequest;
class CreaElementoCommand
{
public $nome;
public $email;
public $telefono;
/* ... */
public static function fromRequest(Request $request): self
{
$params = $request->request->all();
$command = new static();
foreach ($params as $name => $value) {
if (property_exists(self::class, $name) {
$command->$name = $value;
}
}
return $command;
}
}
<?php
namespace ApplicationCommand;
use PsrHttpMessageServerRequestInterface;
class CreaElementoCommand
{
public $nome;
public $email;
public $telefono;
/* ... */
public static function fromRequest(ServerRequestInterface $request): self
{
$params = $request->getParsedBody();
$command = new static();
foreach ($params as $name => $value) {
if (property_exists(self::class, $name) {
$command->$name = $value;
}
}
return $command;
}
}
$ composer require 
symfony/psr-http-message-bridge 
sensio/framework-extra-bundle 
zendframework/zend-diactoros
<?php
namespace AppController;
use ApplicationCommandCreaElementoCommand;
use SimpleBusMessageBusMessageBus;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpFoundationResponse;
use SymfonyBundleFrameworkBundleControllerAbstractController
final class PippoController extends AbstractController
{
public function creaElemento(MessageBus $bus, Request $request): Response
{
$command = CreaElementoCommand::fromRequest($request);
$bus->handle($command);
return $this->json([], Response::HTTP_CREATED);
}
}
<?php
namespace AppController;
use ApplicationCommandCreaElementoCommand;
use PsrHttpMessageServerRequestInterface;
use SimpleBusMessageBusMessageBus;
use SymfonyComponentHttpFoundationResponse;
use SymfonyBundleFrameworkBundleControllerAbstractController
final class PippoController extends AbstractController
{
public function creaElemento(MessageBus $bus, ServerRequestInterface $request): Response
{
$command = CreaElementoCommand::fromRequest($request);
$bus->handle($command);
return $this->json([], Response::HTTP_CREATED);
}
}
https://packagist.org/providers/psr/http-message-implementation
Happy coding!

More Related Content

PDF
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce
PDF
Dynamic PHP web-application analysis
PDF
Boosting Developer Productivity with Clang
PDF
clang-intro
ODP
Php4android TDC 2011
PDF
Portscan all the things! PyCon CZ 2018
PDF
Last 2 Months in PHP - July & August 2016
PDF
RIPS - static code analyzer for vulnerabilities in PHP
OpenShift Origin Community Day (Boston) Writing Cartridges V2 by Jhon Honce
Dynamic PHP web-application analysis
Boosting Developer Productivity with Clang
clang-intro
Php4android TDC 2011
Portscan all the things! PyCon CZ 2018
Last 2 Months in PHP - July & August 2016
RIPS - static code analyzer for vulnerabilities in PHP

What's hot (19)

ODP
PHP for Android: prototyping Android apps in php
PDF
Writing an Ostinato Protocol Builder [FOSDEM 2021]
PDF
Hands on clang-format
PDF
[COSCUP 2021] A trip about how I contribute to LLVM
PDF
In Vogue Dynamic
PDF
[COSCUP 2020] How to use llvm frontend library-libtooling
PDF
PHP & MySQL: PDO x MySQLi
PDF
fastcgi_conf and mime_types
PPTX
PHP 8 - nouvelles fonctionnalités
PPTX
C++ interoperability with other languages
PDF
how u can learn C/C++
PDF
不深不淺,帶你認識 LLVM (Found LLVM in your life)
PDF
EclipseCon France 2017 - Xtending Our Vhdl Xtext Formatter With The Formatter...
PPT
OpenID
PDF
JavaLand gRPC vs REST API
PDF
Testable Code
PDF
Violent python
PDF
Frida Android run time hooking - Bhargav Gajera & Vitthal Shinde
PDF
What is a Service Mesh and what can it do for your Microservices
PHP for Android: prototyping Android apps in php
Writing an Ostinato Protocol Builder [FOSDEM 2021]
Hands on clang-format
[COSCUP 2021] A trip about how I contribute to LLVM
In Vogue Dynamic
[COSCUP 2020] How to use llvm frontend library-libtooling
PHP & MySQL: PDO x MySQLi
fastcgi_conf and mime_types
PHP 8 - nouvelles fonctionnalités
C++ interoperability with other languages
how u can learn C/C++
不深不淺,帶你認識 LLVM (Found LLVM in your life)
EclipseCon France 2017 - Xtending Our Vhdl Xtext Formatter With The Formatter...
OpenID
JavaLand gRPC vs REST API
Testable Code
Violent python
Frida Android run time hooking - Bhargav Gajera & Vitthal Shinde
What is a Service Mesh and what can it do for your Microservices
Ad

Similar to PSR7 - interoperabilità HTTP (20)

PDF
Psr 7 symfony-day
PDF
PSR-7 and PSR-15, why can't you ignore them
PDF
Services Drupalcamp Stockholm 2009
PDF
Meet up symfony 16 juin 2017 - Les PSR
PDF
Introducción a aplicaciones php basadas en middleware y psr 7
PDF
PSR-7, middlewares e o futuro dos frameworks
PDF
Php and-web-services-24402
PDF
Php And Web Services
PDF
PHP and Web Services
PDF
Stacking Up Middleware
PDF
PDF
JugTAAS ReSTful
PDF
PSR-7 - HTTP message interfaces
PDF
Future of HTTP in CakePHP
PPTX
PDF
Making the Most of Modern PHP in Drupal 7
PDF
Writing RESTful Web Services
PDF
Zend/Expressive 3 – The Next Generation
PDF
Web services tutorial
PDF
Web Services Tutorial
Psr 7 symfony-day
PSR-7 and PSR-15, why can't you ignore them
Services Drupalcamp Stockholm 2009
Meet up symfony 16 juin 2017 - Les PSR
Introducción a aplicaciones php basadas en middleware y psr 7
PSR-7, middlewares e o futuro dos frameworks
Php and-web-services-24402
Php And Web Services
PHP and Web Services
Stacking Up Middleware
JugTAAS ReSTful
PSR-7 - HTTP message interfaces
Future of HTTP in CakePHP
Making the Most of Modern PHP in Drupal 7
Writing RESTful Web Services
Zend/Expressive 3 – The Next Generation
Web services tutorial
Web Services Tutorial
Ad

More from Massimiliano Arione (20)

PDF
Typed models pug roma febbraio 2020
PPTX
Pipelines!
PDF
Il nostro amico Stan
PDF
Disinstallare fos user bundle e vivere felici
PDF
MAGA - PUG Roma giugno 2017
PDF
PHP7 e Rich Domain Model
PDF
PHP on the desktop
PDF
Scrivere e leggere log con elastic
PDF
The metrics
PDF
Managing frontend libs in your Symfony project
PDF
Translating symfony docs
PDF
Managing frontend libs in your php project
PDF
Gestire librerie di frontend in php
PDF
PHP, non lo stesso vecchio linguaggio
PDF
Gestione delle dipendenze con Composer
PDF
Migrare da symfony 1 a Symfony2
PDF
Case study OmniAuto.it
ODP
Symfony: un framework per il web
PPT
Paypal + symfony
ODP
Sviluppo rapido di applicazioni con PHP
Typed models pug roma febbraio 2020
Pipelines!
Il nostro amico Stan
Disinstallare fos user bundle e vivere felici
MAGA - PUG Roma giugno 2017
PHP7 e Rich Domain Model
PHP on the desktop
Scrivere e leggere log con elastic
The metrics
Managing frontend libs in your Symfony project
Translating symfony docs
Managing frontend libs in your php project
Gestire librerie di frontend in php
PHP, non lo stesso vecchio linguaggio
Gestione delle dipendenze con Composer
Migrare da symfony 1 a Symfony2
Case study OmniAuto.it
Symfony: un framework per il web
Paypal + symfony
Sviluppo rapido di applicazioni con PHP

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Modernizing your data center with Dell and AMD
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
A Presentation on Artificial Intelligence
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
NewMind AI Monthly Chronicles - July 2025
Network Security Unit 5.pdf for BCA BBA.
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Empathic Computing: Creating Shared Understanding
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
The AUB Centre for AI in Media Proposal.docx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Modernizing your data center with Dell and AMD
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Big Data Technologies - Introduction.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Mobile App Security Testing_ A Comprehensive Guide.pdf
A Presentation on Artificial Intelligence
Understanding_Digital_Forensics_Presentation.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Review of recent advances in non-invasive hemoglobin estimation
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
NewMind AI Monthly Chronicles - July 2025

PSR7 - interoperabilità HTTP