From 93551f53956e5e9e477b0c174c0a68ddef2066bb Mon Sep 17 00:00:00 2001 From: Pieter Colpaert Date: Thu, 24 Jan 2013 17:59:43 +0100 Subject: [PATCH] Added PSR-0 compliance and created a composor.json. Will extend functionality later --- .gitignore | 2 ++ README | 9 ------ README.md | 28 +++++++++++++++++++ composer.json | 19 +++++++++++++ example.php => examples/example.php | 5 ++-- .../tdt/json/JSONCharInputReader.php | 4 ++- .../tdt/json/JSONChunkProcessor.php | 2 ++ {test => tests}/test.php | 12 ++++---- 8 files changed, 62 insertions(+), 19 deletions(-) create mode 100644 .gitignore delete mode 100644 README create mode 100644 README.md create mode 100644 composer.json rename example.php => examples/example.php (90%) rename JSONCharInputReader.php => src/tdt/json/JSONCharInputReader.php (96%) rename JSONChunkProcessor.php => src/tdt/json/JSONChunkProcessor.php (94%) rename {test => tests}/test.php (89%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d8a7996 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +composer.lock +vendor/ diff --git a/README b/README deleted file mode 100644 index d0933c8..0000000 --- a/README +++ /dev/null @@ -1,9 +0,0 @@ -JSONCharInputReader processes JSON data streams character-by-character - -The data stream must be in the form of a JSON array. -ie. [1, 2, [3, 4], {"five": "six"}, ... - -To run the example execute the following in your terminal: -cat | php example.php - -[Terminate with CTRL^D or CTRL^C] diff --git a/README.md b/README.md new file mode 100644 index 0000000..03bd8e6 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +tdt/json +======== + +JSONCharInputReader processes JSON data streams character-by-character + +The data stream *must* be in the form of a JSON array (atm). +ie. [1, 2, [3, 4], {"five": "six"}, ... + + +examples +======== + +To run the examples/example.php execute the following in your terminal: +```bash +$ cd examples +$ cat | php example.php +``` + +Testing //todo +======= + +We have a few tests in the tests directory. You can run them as follows if you have phpunit installed: + +```bash +$ phpunit tests/ +``` + +Or you can watch our travis-ci.org page when you have pushed to this repository. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..37c7aef --- /dev/null +++ b/composer.json @@ -0,0 +1,19 @@ +{ + "name": "tdt/json", + "description": "Reads a json stream memory efficiently.", + "keywords": ["json", "stream", "chunk", "buffer"], + "homepage": "http://thedatatank.com", + "type": "library", + "license": "AGPLv3", + "suggest": { + }, + "require": { + }, + "minimum-stability" : "dev", + "autoload": { + "psr-0": { + "tdt\\json\\": "src/" + } + } +} + diff --git a/example.php b/examples/example.php similarity index 90% rename from example.php rename to examples/example.php index c743863..b6e7b80 100644 --- a/example.php +++ b/examples/example.php @@ -1,7 +1,8 @@ state) diff --git a/JSONChunkProcessor.php b/src/tdt/json/JSONChunkProcessor.php similarity index 94% rename from JSONChunkProcessor.php rename to src/tdt/json/JSONChunkProcessor.php index c2d21ba..99e91ba 100644 --- a/JSONChunkProcessor.php +++ b/src/tdt/json/JSONChunkProcessor.php @@ -6,6 +6,8 @@ * @author janeklb * */ +namespace tdt\json; + interface JSONChunkProcessor { /** diff --git a/test/test.php b/tests/test.php similarity index 89% rename from test/test.php rename to tests/test.php index aea7323..9315148 100644 --- a/test/test.php +++ b/tests/test.php @@ -7,11 +7,9 @@ // // ////////////////////////////////////////////////////////////////////////////// +require("vendor/autoload.php"); -require_once __DIR__ . '/../JSONChunkProcessor.php'; -require_once __DIR__ . '/../JSONCharInputReader.php'; - -class JSONChunkProcessorImpl implements JSONChunkProcessor +class JSONChunkProcessorImpl implements \tdt\json\JSONChunkProcessor { private $objects = array(); @@ -39,7 +37,7 @@ class JSONCarInputReaderTest extends PHPUnit_Framework_TestCase public function setUp() { $this->processor = new JSONChunkProcessorImpl(); - $this->inputReader = new JSONCharInputReader($this->processor); + $this->inputReader = new \tdt\json\JSONCharInputReader($this->processor); $this->inputReader->readChar('['); } @@ -109,10 +107,10 @@ public function testEscaped() { $this->sendInput('{"x": "x\"a"},{"a\"b":1}'); - $objA = new stdClass(); + $objA = new \stdClass(); $objA->x = 'x"a'; - $objB = new stdClass(); + $objB = new \stdClass(); $objB->{"a\"b"} = 1; $this->assertObjects($objA, $objB);