PHP code example of fleshgrinder / constraint-violations

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

    

fleshgrinder / constraint-violations example snippets


$input = 'some data';
$errors = new ViolationCollector();
$warnings = new ViolationCollector();

if (some_validation($input) === false) {
	$errors->addViolation('some message');
}

if (some_other_validation($input) === false) {
	$warnings->addViolation('some other message');
}

// More validations ...

if ($warnings->hasViolations) {
	echo "WARNINGS\n";
	foreach ($warnings->getMessages() as $message) {
		echo "{$message}\n";
	}
}

if ($errors->hasViolations) {
	echo "ERRORS\n";
	foreach ($warnings->getMessages() as $message) {
		echo "{$message}\n";
	}
	exit(1);
}

// Continue ...