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

Cache data presented as String and not Array #55

Open
Krayt1x opened this issue Jan 2, 2016 · 13 comments
Open

Cache data presented as String and not Array #55

Krayt1x opened this issue Jan 2, 2016 · 13 comments

Comments

@Krayt1x
Copy link

Krayt1x commented Jan 2, 2016

I apologies firstly as i am quite new to JSON

When i run the following line the first time with DECODE_ENABLED = TRUE;
$getGame = $testCache->getCurrentGame($summoner_id,OC1);
var_dump ($getGame);

It returns an array, but if i go and refresh the page it will return it as a string.

If i do the same thing again with DECODE_ENABLED = FALSE;
it returns a string both times.

Am i missing an option to decode from cache somewhere or am i making a silly mistake?

@Krayt1x Krayt1x changed the title Not pulling data from Cache Cache data presented as String and not Array Jan 2, 2016
@Krayt1x
Copy link
Author

Krayt1x commented Jan 2, 2016

#42

I think might have solved this.

@Krayt1x Krayt1x closed this as completed Jan 2, 2016
@Krayt1x
Copy link
Author

Krayt1x commented Jan 2, 2016

I am able to read code, but quite poor at writing so if this is wrong can someone please correct me.

I modified line 64 in FileSystemCache.php from
return json_decode(file_get_contents($this->getPath($key)));
to
return json_decode(file_get_contents($this->getPath($key)),true);

and it "seems" to be working.

@kevinohashi
Copy link
Owner

It actually looks like a mistake in the library itself

    //returns a summoner's id
    public function getSummonerId($name) {
            $name = strtolower($name);
            $summoner = $this->getSummonerByName($name);
            if (self::DECODE_ENABLED) {
                return $summoner[$name]['id'];
            }
            else {
                $summoner = json_decode($summoner, true);
                return $summoner[$name]['id'];
            }
    }   

the if and else should probably be reversed

    //returns a summoner's id
    public function getSummonerId($name) {
            $name = strtolower($name);
            $summoner = $this->getSummonerByName($name);
            if (!self::DECODE_ENABLED) {
                return $summoner[$name]['id'];
            }
            else {
                $summoner = json_decode($summoner, true);
                return $summoner[$name]['id'];
            }
    }   

Does that fix the issue instead of having to add your own true?

@kevinohashi kevinohashi reopened this Jan 2, 2016
@Krayt1x
Copy link
Author

Krayt1x commented Jan 2, 2016

Just testing

@kevinohashi
Copy link
Owner

Let me know if that fixes it, I will patch the library :)

@Krayt1x
Copy link
Author

Krayt1x commented Jan 2, 2016

That seems to be working, i will have to play around some more as the site is still being created an a lot of stuff doesn't currently work.

@Krayt1x
Copy link
Author

Krayt1x commented Jan 2, 2016

Getting the same issue on

$getSummonerName = $testCache->getSummoner($summoner_id);
var_dump ($getSummonerName);

@kevinohashi
Copy link
Owner

I really need to sit down one of these days and go through a bunch of fixes, it hasn't been well thought out lately. I haven't had the time to do everything right.

It shouldn't need DECODE_ENABLED checks anywhere. It's done in request(). All those other ones should be redundant. But if it's not working right, I need to really take a deeper look.

@kevinohashi kevinohashi reopened this Jan 2, 2016
@Krayt1x
Copy link
Author

Krayt1x commented Jan 2, 2016

honestly, it could just be me..

@kevinohashi
Copy link
Owner

it could be, but I haven't had the time to maintain this library as well I should lately. I am looking through it and it's me quickly patching stuff and not really fully thinking about the design and structure. Even if it's just you, I need to sit down for a day and just clean the whole thing up.

@Krayt1x
Copy link
Author

Krayt1x commented Jan 5, 2016

Is there any way i would be able to assist you with this?

@kevinohashi
Copy link
Owner

I appreciate the offer, if you want to look through and see what you think is wrong, how you would change it, I'm always open to help and ideas

@sylven
Copy link
Contributor

sylven commented Jan 18, 2016

I also noticed that.
You can fix it by deleting the ifs where it checks for "self:DECODE_ENABLED" on "request" method, and then add one of those at the end of the "request" method, so you check if you need to decode just before you return the $result.

It would look like this:

if (self::DECODE_ENABLED) {
    return json_decode($result, true);
}
return $result;

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

No branches or pull requests

3 participants