Skip to main content

Middleware

Building Modular Applications With PSR-7

·1152 words·6 mins
PSR-7, the HTTP message interfaces opened a new door of creating modular applications. Sadly many of the PSR-7 implementations added many helper methods. So if someone is creating a library that needs a PSR-7 implementations they tie the particular library with the PSR-7 implementation and use these convinient helper methods. So was PSR-15: interfaces for HTTP Middleware and PSR-17: interfaces for HTTP Factories was proposed. When creating a module one of the most challenging part is how to serve the javascript, css and images. We are going to use hkt/psr7-asset which is a fork of Aura.Asset_Bundle . What you want to do is only map the path to the assets folder.

Eloquent and Pagination Inside Zend Expressive

·154 words·1 min
Recently working with eloquent (Laravel’s orm), zend expressive and zend view, I wanted to integrate pagination. It was simple as registering a Paginator middleware. 1 2 3 4 5 6 7 8 9 10 11 12 <?php use Illuminate\Pagination\Paginator; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; IlluminatePaginator::currentPageResolver(function ($pageName) use ($request) { $params = $request->getQueryParams(); return empty($params[$pageName]) ? 1 : $params[$pageName]; }); IlluminatePaginator::currentPathResolver(function () use ($request) { return $request->getUri()->getPath(); }); and you can call paginate on the Model. Eg : Consider you have a Post model.

Conduit: Middleware for PHP

·618 words·3 mins
Long back, I happened to talk with Beau Simensen about stackphp on #auraphp channel. It was hard for me to digest when I noticed it need symfony/http-kernel and its dependencies. After a few months, I started to like the middleware approach of slim framework and wanted to push it to aura. But nothing happened there. Conduit to rescue # Conduit is a Middleware for PHP built by Matthew Weier O’Phinney lead of Zend framework. Conduit supports the current PSR-7 proposal. I believe like the many PSR’s, PSR-7 will be a revolution in the PHP world. Conduit is really a micro framework and can grow with your project.