2017 © Pedro Peláez
 

library common

This is a library for creating the structure of the JSON for PHP 5.4+

image

jbuilder/common

This is a library for creating the structure of the JSON for PHP 5.4+

  • Tuesday, May 21, 2013
  • by dakatsuka
  • Repository
  • 1 Watchers
  • 13 Stars
  • 16,101 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 2 Versions
  • 4 % Grown

The README.md

JBuilder for PHP Build Status

This is a library for creating the structure of the JSON for PHP., (*1)

use JBuilder\Common\Encoder;

echo Encoder::encode(function($json) use ($comments) {
    $json->title = "This is a pen";
    $json->created_at = (new \DateTime())->format(\DateTime::ISO8601);
    $json->updated_at = (new \DateTime())->format(\DateTime::ISO8601);

    $json->author(function($json) {
        $json->name  = "Dai Akatsuka";
        $json->email = "d.akatsuka@gmail.com";
        $json->url   = "https://github.com/dakatsuka";
    });

    $json->comments($comments, function($json, $comment) {
        $json->content    = $comment->getContent();
        $json->created_at = $comment->getCreatedAt();
    });
});

This will build the following structure:, (*2)

{
  "title": "This is a pen",
  "created_at": "2013-05-21T16:49:37+0900",
  "updated_at": "2013-05-21T16:49:37+0900",

  "author": {
    "name": "Dai Akatsuka",
    "email": "d.akatsuka@gmail.com",
    "url": "https://github.com/dakatsuka"
  },

  "comments": [
    {
      "content": "Hello! Great!",
      "created_at": "2013-05-21T16:49:37+0900"
    },
    {
      "content": "Hello! Great!",
      "created_at": "2013-05-21T16:49:37+0900"
    }
  ]
}

Installation

Add this lines to your composer.json:, (*3)

{
    "require": {
        "jbuilder/common": "dev-master"
    }
}

And then execute:, (*4)

$ php composer.phar install

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Copyright (C) 2013 Dai Akatsuka, released under the MIT License., (*5)

The Versions

21/05 2013

dev-master

9999999-dev

This is a library for creating the structure of the JSON for PHP 5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

json library

21/05 2013

1.0.0

1.0.0.0

This is a library for creating the structure of the JSON for PHP 5.4+

  Sources   Download

MIT

The Requires

  • php >=5.4

 

json library