Skip to content
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

ISSUE-209: Encode keys before storing on mongo. #210

Closed

Conversation

samt2497
Copy link

Issue: #209

Notes:

  • Added encoding on the profile ( replace . with it Unicode equivalent )

src/Xhgui/Profile.php Outdated Show resolved Hide resolved
src/Xhgui/Profile.php Outdated Show resolved Hide resolved
src/Xhgui/Profiles.php Outdated Show resolved Hide resolved
src/Xhgui/Profiles.php Outdated Show resolved Hide resolved
@markstory markstory added this to the 0.7.0 milestone Oct 10, 2017
@markstory
Copy link
Member

Looks good. I will get the build fixed for php7.

@markstory markstory self-assigned this Oct 10, 2017
@lauripiisang
Copy link
Contributor

It worries me that for me, everything works with mongodb 3.0 (see issue #209 ).

I would like to set up a docker env to test this and find out what the real cause of this issue is before we hurry to a fix that might not work. If you need to use your fix, you can do so via https://getcomposer.org/doc/05-repositories.md#loading-a-package-from-a-vcs-repository

);
foreach ($profile as $k => $v) {
if (is_array($v)) {
$v = $this->encodeProfile($v);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this recursive call? do we have any other problematic keys than the content of array_keys($profile['profile'])?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any nested structures inside a profile that I have ignored?

Copy link
Contributor

@lauripiisang lauripiisang Oct 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the case that we do not need recursive checking, we should instead opt for an easier solution.

What do you think about something like

public function encode($profile) {
  // return $profile if the array is empty or not an array
  $replacedKeys = str_replace('.', '', array_keys($profile));
  return array_combine($replacedKeys, $profile);
}

?

Here's a demonstration, if you're intersted

<?php
$a = ['fx' => ['a' => 'xxx', 'b' => 2, 'c' => 3], 'quux' => ['f' => 7, 'cx' => 3]];
print_r(array_combine(str_replace('x', 'y', array_keys($a)), $a));

prints

Array
(
    [fy] => Array
        (
            [a] => xxx
            [b] => 2
            [c] => 3
        )

    [quuy] => Array
        (
            [f] => 7
            [cx] => 3
        )

)

Copy link
Contributor

@lauripiisang lauripiisang Oct 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also recommend defining the . and as constants (UNICODE_PERIOD and UNICODE_FULLWIDTH_PERIOD for example?)

@markstory markstory removed their assignment Oct 18, 2017
@glensc
Copy link
Contributor

glensc commented Oct 22, 2020

Superseded by #352

@glensc glensc closed this Oct 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants