Carion is a simple singleton manager framework.
composer require wallaceosmar/carion-framework
The access of the values can be due to a object value or array access.
require_once './vendor/autoload.php';
$carion->example = 'example';
$carion['example2'] = 'example2';
echo $cation->example;
echo $carion['example2'];
Singleton is used to call some functions or instantiate custom class.
$carion = new Carion\Carion();
$carion->singleton( 'example', function () {
return 'example';
});
echo $carion->example;
The function singleton map the names of the paramter to a singleton register in the class.
$carion = new Carion\Carion();
$carion->set('value', 'example');
$carion->singleton( 'example', function ( $value ) {
return $value;
});
echo $carion->example;
If the does`t have a value to the paramter, will be seted null as the value.
$carion = new Carion\Carion();
$carion->singleton( 'example', function ( $value ) {
if ( 'example' == $value ) {
$value = md5( $value )';
}
return $value;
});
echo $carion->example;
You can call a function or a class method using the function call.
The function call is reponsibly to map all the paramters.
echo $carion->call(function( $value1, $value2 ) {
return $value1 + $value2;
}, array( 10, 20 ));
Parsing a array with key name overwrite the order of values.
echo $carion->call(function( $value1, $value2 ) {
return $value1 + $value2;
}, array( 10, 20, 'value1' => 0 ));