squille / sln
This is a temporary fork of Slim Framework meant to fix some issues with old versions in order to facilitate migration from slim 2 to slim 4
Fund package maintenance!
Open Collective
Tidelift
Requires
- php: ^7.4 || ^8.0
- ext-json: *
- nikic/fast-route: ^1.3
- psr/container: ^1.0 || ^2.0
- psr/http-factory: ^1.1
- psr/http-message: ^1.1 || ^2.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
- psr/log: ^1.1 || ^2.0 || ^3.0
Requires (Dev)
- ext-simplexml: *
- adriansuter/php-autoload-override: ^1.4
- guzzlehttp/psr7: ^2.6
- httpsoft/http-message: ^1.1
- httpsoft/http-server-request: ^1.1
- laminas/laminas-diactoros: ^2.17 || ^3
- nyholm/psr7: ^1.8
- nyholm/psr7-server: ^1.1
- phpspec/prophecy: ^1.19
- phpspec/prophecy-phpunit: ^2.1
- phpstan/phpstan: ^1.11
- phpunit/phpunit: ^9.6
- slim/http: ^1.3
- slim/psr7: ^1.6
- squizlabs/php_codesniffer: ^3.10
- vimeo/psalm: ^5.24
Suggests
- ext-simplexml: Needed to support XML format in BodyParsingMiddleware
- ext-xml: Needed to support XML format in BodyParsingMiddleware
- php-di/php-di: PHP-DI is the recommended container library to be used with Slim
- slim/psr7: Slim PSR-7 implementation. See https://www.slimframework.com/docs/v4/start/installation.html for more information.
- 5.x-dev
- 4.x-dev
- 4.14.0
- 4.13.0
- 4.12.0
- 4.11.0
- 4.10.0
- 4.9.0
- 4.8.1
- 4.8.0
- 4.7.1
- 4.7.0
- 4.6.0
- 4.5.0
- 4.4.0
- 4.3.0
- 4.2.0
- 4.1.0
- 4.0.0
- 4.0.0-beta
- 4.0.0-alpha
- 3.x-dev
- 3.12.5
- 3.12.4
- 3.12.3
- 3.12.2
- 3.12.1
- 3.12.0
- 3.11.0
- 3.10.0
- 3.9.2
- 3.9.1
- 3.9.0
- 3.8.1
- 3.8.0
- 3.7.0
- 3.6.0
- 3.5.0
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.0
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.0
- 3.0.0-RC3
- 3.0.0-RC2
- 3.0.0-RC1
- 3.0.0-beta2
- 3.0.0-beta1
- 2.x-dev
- 2.6.4
- 2.6.3
- 2.6.2
- 2.6.1
- 2.6.0
- 2.5.0
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.0
- 1.6.7
- 1.6.6
- 1.6.5
- 1.6.4
- 1.6.3
- 1.6.2
- 1.6.1
- 1.6.0
This package is auto-updated.
Last update: 2024-12-10 03:12:32 UTC
README
Slim is a PHP micro-framework that helps you quickly write simple yet powerful web applications and APIs.
Installation
It's recommended that you use Composer to install Slim.
$ composer require slim/slim
This will install Slim and all required dependencies. Slim requires PHP 7.4 or newer.
Choose a PSR-7 Implementation & 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. A few notable ones:
- Slim-Psr7 - This is the Slim Framework PSR-7 implementation
- httpsoft/http-message & httpsoft/http-server-request - This is the fastest, strictest and most lightweight implementation available
- Nyholm/psr7 & Nyholm/psr7-server - Performance is almost the same as the HttpSoft implementation
- Guzzle/psr7 - This is the implementation used by the Guzzle Client, featuring extra functionality for stream and file handling
- laminas-diactoros - This is the Laminas (Zend) PSR-7 implementation
Slim-Http Decorators
Slim-Http is a set of decorators for any PSR-7 implementation that we recommend is used with Slim Framework. To install the Slim-Http library simply run the following command:
composer require slim/http
The ServerRequest
and Response
object decorators are automatically detected and applied by the internal factories. If you have installed Slim-Http and wish to turn off automatic object decoration then you can use the following statements:
<?php use Slim\Factory\AppFactory; use Slim\Factory\ServerRequestCreatorFactory; AppFactory::setSlimHttpDecoratorsAutomaticDetection(false); ServerRequestCreatorFactory::setSlimHttpDecoratorsAutomaticDetection(false); $app = AppFactory::create(); // ...
Hello World using AppFactory with PSR-7 auto-detection
In order for auto-detection to work and enable you to use AppFactory::create()
and App::run()
without having to manually create a ServerRequest
you need to install one of the following implementations:
- Slim-Psr7 - Install using
composer require slim/psr7
- httpsoft/http-message & httpsoft/http-server-request - Install using:
composer require httpsoft/http-message httpsoft/http-server-request
- Nyholm/psr7 & Nyholm/psr7-server - Install using
composer require nyholm/psr7 nyholm/psr7-server
- Guzzle/psr7 - Install using
composer require guzzlehttp/psr7
- laminas-diactoros - Install using
composer require laminas/laminas-diactoros
Then create file public/index.php.
<?php use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Factory\AppFactory; require __DIR__ . '/../vendor/autoload.php'; // Instantiate App $app = AppFactory::create(); // Add error middleware $app->addErrorMiddleware(true, true, true); // Add routes $app->get('/', function (Request $request, Response $response) { $response->getBody()->write('<a href="/hello/world">Try /hello/world</a>'); return $response; }); $app->get('/hello/{name}', function (Request $request, Response $response, $args) { $name = $args['name']; $response->getBody()->write("Hello, $name"); return $response; }); $app->run();
You may quickly test this using the built-in PHP server:
$ php -S localhost:8000 -t public
Going to http://localhost:8000/hello/world will now display "Hello, world".
For more information on how to configure your web server, see the Documentation.
Tests
To execute the test suite, you'll need to install all development dependencies.
$ git clone https://github.com/slimphp/Slim
$ composer install
$ composer test
Contributing
Please see CONTRIBUTING for details.
Learn More
Learn more at these links:
Security
If you discover security related issues, please email security@slimframework.com instead of using the issue tracker.
For enterprise
Available as part of the Tidelift Subscription.
The maintainers of Slim
and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.
Contributors
Code Contributors
This project exists thanks to all the people who contribute. Contribute.
Financial Contributors
Become a financial contributor and help us sustain our community. Contribute
Individuals
Organizations
Support this project with your organization. Your logo will show up here with a link to your website. Contribute
License
The Slim Framework is licensed under the MIT license. See License File for more information.