PHP code example of harmonyio / validation

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

    

harmonyio / validation example snippets


 declare(strict_types=1);

namespace HarmonyIO\Validation\Examples;

use Amp\Loop;
use HarmonyIO\Validation\Result\Result;
use HarmonyIO\Validation\Rule\Numeric\NumericType;


object(HarmonyIO\Validation\Result\Result)#11 (2) {
  ["valid":"HarmonyIO\Validation\Result\Result":private]=>
  bool(false)
  ["errors":"HarmonyIO\Validation\Result\Result":private]=>
  array(1) {
    [0]=>
    object(HarmonyIO\Validation\Result\Error)#10 (2) {
      ["message":"HarmonyIO\Validation\Result\Error":private]=>
      string(19) "Numeric.NumericType"
      ["parameters":"HarmonyIO\Validation\Result\Error":private]=>
      array(0) {
      }
    }
  }
}

 declare(strict_types=1);

namespace HarmonyIO\Validation\Examples;

use Amp\Loop;
use HarmonyIO\Validation\Result\Result;
use HarmonyIO\Validation\Rule\Combinator\All;
use HarmonyIO\Validation\Rule\Numeric\Maximum;
use HarmonyIO\Validation\Rule\Numeric\Minimum;
use HarmonyIO\Validation\Rule\Numeric\NumericType;


object(HarmonyIO\Validation\Result\Result)#11 (2) {
  ["valid":"HarmonyIO\Validation\Result\Result":private]=>
  bool(false)
  ["errors":"HarmonyIO\Validation\Result\Result":private]=>
  array(1) {
    [0]=>
    object(HarmonyIO\Validation\Result\Error)#26 (2) {
      ["message":"HarmonyIO\Validation\Result\Error":private]=>
      string(15) "Numeric.Maximum"
      ["parameters":"HarmonyIO\Validation\Result\Error":private]=>
      array(1) {
        [0]=>
        object(HarmonyIO\Validation\Result\Parameter)#24 (2) {
          ["key":"HarmonyIO\Validation\Result\Parameter":private]=>
          string(7) "maximum"
          ["value":"HarmonyIO\Validation\Result\Parameter":private]=>
          float(100)
        }
      }
    }
  }
}

 declare(strict_types=1);

namespace HarmonyIO\Validation\Rule;

use Amp\Promise;

interface Rule
{
    /**
     * @param mixed $value
     * @return Promise<HarmonyIO\Validation\Result\Result>
     */
    public function validate($value): Promise;
}

object(HarmonyIO\Validation\Result\Error)#17 (2) {
      ["message":"HarmonyIO\Validation\Result\Error":private]=>
      string(18) "Text.MinimumLength"
      ["parameters":"HarmonyIO\Validation\Result\Error":private]=>
      array(1) {
        [0]=>
        object(HarmonyIO\Validation\Result\Parameter)#15 (2) {
          ["key":"HarmonyIO\Validation\Result\Parameter":private]=>
          string(6) "length"
          ["value":"HarmonyIO\Validation\Result\Parameter":private]=>
          int(4)
        }
      }
    }

 declare(strict_types=1);

namespace HarmonyIO\Validation\Examples;

use HarmonyIO\Validation\Result\Result;
use HarmonyIO\Validation\Rule\Numeric\NumericType;
use function Amp\Promise\wait;