2017 © Pedro Peláez
 

library phpcollectionjson

PHP classes for building a Collection+JSON response

image

jjware/phpcollectionjson

PHP classes for building a Collection+JSON response

  • Tuesday, October 11, 2016
  • by JJWare
  • Repository
  • 1 Watchers
  • 1 Stars
  • 547 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 14 % Grown

The README.md

PhpCollectionJson

PHP classes for building a Collection+JSON response., (*1)

Installation

composer require jjware/phpcollectionjson

Usage

Creating a response

use PhpCollectionJson\Document;
use PhpCollectionJson\Collection;
use PhpCollectionJson\Item;
use PhpCollectionJson\Data;

$document = new Document();
$collection = new Collection('http://www.somesite.com/users');
$document->setCollection($collection);

$item = new Item('http://www.somesite.com/users/123');
$item->getData()
    ->add(new Data('firstName', 'John'))
    ->add(new Data('lastName', 'Smith'))
    ->add(new Data('username', 'jsmith'));

$collection->getItems()->add($item);

echo json_encode($document);

Building from a response

The JSON

{
  "collection": {
    "version": "1.0",
    "href": "http://www.somesite.com/users",
    "items": [
      {
        "href": "http://www.somesite.com/users/123",
        "data": [
          {
            "name": "firstName",
            "value": "John"
          },
          {
            "name": "lastName",
            "value": "Smith"
          },
          {
            "name": "username",
            "value": "jsmith"
          }
        ]
      }
    ]
  }
}

The PHP

use PhpCollectionJson\Document;

$json = file_get_contents('http://www.somesite.com/users'); // don't do this at home kids

$document = Document::fromJSON($json);

$firstName = $document->getCollection()->getItems()->elementAt(0)->getData()->elementAt(0)->getValue();

// $firstName === 'John'

The Versions

11/10 2016

dev-master

9999999-dev

PHP classes for building a Collection+JSON response

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

by Joshua Jones

json library collections collectionjson

11/10 2016

3.2.0

3.2.0.0

PHP classes for building a Collection+JSON response

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

by Joshua Jones

json library collections collectionjson

10/10 2016

3.1.1

3.1.1.0

PHP classes for building a Collection+JSON response

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

by Joshua Jones

json library collections collectionjson

10/10 2016

3.1.0

3.1.0.0

PHP classes for building a Collection+JSON response

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

by Joshua Jones

json library collections collectionjson

10/10 2016

3.0.0

3.0.0.0

PHP classes for building a Collection+JSON response

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

by Joshua Jones

json library collections collectionjson

07/10 2016

2.0.0

2.0.0.0

PHP classes for building a Collection+JSON response

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

by Joshua Jones

json library collections collectionjson