2017 © Pedro Peláez
 

library pjson

image

corneltek/pjson

  • Monday, February 5, 2018
  • by c9s
  • Repository
  • 2 Watchers
  • 8 Stars
  • 2,036 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 3 % Grown

The README.md

PJSON

PJSONEncoder implements a JSON encoder with PHP object to JavaScript object translation support., (*1)

You can specify your own encoder for each PHP types:, (*2)

use PJSON\PJSONEncoder;
use PJSON\DateTimeEncoder;
$encoder = new PJSONEncoder;
$encoder->setDateTimeEncoder(new DateTimeEncoder(DateTime::ATOM));
$encoder->setStringEncoder(function($value, $encoder) {
    return '"' . addcslashes($value) . '"';
});
$encoder->setClosureEncoder(function($closure, $encoder) {
    return $encoder->encode($closure(1,2,3));
});
$output = $encoder->encode([ ... PHP Array here ... ]);

And you can also encode JavaScript symbols or JavaScript function call in JSON from PHP:, (*3)

$encoder = new PJSONEncoder;
$call = new JsFunctionCall('jQuery', ['#documentId']);
$encoder->encode($call); // outputs 'jQuery("#documentId")'
$encoder->encode(['a' => new JsSymbol('js_var')]); // outputs {"a": js_var}

Install

composer require corneltek/pjson '*'

License

This package is released under MIT License, (*4)

The Versions

05/02 2018

dev-master

9999999-dev

  Sources   Download

MIT

by Avatar c9s

24/04 2016

1.1.0

1.1.0.0

  Sources   Download

MIT

by Avatar c9s

24/04 2016

1.0.1

1.0.1.0

  Sources   Download

MIT

by Avatar c9s