fleshgrinder/constraint-violations

This package is abandoned and no longer maintained. No replacement package was suggested.

This library provides an implementation of the Notification Pattern with additional functionality to keep code DRY and to be more useful in the context of Domain-Driven Design (DDD) and its value objects.

0.1.0 2016-04-03 19:29 UTC

This package is not auto-updated.

Last update: 2020-01-24 16:07:58 UTC


README

Build Status Code Climate Test Coverage Packagist Packagist License VersionEye

PHP Constraint Violations

This library provides an implementation of the Notification Pattern with additional functionality to keep code DRY and to be more useful in the context of Domain-Driven Design (DDD) and its value objects.

Installation

Open a terminal, enter your project directory and execute the following command to add this package to your dependencies:

$ composer require fleshgrinder/constraint-violations

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Usage

Most basic usage is as illustrated in the following example:

$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 ...

Please have a look at the wiki for more examples.

Weblinks

License

MIT License