Slim 4.0.0 has been released

Baris Eser
3 min readAug 2, 2019

Slim is a lightweight and very fast micro framework for building powerful web app or Restful API. Slim contains very handy URL structure with routers, middlewares, bodyparser along with page templates, encrypted cookies and lots more. It also has a very clear documentation. If you want to get more details, you can check slim documentation or github page.

I have been using to slim framework for a long time especially create Restful Api for mobile app service. My last Slim project is loco, Loco is the most user friendly and accurate location tracking app to find and track live locations of your Friends, Loved Ones, Children & Family. Simply invite and follow others to immediately see not just their positions on the map but also the name of the places they have been, how much time they spent there, real time movement with animation on the map.

So, Back to our main topic, Slim 4.0.0 has been released (2019–08–01). It comes lots of new feature and depreceted. I think The most important change was in the php version. According to composer.json Slim 4 require PHP 7.1 or higher.

For this major release the focus was on the following, Lets check this

  • Implementing PSR-15 Middleware Support
  • Decoupling our dependency on Slim’s PSR-7 implementation and enabling usage of any PSR-7 implementation
  • Decoupling our dependency on Pimple and enabling usage of any PSR-11 ContainerInterface implementation
  • Decoupling our dependency on FastRoute and implement interfaces enabling the user to use any routing library
  • Decoupling error handling from the core and enable users to easily use their own implementations
  • Decoupling response emitting from the core and enable users to easily use their own implementation
  • Remove all traits for a cleaner call stack trace when debugging
  • Create an app factory that makes it easier to create an App instance due to the higher complexity of the increased modularity

Major Changes

  • Slim requires PHP 7.1 or higher.
  • Slim no longer ships with a PSR-7 Implementation.
  • Slim no longer ships with Pimple.
  • Slim no longer sets the default_mimetype to an empty string, so you need to set it yourself in php.ini or your app using ini_set(‘default_mimetype’,‘’).
  • Slim App::$settings have been removed, multiple middleware have been implemented to replace the functionality from each individual settings.
  • Routing is now done via the Slim\Middleware\RoutingMiddleware. By default routing will be performed last in the middleware queue. If you want to access the route and routingResults attributes from $request you will need to add this middleware last as it will get executed first within the queue when running the app. The middleware queue is still being executed in Last In First Out (LIFO) order. This replaces the determineRouteBeforeAppMiddleware setting.
  • Output buffering is now done via Slim\Middleware\OutputBufferingMiddleware. This replaces the outputBuffering setting.
  • Content length header calculation is now done via Slim\Middleware\ContentLengthMiddleware. This replaces the addContentLengthHeader setting.
  • The RouterInterface component has been split into 4 interfaces RouteCollectorInterface, RouteParserInterface, RouteResolverInterface and DispatcherInterface.
  • Double-Pass middleware has been deprecated. Middleware signature is now the PSR-15 MiddlewareInterface signature process(Request $request, RequestHandler $handler). We no longer support the double-pass function ($request, $response, $next) signature. You can still use callables with the signature function (Request $request, RequestHandler $handler) {} to create middleware or use an invokable class with that signature.
  • Slim App now implements the PSR-15 RequestHandlerInterface. Use $app->handle($request) instead of $app($request).
  • PSR-15 RequestHandler can now be used as route callables.
  • Binding of $app to the RouteGroup callable has been removed. RouteCollectorProxy gets injected into the RouteGroup’s callable instead. $app->group(‘/group’, function (RouteCollectorProxy $group) { $group->get(…); }
  • The App::subRequest() method has been removed. You can perform sub-requests via $app->handle($request) from within a route callable.
  • Removed SlimException. New HttpException have been implemented, namely HttpBadRequestException, HttpForbiddenException, HttpInternalServerErrorException, HttpMethodNotAllowedException, HttpNotFoundException, HttpNotImplementedException and HttpUnauthorizedException. You can also create your own by extending HttpException or HttpSpecializedException.
  • Request method names are now case-sensitive when user App::map().
  • All traits have been removed. CallableResolverTrait and MiddlewareAwareTrait no longer exist.
  • Two new factories have been introduced. AppFactory and ServerRequestCreatorFactory to facilitate App and ServerRequest creation. We currently support 4 PSR-7/ServerRequest creator combinations (Slim-Psr7, Nyholm PSR-7 & Nyholm PSR-7 Server, Guzzle PSR-7 and Guzzle HTTP Factory and Zend-Diactoros.

“Hello World”

composer require slim/slim:4.0.0composer require slim/psr7composer require nyholm/psr7 nyholm/psr7-servercomposer require guzzlehttp/psr7 http-interop/http-factory-guzzlecomposer require zendframework/zend-diactoros

--

--