-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[VarDumper] add a GMP caster in order to cast GMP resources into string or integer #25237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[VarDumper] add a GMP caster in order to cast GMP resources into string or integer #25237
Conversation
75d9636
to
d4c7ce7
Compare
*/ | ||
class GmpCaster | ||
{ | ||
public static function convertToInt(\GMP $value): int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not what a VarDumper caster is.
@@ -29,7 +29,8 @@ | |||
}, | |||
"suggest": { | |||
"ext-iconv": "To convert non-UTF-8 strings to UTF-8 (or symfony/polyfill-iconv in case ext-iconv cannot be used).", | |||
"ext-intl": "To show region name in time zone dump" | |||
"ext-intl": "To show region name in time zone dump", | |||
"ext-gmp": "To dump GMP resources to string or integer" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this does not make any sense: the VarDumper component does not provide any feature needing gmp. It would just improve the dumping when your own code uses gmp. So there is no point suggesting it. It would just be spam in the suggestions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'll remove it
.travis.yml
Outdated
@@ -97,6 +97,7 @@ before_install: | |||
echo extension = redis.so >> $INI | |||
echo extension = memcached.so >> $INI | |||
echo extension = mongodb.so >> $INI | |||
echo extension = gmp.so >> $INI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no gmp.so on Travis. So this is breaking the CI.
gmp is already available on Travis, as it is built as a bundled extension
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'll remove it too
It's clearly a WIP PR. @Simperfit I suggest you either add |
2a4413b
to
dd04bd0
Compare
*/ | ||
class GmpCaster | ||
{ | ||
public static function castInt(\GMP $value): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see other casters: that not their typical signature, we should use the same here also
|
||
public static function castString(\GMP $value): array | ||
{ | ||
return array('value' => gmp_strval($value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means "value" will be displayed as if it were a public property on the object, which is wrong
should be a virtual property (see other casters)
Also: this will display the value as if it were a string, which is also a bad hint. I suggest to use a ConstStub to wrap the value, to that it is displayed in a more specific way. I invite you to compare with/without and decide.
@@ -112,6 +112,8 @@ | |||
'DateTimeZone' => array('Symfony\Component\VarDumper\Caster\DateCaster', 'castTimeZone'), | |||
'DatePeriod' => array('Symfony\Component\VarDumper\Caster\DateCaster', 'castPeriod'), | |||
|
|||
'GMP' => array('Symfony\Component\VarDumper\Caster\GmpCaster', 'castInt'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not all GMP object's values can be represented as strings, so castString should be the implementation
@@ -126,6 +128,9 @@ | |||
':persistent stream' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStream'), | |||
':stream-context' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castStreamContext'), | |||
':xml' => array('Symfony\Component\VarDumper\Caster\XmlResourceCaster', 'castXml'), | |||
':gmp' => array('Symfony\Component\VarDumper\Caster\GmpCaster', 'castInt'), | |||
':gmp int' => array('Symfony\Component\VarDumper\Caster\GmpCaster', 'castInt'), | |||
':gmp string' => array('Symfony\Component\VarDumper\Caster\GmpCaster', 'castString'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GMP as resources cannot happen anymore on PHP 7.1, this should be removed.
return array('value' => gmp_intval($value)); | ||
} | ||
|
||
public static function castString(\GMP $value): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be renamed "castGmp"
{ | ||
public function testCastInt() | ||
{ | ||
if (false === extension_loaded('gmp')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@requires extension gmp
instead
|
||
EOTXT; | ||
|
||
$this->assertStringMatchesFormat($expected, print_r($clone, true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use assertDumpEquals
instead
dd04bd0
to
452a273
Compare
452a273
to
516e25d
Compare
""" | ||
EODUMP; | ||
|
||
$this->assertDumpEquals($expected, print_r($clone, true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is playing around assertDumpEquals
just $this->assertDumpEquals($expected, gmp_init('0101'));
instead
516e25d
to
5f1f345
Compare
/** | ||
* @requires extension gmp | ||
*/ | ||
public function testGmpCast() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but in fact, this should not be in VarClonerTest
the existing test in the caster in enough IMO
/** | ||
* @requires extension gmp | ||
*/ | ||
public function testCastString() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad name
{ | ||
public static function castGmp(\GMP $gmp, array $a, Stub $stub, $isNested, $filter): array | ||
{ | ||
$a[Caster::PREFIX_VIRTUAL.'gmpString'] = (string) new ConstStub(\GMP::class, gmp_strval($gmp)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/gmpString/value/
the what's the prupose of the cast to string? looks wrong to me
should be:
$a[Caster::PREFIX_VIRTUAL.'num'] = new ConstStub(gmp_strval($gmp), gmp_strval($gmp));
use Symfony\Component\VarDumper\Cloner\Stub; | ||
|
||
/** | ||
* Transform a GMP object to a integer or a string. It need the gmp php extension. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Casts GMP objects to array representation.
369e481
to
530d71b
Compare
530d71b
to
4c7a3f7
Compare
4c7a3f7
to
ed2c1af
Compare
Thank you @Simperfit. |
…urces 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:  Commits ------- ed2c1af [VarDumper] add a GMP caster in order to cast GMP resources into string or integer
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:
