Slim README

The project's README from github.com/slimphp/Slim. As one markdown file: README.md.

Slim Framework

Build Status Coverage Status Total Downloads License

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-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:

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 [email protected] 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.

Slim (slimphp/Slim)

Searching Database…

12.3K ·GitHub
Что это такое?Slim — это микрофреймворк для PHP, который помогает быстро писать простые, но при этом мощные веб-приложения и API.
Это микрофреймворк или фулстек-фреймворк?Микрофреймворк: ядро Slim намеренно минимальное, а весь стек вы собираете сами, начиная с реализации PSR-7 на свой выбор.
Как его установить и запустить первое приложение?Установите Slim через Composer — он подтянет сам Slim и все нужные зависимости. Дальше README проводит вас через hello world в одном файле public/index.php.
Что должно быть установлено до начала работы?PHP 7.4 или новее плюс Composer, а в процессе установки нужно будет выбрать и поставить один пакет — реализацию PSR-7.
Хватит ли встроенного сервера PHP для продакшена?Он рекомендуется только как быстрый способ для тестирования; для реального хостинга README отсылает к документации по настройке веб-сервера.
Под какой лицензией выпускается Slim — есть ли платный вариант для компаний?MIT, так что использовать его в любом проекте можно бесплатно. Компании могут купить коммерческую поддержку и обслуживание по подписке Tidelift Subscription.
Какую реализацию PSR-7 выбрать?Варианты: Slim-Psr7 (собственная реализация команды Slim), httpsoft/http-message (самая быстрая, строгая и лёгкая, по словам из README), Nyholm/psr7 (почти такая же быстрая), Guzzle/psr7 и laminas-diactoros. Любая из них позволяет AppFactory определять её автоматически.
Есть ли в Slim свои объекты запроса и ответа?В комплект не входят — проект рекомендует Slim-Http, набор декораторов, которые оборачивают любую реализацию PSR-7. После установки они определяются и применяются автоматически, причём автоматическое оборачивание можно отключить.
Как выглядит самое маленькое приложение на Slim?Один файл: создайте public/index.php, соберите приложение через AppFactory::create() и вызовите run(). Проверено на встроенном сервере PHP — на странице выводится 'Hello, world'.
What are similar projects?flask, echo, express, martini, guzzle, axum, sinatra, Rocket
Creator
slimphp
Size
7.1 MB
Stars
12.3K
Age
16y
Commits · 90 Days