PHP code example of proklung / controller-sanitizer-validator

1. Go to this page and download the library: Download proklung/controller-sanitizer-validator 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/ */

    

proklung / controller-sanitizer-validator example snippets


use Prokl\RequestValidatorSanitizer\Sanitizing\SanitizableTrait;

class SimpleController extends AbstractController
{
    use SanitizableTrait;
    
    public function action(Request $request) {
         // Санитизированный Request.
            $requestSanitized = $this->sanitizeRequest(
                $request,
                $this->getSanitizingRules()
            );

    }

   /**
     * Правила санации.
     *
     * @return array
     */
    private function getSanitizingRules(): array
    {
        return [
            'id' => 'trim|escape|strip_tags|cast:string',
            'url' => 'trim|escape|strip_tags|cast:string',
            'name' => 'trim|escape|strip_tags|cast:string',
            'email' => 'trim|escape|strip_tags|cast:string',
            'phone' => 'trim|escape|strip_tags|cast:string'
        ];
    }
}

use Prokl\RequestValidatorSanitizer\Validation\Custom\CustomEmailValidatorNullable;
use Prokl\RequestValidatorSanitizer\Validation\Custom\LaravelPhoneValidator;

class SimpleController extends AbstractController
{
    use ValidateableTrait;

    public function action(Request $request) {
            $this->validateRequest(
                $request,
                $this->getRules()
            );
    }
    /**
     * Правила валидации.
     *
     * @return string[]
     */
    private function getRules() : array
    {
        return [
            'name' => '