redgnar / whisky
内部PHP编程语言
1.0.6
2024-03-21 14:06 UTC
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
Whisky库是为了安全执行PHP脚本而设计的,能够设置输入变量并读取输出变量。该库允许定义自定义函数以及安全规则。
安装
使用composer安装whisky库。
composer require redgnar/whisky
使用方法
安装后,您可以使用composer自动加载将whisky库包含在您的PHP脚本中。
require_once 'vendor/autoload.php';
现在,您可以使用whisky库提供的功能。
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文件。
支持
如有任何疑问或问题,您可以在我们的GitHub存储库上[提交问题](问题页面链接)。
致谢
感谢所有帮助开发此库的贡献者。