function ExportUtil::recursiveExport
Recursive implementation of export
Parameters
mixed $value The value to export:
int $indentation The indentation level of the 2nd+ line:
\SebastianBergmann\RecursionContext\Context $processed Previously processed objects:
Return value
string
See also
SebastianBergmann\Exporter\Exporter::export
1 call to ExportUtil::recursiveExport()
- ExportUtil::export in vendor/
phpspec/ prophecy/ src/ Prophecy/ Util/ ExportUtil.php - Exports a value as a string
File
-
vendor/
phpspec/ prophecy/ src/ Prophecy/ Util/ ExportUtil.php, line 102
Class
- ExportUtil
- This class is a modification from sebastianbergmann/exporter
Namespace
Prophecy\UtilCode
protected static function recursiveExport(&$value, $indentation, $processed = null) {
if ($value === null) {
return 'null';
}
if ($value === true) {
return 'true';
}
if ($value === false) {
return 'false';
}
if (is_float($value) && floatval(intval($value)) === $value) {
return "{$value}.0";
}
if (is_resource($value)) {
return sprintf('resource(%d) of type (%s)', (int) $value, get_resource_type($value));
}
if (is_string($value)) {
// Match for most non printable chars somewhat taking multibyte chars into account
if (preg_match('/[^\\x09-\\x0d\\x20-\\xff]/', $value)) {
return 'Binary String: 0x' . bin2hex($value);
}
return "'" . str_replace(array(
"\r\n",
"\n\r",
"\r",
), array(
"\n",
"\n",
"\n",
), $value) . "'";
}
$whitespace = str_repeat(' ', 4 * $indentation);
if (!$processed) {
$processed = new Context();
}
if (is_array($value)) {
if (($key = $processed->contains($value)) !== false) {
return 'Array &' . $key;
}
\assert(\is_array($value));
$array = $value;
$key = $processed->add($value);
$values = '';
if (count($array) > 0) {
foreach ($array as $k => $v) {
$values .= sprintf('%s %s => %s' . "\n", $whitespace, self::recursiveExport($k, $indentation), self::recursiveExport($value[$k], $indentation + 1, $processed));
}
$values = "\n" . $values . $whitespace;
}
return sprintf('Array &%s (%s)', $key, $values);
}
if (is_object($value)) {
$class = get_class($value);
if ($processed->contains($value)) {
\assert(\is_object($value));
return sprintf('%s#%d Object', $class, spl_object_id($value));
}
$processed->add($value);
\assert(\is_object($value));
$values = '';
$array = self::toArray($value);
if (count($array) > 0) {
foreach ($array as $k => $v) {
$values .= sprintf('%s %s => %s' . "\n", $whitespace, self::recursiveExport($k, $indentation), self::recursiveExport($v, $indentation + 1, $processed));
}
$values = "\n" . $values . $whitespace;
}
return sprintf('%s#%d Object (%s)', $class, spl_object_id($value), $values);
}
return var_export($value, true);
}