Skip to content

Commit

Permalink
Removed storage providers
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Sep 11, 2016
1 parent 9db73e2 commit 0f1886a
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 201 deletions.
44 changes: 0 additions & 44 deletions lib/FileProvider.php

This file was deleted.

22 changes: 0 additions & 22 deletions lib/ProviderCollection.php

This file was deleted.

28 changes: 0 additions & 28 deletions lib/ProviderStorageBinding.php

This file was deleted.

22 changes: 0 additions & 22 deletions lib/RedisProvider.php

This file was deleted.

22 changes: 0 additions & 22 deletions lib/RunTimeProvider.php

This file was deleted.

58 changes: 2 additions & 56 deletions lib/WebProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@

namespace ICanBoogie\CLDR;

use ICanBoogie\Storage\Storage;

/**
* Retrieves sections from the CLDR source using cURL.
*/
class WebProvider implements Storage, Provider
class WebProvider implements Provider
{
use ProviderStorageBinding;

const DEFAULT_ORIGIN = "http://www.unicode.org/repos/cldr-aux/json/26/";

/**
Expand All @@ -42,15 +38,6 @@ public function __construct($origin = self::DEFAULT_ORIGIN)
$this->origin = $origin;
}

/**
* @inheritdoc
* @codeCoverageIgnore
*/
public function store($key, $value, $ttl = null)
{
# does nothing
}

/**
* The section path, following the pattern "<identity>/<section>".
*
Expand All @@ -60,7 +47,7 @@ public function store($key, $value, $ttl = null)
*
* @throws ResourceNotFound when the specified path does not exists on the CLDR source.
*/
public function retrieve($key)
public function provide($key)
{
$connection = $this->obtain_connection();

Expand All @@ -78,47 +65,6 @@ public function retrieve($key)
return json_decode($rc, true);
}

/**
* The method does nothing.
*
* @inheritdoc
* @codeCoverageIgnore
*/
public function eliminate($key)
{
# does nothing
}

/**
* The method does nothing.
*
* @inheritdoc
* @codeCoverageIgnore
*/
public function exists($key)
{
# does nothing
}

/**
* The method does nothing.
*
* @inheritdoc
* @codeCoverageIgnore
*/
public function clear()
{
# does nothing
}

/**
* @inheritdoc
*/
public function getIterator()
{
# does nothing
}

/**
* Returns a reusable cURL connection.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/CalendarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CalendarTest extends \PHPUnit_Framework_TestCase

static public function setupBeforeClass()
{
$repository = new Repository(create_provider_collection());
$repository = new Repository(create_provider());
self::$calendar = $repository->locales['fr']->calendars['gregorian'];
}

Expand Down
2 changes: 1 addition & 1 deletion tests/RepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase
*/
public function test_properties_instanceof($property, $expected)
{
$repository = new Repository(create_provider_collection());
$repository = new Repository(create_provider());
$instance = $repository->$property;
$this->assertInstanceOf($expected, $instance);
$this->assertSame($instance, $repository->$property);
Expand Down
92 changes: 87 additions & 5 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

namespace ICanBoogie\CLDR;

use ICanBoogie\Storage\FileStorage;
use ICanBoogie\Storage\RunTimeStorage;
use ICanBoogie\Storage\Storage;
use ICanBoogie\Storage\StorageCollection;

$autoload = require __DIR__ . '/../vendor/autoload.php';
$autoload->addPsr4(__NAMESPACE__ . '\\', __DIR__);

Expand All @@ -19,16 +24,93 @@
mkdir(__DIR__ . '/repository');
}

class ProviderCollection extends StorageCollection implements Provider
{
/**
* @inheritdoc
*/
public function provide($path)
{
return $this->retrieve($path);
}
}

class WebStorage implements Storage
{
private $provider;

public function __construct(WebProvider $provider)
{
$this->provider = $provider;
}

/**
* Checks if a key exists in a storage.
*
* @param $key
*
* @return bool `true` if the key exists, `false` otherwise.
*/
public function exists($key)
{
// TODO: Implement exists() method.
}

/**
* Retrieves a value.
*
* @param string $key The key of the value.
*
* @return mixed|null The value associated with the key, or `null` if the key doesn't exists.
*/
public function retrieve($key)
{
return $this->provider->provide($key);
}

/**
* @inheritdoc
*/
public function getIterator()
{
// TODO: Implement getIterator() method.
}

/**
* @inheritdoc
*/
public function store($key, $value, $ttl = null)
{
// TODO: Implement store() method.
}

/**
* @inheritdoc
*/
public function eliminate($key)
{
// TODO: Implement eliminate() method.
}

/**
* @inheritdoc
*/
public function clear()
{
// TODO: Implement clear() method.
}
}

/**
* @return Provider
*/
function create_provider_collection()
function create_provider()
{
return new ProviderCollection([

new RunTimeProvider,
new FileProvider(__DIR__ . '/repository'),
new WebProvider
new RunTimeStorage,
new FileStorage(__DIR__ . '/repository'),
new WebStorage(new WebProvider)

]);
}
Expand All @@ -42,7 +124,7 @@ function get_repository()

if (!$repository)
{
$repository = new Repository(create_provider_collection());
$repository = new Repository(create_provider());
}

return $repository;
Expand Down

0 comments on commit 0f1886a

Please sign in to comment.