Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ed2c1af

Browse files
author
Amrouche Hamza
committed
[VarDumper] add a GMP caster in order to cast GMP resources into string or integer
1 parent 424cbcc commit ed2c1af

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarDumper\Caster;
13+
14+
use Symfony\Component\VarDumper\Cloner\Stub;
15+
16+
/**
17+
* Casts GMP objects to array representation.
18+
*
19+
* @author Hamza Amrouche <[email protected]>
20+
* @author Nicolas Grekas <[email protected]>
21+
*/
22+
class GmpCaster
23+
{
24+
public static function castGmp(\GMP $gmp, array $a, Stub $stub, $isNested, $filter): array
25+
{
26+
$a[Caster::PREFIX_VIRTUAL.'value'] = new ConstStub(gmp_strval($gmp), gmp_strval($gmp));
27+
28+
return $a;
29+
}
30+
}

src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ abstract class AbstractCloner implements ClonerInterface
112112
'DateTimeZone' => array('Symfony\Component\VarDumper\Caster\DateCaster', 'castTimeZone'),
113113
'DatePeriod' => array('Symfony\Component\VarDumper\Caster\DateCaster', 'castPeriod'),
114114

115+
'GMP' => array('Symfony\Component\VarDumper\Caster\GmpCaster', 'castGmp'),
116+
115117
':curl' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castCurl'),
116118
':dba' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'),
117119
':dba persistent' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'),
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\VarDumper\Tests\Caster;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\VarDumper\Caster\GmpCaster;
16+
use Symfony\Component\VarDumper\Cloner\Stub;
17+
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
18+
19+
class GmpCasterTest extends TestCase
20+
{
21+
use VarDumperTestTrait;
22+
23+
/**
24+
* @requires extension gmp
25+
*/
26+
public function testCastGmp()
27+
{
28+
$gmpString = gmp_init('1234');
29+
$gmpOctal = gmp_init(010);
30+
$gmp = gmp_init('01101');
31+
$gmpDump = <<<EODUMP
32+
array:1 [
33+
"\\x00~\\x00value" => %s
34+
]
35+
EODUMP;
36+
$this->assertDumpEquals(sprintf($gmpDump, $gmpString), GmpCaster::castGmp($gmpString, array(), new Stub(), false, 0));
37+
$this->assertDumpEquals(sprintf($gmpDump, $gmpOctal), GmpCaster::castGmp($gmpOctal, array(), new Stub(), false, 0));
38+
$this->assertDumpEquals(sprintf($gmpDump, $gmp), GmpCaster::castGmp($gmp, array(), new Stub(), false, 0));
39+
40+
$dump = <<<EODUMP
41+
GMP {
42+
value: 577
43+
}
44+
EODUMP;
45+
46+
$this->assertDumpEquals($dump, $gmp);
47+
}
48+
}

0 commit comments

Comments
 (0)