redgnar / whisky
Internal PHP programming language
Installs: 2 991
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=8.1
- nikic/php-parser: ^4.10
- psr/log: ^1.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.14
- monolog/monolog: ^2.2.0
- phpstan/phpstan: ^1.10
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
README
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.