Skip to content

Commit

Permalink
Added SchemaStorageInterface (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
kynx authored and bighappyface committed Dec 8, 2016
1 parent 9da41b0 commit 3e9f6fb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/JsonSchema/Constraints/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use JsonSchema\Exception\InvalidArgumentException;
use JsonSchema\SchemaStorage;
use JsonSchema\SchemaStorageInterface;
use JsonSchema\Uri\UriRetriever;
use JsonSchema\UriRetrieverInterface;

Expand Down Expand Up @@ -68,7 +69,7 @@ class Factory
* @param int $checkMode
*/
public function __construct(
SchemaStorage $schemaStorage = null,
SchemaStorageInterface $schemaStorage = null,
UriRetrieverInterface $uriRetriever = null,
$checkMode = Constraint::CHECK_MODE_NORMAL
) {
Expand Down
14 changes: 7 additions & 7 deletions src/JsonSchema/SchemaStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use JsonSchema\Uri\UriResolver;
use JsonSchema\Uri\UriRetriever;

class SchemaStorage
class SchemaStorage implements SchemaStorageInterface
{
protected $uriRetriever;
protected $uriResolver;
Expand Down Expand Up @@ -39,8 +39,7 @@ public function getUriResolver()
}

/**
* @param string $id
* @param object $schema
* {@inheritdoc}
*/
public function addSchema($id, $schema = null)
{
Expand All @@ -58,8 +57,7 @@ public function addSchema($id, $schema = null)
}

/**
* @param string $id
* @return object
* {@inheritdoc}
*/
public function getSchema($id)
{
Expand All @@ -70,6 +68,9 @@ public function getSchema($id)
return $this->schemas[$id];
}

/**
* {@inheritdoc}
*/
public function resolveRef($ref)
{
$jsonPointer = new JsonPointer($ref);
Expand All @@ -93,8 +94,7 @@ public function resolveRef($ref)
}

/**
* @param $refSchema
* @return object
* {@inheritdoc}
*/
public function resolveRefSchema($refSchema)
{
Expand Down
34 changes: 34 additions & 0 deletions src/JsonSchema/SchemaStorageInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace JsonSchema;

interface SchemaStorageInterface
{
/**
* Adds schema with given identifier
* @param string $id
* @param object $schema
*/
public function addSchema($id, $schema = null);

/**
* Returns schema for given identifier, or null if it does not exist
* @param string $id
* @return object
*/
public function getSchema($id);

/**
* Returns schema for given reference with all sub-references resolved
* @param string $ref
* @return object
*/
public function resolveRef($ref);

/**
* Returns schema referenced by '$ref' property
* @param mixed $refSchema
* @return object
*/
public function resolveRefSchema($refSchema);
}

0 comments on commit 3e9f6fb

Please sign in to comment.