1. Go to this page and download the library: Download weskiller/hyperf-middleware 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/ */
use App\Controller\DeveloperController;
use App\Middleware\CommonMiddleware;
use App\Middleware\NeedParametersMiddleware;
use App\Middleware\NeedTwoParameterMiddleware;
use Hyperf\HttpServer\Router\Router;
use Weskiller\HyperfMiddleware\Middleware\Middleware;
use Weskiller\HyperfMiddleware\Middleware\Direct;
use Weskiller\HyperfMiddleware\Middleware\Exclude;
use Weskiller\HyperfMiddleware\Middleware\Expect;
Router::get(
'/debug',
[DeveloperController::class,'index'],
[
'middleware' => [
CommonMiddleware::class, //default
[NeedParametersMiddleware::class,'parameters'], //with parameters
new Middleware(NeedTwoParameterMiddleware::class,'parameter1','parameter2'), //use instance
],
Exclude::Option => [
CommonMiddleware::class //exclude
],
Expect::Option => [
NeedParametersMiddleware::class //expect
],
Direct::Option => ture //skip all middlewares
],
);
namespace App\Controller;
use App\Middleware\CommonMiddleware;
use App\Middleware\NeedParametersMiddleware;
use App\Middleware\NeedTwoParameterMiddleware;
use Hyperf\HttpServer\Annotation\Controller;
use Weskiller\HyperfMiddleware\Middleware\Middleware;
use Weskiller\HyperfMiddleware\Middleware\Direct;
use Weskiller\HyperfMiddleware\Middleware\Exclude;
use Weskiller\HyperfMiddleware\Middleware\Expect;
#[Controller(prefix='developer')]
class DeveloperController
{
#[RequestMapping(method:["GET"],value: 'debug')]
#[Middleware(CommonMiddleware::class)] //default
#[ParameterMiddleware(NeedParametersMiddleware::class,"parameter")] //with parameters
#[ParameterMiddleware(NeedTwoParameterMiddleware::class,"parameter")] //multiple middleware
#[Exclude([NeedTwoParameterMiddleware::class])] //exclude
#[Expect([NeedParametersMiddleware::class])] //expect
#[Direct] //skip all middlewares
public function index(ServerRequestInterface $request)
{
$user = $request->input('user', 'Hyperf');
$method = $request->getMethod();
return [
'method' => $method,
'message' => "Hello {$user}.",
];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.