mossengine/poignant

PHP Class to provide quick validation building and execution logic based on validation results.

2.1.0 2019-10-03 14:33 UTC

This package is auto-updated.

Last update: 2024-10-29 05:28:32 UTC


README

Latest Stable Version Latest Unstable Version License composer.lock

Build Status codecov

Total Downloads Monthly Downloads Daily Downloads

PHP Class to provide quick validation building and execution logic based on validation results.

Functions

__constructor()

<?php
// Currently no constructor but one will be here soon to support limits and settings.

Installation

With Composer

$ composer require mossengine/poignant
{
    "require": {
        "mossengine/poignant": "^1.0.0"
    }
}
<?php
// Require the autoloader, normal composer stuff
require 'vendor/autoload.php';

// Instantiate a FiveCode class
$classPoignant = new Mossengine\Poignant\Poignant;

// Execute an array of JCode directly into the class
$classPoignant = Mossengine\Poignant\Poignant::create()
    ->withName(function($condition) {
        return $condition->required();
    });

Without Composer

Why are you not using composer? Download Jcode.php from the repo and save the file into your project path somewhere. This project does not support composerless environments.

Build and Validate

<?php
$results = null;

$arrayData = [
    'name' => 'Tom'
];

$classPoignant = Mossengine\Poignant\Poignant::create()
    ->withName(function($condition) {
        return $condition->required();
    })
    ->onFail($arrayData, function($mixedResults) use (&$results) {
        $results = $mixedResults;
        return 'fail';
    })
    ->onPass($arrayData, function($mixedResults) use (&$results) {
        $results = $mixedResults;
        return 'pass';
    });

echo json_encode($classPoignant->getResults());
// {"valid":"pass","invalid":null}