Skip to content
Daniel Opitz edited this page Aug 27, 2024 · 26 revisions

Status: In progress

Current working branch: https://github.com/odan/Slim/tree/5.x

Changelog: https://github.com/odan/Slim/blob/5.x/CHANGELOG.md

Slim 5 Issues: https://github.com/slimphp/Slim/issues?q=is%3Aissue+is%3Aopen+label%3A%22Slim+5%22

Planning

  • Collect feedback from the Slim community to identify pain points and desired features.
  • Identify how new PHP 8 features can be integrated to enhance Slim 5

Changes

  • Bring back the simplicity. Simplify App instantiation.
  • Improve DI container integration. Make the DI container a first-class citizen. Require a PSR-11 package.
  • Ensure that route attributes are always in the Request #3280. See new RoutingArgumentsMiddleware.
  • Unify CallableResolver and AdvancedCallableResolver #3073. Resolved with the new CallableResolver.
  • Resolving middleware breaks if resolver throws unexpected exception type #3071. Resolved with the new CallableResolver.
  • Forward logger to own ErrorHandlingMiddleware #2943. See new ExceptionLoggingMiddleware.

New Features

  • Add new RoutingMiddleware and the new EndpointMiddleware.
  • Optimize middleware execution pipeline: Provide FIFO middleware support. FIFO by default. Can be changed to LIFO using the AppBuilder.
  • Provide integrated base path middleware. See new BasePathMiddleware.
  • Provide support for other routing packages. The RoutingMiddleware and/or EndpointMiddleware can be replaced with custom middleware implementations.
  • Provide support for custom error handlers using a new interface (ExceptionHandlerInterface). See new ExceptionHandlingMiddleware.
  • Provide support for custom error logging. See new ExceptionLoggingMiddleware.

Dependencies

  • Require >= PHP 8.2
  • PSR-7 and PSR-15 compliance: Require at least psr/http-message 2.0.
  • PSR-11 compliance: Require at least psr/container 2.0.
  • PSR-3 compliance: Require at least psr/log 3.0

Documentation

  • Update changelog
  • Update and expand the official documentation to cover new features and best practices.
  • Provide updated tutorials and example applications to help developers get started with Slim 5.
  • Add migration guide

Remove

  • ErrorMiddleware. Replaced by ExceptionHandlingMiddleware and ExceptionLoggingMiddleware.

Testing

  • Require PHPUnit 11.
  • Optimize tests. Avoid mocking wherever possible. Drop prophecy.

Final Release

  • Release Candidate: Prepare and release the Slim 5 release candidate for final testing.
  • Official Release: Launch Slim 5 with complete documentation and migration guides.

Minimal Slim 5 Example

Installation:

composer require slim/slim:5.*
composer require slim/psr7
composer require php-di/php-di

File: public/index.php

<?php

use Slim\Builder\AppBuilder;
use Slim\Middleware\BodyParsingMiddleware;
use Slim\Middleware\EndpointMiddleware;
use Slim\Middleware\ExceptionHandlingMiddleware;
use Slim\Middleware\ExceptionLoggingMiddleware;
use Slim\Middleware\RoutingMiddleware;

require __DIR__ . '/../vendor/autoload.php';

// Build the App instance
$builder = new AppBuilder();

$app = $builder->build();

// Add middleware (New: FIFO by default)
$app->add(RoutingMiddleware::class);
$app->add(BodyParsingMiddleware::class);
$app->add(ExceptionHandlingMiddleware::class);
$app->add(ExceptionLoggingMiddleware::class);
$app->add(EndpointMiddleware::class);

// Register Routes
$app->get('/', function ($request, $response, $args) {
    $response->getBody()->write("Hello, World!");
    return $response;
});

// Register route with action class
$app->get('/ping', \App\Action\PingAction::class);

// Run the app
$app->run();
Clone this wiki locally