PHP code example of hyperf / validation

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

    

hyperf / validation example snippets



return [
    'locale' => 'zh_CN',
    'fallback_locale' => 'en',
    'path' => BASE_PATH . '/storage/languages',
];


return [
    'handler' => [
        'http' => [
            \Hyperf\Validation\ValidationExceptionHandler::class,
        ],
    ],
];


return [
    'http' => [
        \Hyperf\Validation\Middleware\ValidationMiddleware::class,
    ],
];

class IndexController
{
    public function foo(FooRequest $request)
    {
        $request->input('foo');
    }
    
    public function bar(RequestInterface $request)
    {
        $factory = $this->container->get(\Hyperf\Validation\Contract\ValidatorFactoryInterface::class);

        $factory->extend('foo', function ($attribute, $value, $parameters, $validator) {
            return $value == 'foo';
        });

        $factory->replacer('foo', function ($message, $attribute, $rule, $parameters) {
            return str_replace(':foo', $attribute, $message);
        });

        $validator = $factory->make(
            $request->all(),
            [
                'name' => '

# 发布国际化配置,已经发布过国际化配置可以省略
php bin/hyperf.php vendor:publish hyperf/translation

php bin/hyperf.php vendor:publish hyperf/validation

your/config/path/autoload/translation.php

php bin/hyperf.php gen:request FooRequest