GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - senojj/PhpCollectionJson: Collection+JSON classes for PHP

BranchesTags
Open more actions menu

Latest commit

 

History

21 Commits
21 Commits

Folders and files

NameName
Last commit message
Last commit date
src
src
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 

Repository files navigation

PhpCollectionJson

PHP classes for building a Collection+JSON response.

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'

About

Collection+JSON classes for PHP

Resources

Readme
Activity

Stars

2 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.