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

Unexpected behavior if fetched xml contains only one position #2

Open
jonastemmen opened this issue Feb 14, 2023 · 0 comments
Open

Comments

@jonastemmen
Copy link

When the fetched XML contains only one position, the array that "fetchFeedItems" will return doesn't contain one entry but a flat array of the properties.
This is a side-effect of the "json_decode(json_encode())" trick as discussed here: #https://stackoverflow.com/questions/23766159/php-simplexml-arrays-generated-differently-for-single-child-and-multiple-child#comment36552222_23767934

It can be solved by simply using a foreach to loop over the result. It doesn't look that fancy but it works :-)

change

if ($response->getStatusCode() === 200 && strpos($response->getHeaderLine('Content-Type'), 'text/xml') === 0) {
    $content = $response->getBody()->getContents();
    return json_decode(
        json_encode(
          simplexml_load_string($content, 'SimpleXMLElement', LIBXML_NOCDATA)
        ),TRUE
      )['position'];
    }

to

 if ($response->getStatusCode() === 200 && strpos($response->getHeaderLine('Content-Type'), 'text/xml') === 0) {
      $xmlContent = simplexml_load_string($response->getBody()->getContents(), 'SimpleXMLElement', LIBXML_NOCDATA);
      $jobs = [];
      foreach($xmlContent as $xmlJob){
          $jobs[] = (array)$xmlJob;
      }
      return $jobs;
    }

in PersonioService.php L40 ff

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

1 participant