Getting Started
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.
On this page
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,/publicinstead of 1 file - Module system —
composer require strataphp/adminfor admin panel - CLI —
php bin/migrate.phpinstead of writing your own - Database migrations — Built-in, no need for Phinx
Migration Strategy
- Create new StrataPHP project:
composer create-project strataphp/skeleton - Copy your Slim routes into
routes/web.php - Move middleware to
app/Middleware/ - 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.