Git Product home page Git Product logo

Comments (2)

lindyhopchris avatar lindyhopchris commented on August 10, 2024

Hi!

I'm assuming you're on the latest version of the library (if not, just say). To get the array from the data key, you can do:

use CloudCreativity\JsonApi\Decoders\DocumentDecoder;
use CloudCreativity\JsonApi\Object\Resource;

/** @var string $content    the response content */
$decoder = new DocumentDecoder();
$document = $decoder->decode($content);

/** @var stdClass[] $data */
$data = $document->get('data');

/** If you want these as actual resource objects... */
$resources = array_map(function (stdClass $object) {
    return new Resource($object);
}, $data);

The reason there isn't an inbuilt way of doing this is because the library has been built to validate content coming from a client, rather than a client handling the response from a server. However, this is definitely an intended use case for the package, we just haven't put a huge amount of dev time into it yet.

It'd be a great addition if I added support for this in, because what you're trying to do is an obvious omission for the use case of handling responses

All I need to do is add a collection that holds instances of this class:
https://github.com/cloudcreativity/json-api/blob/master/src/Contracts/Object/ResourceInterface.php

And then add a method to this interface:
https://github.com/cloudcreativity/json-api/blob/master/src/Contracts/Object/DocumentInterface.php
To get the collection from the data key.

I'm happy to do this but I won't be able to get to it until the weekend at the earliest, or next week.

from json-api.

lindyhopchris avatar lindyhopchris commented on August 10, 2024

Closing as this change is available on the 0.6.x-dev version and will be release at v0.6

from json-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.