lundi 31 mai 2021

PHP - Design Pattern to a complex validation

What is the recommended design pattern or methodology to make multiple validations where the parameter can have different structures? Ex:

// Case A:
$toValidate = ["test" => 1]
$toValidate["test"] > 0 // First Validation
$toValidate["test"] === $x // Second Validation

// Case B:
$toValidate = [["test": 1], ["test": 2]]
$toValidate[0]["test"] === 1 && $toValidate[1]["test"] === 2 // First collection item validation...

I've made some tests with the Chain Of Responsibility, but i didn't think fluid for this case. Some alternative?

Aucun commentaire:

Enregistrer un commentaire