Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-2910

JSON Pointer and JSON Patch syntax support



      I plan to add support for JSON Pointer (RFC 6901: http://tools.ietf.org/html/rfc6901) and JSON Patch (RFC 6902: http://tools.ietf.org/html/rfc6902) syntaxes to Doctrine.

      JSON Pointer and JSON Patch are useful to create Hypermedia REST API (HATEOAS).
      Some higher level standards such as JSON API (http://jsonapi.org/) also rely on JSON Pointer and JSON Patch. My final thought is to implement JSON API support (serialization and update) on top of the Doctrine ORM.

      The use case for the JSON pointer syntax is to access entity properties through an object graph.


      $jpa = new JsonPointerAccess();
      $jpa->get($myEntityOrCollection, '/foo/0/bar'); # Get the value of $myEntityOrCollection->$foo[0]->bar
      $jpa->set($myEntityOrCollection, '/foo/0/bar', 22); # Set the value of $myEntityOrCollection->$foo[0]->bar to 22

      And for JSON Patch it's to modify a whole object graph.

      $jpe = new JsonPatchExecuter();
      $jpe->apply($myEntityOrCollection, '{ "op": "replace", "path": "/a/b/c", "value": 42 }'); # Set the value of $myEntityOrCollection->a->b->c to 42

      In order to add some security, I also plan to create a new annotation to set access permissions on properties.

      Ex :

      use Doctrine\ORM\Mapping as ORM;
      class MyEntity {
         * @ORM\Column(type="integer")
         * @ORM\Id
         * @ORM\Expose({"group_read"})
         public $id;
      $jpa = new JsonPointerAccess();
      $jpa->get($myEntity, '/id', ['group_read']); # OK
      $jpa->set($myEntity, '/id', 22, ['group_read']); # Throw an exception

      I'd like some feedback before starting the implementation:

      • Do you thing a such component should be in Doctrine or in a separate package?
      • What do you think of the purposed syntax?
      • Do you see other important features in this scope I've missed?

      Thank you.



          • Assignee:
            ocramius Marco Pivetta
            dunglas Kévin Dunglas
          • Votes:
            0 Vote for this issue
            2 Start watching this issue


            • Created: