Skip to content

Commit

Permalink
Added PSR-0 compliance and created a composor.json. Will extend funct…
Browse files Browse the repository at this point in the history
…ionality later
  • Loading branch information
pietercolpaert committed Jan 24, 2013
1 parent a65fb65 commit 93551f5
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
composer.lock
vendor/
9 changes: 0 additions & 9 deletions README

This file was deleted.

28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
19 changes: 19 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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/"
}
}
}

5 changes: 3 additions & 2 deletions example.php → examples/example.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

require_once 'JSONChunkProcessor.php';
require_once 'JSONCharInputReader.php';
namespace tdt\json;
require("../vendor/autoload.php");


class JSONChunkProcessorImpl implements JSONChunkProcessor
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* @author janeklb
*
*/
namespace tdt\json;

class JSONCharInputReader
{
const STATE_OUTSIDE = -1; // Outside of a JSON stream
Expand Down Expand Up @@ -46,7 +48,7 @@ public function readChar($char)
{
if (!is_string($char) || strlen($char) != 1)
{
throw new InvalidArgumentException(__CLASS__ . ': readChar requires a single charater as its input argument');
throw new \InvalidArgumentException(__CLASS__ . ': readChar requires a single charater as its input argument');
}

switch ($this->state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* @author janeklb
*
*/
namespace tdt\json;

interface JSONChunkProcessor
{
/**
Expand Down
12 changes: 5 additions & 7 deletions test/test.php → tests/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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('[');
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 93551f5

Please sign in to comment.