ntk-andr/multi-exception

dev-master 2017-02-03 11:45 UTC

This package is not auto-updated.

Last update: 2025-06-08 04:55:37 UTC


README

Usage Example

use NtkAndr\MultiException;

function checkPassword($passwd): bool
{
    $errors = new MultiException();
    if (empty($passwd)) {
        $errors->add(new Exception('Empty password'));
    }
    if (strlen($passwd) < 6) {
        $errors->add(new Exception('The password is too short'));
    }
    if (!preg_match('~\d~', $passwd)) {
        $errors->add(new Exception('The password doesn\'t contain numbers'));
    }
    if (!$errors->isEmpty()) {
        throw $errors;
    }
    return true;
}

try {
    checkPassword('');
} catch (MultiException $errors) {
    foreach ($errors as $error) {
        echo $error->getMessage() . "\n";
    }
}