Skip to content

Commit 0275100

Browse files
committed
dropping SchemaLoader
1 parent 90f1f4f commit 0275100

File tree

12 files changed

+71
-427
lines changed

12 files changed

+71
-427
lines changed

src/JsonSchema.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Swaggest\JsonSchema;
44

55
use Swaggest\JsonSchema\Constraint\Properties;
6+
use Swaggest\JsonSchema\Structure\ClassStructure;
67
use Swaggest\JsonSchema\Structure\SchemaStructure;
78

89

src/ProcessingOptions.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class ProcessingOptions extends MagicMap
66
{
77

88

9-
protected $import = true;
9+
public $import = true;
1010
/** @var DataPreProcessor */
1111
public $dataPreProcessor;
1212
/** @var RefResolver */
@@ -18,6 +18,9 @@ class ProcessingOptions extends MagicMap
1818
/** @var string */
1919
public $propagateObjectItemClass;
2020

21+
/** @var \SplObjectStorage */
22+
public $circularReferences;
23+
2124
/**
2225
* ProcessingOptions constructor.
2326
* @param RemoteRefProvider $remoteRefProvider

src/Schema.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class Schema extends ObjectItem
2626
{
2727
const SCHEMA_DRAFT_04_URL = 'http://json-schema.org/draft-04/schema';
2828

29+
const REF = '$ref';
30+
31+
2932
/*
3033
public $__seqId;
3134
public static $seq = 0;
@@ -167,12 +170,14 @@ public function import($data, ProcessingOptions $options = null)
167170
return $this->process($data, $options, '#');
168171
}
169172

173+
170174
public function export($data, ProcessingOptions $options = null)
171175
{
172176
if ($options === null) {
173177
$options = new ProcessingOptions();
174178
}
175179

180+
$options->circularReferences = new \SplObjectStorage();
176181
$options->import = false;
177182
return $this->process($data, $options);
178183
}
@@ -184,6 +189,16 @@ public function process($data, ProcessingOptions $options, $path = '#', $result
184189
//$pathTrace = explode('->', $path);
185190

186191
if (!$import && $data instanceof ObjectItem) {
192+
$result = new \stdClass();
193+
if ($options->circularReferences->contains($data)) {
194+
/** @noinspection PhpIllegalArrayKeyTypeInspection */
195+
$path = $options->circularReferences[$data];
196+
$result->{self::REF} = $path;
197+
return $result;
198+
}
199+
$options->circularReferences->attach($data, $path);
200+
201+
187202
$data = $data->jsonSerialize();
188203
}
189204
if (!$import && is_array($data) && $this->useObjectAsArray) {

0 commit comments

Comments
 (0)