PHP code example of xu767142206 / x-validated

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

    

xu767142206 / x-validated example snippets


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

use XValidated\Annotation\Rule;
use XValidated\ValidatedData;

class LoginDto extends ValidatedData
{
    #[Rule(values: ["])]
    public string $password;
}

use XValidated\Annotation\Validated;
use App\Model\LoginDto;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Contract\RequestInterface;

#[AutoController]
class IndexController extends AbstractController
{
    #[RequestMapping(path: "index", methods: "get,post")]
    #[Validated]
    public function index(RequestInterface $request, LoginDto $loginDto)
    {
        var_dump($loginDto->toArray());
        return [
            'param' => $request->getServerParams(),
        ];
    }
}