Skip to content

[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

Merged

Conversation

Simperfit
Copy link
Contributor

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

*/
class GmpCaster
{
public static function convertToInt(\GMP $value): int
Copy link
Member

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"
Copy link
Member

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

Copy link
Contributor Author

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
Copy link
Member

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

Copy link
Contributor Author

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

@sroze
Copy link
Contributor

sroze commented Dec 1, 2017

It's clearly a WIP PR. @Simperfit I suggest you either add WIP to your PR title or just not open the PR yet (and enable Travis on your fork if you need the tests to run) :)

@Simperfit Simperfit changed the title [VarDumper] add a GMP caster in order to cast GMP resources into string or integer [VarDumper] [WIP] add a GMP caster in order to cast GMP resources into string or integer Dec 1, 2017
@Simperfit Simperfit force-pushed the feature/add-a-caster-for-gmp-numbers branch 3 times, most recently from 2a4413b to dd04bd0 Compare December 1, 2017 10:33
*/
class GmpCaster
{
public static function castInt(\GMP $value): array
Copy link
Member

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));
Copy link
Member

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'),
Copy link
Member

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'),
Copy link
Member

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
Copy link
Member

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')) {
Copy link
Member

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));
Copy link
Member

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

@Simperfit Simperfit force-pushed the feature/add-a-caster-for-gmp-numbers branch from dd04bd0 to 452a273 Compare December 1, 2017 14:29
@Simperfit Simperfit changed the title [VarDumper] [WIP] add a GMP caster in order to cast GMP resources into string or integer [VarDumper] add a GMP caster in order to cast GMP resources into string or integer Dec 1, 2017
@Simperfit Simperfit force-pushed the feature/add-a-caster-for-gmp-numbers branch from 452a273 to 516e25d Compare December 1, 2017 14:34
"""
EODUMP;

$this->assertDumpEquals($expected, print_r($clone, true));
Copy link
Member

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

@Simperfit Simperfit force-pushed the feature/add-a-caster-for-gmp-numbers branch from 516e25d to 5f1f345 Compare December 1, 2017 14:44
/**
* @requires extension gmp
*/
public function testGmpCast()
Copy link
Member

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()
Copy link
Member

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));
Copy link
Member

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.
Copy link
Member

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.

@Simperfit Simperfit force-pushed the feature/add-a-caster-for-gmp-numbers branch 3 times, most recently from 369e481 to 530d71b Compare December 1, 2017 14:57
@Simperfit
Copy link
Contributor Author

here is a little gif of the french fields with snow:
image uploaded from ios

@Simperfit Simperfit force-pushed the feature/add-a-caster-for-gmp-numbers branch from 530d71b to 4c7a3f7 Compare December 1, 2017 15:54
@Simperfit Simperfit force-pushed the feature/add-a-caster-for-gmp-numbers branch from 4c7a3f7 to ed2c1af Compare December 1, 2017 15:54
@nicolas-grekas nicolas-grekas added this to the 4.1 milestone Dec 1, 2017
@fabpot
Copy link
Member

fabpot commented Dec 1, 2017

Thank you @Simperfit.

@fabpot fabpot merged commit ed2c1af into symfony:master Dec 1, 2017
fabpot added a commit that referenced this pull request Dec 1, 2017
…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:
![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
@fabpot fabpot mentioned this pull request May 7, 2018
@Simperfit Simperfit deleted the feature/add-a-caster-for-gmp-numbers branch May 30, 2018 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants