fas / exportable
快速简单的变量导出器
0.2.0
2021-07-09 06:41 UTC
Requires
- php: >=7.4.0
- opis/closure: ^3.6
Requires (Dev)
- phpmd/phpmd: ^2.10
- phpunit/phpunit: ^9
- squizlabs/php_codesniffer: ^3.6
README
安装
composer require fas/exportable
用法
闭包
<?php require './vendor/autoload.php'; use Fas\Exportable\Exporter; $exporter = new Exporter(); $data = [ 'somefunc' => static function () { return 'test'; } ]; $output = $exporter->export($data); print "$output\n";
输出
[
'somefunc' => static function () {
return 'test';
}
]
自定义对象
<?php require './vendor/autoload.php'; use Fas\Exportable\ExportableInterface; use Fas\Exportable\Exporter; class UpperCase implements ExportableInterface { private string $str; public function __construct(string $str) { $this->str = $str; } public function exportable(Exporter $exporter, $level = 0): string { return var_export(strtoupper($this->str), true); } } $exporter = new Exporter(); $data = [ 'somekey' => new UpperCase('somevalue'), ]; $output = $exporter->export($data); print "$output\n";
输出
[
'somekey' => 'SOMEVALUE'
]