Skip to content

Commit

Permalink
[VarDumper] Add support for Fiber
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrixx committed Oct 23, 2021
1 parent 5247e8f commit 31aae3b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

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

5.2.0
-----
Expand Down
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 <[email protected]>
*
* 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 <[email protected]>
*/
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;
}
}
2 changes: 2 additions & 0 deletions Cloner/AbstractCloner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit 31aae3b

Please sign in to comment.