Skip to content

Commit

Permalink
Added JSONFileStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Sep 5, 2016
1 parent f496a88 commit 9715bb5
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -21,6 +21,7 @@ The following storages are included in this package:
- [RedisStorage][]: Uses a [Redis][] instance.
- [APCStorage][]: Uses [APC][] or [APCu][].
- [FileStorage][]: Uses the file system.
- [JSONFileStorage][]: Uses the file system to store JSON files.
- [StorageCollection][]: Uses a collection of storage.


Expand Down Expand Up @@ -242,8 +243,9 @@ The package is continuously tested by [Travis CI](http://about.travis-ci.org/).
[documentation]: http://api.icanboogie.org/storage/latest/
[APCStorage]: http://api.icanboogie.org/storage/latest/class-ICanBoogie.Storage.APCStorage.html
[Cache]: http://api.icanboogie.org/storage/latest/class-ICanBoogie.Storage.Cache.html
[Cachecollection]: http://api.icanboogie.org/storage/latest/class-ICanBoogie.Storage.CacheCollection.html
[CacheCollection]: http://api.icanboogie.org/storage/latest/class-ICanBoogie.Storage.CacheCollection.html
[FileStorage]: http://api.icanboogie.org/storage/latest/class-ICanBoogie.Storage.FileStorage.html
[JSONFileStorage]: http://api.icanboogie.org/storage/latest/class-ICanBoogie.Storage.JSONFileStorage.html
[RedisStorage]: http://api.icanboogie.org/storage/latest/class-ICanBoogie.Storage.RedisStorage.html
[RunTimeStorage]: http://api.icanboogie.org/storage/latest/class-ICanBoogie.Storage.RunTimeStorage.html
[Storage]: http://api.icanboogie.org/storage/latest/class-ICanBoogie.Storage.Storage.html
Expand Down
35 changes: 35 additions & 0 deletions lib/JSONFileStorage.php
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <olivier.laviale@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ICanBoogie\Storage;

class JSONFileStorage extends FileStorage
{
/**
* Serialize the value using `json_encode()`.
*
* @inheritdoc
*/
protected function serialize($value)
{
return json_encode($value);
}

/**
* Unserialize the value using `json_decode()`.
*
* @inheritdoc
*/
protected function unserialize($value)
{
return json_decode($value, true);
}
}
27 changes: 27 additions & 0 deletions tests/JSONFileStorageTest.php
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <olivier.laviale@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ICanBoogie\Storage;

class JSONFileStorageTest extends \PHPUnit_Framework_TestCase
{
use TestStorageTrait;

/**
* @var FileStorage
*/
private $storage;

public function setUp()
{
$this->storage = new JSONFileStorage(__DIR__ . '/sandbox/' . uniqid());
}
}

0 comments on commit 9715bb5

Please sign in to comment.