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-alpha Release
We are excited to announce the Slim 4.0.0 alpha release. Please direct all your feedback for this release to the Slim 4 Alpha Release Feedback Thread. The new docs are located here.
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
Added
AppFactory
to enable PSR-7 implementation and ServerRequest creator auto-detection.RouteCollectorProxyInterface
which extracts all the route mapping functionality from app into its own interface.RouteParserInterface
and decouple FastRoute route parser entirely from core. The methodsrelativePathFor()
,urlFor()
andfullUrlFor()
are now located on this interface.DispatcherInterface
and decouple FastRoute dispatcher entirely from core. This enables us to swap out our router implementation for any other router.RouteCollector::fullUrlFor()
to give the ability to generate fully qualified URLs$app->get(...)->setInvocationStrategy($strategy)
Router::map()
, and so, by extension, in App::map()RoutingMiddleware
now adds theroutingResults
request attribute to hold the results of routing$app->redirect()
Middleware\ErrorMiddleware
Middleware\MethodOverrideMiddleware
Middleware\ContentLengthMiddleware
Middleware\OutputBufferingMiddleware
Deprecated
RouteParser::pathFor()
andRouteParser::relativePathFor()
are deprecated. UseRouteParser::urlFor()
andRouteParser::relativeUrlFor()
RouteCollector::pushGroup()
,RouteCollector::popGroup()
which gets replaced byRouteCollector::group()
RouteCollector::pathFor()
which gets replaced byRouteCollector::urlFor()
preserving the orignal functionalityApp::$settings
$this
toRouteGroup
callable.Removed
App::$settings
altogetherSlim\Middleware\ErrorMiddleware
as the outermost middleware.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 now.addContentLengthHeader
setting is removedSlim\Http
has been removed and Slim now depends on the separate Slim-Http componentoutputBuffering
setting is removedApp::subRequest()
Slim\Exception\SlimException
$this
togroup()
Fixed
Router::setCacheFile()
rawurldecode()
the path before passing to FastRoute, so UTF-8 characters in paths should now work.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
@l0gicgate created an app skeleton with a DDD style directory structure, example files and test coverage. It is a very opinionated and we're not sure yet if it is the right fit for a skeleton but we would like some feedback. You can clone the skeleton and try it out: