fas / exportable
Fast and simple var exporter
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
Installation
composer require fas/exportable
Usage
Closures
<?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";
output:
[
'somefunc' => static function () {
return 'test';
}
]
Custom objects
<?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";
output:
[
'somekey' => 'SOMEVALUE'
]