wegar/validate

Webman plugin wegar/validate

Installs: 10

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/wegar/validate

v1.0.8 2025-04-23 04:00 UTC

This package is auto-updated.

Last update: 2025-10-20 06:52:25 UTC


README

通过注解来限制路由的请求方式,如未设置则自由访问;
如设置 app.force = true 则强制所有路由使用注解才能被访问 如设置 app.throw = false 则响应的的是 404

基本使用

Example

<?php

use Wegar\Validate\Annotation\Method\GET;

class ExampleController {
    /**
     * POST /example/index => Method not allowed or 404
     * GET /example/index => Hello World!
     */
    #[GET]
    function index(){
        return response('Hello World!');        
    }
    /**
     * POST /example/page => Hello Page!
     * GET /example/page => Hello Page!
     * ...
     * 
     * if app.force = true
     * POST /example/page => Method not allowed
     * GET /example/page => Method not allowed
     * ...
     * 
     * if app.force = true and app.throw=false
     * POST /example/page => 404
     * GET /example/page => 404
     * ...
     */
    function page(){
        return response('Hello Page!');
    }
}

输入校验

POST/PUT/PATCH方法body优先级高于query,其他方法query优先级高于body

Example

<?php

use Wegar\Validate\Annotation\Method\GET;

class ExampleController {
    #[GET(
      'field' => 'required:msg->Field is required',
      'field2' => 'max:10',
    )]
    function index(){
        return response('Hello World!');        
    }
}