redgnar/whisky

Internal PHP programming language

1.0.6 2024-03-21 14:06 UTC

This package is auto-updated.

Last update: 2024-05-10 14:45:30 UTC


README

Latest Quality Downloads

The Whisky The library is designed for the safe execution of PHP scripts, with the ability to set input variables and read output variables. The library allows for defining custom functions as well as security rules.

Installation

Use composer to install the whisky library.

composer require redgnar/whisky

Usage

After installation, you can include the whisky library in your PHP scripts using composer auto-load.

require_once 'vendor/autoload.php';

Now, you can use the functionalities provided by the whisky library.

use PhpParser\ParserFactory;
...

$functionRepository = new FunctionRepository();
$builder = new BasicBuilder(
    new PhpParser((new ParserFactory())->create(ParserFactory::ONLY_PHP7)),
    new VariableHandler(),
    new FunctionHandler($functionRepository)
);
$builder->addExtension(new BasicSecurity());
$executor = new BasicExecutor($functionRepository);
$variables = new BasicScope(['collection' => ['a', 'b']]);
$functionRepository->addFunction('testIt', function (string $text) {return $text; });
$script = $builder->build(
            <<<'EOD'
    $result = [];
    foreach ($collection as $item) {
        if ("b" === $item) {
            continue;
        }
        $result[] = testIt($item."aaa4bbb");
    }
EOD
);
$executor->execute($script, $variables);
var_dump($variables->get('result'));

License

This library is released under an open-source license. For more information, please see the LICENSE file in the repository.

Support

For any questions or issues, you may [open an issue](Link to issue page) on our GitHub repository.

Acknowledgements

Thank you to all the contributors who have helped in developing this library.