Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #30311 [VarDumper] Implement DsCaster (enumag)
This PR was merged into the 4.3-dev branch. Discussion ---------- [VarDumper] Implement DsCaster | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | When dumping the data structures from [Ds extension](http://php.net/manual/en/book.ds.php) Symfony only shows the class name but not the actual data. So in this PR I tried to write a Caster for these data structures. Map can't be simply casted to array because it can contain objects as keys so I dump the pairs instead. Commits ------- eab631f [VarDumper] Implement DsCaster
- Loading branch information
Showing
3 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?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 Ds\Deque; | ||
use Ds\Map; | ||
use Ds\PriorityQueue; | ||
use Ds\Queue; | ||
use Ds\Set; | ||
use Ds\Stack; | ||
use Ds\Vector; | ||
use Symfony\Component\VarDumper\Cloner\Stub; | ||
|
||
/** | ||
* Casts Ds extension classes to array representation. | ||
* | ||
* @author Jáchym Toušek <enumag@gmail.com> | ||
*/ | ||
class DsCaster | ||
{ | ||
/** | ||
* @param Set|Deque|Vector|Stack|Queue|PriorityQueue $c | ||
*/ | ||
public static function castDs($c, array $a, Stub $stub, bool $isNested): array | ||
{ | ||
$prefix = Caster::PREFIX_VIRTUAL; | ||
$a = $c->toArray(); | ||
$a[$prefix.'capacity'] = $c->capacity(); | ||
|
||
return $a; | ||
} | ||
|
||
public static function castMap(Map $c, array $a, Stub $stub, bool $isNested): array | ||
{ | ||
$prefix = Caster::PREFIX_VIRTUAL; | ||
$a = $c->pairs()->toArray(); | ||
$a[$prefix.'capacity'] = $c->capacity(); | ||
|
||
return $a; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters