10000 feature #25237 [VarDumper] add a GMP caster in order to cast GMP reso… · symfony/symfony@5b360e2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5b360e2

Browse files
committed
feature #25237 [VarDumper] add a GMP caster in order to cast GMP resources into string or integer (Simperfit)
This PR was merged into the 4.1-dev branch. Discussion ---------- [VarDumper] add a GMP caster in order to cast GMP resources into string or integer | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #25222 | License | MIT | Doc PR | todo Do you want to dump that kind of resources ? Then it means that the app you are writing is doing some math... why?! :p It quite nice the little snow that we have in the north of france right now: ![img_2844](https://user-images.githubusercontent.com/3451634/33472917-8b48913e-d674-11e7-923f-ad951f7f2966.JPG) Commits ------- ed2c1af [VarDumper] add a GMP caster in order to cast GMP resources into string or integer
2 parents 2edb7fa + ed2c1af commit 5b360e2

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 <fabien@symfony.com>
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 <hamza.simperfit@gmail.com>
20+
* @author Nicolas Grekas <p@tchwork.com>
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 <fabien@symfony.com>
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)
0