Migrate from Slim 4 to StrataPHP

Slim and StrataPHP are 90% identical. StrataPHP just adds structure + modules.

Good news: Your Slim routes, middleware, and DI container all work in StrataPHP with minimal changes.

1. Application Bootstrap

Slim 4

use Slim\Factory\AppFactory;

$app = AppFactory::create();
$app->get('/hello/{name}', function ($request, $response, $args) {
    $response->getBody()->write("Hello {$args['name']}");
    return $response;
});
$app->run();

StrataPHP

use StrataPHP\App;

$app = new App();
$router = $app->getRouter();
$router->get('/hello/{name}', function ($request) {
    $name = $request->getAttribute('name');
    return new Response("Hello {$name}");
});
$app->run();

Change: AppFactory::create()new App(). Responses are explicit PSR-7.

2. Middleware — Zero Changes

Slim 4 PSR-15 middleware works directly.

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

// This Slim middleware works in StrataPHP unchanged
$app->add(function (ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface {
    $response = $handler->handle($request);
    return $response->withHeader('X-Powered-By', 'StrataPHP');
});

3. Dependency Injection

Both use PSR-11. If you used PHP-DI with Slim, keep using it.

composer require php-di/php-di

$container = new Container();
$app = new App($container);

4. What StrataPHP Adds

  • Folder structure/app, /config, /public instead of 1 file
  • Module systemcomposer require strataphp/admin for admin panel
  • CLIphp bin/migrate.php instead of writing your own
  • Database migrations — Built-in, no need for Phinx

Migration Strategy

  1. Create new StrataPHP project: composer create-project strataphp/skeleton
  2. Copy your Slim routes into routes/web.php
  3. Move middleware to app/Middleware/
  4. Test. Your Slim app is now StrataPHP.

Time estimate: 2-4 hours for a typical Slim API.

Why Switch from Slim?

Slim stays micro forever. If you need admin, CMS, or user management, you'll build it yourself. StrataPHP gives you official modules for that. Same speed, more tools.