An open API service indexing awesome lists of open source software.

https://github.com/sackrin/fission

Fission aims to provide an easy to understand set of concepts and tools for handling the creation and manipulation of nested array data which can be built into any framework. These tools include object schema building, value sanitization, value validation, value manipulation and, most importantly, role and scope based property access control.
https://github.com/sackrin/fission

Last synced: over 1 year ago
JSON representation

Fission aims to provide an easy to understand set of concepts and tools for handling the creation and manipulation of nested array data which can be built into any framework. These tools include object schema building, value sanitization, value validation, value manipulation and, most importantly, role and scope based property access control.

Awesome Lists containing this project

README

          

# Fission PHP Object Schema

A simple to use and extendable php object schema library


Latest Stable Version
License
Build Status

Add to your project using composer

## Installation

Via composer:

``
composer require sackrin/fission
``

## Example Simple Usage

```php
// 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](examples/) folder for how to use fission