upgraded dependencies
This commit is contained in:
184
vendor/sebastian/exporter/src/Exporter.php
vendored
184
vendor/sebastian/exporter/src/Exporter.php
vendored
@@ -1,6 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of exporter package.
|
||||
* This file is part of sebastian/exporter.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
@@ -9,7 +9,32 @@
|
||||
*/
|
||||
namespace SebastianBergmann\Exporter;
|
||||
|
||||
use function bin2hex;
|
||||
use function count;
|
||||
use function function_exists;
|
||||
use function get_class;
|
||||
use function get_resource_type;
|
||||
use function gettype;
|
||||
use function implode;
|
||||
use function ini_get;
|
||||
use function ini_set;
|
||||
use function is_array;
|
||||
use function is_float;
|
||||
use function is_object;
|
||||
use function is_resource;
|
||||
use function is_string;
|
||||
use function mb_strlen;
|
||||
use function mb_substr;
|
||||
use function preg_match;
|
||||
use function spl_object_hash;
|
||||
use function sprintf;
|
||||
use function str_repeat;
|
||||
use function str_replace;
|
||||
use function strlen;
|
||||
use function substr;
|
||||
use function var_export;
|
||||
use SebastianBergmann\RecursionContext\Context;
|
||||
use SplObjectStorage;
|
||||
|
||||
/**
|
||||
* A nifty utility for visualizing PHP variables.
|
||||
@@ -25,7 +50,7 @@ use SebastianBergmann\RecursionContext\Context;
|
||||
class Exporter
|
||||
{
|
||||
/**
|
||||
* Exports a value as a string
|
||||
* Exports a value as a string.
|
||||
*
|
||||
* The output of this method is similar to the output of print_r(), but
|
||||
* improved in various aspects:
|
||||
@@ -65,11 +90,11 @@ class Exporter
|
||||
$context->add($data);
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
if (\is_array($value)) {
|
||||
if (is_array($value)) {
|
||||
if ($context->contains($data[$key]) !== false) {
|
||||
$result[] = '*RECURSION*';
|
||||
} else {
|
||||
$result[] = \sprintf(
|
||||
$result[] = sprintf(
|
||||
'array(%s)',
|
||||
$this->shortenedRecursiveExport($data[$key], $context)
|
||||
);
|
||||
@@ -79,11 +104,11 @@ class Exporter
|
||||
}
|
||||
}
|
||||
|
||||
return \implode(', ', $result);
|
||||
return implode(', ', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports a value into a single-line string
|
||||
* Exports a value into a single-line string.
|
||||
*
|
||||
* The output of this method is similar to the output of
|
||||
* SebastianBergmann\Exporter\Exporter::export().
|
||||
@@ -97,34 +122,34 @@ class Exporter
|
||||
*/
|
||||
public function shortenedExport($value)
|
||||
{
|
||||
if (\is_string($value)) {
|
||||
$string = \str_replace("\n", '', $this->export($value));
|
||||
if (is_string($value)) {
|
||||
$string = str_replace("\n", '', $this->export($value));
|
||||
|
||||
if (\function_exists('mb_strlen')) {
|
||||
if (\mb_strlen($string) > 40) {
|
||||
$string = \mb_substr($string, 0, 30) . '...' . \mb_substr($string, -7);
|
||||
if (function_exists('mb_strlen')) {
|
||||
if (mb_strlen($string) > 40) {
|
||||
$string = mb_substr($string, 0, 30) . '...' . mb_substr($string, -7);
|
||||
}
|
||||
} else {
|
||||
if (\strlen($string) > 40) {
|
||||
$string = \substr($string, 0, 30) . '...' . \substr($string, -7);
|
||||
if (strlen($string) > 40) {
|
||||
$string = substr($string, 0, 30) . '...' . substr($string, -7);
|
||||
}
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
if (\is_object($value)) {
|
||||
return \sprintf(
|
||||
if (is_object($value)) {
|
||||
return sprintf(
|
||||
'%s Object (%s)',
|
||||
\get_class($value),
|
||||
\count($this->toArray($value)) > 0 ? '...' : ''
|
||||
get_class($value),
|
||||
count($this->toArray($value)) > 0 ? '...' : ''
|
||||
);
|
||||
}
|
||||
|
||||
if (\is_array($value)) {
|
||||
return \sprintf(
|
||||
if (is_array($value)) {
|
||||
return sprintf(
|
||||
'Array (%s)',
|
||||
\count($value) > 0 ? '...' : ''
|
||||
count($value) > 0 ? '...' : ''
|
||||
);
|
||||
}
|
||||
|
||||
@@ -139,7 +164,7 @@ class Exporter
|
||||
*/
|
||||
public function toArray($value)
|
||||
{
|
||||
if (!\is_object($value)) {
|
||||
if (!is_object($value)) {
|
||||
return (array) $value;
|
||||
}
|
||||
|
||||
@@ -157,7 +182,7 @@ class Exporter
|
||||
// private $property => "\0Classname\0property"
|
||||
// protected $property => "\0*\0property"
|
||||
// public $property => "property"
|
||||
if (\preg_match('/^\0.+\0(.+)$/', (string) $key, $matches)) {
|
||||
if (preg_match('/^\0.+\0(.+)$/', (string) $key, $matches)) {
|
||||
$key = $matches[1];
|
||||
}
|
||||
|
||||
@@ -172,9 +197,9 @@ class Exporter
|
||||
// Some internal classes like SplObjectStorage don't work with the
|
||||
// above (fast) mechanism nor with reflection in Zend.
|
||||
// Format the output similarly to print_r() in this case
|
||||
if ($value instanceof \SplObjectStorage) {
|
||||
if ($value instanceof SplObjectStorage) {
|
||||
foreach ($value as $key => $val) {
|
||||
$array[\spl_object_hash($val)] = [
|
||||
$array[spl_object_hash($val)] = [
|
||||
'obj' => $val,
|
||||
'inf' => $value->getInfo(),
|
||||
];
|
||||
@@ -185,7 +210,7 @@ class Exporter
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive implementation of export
|
||||
* Recursive implementation of export.
|
||||
*
|
||||
* @param mixed $value The value to export
|
||||
* @param int $indentation The indentation level of the 2nd+ line
|
||||
@@ -209,10 +234,10 @@ class Exporter
|
||||
return 'false';
|
||||
}
|
||||
|
||||
if (\is_float($value)) {
|
||||
$precisionBackup = \ini_get('precision');
|
||||
if (is_float($value)) {
|
||||
$precisionBackup = ini_get('precision');
|
||||
|
||||
\ini_set('precision', '-1');
|
||||
ini_set('precision', '-1');
|
||||
|
||||
try {
|
||||
$valueStr = (string) $value;
|
||||
@@ -223,33 +248,33 @@ class Exporter
|
||||
|
||||
return $valueStr;
|
||||
} finally {
|
||||
\ini_set('precision', $precisionBackup);
|
||||
ini_set('precision', $precisionBackup);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->isClosedResource($value)) {
|
||||
if (gettype($value) === 'resource (closed)') {
|
||||
return 'resource (closed)';
|
||||
}
|
||||
|
||||
if (\is_resource($value)) {
|
||||
return \sprintf(
|
||||
if (is_resource($value)) {
|
||||
return sprintf(
|
||||
'resource(%d) of type (%s)',
|
||||
$value,
|
||||
\get_resource_type($value)
|
||||
get_resource_type($value)
|
||||
);
|
||||
}
|
||||
|
||||
if (\is_string($value)) {
|
||||
if (is_string($value)) {
|
||||
// Match for most non printable chars somewhat taking multibyte chars into account
|
||||
if (\preg_match('/[^\x09-\x0d\x1b\x20-\xff]/', $value)) {
|
||||
return 'Binary String: 0x' . \bin2hex($value);
|
||||
if (preg_match('/[^\x09-\x0d\x1b\x20-\xff]/', $value)) {
|
||||
return 'Binary String: 0x' . bin2hex($value);
|
||||
}
|
||||
|
||||
return "'" .
|
||||
\str_replace(
|
||||
str_replace(
|
||||
'<lf>',
|
||||
"\n",
|
||||
\str_replace(
|
||||
str_replace(
|
||||
["\r\n", "\n\r", "\r", "\n"],
|
||||
['\r\n<lf>', '\n\r<lf>', '\r<lf>', '\n<lf>'],
|
||||
$value
|
||||
@@ -258,13 +283,13 @@ class Exporter
|
||||
"'";
|
||||
}
|
||||
|
||||
$whitespace = \str_repeat(' ', (int)(4 * $indentation));
|
||||
$whitespace = str_repeat(' ', 4 * $indentation);
|
||||
|
||||
if (!$processed) {
|
||||
$processed = new Context;
|
||||
}
|
||||
|
||||
if (\is_array($value)) {
|
||||
if (is_array($value)) {
|
||||
if (($key = $processed->contains($value)) !== false) {
|
||||
return 'Array &' . $key;
|
||||
}
|
||||
@@ -273,9 +298,9 @@ class Exporter
|
||||
$key = $processed->add($value);
|
||||
$values = '';
|
||||
|
||||
if (\count($array) > 0) {
|
||||
if (count($array) > 0) {
|
||||
foreach ($array as $k => $v) {
|
||||
$values .= \sprintf(
|
||||
$values .= sprintf(
|
||||
'%s %s => %s' . "\n",
|
||||
$whitespace,
|
||||
$this->recursiveExport($k, $indentation),
|
||||
@@ -286,23 +311,23 @@ class Exporter
|
||||
$values = "\n" . $values . $whitespace;
|
||||
}
|
||||
|
||||
return \sprintf('Array &%s (%s)', $key, $values);
|
||||
return sprintf('Array &%s (%s)', $key, $values);
|
||||
}
|
||||
|
||||
if (\is_object($value)) {
|
||||
$class = \get_class($value);
|
||||
if (is_object($value)) {
|
||||
$class = get_class($value);
|
||||
|
||||
if ($hash = $processed->contains($value)) {
|
||||
return \sprintf('%s Object &%s', $class, $hash);
|
||||
return sprintf('%s Object &%s', $class, $hash);
|
||||
}
|
||||
|
||||
$hash = $processed->add($value);
|
||||
$values = '';
|
||||
$array = $this->toArray($value);
|
||||
|
||||
if (\count($array) > 0) {
|
||||
if (count($array) > 0) {
|
||||
foreach ($array as $k => $v) {
|
||||
$values .= \sprintf(
|
||||
$values .= sprintf(
|
||||
'%s %s => %s' . "\n",
|
||||
$whitespace,
|
||||
$this->recursiveExport($k, $indentation),
|
||||
@@ -313,68 +338,9 @@ class Exporter
|
||||
$values = "\n" . $values . $whitespace;
|
||||
}
|
||||
|
||||
return \sprintf('%s Object &%s (%s)', $class, $hash, $values);
|
||||
return sprintf('%s Object &%s (%s)', $class, $hash, $values);
|
||||
}
|
||||
|
||||
return \var_export($value, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a variable represents a resource, either open or closed.
|
||||
*
|
||||
* @param mixed $actual The variable to test.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isResource($value)
|
||||
{
|
||||
return $value !== null
|
||||
&& \is_scalar($value) === false
|
||||
&& \is_array($value) === false
|
||||
&& \is_object($value) === false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a variable represents a closed resource.
|
||||
*
|
||||
* @param mixed $actual The variable to test.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isClosedResource($value)
|
||||
{
|
||||
/*
|
||||
* PHP 7.2 introduced "resource (closed)".
|
||||
*/
|
||||
if (\gettype($value) === 'resource (closed)') {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* If gettype did not work, attempt to determine whether this is
|
||||
* a closed resource in another way.
|
||||
*/
|
||||
$isResource = \is_resource($value);
|
||||
$isNotNonResource = $this->isResource($value);
|
||||
|
||||
if ($isResource === false && $isNotNonResource === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($isNotNonResource === true) {
|
||||
try {
|
||||
$resourceType = @\get_resource_type($value);
|
||||
|
||||
if ($resourceType === 'Unknown') {
|
||||
return true;
|
||||
}
|
||||
} catch (TypeError $e) {
|
||||
// Ignore. Not a resource.
|
||||
} catch (Exception $e) {
|
||||
// Ignore. Not a resource.
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return var_export($value, true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user