PHP code example of shayvmo / webman-annotations

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

    

shayvmo / webman-annotations example snippets



// config/plugin/shayvmo/webman-annotations/annotation.php
return [
    // 注解扫描路径, 只扫描应用目录下已定义的文件夹,例如: app/admin/controller 及其下级目录
    'include_paths' => [
        'admin'
    ],
    // requestMapping 允许的请求method
    'allow_methods' => ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'HEAD', 'PATCH'],
    // 忽略解析的注解名称,适用于 php7 使用 doctrine/annotations 解析
    'ignored' => [
        "after", "afterClass", "backupGlobals", "backupStaticAttributes", "before", "beforeClass", "codeCoverageIgnore*",
        "covers", "coversDefaultClass", "coversNothing", "dataProvider", "depends", "doesNotPerformAssertions",
        "expectedException", "expectedExceptionCode", "expectedExceptionMessage", "expectedExceptionMessageRegExp", "group",
        "large", "medium", "preserveGlobalState", "



declare (strict_types=1);

namespace App\third\controller;

use Shayvmo\WebmanAnnotations\Annotations\RestController;
use Shayvmo\WebmanAnnotations\Annotations\DeleteMapping;
use Shayvmo\WebmanAnnotations\Annotations\GetMapping;
use Shayvmo\WebmanAnnotations\Annotations\Middleware;
use Shayvmo\WebmanAnnotations\Annotations\PostMapping;
use Shayvmo\WebmanAnnotations\Annotations\PutMapping;
use Shayvmo\WebmanAnnotations\Annotations\RequestMapping;
use Shayvmo\WebmanAnnotations\Annotations\ResourceMapping;

use App\third\middleware\SignatureCheck;

use support\Request;
use Tinywan\LimitTraffic\Middleware\LimitTrafficMiddleware;

/**
 * @RestController("/test")
 * @ResourceMapping("/dddd", allow_methods={"index", "show"})
 * @Middleware(SignatureCheck::class)
 */
class ATest
{
    public function index()
    {
        // 
        return 'Test/index';
    }

    public function show(Request $request, $id)
    {
        return "Test/show $id";
    }

    /**
     * @GetMapping("/test")
     * @Middleware(SignatureCheck::class)
     */
    public function get()
    {
        return 'Test/get';
    }

    /**
     * @RequestMapping(methods={"get", "post"}, path="/test1")
     * @Middleware({
     *     LimitTrafficMiddleware::class,
     * })
     */
    public function test()
    {
        return 'Test/test';
    }

    /**
     * @PostMapping("/post")
     */
    public function post()
    {
        return 'Test/post';
    }

    /**
     * @PutMapping("/put")
     */
    public function put()
    {
        return 'Test/put';
    }

    /**
     * @DeleteMapping("/delete")
     */
    public function delete()
    {
        return 'Test/delete';
    }
}