Skip to content

Loading…

DDC-3183: Add JsonSerializable to Collections #3965

Closed
doctrinebot opened this Issue · 5 comments

4 participants

@doctrinebot

Jira issue originally created by user gabrielbull:

Implement this:

http://www.php.net/manual/fr/class.jsonserializable.php

Can't really make this claim if Doctrine is not implementing basic interfaces for collections:

The missing (SPL) Collection/Array/OrderedMap interface.

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 3.0 milestone
@Richard87

I also would like this, would make some use-cases slightly simpler :) Also, as far as I can imagine, all that is needed is this function in ArrayCollection:

function jsonSerialize()
{
    return $this->elements;
}

Obvously this would require all elements in the array to also be json serializable... Should I try to create a pull-request for this, and if so, add it sooner that v. 3?

@Ocramius
Doctrine member

This is a basic SRP violation. Serialization (into JSON in this case) is out of the scope of the ORM, and also of the entire doctrine project at the moment.

@Ocramius Ocramius closed this
@beberlei beberlei was unassigned by Ocramius
@Ocramius Ocramius self-assigned this
@Ocramius Ocramius removed this from the 3.0 milestone
@Ocramius Ocramius added the Won't Fix label
@Richard87

I see your point, but ArrayCollection is not a part of ORM(?)... And as GabrielBull commented, that it belongs in a object that seeks to replace PHPs array?

@Ocramius
Doctrine member

The doctrine collections library abstracts reading/writing of elements in a collection-alike structure: it doesn't abstract transforming the collection into something else (SRP still applies).

It is trivial to simply call toArray on a collection inside an entity's JsonSerializable implementation.

@Richard87

Yeah, thats true... thanks for the explanation :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.