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

Skip to content

Commit 75d9636

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

File tree

4 files changed

+93
-1
lines changed

4 files changed

+93
-1
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ before_install:
9797
echo extension = redis.so >> $INI
9898
echo extension = memcached.so >> $INI
9999
echo extension = mongodb.so >> $INI
100+
echo extension = gmp.so >> $INI
101+
100102
101103
# Matrix lines for intermediate PHP versions are skipped for pull requests
102104
if [[ ! $deps && ! $PHP = $MIN_PHP && $TRAVIS_PULL_REQUEST != false ]]; then
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
/**
15+
* Transform a GMP object to a integer or a string. It need the gmp php extension
16+
*
17+
*
18+
* @author Amrouche Hamza <[email protected]>
19+
*/
20+
class GmpCaster
21+
{
22+
public static function convertToInt(\GMP $value): int
23+
{
24+
return gmp_intval($value);
25+
}
26+
27+
public static function convertToString(\GMP $value): string
28+
{
29+
return gmp_strval($value);
30+
}
31+
32+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: hamza
5+
* Date: 01/12/2017
6+
* Time: 08:24
7+
*/
8+
9+
/*
10+
* This file is part of the ***PROJECT*** project.
11+
*
12+
* (c) hamza <hamza>
13+
*
14+
* For the full copyright and license information, please view the LICENSE
15+
* file that was distributed with this source code.
16+
*/
17+
18+
namespace Symfony\Component\VarDumper\Tests\Caster;
19+
20+
use PHPUnit\Framework\TestCase;
21+
use Symfony\Component\VarDumper\Caster\GmpCaster;
22+
23+
class GmpCasterTest extends TestCase
24+
{
25+
public function testConvertToInt()
26+
{
27+
if (false === extension_loaded('gmp')) {
28+
$this->markTestSkipped('GMP PHP extension should be loaded to run be able to parse GMP resources');
29+
}
30+
31+
$gmpString = gmp_init('1234');
32+
$gmpOctal = gmp_init(010);
33+
$gmp = gmp_init('01101');
34+
35+
$this->assertEquals(1234, GmpCaster::convertToInt($gmpString));
36+
$this->assertEquals(8, GmpCaster::convertToInt($gmpOctal));
37+
$this->assertEquals(577, GmpCaster::convertToInt($gmp));
38+
39+
40+
}
41+
42+
public function testConvertToString()
43+
{
44+
if (false === extension_loaded('gmp')) {
45+
$this->markTestSkipped('GMP PHP extension should be loaded to run be able to parse GMP resources');
46+
}
47+
48+
$gmpString = gmp_init('1234');
49+
$gmpOctal = gmp_init(010);
50+
$gmp = gmp_init('01101');
51+
52+
$this->assertEquals('1234', GmpCaster::convertToString($gmpString));
53+
$this->assertEquals('8', GmpCaster::convertToString($gmpOctal));
54+
$this->assertEquals('577', GmpCaster::convertToString($gmp));
55+
56+
}
57+
}

src/Symfony/Component/VarDumper/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
},
3030
"suggest": {
3131
"ext-iconv": "To convert non-UTF-8 strings to UTF-8 (or symfony/polyfill-iconv in case ext-iconv cannot be used).",
32-
"ext-intl": "To show region name in time zone dump"
32+
"ext-intl": "To show region name in time zone dump",
33+
"ext-gmp": "To dump GMP resources to string or integer"
3334
},
3435
"autoload": {
3536
"files": [ "Resources/functions/dump.php" ],

0 commit comments

Comments
 (0)