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 ($req, $res, $args) {
    return $res->write("Hello {$args['name']}");
});
$app->run();

StrataPHP

use StrataPHP\App;

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

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

2. Middleware — Zero Changes

Slim 4 middleware is PSR-15. Copy it directly.

// This Slim middleware works in StrataPHP unchanged
$app->add(function ($request, $handler) {
    $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 system — `composer require strataphp/admin` for admin panel
  • CLI — `bin/console migrate` 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.