PHP code example of aaronmacaron / reaction

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

    

aaronmacaron / reaction example snippets




use Aaronmacaron\Reaction\Reaction;

): Reaction
{
    if (empty($password)) {
        return Reaction::failure("The password must not be empty!");
    }

    if (strlen($password) >= 8) {
        return Reaction::success();
    }

    return Reaction::failure("The password must be at least eight chars long.");
}

validatePassword("secret")
    ->succeed(function () {
        echo "Password is valid" . PHP_EOL;
    })->fail(function (Reaction $reaction) {
        echo "The password is not valid: " . $reaction->getMessage() . PHP_EOL;
    });

// Output: The password is not valid: The password must be at least eight chars long.