PHP code example of fengdangxing / hyperf-validator-quote

1. Go to this page and download the library: Download fengdangxing/hyperf-validator-quote 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/ */

    

fengdangxing / hyperf-validator-quote example snippets


#配置路径 config/annotations.php 没有改文件新建
return [
    'scan' => [
        'paths' => [
            BASE_PATH . '/app',
            BASE_PATH . '/vendor/fengdangxing',//增加该配置
        ],
        'ignore_annotations' => [
            'mixin',
            'Notes',
            'Author',
            'Data',
            'Date'
        ],
    ],
];

namespace App\Validator;

use Fengdangxing\ValidatorQuote\ValidatorQuote;
use Hyperf\Validation\Validator;


class PublishValidator extends ValidatorQuote
{
    protected $scenes = [
        'publish' => ['id', 'mark'],
        'publish_retry' => ['id'],
        'addBatch' => ['merchant_site_id', 'merchant_page_id', 'mark']
    ];

    protected $extendList = ['check_publish'];

    protected $rules = [
        'merchant_site_id' => 'id.check_type_empty' => "1003|merchant_page_id is empty",
        'merchant_site_id.check_publish' => "1004|check_publish"
    ];

    protected $filter = [
        'mark' => 'fliter_sql|fliter_str',
    ];

    public function check_publish($attribute, $value, $parameters, Validator $validator)
    {
        return true;
    }
}



namespace App\Controller;

use Fengdangxing\ValidatorQuote\Annotation\ValidatorQuote;

class IndexController extends AbstractController
{
    /**
     * @VQ(class="\App\Validator\PublishValidator::class",scene="publish")
     */
    public function index()
    {
        $user = $this->request->input('user', 'Hyperf');
        $method = $this->request->getMethod();
        return [
            'method' => $method,
            'message' => "Hello {$user}.",
        ];
    }
}