PHP code example of next / simple

1. Go to this page and download the library: Download next/simple library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

next / simple example snippets


php bin/cli.php serve:swoole     // swoole异步模式
php bin/cli.php serve:swoole-co  // swoole协程模式
php bin/cli.php serve:workerman  // workerman服务
php bin/cli.php serve:cli-server // 内置服务



namespace App\Controllers;

use App\Http\Response;
use Next\Routing\Attribute\Controller;
use Next\Routing\Attribute\GetMapping;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

#[Controller(prefix: '/')]
class IndexController
{
    #[GetMapping(path: '/')]
    public function index(ServerRequestInterface $request): ResponseInterface
    {
        return Response::HTML('Hello, ' . $request->query('name', 'nextphp!'));
    }
}


$router->middleware(TestMiddleware::class)->group(function(Router $router) {
    $router->get('/', [IndexController::class, 'index']);
    $router->get('/test', function(\Psr\Http\Message\ServerRequestInterface $request) {
        return \App\Http\Response::HTML('new');
    });
});

PHP  ^8.2