PHP code example of kingbes / attribute

1. Go to this page and download the library: Download kingbes/attribute 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/ */

    

kingbes / attribute example snippets


use Kingbes\Attribute\Annotation;

#[Annotation([
    "title" => "首页控制器",
])]
class IndexController
{
    #[Annotation([
        "title"   => "首页",
        "path"    => ["/index", "/", "/home"],
        "request" => ["get", "post"],
        "auth"    => true,
    ])]
    public function index(Request $request)
    {
        return json(['code' => 0, 'msg' => 'ok']);
    }
}

#[Annotation([
    "name" => "other.hello",
])]
public function sayHello()
{
    // 模板中可用 {:route("other.hello")} 生成该方法的 URL
}

#[Annotation(["path" => ["/a"]])]
#[Annotation(["path" => ["/b"]])]
public function index()
{
    // 同时注册 /a 与 /b 两个路由
}

use Kingbes\Attribute\Data;

Data::$data  // 按 app / plugin 层级分组的全部注解
shell
php webman route:list
shell
php windows.php