for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/**
* ReportingCloud PHP SDK
*
* PHP SDK for ReportingCloud Web API. Authored and supported by Text Control GmbH.
* @link https://www.reporting.cloud to learn more about ReportingCloud
* @link https://tinyurl.com/vmbbh6kd for the canonical source repository
* @license https://tinyurl.com/3pc9am89
* @copyright © 2023 Text Control GmbH
*/
namespace TextControl\ReportingCloud\Stdlib;
use Riimu\Kit\PHPEncoder\PHPEncoder;
class ArrayUtils extends AbstractStdlib
{
* Write the array of passed data to a file as a PHP structure
public static function varExportToFile(string $filename, array $values, string $generator = ''): int
$options = [
'array.indent' => 4,
'array.align' => true,
'array.omit' => true,
'array.short' => true,
'object.format' => 'export',
'string.utf8' => true,
'whitespace' => true,
];
$encoder = new PHPEncoder($options);
$format = '<?php';
$format .= PHP_EOL;
$format .= 'declare(strict_types=1);';
$format .= PHP_EOL . PHP_EOL;
$format .= '%s';
$format .= 'return ';
$format .= ';';
if ('' === $generator) {
$prefix = '';
} else {
$prefix = sprintf('// File generated by %s.', $generator);
$prefix .= PHP_EOL;
$prefix .= '// Do not edit.';
$prefix .= PHP_EOL . PHP_EOL;
}
$buffer = sprintf($format, $prefix, $encoder->encode($values));
$ret = file_put_contents($filename, $buffer);
if (!is_int($ret)) {
is_int($ret)
true
$ret = 0;
return $ret;