Skip to content

Added SchemaStorageInterface #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}