Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Slim 4.0.0 Release
We are excited to announce the Slim 4.0.0 release. Please direct all your feedback for this release to the Slim 4 Release Feedback Thread. The new docs are located here.
Supported PSR-7 Implementations CI Status
Note: Travis-CI is configured to be triggered automatically at least every 24 hours.
General Direction
For this major release the focus was on the following:
App
instance due to the higher complexity of the increased modularityMajor Changes
default_mimetype
to an empty string, so you need to set it yourself in php.ini or your app usingini_set('default_mimetype', '')
.App::$settings
have been removed, multiple middleware have been implemented to replace the functionality from each individual settings.Slim\Middleware\RoutingMiddleware
. By default routing will be performed last in the middleware queue. If you want to access theroute
androutingResults
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 thedetermineRouteBeforeAppMiddleware
setting.Slim\Middleware\OutputBufferingMiddleware
. This replaces theoutputBuffering
setting.Slim\Middleware\ContentLengthMiddleware
. This replaces theaddContentLengthHeader
setting.RouterInterface
component has been split into 4 interfacesRouteCollectorInterface
,RouteParserInterface
,RouteResolverInterface
andDispatcherInterface
.MiddlewareInterface
signatureprocess(Request $request, RequestHandler $handler)
. We no longer support the double-passfunction ($request, $response, $next)
signature. You can still use callables with the signaturefunction (Request $request, RequestHandler $handler) {}
to create middleware or use an invokable class with that signature.App
now implements the PSR-15RequestHandlerInterface
. Use$app->handle($request)
instead of$app($request)
.$app
to theRouteGroup
callable has been removed.RouteCollectorProxy
gets injected into theRouteGroup
's callable instead.$app->group('/group', function (RouteCollectorProxy $group) { $group->get(...); }
App::subRequest()
method has been removed. You can perform sub-requests via$app->handle($request)
from within a route callable.SlimException
. NewHttpException
have been implemented, namelyHttpBadRequestException
,HttpForbiddenException
,HttpInternalServerErrorException
,HttpMethodNotAllowedException
,HttpNotFoundException
,HttpNotImplementedException
andHttpUnauthorizedException
. You can also create your own by extendingHttpException
orHttpSpecializedException
.App::map()
.CallableResolverTrait
andMiddlewareAwareTrait
no longer exist.AppFactory
andServerRequestCreatorFactory
to facilitateApp
andServerRequest
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.Changelog
4.0.0 - 2019-08-01
Added
ErrorMiddleware
andRoutingMiddleware
RouteContext
to enable access to the current route, route parser, and routing resultsErrorHandler
componentErrorRendererInterface
changed to use invokable pattern to leverageCallableResolver
RouteParser::pathFor()
andRouteParser::relativePathFor()
are deprecated. UseRouteParser::urlFor()
andRouteParser::relativeUrlFor()
AppFactory
to enable PSR-7 implementation and ServerRequest creator auto-detectionRouteCollectorProxyInterface
which extracts all the route mapping functionality from app into its own interfaceRouteParserInterface
and decouple FastRoute route parser entirely from core. The methodsrelativePathFor()
,urlFor()
andfullUrlFor()
are now located on this interfaceDispatcherInterface
and decouple FastRoute dispatcher entirely from core. This enables us to swap out our router implementation for any other routerRouteCollector::fullUrlFor()
to give the ability to generate fully qualified URLsroutingResults
request attribute to hold the results of routingDeprecated
RouteCollector::pushGroup()
,RouteCollector::popGroup()
which gets replaced byRouteCollector::group()
RouteCollector::pathFor()
which gets replaced byRouteCollector::urlFor()
preserving the orignal functionalityRemoved
default_mimetype
to an empty string, so you need to set it yourself in php.ini or your app usingini_set('default_mimetype', '');
determineRouteBeforeAppMiddleware
setting is removed. Add RoutingMiddleware() where you need it nowaddContentLengthHeader
setting is removedSlim\Http
has been removed and Slim now depends on the separate Slim-Http componentoutputBuffering
setting is removedApp::setContainer()
Changed
App::__construct()
Fixed
Router::setCacheFile()
Step-By-Step Hello World
Step 1: Install Composer
Don't have Composer? It's easy to install by following the instructions on their download page.
Step 2: Install Slim
We recommend you install Slim with Composer.
Navigate into your project's root directory and execute the bash command
shown below. This command downloads the Slim Framework and its third-party
dependencies into your project's
vendor/
directory.Step 3: Install a PSR-7 Implementation and ServerRequest Creator
Before you can get up and running with Slim you will need to choose a PSR-7 implementation that best fits your application.
In order for auto-detection to work and enable you to use
AppFactory::create()
andApp::run()
without having to manually create aServerRequest
you need to install one of the following implementations:Slim PSR-7
Nyholm PSR-7 and Nyholm PSR-7 Server
Guzzle PSR-7 and Guzzle HTTP Factory
Zend Diactoros
Step 4: Hello World
Slim 4 DDD Skeleton
Slim 4 MVC Skeleton
@adriansuter created an MVC skeleton. You can clone the skeleton and try it out: