phpokeapi icon indicating copy to clipboard operation
phpokeapi copied to clipboard

Hack to fix pokeapi bug not working

Open renecatharsis opened this issue 5 years ago • 1 comments

There's a workaround in PokeAPI\Client class to address this open issue: https://github.com/PokeAPI/pokeapi/issues/345

That workaround doesn't work correctly for me, either. Possibly because my local pokeapi installation doesn't run on localhost but a custom hostname. It does try to resolve the expected Collection by calling the falsely delivered URL but doesn't prepend the baseUrl properly.

My (also ugly) fix for this was to replace:

if ($uri === Pokemon::POKEAPI_ENDPOINT && isset($data['location_area_encounters'])) { 
    $data['location_area_encounters'] = $this->fixEncounters($data['location_area_encounters']);
}

with

if ($uri === Pokemon::POKEAPI_ENDPOINT && isset($data['location_area_encounters'])) {
    $prepend = str_replace('/api/v2/', '', $this->baseUrl);
    $data['location_area_encounters'] = $this->fixEncounters($prepend . $data['location_area_encounters']);
}

renecatharsis avatar Feb 28 '20 22:02 renecatharsis

See PR #11

renecatharsis avatar Mar 07 '20 00:03 renecatharsis