PHP code example of gemini / hyperf-router
1. Go to this page and download the library: Download gemini/hyperf-router 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/ */
gemini / hyperf-router example snippets
use Hyperf\HttpServer\Router\Router;
Router::get('/', 'App\Controller\IndexController::index', ['name' => 'index']);
Router::get('/user/{id:\d+}', 'App\Controller\UserController::info', ['name' => 'user.info']);
Router::get('/user', 'App\Controller\UserController::index', ['name' => 'user.list']);
declare(strict_types=1);
namespace App\Controller;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use function Gemini\Router\route;
/**
* @Controller(prefix="/user")
*/
class UserController
{
/**
* @GetMapping(path="info/{id:\d+}", options={"name": "user.info"})
*/
public function info(int $id)
{
return [
'id' => $id,
'next_path' => route('user.info', ['id' => ++$id]),
];
}
}
use function \Gemini\Router\route;
var_dump(route('index'));
var_dump(route('user.info', [1]));
declare(strict_types=1);
namespace App\Controller;
use Gemini\Router\Annotation\WithoutMiddleware;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use function Gemini\Router\route;
use Han\Utils\Middleware\DebugMiddleware;
/**
* @Controller(prefix="/user")
* @WithoutMiddleware(DebugMiddleware::class)
*/
class UserController
{
/**
* @GetMapping(path="info/{id:\d+}", options={"name": "user.info"})
* @WithoutMiddleware({Debug2Middleware::class, Debug3Middleware::class})
*/
public function info(int $id)
{
return [
'id' => $id,
'next_path' => route('user.info', ['id' => ++$id]),
];
}
}