Slim 4 Release#2769
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
Appinstance due to the higher complexity of the increased modularityMajor Changes
default_mimetypeto an empty string, so you need to set it yourself in php.ini or your app usingini_set('default_mimetype', '').App::$settingshave 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 therouteandroutingResultsattributes from$requestyou 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 thedetermineRouteBeforeAppMiddlewaresetting.Slim\Middleware\OutputBufferingMiddleware. This replaces theoutputBufferingsetting.Slim\Middleware\ContentLengthMiddleware. This replaces theaddContentLengthHeadersetting.RouterInterfacecomponent has been split into 4 interfacesRouteCollectorInterface,RouteParserInterface,RouteResolverInterfaceandDispatcherInterface.MiddlewareInterfacesignatureprocess(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.Appnow implements the PSR-15RequestHandlerInterface. Use$app->handle($request)instead of$app($request).$appto theRouteGroupcallable has been removed.RouteCollectorProxygets 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. NewHttpExceptionhave been implemented, namelyHttpBadRequestException,HttpForbiddenException,HttpInternalServerErrorException,HttpMethodNotAllowedException,HttpNotFoundException,HttpNotImplementedExceptionandHttpUnauthorizedException. You can also create your own by extendingHttpExceptionorHttpSpecializedException.App::map().CallableResolverTraitandMiddlewareAwareTraitno longer exist.AppFactoryandServerRequestCreatorFactoryto facilitateAppandServerRequestcreation. 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
ErrorMiddlewareandRoutingMiddlewareRouteContextto enable access to the current route, route parser, and routing resultsErrorHandlercomponentErrorRendererInterfacechanged to use invokable pattern to leverageCallableResolverRouteParser::pathFor()andRouteParser::relativePathFor()are deprecated. UseRouteParser::urlFor()andRouteParser::relativeUrlFor()AppFactoryto enable PSR-7 implementation and ServerRequest creator auto-detectionRouteCollectorProxyInterfacewhich extracts all the route mapping functionality from app into its own interfaceRouteParserInterfaceand decouple FastRoute route parser entirely from core. The methodsrelativePathFor(),urlFor()andfullUrlFor()are now located on this interfaceDispatcherInterfaceand 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 URLsroutingResultsrequest 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_mimetypeto an empty string, so you need to set it yourself in php.ini or your app usingini_set('default_mimetype', '');determineRouteBeforeAppMiddlewaresetting is removed. Add RoutingMiddleware() where you need it nowaddContentLengthHeadersetting is removedSlim\Httphas been removed and Slim now depends on the separate Slim-Http componentoutputBufferingsetting 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 aServerRequestyou 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: