2017 © Pedro Peláez
 

library fission

PHP Object schema builder with validation and access control

image

sackrin/fission

PHP Object schema builder with validation and access control

  • Saturday, April 7, 2018
  • by sackrin
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Fission PHP Object Schema

A simple to use and extendable php object schema library, (*1)

Latest Stable Version License Build Status , (*2)

Add to your project using composer, (*3)

Installation

Via composer:, (*4)

composer require sackrin/fission, (*5)

Example Simple Usage

// Create a new Atom instance
// This will hold the object schema
$atom = Atom::create('person');

// Create some fields to be added to the schema
// These are called nucleus and describe schema properties
$nuclei = [
    Nucleus::create('first_name')
        ->type(Type::string())
        ->label('First Name')
        ->policies([
            Deny::for("*")->scope("*"),
            Allow::for(["administrator","owner"])->scope(["r","w"]),
            Allow::for("user")->scope(["r"])
        ])
        ->sanitizers([
            GUMPSanitizer::using("trim|sanitize_string")
        ])
        ->validators([
            GUMPValidator::against("required|min_len,5")
        ])
];

// Inject the nucleus instances into the atom
// The collective of nucleus is nuclei (just fyi)
$atom->nuclei($nuclei);

// The reactor instance is used to react the atom schema with the nuclei against data
// This is where you will get a hydrated object tree of data
$reactor = Reactor::using($atom)
    ->roles(['user'])
    ->scope(['w','r']);

// Reactors will output a tree of isotopes using the with method
// Isotopes are the hydrated form of a nucleus instance and contain values
// Sanitization, Validation and Policy rules are applied to isotopes
// Press is a util class used to combine and supply data to the reactor instance
// You can just use a standard array if you like
$isotopes = $reactor->with(Press::values([
    'first_name' => ' John '
]));

// Pass the isotope through the validator
$validator = Validator::validate($isotopes);

// Check if the validator has detected any errors
if ($validator->hasErrors()) {
    echo "Oh No, Failed Validation!";
    $errors = $validator->errors();
    var_dump($errors);
} // Otherwise if the validator passed 
else {
    // Using the Values walker you can scrape the data from the isotope tree
    // This will output a simple array tree representing the processed data
    $values = Values::gather($isotopes)->all();
    echo "Everything Validated!";
    $values = Values::gather($isotopes)->all();
    var_dump($values);
}

More Examples

Refer to the examples folder for how to use fission, (*6)

The Versions

07/04 2018

dev-diff-feature

dev-diff-feature

PHP Object schema builder with validation and access control

  Sources   Download

MIT

The Requires

 

The Development Requires

27/03 2018

dev-master

9999999-dev

PHP Object schema builder with validation and access control

  Sources   Download

MIT

The Requires

 

The Development Requires

18/03 2018

dev-conditions

dev-conditions

PHP Object schema builder with validation and access control

  Sources   Download

MIT

The Requires

 

The Development Requires