Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: symfony/var-dumper
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.3.14
Choose a base ref
...
head repository: symfony/var-dumper
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.4.0
Choose a head ref

Commits on May 19, 2021

  1. Allow Symfony 6

    derrabus committed May 19, 2021
    Copy the full SHA
    abeb5b2 View commit details

Commits on May 21, 2021

  1. Merge branch '5.3' into 5.4

    * 5.3:
      [Ldap] Avoid calling the deprecated getUsername()
      Report the correct package in the deprecation message
      Wrapping exception js in Sfjs check and also loading base_js Sfjs if needed
      Fix PHP 8.1 deprecations
      Add missing deprecation entry
      [VarDumper] Don't pass null to parse_url()
      Invalid copy-paste fix
    derrabus committed May 21, 2021
    Copy the full SHA
    1fdfc99 View commit details

Commits on May 26, 2021

  1. Merge branch '5.3' into 5.4

    * 5.3:
      Fix CS in README files
      Fix markdown
      [HttpKernel] Fixes tests for PHP7.4+
      [Filesystem] fix readlink for Windows
    nicolas-grekas committed May 26, 2021
    Copy the full SHA
    5bbd4e9 View commit details

Commits on May 27, 2021

  1. Merge branch '5.3' into 5.4

    * 5.3:
      [VarDumper] fix tests
      [Intl] fix bad merge
      Remove notice about reverted behavior
      [PhpUnitBridge] fix PHP version check
      keep container.service_subscriber tag on the decorated definition
    nicolas-grekas committed May 27, 2021
    Copy the full SHA
    173cf39 View commit details

Commits on Jun 6, 2021

  1. Merge branch '5.3' into 5.4

    * 5.3:
      Fix incompatible implicit float-to-int conversions
      [Translation] Don't pass null to strtoupper()
      cs fix
      [String] Fix implicit float-to-int casts
      [Asset] Don't pass null to strpos()
      [Messenger] Fix broken mock
      [DependencyInjection] Don't pass null to trim()
      Add return types to JsonSerializable implementations
      Fix Serializable deprecations triggered by token mocks
      Add missing security translations
    derrabus committed Jun 6, 2021
    Copy the full SHA
    381e6d7 View commit details

Commits on Jun 11, 2021

  1. Copy the full SHA
    2e6661f View commit details

Commits on Jun 12, 2021

  1. feature #41540 [VarDumper] Add casters for Symfony UUIDs and ULIDs (f…

    …ancyweb)
    
    This PR was merged into the 5.4 branch.
    
    Discussion
    ----------
    
    [VarDumper] Add casters for Symfony UUIDs and ULIDs
    
    | Q             | A
    | ------------- | ---
    | Branch?       | 5.4
    | Bug fix?      | no
    | New feature?  | yes
    | Deprecations? | no
    | Tickets       | -
    | License       | MIT
    | Doc PR        | -
    
    Before:
    ![Screenshot from 2021-06-04 10-29-30](https://user-images.githubusercontent.com/3658119/120772362-87a07f80-c520-11eb-9430-3bdda6ed164b.png)
    
    After:
    ![Screenshot from 2021-06-11 14-18-48](https://user-images.githubusercontent.com/3658119/121685253-fef58680-cabf-11eb-9c86-add575fee97e.png)
    
    Commits
    -------
    
    0dde2cce14 [VarDumper] Add casters for Symfony UUIDs and ULIDs
    nicolas-grekas committed Jun 12, 2021
    Copy the full SHA
    b6bebc6 View commit details

Commits on Jun 24, 2021

  1. Merge branch '5.3' into 5.4

    * 5.3: (22 commits)
      [DI] fix fixture
      [ErrorHandler] fix handling buffered SilencedErrorContext
      [HttpClient] fix Psr18Client when allow_url_fopen=0
      [DependencyInjection] Add support of PHP enumerations
      [Cache] handle prefixed redis connections when clearing pools
      [Cache] fix eventual consistency when using RedisTagAwareAdapter with a cluster
      [Uid] Prevent double validation in Uuid::fromString() with base32 values
      [Uid] Fix fromString() with low base58 values
      [Validator][Translation] Add ExpressionLanguageSyntax en and fr
      [HttpKernel] [HttpCache] Keep s-maxage=0 from ESI sub-responses
      Avoid broken action URL in text notification mail
      Fix references to CheckRememberMeConditionsListener
      [DependencyInjection] accept service locator definitions with no class
      [Cache] Disable locking on Windows by default
      [DependencyInjection] Fix binding "iterable $foo" when using the PHP-DSL
      [Config] fix tracking default values that reference the parent class
      [DependencyInjection] fix accepted types on FactoryTrait::factory()
      Fix special char used to create cache key
      [Runtime] Fix project dir variable when vendor not in project root
      [VarDumper] Fix tests for PHP 8.1
      ...
    nicolas-grekas committed Jun 24, 2021
    Copy the full SHA
    eb853ec View commit details

Commits on Jun 29, 2021

  1. Copy the full SHA
    2b61222 View commit details

Commits on Jul 3, 2021

  1. Merge branch '5.3' into 5.4

    * 5.3:
      Backport type fixes
      fix annot
      Backport type fixes
      Fix CS
      Avoid triggering the autoloader in Deprecation::isLegacy()
      fix markdown markup
      Backport type fixes
      uzb translation
      [DependencyInjection] Fix doc blocks
      [DependencyInjection] Turn $defaultDeprecationTemplate into a constant
      [GHA] restore phpunit-bridge job
      rethrow caught exception
      [Form] better form doc types to support static analysis
    nicolas-grekas committed Jul 3, 2021
    Copy the full SHA
    2911e70 View commit details
  2. Copy the full SHA
    7249c87 View commit details

Commits on Jul 15, 2021

  1. Merge branch '5.3' into 5.4

    * 5.3:
      [ErrorHandler] fix parsing `@return array<foo>` annotations
      [HttpFoundation] Fix return types of SessionHandler::gc()
      [Cache] Support decorated Dbal drivers in PdoAdapter
      [VarDumper] Support for intersection types
    nicolas-grekas committed Jul 15, 2021
    Copy the full SHA
    308a0bc View commit details

Commits on Jul 18, 2021

  1. Merge branch '5.3' into 5.4

    * 5.3:
      Simplify some code with null coalesce operator
      Don't use deprecated TestLogger class
    derrabus committed Jul 18, 2021
    Copy the full SHA
    e02df6f View commit details

Commits on Jul 21, 2021

  1. Merge branch '5.3' into 5.4

    * 5.3:
      Leverage str_contains/str_starts_with
      Leverage str_ends_with
    nicolas-grekas committed Jul 21, 2021
    Copy the full SHA
    4b98337 View commit details

Commits on Jul 23, 2021

  1. Merge branch '5.3' into 5.4

    * 5.3:
      [Cache] Add missing return type
      [5.2] Add missing `@return` annotations
      [4.4] Add missing `@return` annotations
      Handle lock with long key
      #42227 update phpdoc to recommend createIndex over ensureIndex
    nicolas-grekas committed Jul 23, 2021
    Copy the full SHA
    d823bfe View commit details

Commits on Jul 29, 2021

  1. Merge branch '5.3' into 5.4

    * 5.3:
      Remove polyfills from Yaml and Dotenv
      HtmlDumper - setDumpHeader accepts null
    fabpot committed Jul 29, 2021
    Copy the full SHA
    22cb67c View commit details

Commits on Aug 4, 2021

  1. Merge branch '5.3' into 5.4

    * 5.3:
      Fix return types for PHP 8.1
    derrabus committed Aug 4, 2021
    Copy the full SHA
    883c425 View commit details
  2. Merge branch '5.3' into 5.4

    Tobion committed Aug 4, 2021
    Copy the full SHA
    0e3758c View commit details

Commits on Aug 17, 2021

  1. Copy the full SHA
    d2cddff View commit details

Commits on Aug 24, 2021

  1. Copy the full SHA
    2aed8e1 View commit details

Commits on Sep 8, 2021

  1. [VarDumper] Backport type fixes

    Signed-off-by: Alexander M. Turek <me@derrabus.de>
    derrabus committed Sep 8, 2021
    Copy the full SHA
    42a7c86 View commit details

Commits on Sep 24, 2021

  1. Copy the full SHA
    b94c3da View commit details
  2. Merge branch '5.3' into 5.4

    * 5.3:
      [VarDumper] fix dumping typed references from properties
      Update README.md
      [Messenger] [Redis] Allow authentication with user and password
      [FrameworkBundle] Avoid secrets:decrypt-to-local command to fail
      fix missing classes
    nicolas-grekas committed Sep 24, 2021
    Copy the full SHA
    083f2bc View commit details

Commits on Oct 5, 2021

  1. Merge branch '5.3' into 5.4

    * 5.3:
      [VarDumper] Fix handling of "new" in initializers on PHP 8.1
    nicolas-grekas committed Oct 5, 2021
    Copy the full SHA
    9036cb3 View commit details

Commits on Oct 6, 2021

  1. Fix "can not" spelling

    mvorisek authored and nicolas-grekas committed Oct 6, 2021
    Copy the full SHA
    5de6c34 View commit details
  2. minor #43299 Fix "can not" spelling (mvorisek)

    This PR was squashed before being merged into the 5.4 branch.
    
    Discussion
    ----------
    
    Fix "can not" spelling
    
    | Q             | A
    | ------------- | ---
    | Branch?       | 5.4
    | Bug fix?      | no
    | New feature?  | no
    | Deprecations? | no
    | Tickets       |
    | License       | MIT
    | Doc PR        |
    
    Commits
    -------
    
    28a438eed4 Fix "can not" spelling
    nicolas-grekas committed Oct 6, 2021
    Copy the full SHA
    162e626 View commit details
  3. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    930a70c View commit details
  4. 2
    Copy the full SHA
    a60e015 View commit details

Commits on Oct 19, 2021

  1. Merge branch '5.3' into 5.4

    * 5.3: (29 commits)
      fix: Improve FR validators translation
      Add swedish translation for issue #43458
      [HttpClient] fix collecting debug info on destruction of CurlResponse
      Fix CS
      added missing thai translations
      Add missing translations for Chinese (zh_TW)
      [DependencyInjection] fix "url" env var processor
      update translation
      Remove untranslated translation for Afrikaans
      [Validator] Add missing validator polish translation
      [Security,Validator] Added missing Latvian translations #41053
      Add the missing translations for Indonesian (id)
      [Validator] Add missing Lithuanian translation
      [Validator] Add missing Czech translation
      replace "ispravna" with "važeća" in translating "valid HTML/CSS"
      added missing translation for galician
      Add missing translation in Vietnamese
      Add missing translation in Bulgarian
      added missing translations for portuguese [#43450]
      Add missing validator slovak translation
      ...
    derrabus committed Oct 19, 2021
    Copy the full SHA
    5247e8f View commit details

Commits on Oct 23, 2021

  1. Copy the full SHA
    31aae3b View commit details

Commits on Oct 24, 2021

  1. Copy the full SHA
    3d42741 View commit details

Commits on Oct 25, 2021

  1. Merge branch '5.3' into 5.4

    * 5.3:
      move username/password fix to non-deprecated Connection class
      cs fix
      [VarDumper] Fix dumping twig templates found in exceptions
      [Validator] Add translations for CIDR constraint
      [Dotenv] Fix testLoadEnv() to start from a fresh context
      [Validator] Update validators.sr_Cyrl.xlf
      [Validator] Update validators.sr_Latn.xlf
      uzb translation
      Update validators.uz.xlf
      Fix logging of impersonator introduced in 5.3
      [Validator] Fix typos in Latvian translations
      [Messenger] Fix Redis Transport when username is empty
    nicolas-grekas committed Oct 25, 2021
    Copy the full SHA
    4c7ce68 View commit details

Commits on Oct 26, 2021

  1. Copy the full SHA
    40bca15 View commit details
  2. Merge branch '5.3' into 5.4

    * 5.3:
      Use GitHub issue form templates
      Add missing translations for Persian (fa)
      Add the missing translations for Bahasa Indonesia (id)
      Update README.md
      Fix deprecations on PHP 8.2
      [DependencyInjection] Fix autowiring tagged arguments from attributes
      Fix commands when local vault is disabled
      [Lock] Fix incorrect return type in PostgreSqlStore
    derrabus committed Oct 26, 2021
    Copy the full SHA
    8c2dbd6 View commit details
  3. Fix some redundant @return phpdoc

    fancyweb committed Oct 26, 2021
    Copy the full SHA
    d9d1e52 View commit details

Commits on Nov 4, 2021

  1. Merge branch '5.3' into 5.4

    * 5.3:
      Fix tests
      [VarExporter] escape unicode chars involved in directionality
      [Intl] Update the ICU data to 70.1
      Fix typos
      Update validators.ca.xlf
      Add missing Validator translations for Estonian
      Fix `Request::getUserInfo()` return type
      [VarDumper] Make dumping DateInterval instances timezone-independent
      Add missing validators translation in Brazillian Portuguese
      I heard you like some Finnish translations #43432
      fix typo and improve TH translation
      Added missing translations for Thai (th)
      [Messenger] Use `TransportMessageIdStamp` in `InMemoryTransport` allows retrying
    fabpot committed Nov 4, 2021
    Copy the full SHA
    ae57e56 View commit details

Commits on Nov 12, 2021

  1. Merge branch '5.3' into 5.4

    * 5.3:
      Fix tests on PHP 8.1
      [Cache] Fix memory leak
      [DependencyInjection] fix inlining when non-shared services are involved
      [DoctrineBridge] add support for the JSON type
      [PHPUnitBridge] Fix Uncaught ValueError
      [FrameworkBundle] fix registering late resettable services
      [Validator] Missing translations for Greek (el)
      translate for japanese 101,102,103
      [HttpClient] Curl http client has to reinit curl multi handle on reset
      [Validator] Add Swedish translation for issue #43737
    nicolas-grekas committed Nov 12, 2021
    Copy the full SHA
    8dcd0b1 View commit details

Commits on Nov 29, 2021

  1. Merge branch '5.3' into 5.4

    * 5.3:
      [Security] Do not overwrite already stored tokens for REMOTE_USER authentication
      [Validator] Fix validation for single level domains
      Fix redundant type casts
      Increased the reserved memory from 10k to 32k
      [DoctrineBridge] Add DbalLoggerTest to group legacy
      Leverage DBAL's getNativeConnection() method
      Fix idempotency of LocoProvider write method
    nicolas-grekas committed Nov 29, 2021
    Copy the full SHA
    89ab66e View commit details
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
CHANGELOG
=========

5.4
---

* Add ability to style integer and double values independently
* Add casters for Symfony's UUIDs and ULIDs
* Add support for `Fiber`

5.2.0
-----

4 changes: 0 additions & 4 deletions Caster/Caster.php
Original file line number Diff line number Diff line change
@@ -41,8 +41,6 @@ class Caster
* Casts objects to arrays and adds the dynamic property prefix.
*
* @param bool $hasDebugInfo Whether the __debugInfo method exists on $obj or not
*
* @return array The array-cast of the object, with prefixed dynamic properties
*/
public static function castObject(object $obj, string $class, bool $hasDebugInfo = false, string $debugClass = null): array
{
@@ -118,8 +116,6 @@ public static function castObject(object $obj, string $class, bool $hasDebugInfo
* @param int $filter A bit field of Caster::EXCLUDE_* constants specifying which properties to filter out
* @param string[] $listedProperties List of properties to exclude when Caster::EXCLUDE_VERBOSE is set, and to preserve when Caster::EXCLUDE_NOT_IMPORTANT is set
* @param int &$count Set to the number of removed properties
*
* @return array The filtered array
*/
public static function filter(array $a, int $filter, array $listedProperties = [], ?int &$count = 0): array
{
43 changes: 43 additions & 0 deletions Caster/FiberCaster.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\VarDumper\Caster;

use Symfony\Component\VarDumper\Cloner\Stub;

/**
* Casts Fiber related classes to array representation.
*
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*/
final class FiberCaster
{
public static function castFiber(\Fiber $fiber, array $a, Stub $stub, bool $isNested, int $filter = 0)
{
$prefix = Caster::PREFIX_VIRTUAL;

if ($fiber->isTerminated()) {
$status = 'terminated';
} elseif ($fiber->isRunning()) {
$status = 'running';
} elseif ($fiber->isSuspended()) {
$status = 'suspended';
} elseif ($fiber->isStarted()) {
$status = 'started';
} else {
$status = 'not started';
}

$a[$prefix.'status'] = $status;

return $a;
}
}
4 changes: 1 addition & 3 deletions Caster/ResourceCaster.php
Original file line number Diff line number Diff line change
@@ -24,10 +24,8 @@ class ResourceCaster
{
/**
* @param \CurlHandle|resource $h
*
* @return array
*/
public static function castCurl($h, array $a, Stub $stub, bool $isNested)
public static function castCurl($h, array $a, Stub $stub, bool $isNested): array
{
return curl_getinfo($h);
}
28 changes: 28 additions & 0 deletions Caster/SymfonyCaster.php
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@
namespace Symfony\Component\VarDumper\Caster;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Uid\Ulid;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\VarDumper\Cloner\Stub;

/**
@@ -66,4 +68,30 @@ public static function castHttpClientResponse($response, array $a, Stub $stub, b

return $a;
}

public static function castUuid(Uuid $uuid, array $a, Stub $stub, bool $isNested)
{
$a[Caster::PREFIX_VIRTUAL.'toBase58'] = $uuid->toBase58();
$a[Caster::PREFIX_VIRTUAL.'toBase32'] = $uuid->toBase32();

// symfony/uid >= 5.3
if (method_exists($uuid, 'getDateTime')) {
$a[Caster::PREFIX_VIRTUAL.'time'] = $uuid->getDateTime()->format('Y-m-d H:i:s.u \U\T\C');
}

return $a;
}

public static function castUlid(Ulid $ulid, array $a, Stub $stub, bool $isNested)
{
$a[Caster::PREFIX_VIRTUAL.'toBase58'] = $ulid->toBase58();
$a[Caster::PREFIX_VIRTUAL.'toRfc4122'] = $ulid->toRfc4122();

// symfony/uid >= 5.3
if (method_exists($ulid, 'getDateTime')) {
$a[Caster::PREFIX_VIRTUAL.'time'] = $ulid->getDateTime()->format('Y-m-d H:i:s.v \U\T\C');
}

return $a;
}
}
22 changes: 18 additions & 4 deletions Cloner/AbstractCloner.php
Original file line number Diff line number Diff line change
@@ -29,6 +29,8 @@ abstract class AbstractCloner implements ClonerInterface
'Symfony\Component\VarDumper\Caster\ConstStub' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'castStub'],
'Symfony\Component\VarDumper\Caster\EnumStub' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'castEnum'],

'Fiber' => ['Symfony\Component\VarDumper\Caster\FiberCaster', 'castFiber'],

'Closure' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castClosure'],
'Generator' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castGenerator'],
'ReflectionType' => ['Symfony\Component\VarDumper\Caster\ReflectionCaster', 'castType'],
@@ -81,11 +83,15 @@ abstract class AbstractCloner implements ClonerInterface
'Symfony\Bridge\Monolog\Logger' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
'Symfony\Component\DependencyInjection\ContainerInterface' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
'Symfony\Component\EventDispatcher\EventDispatcherInterface' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
'Symfony\Component\HttpClient\AmpHttpClient' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClient'],
'Symfony\Component\HttpClient\CurlHttpClient' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClient'],
'Symfony\Component\HttpClient\NativeHttpClient' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClient'],
'Symfony\Component\HttpClient\Response\AmpResponse' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClientResponse'],
'Symfony\Component\HttpClient\Response\CurlResponse' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClientResponse'],
'Symfony\Component\HttpClient\Response\NativeResponse' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castHttpClientResponse'],
'Symfony\Component\HttpFoundation\Request' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castRequest'],
'Symfony\Component\Uid\Ulid' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castUlid'],
'Symfony\Component\Uid\Uuid' => ['Symfony\Component\VarDumper\Caster\SymfonyCaster', 'castUuid'],
'Symfony\Component\VarDumper\Exception\ThrowingCasterException' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castThrowingCasterException'],
'Symfony\Component\VarDumper\Caster\TraceStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castTraceStub'],
'Symfony\Component\VarDumper\Caster\FrameStub' => ['Symfony\Component\VarDumper\Caster\ExceptionCaster', 'castFrameStub'],
@@ -190,8 +196,16 @@ abstract class AbstractCloner implements ClonerInterface
protected $maxString = -1;
protected $minDepth = 1;

/**
* @var array<string, list<callable>>
*/
private $casters = [];

/**
* @var callable|null
*/
private $prevErrorHandler;

private $classInfo = [];
private $filter = 0;

@@ -256,7 +270,7 @@ public function setMinDepth(int $minDepth)
* @param mixed $var Any PHP variable
* @param int $filter A bit field of Caster::EXCLUDE_* constants
*
* @return Data The cloned variable represented by a Data object
* @return Data
*/
public function cloneVar($var, int $filter = 0)
{
@@ -293,7 +307,7 @@ public function cloneVar($var, int $filter = 0)
*
* @param mixed $var Any PHP variable
*
* @return array The cloned variable represented in an array
* @return array
*/
abstract protected function doClone($var);

@@ -302,7 +316,7 @@ abstract protected function doClone($var);
*
* @param bool $isNested True if the object is nested in the dumped structure
*
* @return array The object casted as array
* @return array
*/
protected function castObject(Stub $stub, bool $isNested)
{
@@ -361,7 +375,7 @@ protected function castObject(Stub $stub, bool $isNested)
*
* @param bool $isNested True if the object is nested in the dumped structure
*
* @return array The resource casted as array
* @return array
*/
protected function castResource(Stub $stub, bool $isNested)
{
2 changes: 1 addition & 1 deletion Cloner/ClonerInterface.php
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ interface ClonerInterface
*
* @param mixed $var Any PHP variable
*
* @return Data The cloned variable represented by a Data object
* @return Data
*/
public function cloneVar($var);
}
8 changes: 5 additions & 3 deletions Cloner/Data.php
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ public function __construct(array $data)
}

/**
* @return string|null The type of the value
* @return string|null
*/
public function getType()
{
@@ -65,9 +65,11 @@ public function getType()
}

/**
* Returns a native representation of the original value.
*
* @param array|bool $recursive Whether values should be resolved recursively or not
*
* @return string|int|float|bool|array|Data[]|null A native representation of the original value
* @return string|int|float|bool|array|Data[]|null
*/
public function getValue($recursive = false)
{
@@ -256,7 +258,7 @@ public function withContext(array $context)
*
* @param string|int $key The key to seek to
*
* @return static|null Null if the key is not set
* @return static|null
*/
public function seek($key)
{
70 changes: 38 additions & 32 deletions Cloner/VarCloner.php
Original file line number Diff line number Diff line change
@@ -27,12 +27,12 @@ protected function doClone($var)
$len = 1; // Length of $queue
$pos = 0; // Number of cloned items past the minimum depth
$refsCounter = 0; // Hard references counter
$queue = [[$var]]; // This breadth-first queue is the return value
$hardRefs = []; // Map of original zval ids to stub objects
$objRefs = []; // Map of original object handles to their stub object counterpart
$objects = []; // Keep a ref to objects to ensure their handle cannot be reused while cloning
$resRefs = []; // Map of original resource handles to their stub object counterpart
$values = []; // Map of stub objects' ids to original values
$queue = [[$var]]; // This breadth-first queue is the return value
$hardRefs = []; // Map of original zval ids to stub objects
$objRefs = []; // Map of original object handles to their stub object counterpart
$objects = []; // Keep a ref to objects to ensure their handle cannot be reused while cloning
$resRefs = []; // Map of original resource handles to their stub object counterpart
$values = []; // Map of stub objects' ids to original values
$maxItems = $this->maxItems;
$maxString = $this->maxString;
$minDepth = $this->minDepth;
@@ -100,7 +100,7 @@ protected function doClone($var)
$values[$h] = $v;
}
}
// Create $stub when the original value $v can not be used directly
// Create $stub when the original value $v cannot be used directly
// If $v is a nested structure, put that structure in array $a
switch (true) {
case null === $v:
@@ -139,44 +139,50 @@ protected function doClone($var)
continue 2;
}
$stub = $arrayStub;

if (\PHP_VERSION_ID >= 80100) {
$stub->class = array_is_list($v) ? Stub::ARRAY_INDEXED : Stub::ARRAY_ASSOC;
$a = $v;
break;
}

$stub->class = Stub::ARRAY_INDEXED;

$j = -1;
foreach ($v as $gk => $gv) {
if ($gk !== ++$j) {
$stub->class = Stub::ARRAY_ASSOC;
$a = $v;
$a[$gid] = true;
break;
}
}
$a = $v;

if (Stub::ARRAY_ASSOC === $stub->class) {
// Copies of $GLOBALS have very strange behavior,
// let's detect them with some black magic
if (\PHP_VERSION_ID < 80100 && ($a[$gid] = true) && isset($v[$gid])) {
unset($v[$gid]);
$a = [];
foreach ($v as $gk => &$gv) {
if ($v === $gv && (\PHP_VERSION_ID < 70400 || !isset($hardRefs[\ReflectionReference::fromArrayElement($v, $gk)->getId()]))) {
unset($v);
$v = new Stub();
$v->value = [$v->cut = \count($gv), Stub::TYPE_ARRAY => 0];
$v->handle = -1;
if (\PHP_VERSION_ID >= 70400) {
$gv = &$a[$gk];
$hardRefs[\ReflectionReference::fromArrayElement($a, $gk)->getId()] = &$gv;
} else {
$gv = &$hardRefs[spl_object_id($v)];
}
$gv = $v;
// Copies of $GLOBALS have very strange behavior,
// let's detect them with some black magic
if (isset($v[$gid])) {
unset($v[$gid]);
$a = [];
foreach ($v as $gk => &$gv) {
if ($v === $gv && (\PHP_VERSION_ID < 70400 || !isset($hardRefs[\ReflectionReference::fromArrayElement($v, $gk)->getId()]))) {
unset($v);
$v = new Stub();
$v->value = [$v->cut = \count($gv), Stub::TYPE_ARRAY => 0];
$v->handle = -1;
if (\PHP_VERSION_ID >= 70400) {
$gv = &$a[$gk];
$hardRefs[\ReflectionReference::fromArrayElement($a, $gk)->getId()] = &$gv;
} else {
$gv = &$hardRefs[spl_object_id($v)];
}

$a[$gk] = &$gv;
$gv = $v;
}
unset($gv);
} else {
$a = $v;

$a[$gk] = &$gv;
}
unset($gv);
} else {
$a = $v;
}
break;

11 changes: 1 addition & 10 deletions Command/Descriptor/CliDescriptor.php
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@

namespace Symfony\Component\VarDumper\Command\Descriptor;

use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
@@ -29,12 +28,10 @@ class CliDescriptor implements DumpDescriptorInterface
{
private $dumper;
private $lastIdentifier;
private $supportsHref;

public function __construct(CliDumper $dumper)
{
$this->dumper = $dumper;
$this->supportsHref = method_exists(OutputFormatterStyle::class, 'setHref');
}

public function describe(OutputInterface $output, Data $data, array $context, int $clientId): void
@@ -66,8 +63,7 @@ public function describe(OutputInterface $output, Data $data, array $context, in
if (isset($context['source'])) {
$source = $context['source'];
$sourceInfo = sprintf('%s on line %d', $source['name'], $source['line']);
$fileLink = $source['file_link'] ?? null;
if ($this->supportsHref && $fileLink) {
if ($fileLink = $source['file_link'] ?? null) {
$sourceInfo = sprintf('<href=%s>%s</>', $fileLink, $sourceInfo);
}
$rows[] = ['source', $sourceInfo];
@@ -77,11 +73,6 @@ public function describe(OutputInterface $output, Data $data, array $context, in

$io->table([], $rows);

if (!$this->supportsHref && isset($fileLink)) {
$io->writeln(['<info>Open source in your IDE/browser:</info>', $fileLink]);
$io->newLine();
}

$this->dumper->dump($data);
$io->newLine();
}
18 changes: 15 additions & 3 deletions Command/ServerDumpCommand.php
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@
namespace Symfony\Component\VarDumper\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -55,10 +57,8 @@ public function __construct(DumpServer $server, array $descriptors = [])

protected function configure()
{
$availableFormats = implode(', ', array_keys($this->descriptors));

$this
->addOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format (%s)', $availableFormats), 'cli')
->addOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format (%s)', implode(', ', $this->getAvailableFormats())), 'cli')
->setDescription(self::$defaultDescription)
->setHelp(<<<'EOF'
<info>%command.name%</info> starts a dump server that collects and displays
@@ -99,4 +99,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int

return 0;
}

public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
{
if ($input->mustSuggestOptionValuesFor('format')) {
$suggestions->suggestValues($this->getAvailableFormats());
}
}

private function getAvailableFormats(): array
{
return array_keys($this->descriptors);
}
}
2 changes: 1 addition & 1 deletion Dumper/AbstractDumper.php
Original file line number Diff line number Diff line change
@@ -180,7 +180,7 @@ protected function echoLine(string $line, int $depth, string $indentPad)
/**
* Converts a non-UTF-8 string to UTF-8.
*
* @return string|null The string converted to UTF-8
* @return string|null
*/
protected function utf8Encode(?string $s)
{
13 changes: 11 additions & 2 deletions Dumper/CliDumper.php
Original file line number Diff line number Diff line change
@@ -139,11 +139,20 @@ public function dumpScalar(Cursor $cursor, string $type, $value)

case 'integer':
$style = 'num';

if (isset($this->styles['integer'])) {
$style = 'integer';
}

break;

case 'double':
$style = 'num';

if (isset($this->styles['float'])) {
$style = 'float';
}

switch (true) {
case \INF === $value: $value = 'INF'; break;
case -\INF === $value: $value = '-INF'; break;
@@ -426,7 +435,7 @@ protected function dumpKey(Cursor $cursor)
* @param string $value The value being styled
* @param array $attr Optional context information
*
* @return string The value with style decoration
* @return string
*/
protected function style(string $style, string $value, array $attr = [])
{
@@ -502,7 +511,7 @@ protected function style(string $style, string $value, array $attr = [])
}

/**
* @return bool Tells if the current output stream supports ANSI colors or not
* @return bool
*/
protected function supportsColors()
{
2 changes: 1 addition & 1 deletion Dumper/ContextProvider/ContextProviderInterface.php
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
interface ContextProviderInterface
{
/**
* @return array|null Context data or null if unable to provide any context
* @return array|null
*/
public function getContext(): ?array;
}
7 changes: 7 additions & 0 deletions Resources/functions/dump.php
Original file line number Diff line number Diff line change
@@ -32,8 +32,15 @@ function dump($var, ...$moreVars)
}

if (!function_exists('dd')) {
/**
* @return never
*/
function dd(...$vars)
{
if (!in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && !headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}

foreach ($vars as $v) {
VarDumper::dump($v);
}
4 changes: 4 additions & 0 deletions Server/Connection.php
Original file line number Diff line number Diff line change
@@ -23,6 +23,10 @@ class Connection
{
private $host;
private $contextProviders;

/**
* @var resource|null
*/
private $socket;

/**
6 changes: 5 additions & 1 deletion Server/DumpServer.php
Original file line number Diff line number Diff line change
@@ -25,9 +25,13 @@
class DumpServer
{
private $host;
private $socket;
private $logger;

/**
* @var resource|null
*/
private $socket;

public function __construct(string $host, LoggerInterface $logger = null)
{
if (!str_contains($host, '://')) {
83 changes: 83 additions & 0 deletions Tests/Caster/SymfonyCasterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\VarDumper\Tests\Caster;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Uid\Ulid;
use Symfony\Component\Uid\UuidV4;
use Symfony\Component\Uid\UuidV6;
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;

final class SymfonyCasterTest extends TestCase
{
use VarDumperTestTrait;

public function testCastUuid()
{
$uuid = new UuidV4('83a9db35-3c8c-4040-b3c1-02eccc00b419');
$expectedDump = <<<EODUMP
Symfony\Component\Uid\UuidV4 {
#uid: "83a9db35-3c8c-4040-b3c1-02eccc00b419"
toBase58: "HFzAAuYvev42cCjwqpnKqz"
toBase32: "43N7DKAF4C810B7G82XK601D0S"
}
EODUMP;
$this->assertDumpEquals($expectedDump, $uuid);

$uuid = new UuidV6('1ebc50e9-8a23-6704-ad6f-59afd5cda7e5');
if (method_exists($uuid, 'getDateTime')) {
$expectedDump = <<<EODUMP
Symfony\Component\Uid\UuidV6 {
#uid: "1ebc50e9-8a23-6704-ad6f-59afd5cda7e5"
toBase58: "4o8c5m6v4L8h5teww36JDa"
toBase32: "0YQH8EK2H3CW2ATVTSNZAWV9Z5"
time: "2021-06-04 08:26:44.591386 UTC"
}
EODUMP;
} else {
$expectedDump = <<<EODUMP
Symfony\Component\Uid\UuidV6 {
#uid: "1ebc50e9-8a23-6704-ad6f-59afd5cda7e5"
toBase58: "4o8c5m6v4L8h5teww36JDa"
toBase32: "0YQH8EK2H3CW2ATVTSNZAWV9Z5"
}
EODUMP;
}

$this->assertDumpEquals($expectedDump, $uuid);
}

public function testCastUlid()
{
$ulid = new Ulid('01F7B252SZQGTSQGYSGACASAW6');
if (method_exists($ulid, 'getDateTime')) {
$expectedDump = <<<EODUMP
Symfony\Component\Uid\Ulid {
#uid: "01F7B252SZQGTSQGYSGACASAW6"
toBase58: "1Ba6pJPFWDwghSKFVvfQ1B"
toRfc4122: "0179d622-8b3f-bc35-9bc3-d98298acab86"
time: "2021-06-04 08:27:38.687 UTC"
}
EODUMP;
} else {
$expectedDump = <<<EODUMP
Symfony\Component\Uid\Ulid {
#uid: "01F7B252SZQGTSQGYSGACASAW6"
toBase58: "1Ba6pJPFWDwghSKFVvfQ1B"
toRfc4122: "0179d622-8b3f-bc35-9bc3-d98298acab86"
}
EODUMP;
}

$this->assertDumpEquals($expectedDump, $ulid);
}
}
38 changes: 38 additions & 0 deletions Tests/Command/ServerDumpCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Symfony\Component\VarDumper\Tests\Command;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandCompletionTester;
use Symfony\Component\VarDumper\Command\ServerDumpCommand;
use Symfony\Component\VarDumper\Server\DumpServer;

class ServerDumpCommandTest extends TestCase
{
/**
* @dataProvider provideCompletionSuggestions
*/
public function testComplete(array $input, array $expectedSuggestions)
{
if (!class_exists(CommandCompletionTester::class)) {
$this->markTestSkipped('Test command completion requires symfony/console 5.4+.');
}

$tester = new CommandCompletionTester($this->createCommand());

$this->assertSame($expectedSuggestions, $tester->complete($input));
}

public function provideCompletionSuggestions()
{
yield 'option --format' => [
['--format', ''],
['cli', 'html'],
];
}

private function createCommand(): ServerDumpCommand
{
return new ServerDumpCommand($this->createMock(DumpServer::class));
}
}
6 changes: 6 additions & 0 deletions VarDumper.php
Original file line number Diff line number Diff line change
@@ -32,6 +32,9 @@
*/
class VarDumper
{
/**
* @var callable|null
*/
private static $handler;

public static function dump($var)
@@ -43,6 +46,9 @@ public static function dump($var)
return (self::$handler)($var);
}

/**
* @return callable|null
*/
public static function setHandler(callable $callable = null)
{
$prevHandler = self::$handler;
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -22,8 +22,9 @@
},
"require-dev": {
"ext-iconv": "*",
"symfony/console": "^4.4|^5.0",
"symfony/process": "^4.4|^5.0",
"symfony/console": "^4.4|^5.0|^6.0",
"symfony/process": "^4.4|^5.0|^6.0",
"symfony/uid": "^5.1|^6.0",
"twig/twig": "^2.13|^3.0.4"
},
"conflict": {