<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MV Associati Tech Gems &#187; middleware</title>
	<atom:link href="http://www.mvassociati.it/en/gems/topic/middleware-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mvassociati.it/en/gems</link>
	<description>Technical Article from MV Associati experience</description>
	<lastBuildDate>Fri, 04 Aug 2017 10:31:17 +0000</lastBuildDate>
	<language>en-EN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
		<item>
		<title>PHP-Middleworld is Out!</title>
		<link>http://www.mvassociati.it/en/gems/php/middleware-php-middleworld-is-out?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-middleworld</link>
		<comments>http://www.mvassociati.it/en/gems/php/middleware-php-middleworld-is-out#comments</comments>
		<pubDate>Tue, 14 Feb 2017 09:39:02 +0000</pubDate>
		<dc:creator>marcoshuttle</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[middleware]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[psr-7]]></category>

		<guid isPermaLink="false">http://www.mvassociati.it/en/gems/?p=794</guid>
		<description><![CDATA[We just released php-middleworld.com, a repository for PSR-7 compliant middleware in PHP, and we would like to share our progress and what the future may bring. PSR-7 It all started with PSR-7, a set of common interfaces for representing HTTP messages in PHP, allowing application abstraction from the HTTP layer. The most important aspect of PSR-7 is that it [...]]]></description>
			<content:encoded><![CDATA[<p dir="ltr">We just released <a href="http://www.php-middleworld.com/">php-middleworld.com</a>, a repository for <a href="http://www.php-fig.org/psr/psr-7/">PSR-7</a> compliant middleware in PHP, and we would like to share our progress and what the future may bring.<span id="more-794"></span></p>
<h2>PSR-7</h2>
<p dir="ltr">It all started with <a href="http://www.php-fig.org/psr/psr-7/">PSR-7</a>, a set of common interfaces for representing HTTP messages in PHP, allowing application abstraction from the HTTP layer.</p>
<p dir="ltr">The most important aspect of PSR-7 is that it is framework independent and hence its interfaces can easily be used with multiple frameworks such as <a href="https://symfony.com">Symfony</a>, <a href="https://framework.zend.com">Zend Framework</a>, <a href="https://laravel.com">Laravel</a> or any other framework.</p>
<p dir="ltr">This capability allows developers to write framework agnostic code with a wider opportunity to be reused in other projects, relying on the PSR-7 interfaces only.</p>
<h2>PHP AND MIDDLEWARE</h2>
<p dir="ltr">The other important key-word is middleware: once the PHP ecosystem gained a nice abstraction over HTTP messages, it was time to think about the best way to write web applications on top of this abstraction.</p>
<p dir="ltr">Citing <a href="https://mwop.net/blog/2015-01-08-on-http-middleware-and-psr-7.html">Matthew Weier O&#8217;Phinney</a>, the concept of middleware can be summarized in a single method signature:</p>
<p></p><pre class="crayon-plain-tag">function (request, response) : response</pre><p></p>
<p dir="ltr">The idea is that objects representing the HTTP request and the HTTP response are passed to a callable, which does something with them to return an HTTP response.</p>
<p dir="ltr">This turns out to be a very easy and composable pattern, which had actually already been used with great success in several other programming languages.</p>
<p dir="ltr">The standard way to compose such middleware is to pass a third argument to the callable, so to allow for another layer of middleware to be invoked:</p>
<p></p><pre class="crayon-plain-tag">function (request, response, next) : response
{
    // do something on request

    response = next(request, response)

    // do something on response

    return response
}</pre><p></p>
<p dir="ltr">Several frameworks, as <a href="https://zendframework.github.io/zend-expressive/">Zend Expressive</a>, <a href="https://www.slimframework.com/">Slim</a>, <a href="https://github.com/radarphp/Radar.Project">Radar</a> or <a href="http://spiral-framework.com/">Spiral</a> rely nowadays upon the concept of middleware to create web applications.</p>
<h2>MIDDLEWARE REUSE</h2>
<p dir="ltr">Now that we have a highly composable pattern based upon a framework agnostic HTTP abstraction, we can actually start writing highly reusable components that would work on any PHP project. This definitely helps developers easing their daily job.</p>
<p dir="ltr">We can have middleware taking  care of logging all received requests, middleware to perform routing, middleware to manage authentication and some other to take care of user sessions. We use our framework to simply glue all this pieces together in the appropriate way.</p>
<p dir="ltr">The key question at this point should be: has anybody else already implemented the piece of middleware I need for the application I’m developing?</p>
<h2>PHP-MIDDLEWORLD IS HERE!</h2>
<p dir="ltr">Until now the answer to the previous question could only be gathered through <a href="https://packagist.org/">Packagist</a>, <a href="https://github.com/">Github</a>, or &#8211; in the worst case &#8211; google.</p>
<p dir="ltr"><a href="http://www.mvassociati.it/it/blog/?attachment_id=1404" rel="attachment wp-att-1404"></a></p>
<p dir="ltr">Having received so much from the community over the years, we thought it was about time to give something back. That’s how <a href="http://www.php-middleworld.com/">php-middleworld.com</a> was born. With the aim to provide fellow PHP developers a means to quickly locate the middleware they need (often with multiple implementation choices).</p>
<h2>THE FUTURE</h2>
<p dir="ltr">We already have in mind several improvements for <a href="http://www.php-middleworld.com/">php-middleworld.com</a>.</p>
<p dir="ltr">First of all we would like to enable fellow developers to add their own middleware, so that our database could grow with a shared effort.</p>
<p dir="ltr">Then we would also like to add <a href="https://github.com/php-fig/fig-standards/tree/master/proposed/http-middleware">PSR-15</a> compatible middleware support also, so to be ready when that proposal will be approved.</p>
<p dir="ltr">No need to get any deeper here, to find out more just head to <a href="http://www.php-middleworld.com/">php-middleworld.com</a> and follow <a title="@phpmwd" href="https://twitter.com/phpmwd">@phpmwd</a> on Twitter!</p>
<p dir="ltr">Stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mvassociati.it/en/gems/php/middleware-php-middleworld-is-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
