JCode
, (*1)
, (*2)
, (*3)
PHP Class to enable JSON driven programmatic instructions to execute controlled php code in the backend., (*4)
Functions
__constructor()
<?php
// Currently no constructor but one will be here soon to support limits and settings.
Installation
With Composer
$ composer require mossengine/swagabase
{
"require": {
"mossengine/jcode": "~1.0.0"
}
}
<?php
// Require the autoloader, normal composer stuff
require 'vendor/autoload.php';
// Instantiate a Jcode class
$classJCode = new Mossengine\JCode\JCode;
// Execute an array of JCode directly into the class
$classJCode->execute([
'variables' => [
'boolResult' => false
],
'instructions' => [
[
'type' => 'variables',
'variables' => [
[
'variable' => 'boolResult',
'type' => 'value',
'value' => true
]
]
]
]
]);
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., (*5)
String JSON
Instead of PHP Associative Array you can also just send in JSON stringify structure and to save you the time we decode it for you., (*6)
$classJCode->executeJson('{"variables":{"boolResult":false},"instructions":[{"type":"variables","variables":[{"variable":"boolResult","type":"value","value":true}]}]}');
Getting back the results
Simply call on the variable function and define a variable key to get a specific key value back or no defined key and you will get all the variables back, (*7)
$mixedValue = $classJCode->variable('boolResult');
$arrayVariables = $classJCode->variable();
Modify variables
You can also modify variable values or define new variables by using the exact same variable function but provide a second parameter for the value you wish to assign to the variable name, (*8)
$classJCode->variable('boolResult', false);
$classJCode->variable('stringNewVariable', 'Hello Wolrd is cliché!');
$classJCode->variable(null, [
'new' => 'array'
]);