@@ -30,6 +30,8 @@ class RefResolver
30
30
/** @var UriResolverInterface */
31
31
private $ uriResolver ;
32
32
33
+ private $ paths = array ();
34
+
33
35
/**
34
36
* @param UriRetrieverInterface $retriever
35
37
* @param UriResolverInterface $uriResolver
@@ -48,26 +50,16 @@ public function __construct(UriRetrieverInterface $retriever, UriResolverInterfa
48
50
* @return object
49
51
*/
50
52
public function resolve ($ sourceUri )
51
- {
52
- return $ this ->resolveCached ($ sourceUri , array ());
53
- }
54
-
55
- /**
56
- * @param string $sourceUri URI where this schema was located
57
- * @param array $paths
58
- * @return object
59
- */
60
- private function resolveCached ($ sourceUri , array $ paths )
61
53
{
62
54
$ jsonPointer = new JsonPointer ($ sourceUri );
63
55
64
56
$ fileName = $ jsonPointer ->getFilename ();
65
- if (!array_key_exists ($ fileName , $ paths )) {
57
+ if (!array_key_exists ($ fileName , $ this -> paths )) {
66
58
$ schema = $ this ->uriRetriever ->retrieve ($ jsonPointer ->getFilename ());
67
- $ paths [$ jsonPointer ->getFilename ()] = $ schema ;
68
- $ this ->resolveSchemas ($ schema , $ jsonPointer ->getFilename (), $ paths );
59
+ $ this -> paths [$ jsonPointer ->getFilename ()] = $ schema ;
60
+ $ this ->resolveSchemas ($ schema , $ jsonPointer ->getFilename ());
69
61
}
70
- $ schema = $ paths [$ fileName ];
62
+ $ schema = $ this -> paths [$ fileName ];
71
63
72
64
return $ this ->getRefSchema ($ jsonPointer , $ schema );
73
65
}
@@ -77,16 +69,15 @@ private function resolveCached($sourceUri, array $paths)
77
69
*
78
70
* @param object $unresolvedSchema
79
71
* @param string $fileName
80
- * @param array $paths
81
72
*/
82
- private function resolveSchemas ($ unresolvedSchema , $ fileName, array $ paths )
73
+ private function resolveSchemas ($ unresolvedSchema , $ fileName )
83
74
{
84
75
$ objectIterator = new ObjectIterator ($ unresolvedSchema );
85
76
foreach ($ objectIterator as $ toResolveSchema ) {
86
77
if (property_exists ($ toResolveSchema , '$ref ' ) && is_string ($ toResolveSchema ->{'$ref ' })) {
87
78
$ jsonPointer = new JsonPointer ($ this ->uriResolver ->resolve ($ toResolveSchema ->{'$ref ' }, $ fileName ));
88
- $ refSchema = $ this ->resolveCached ((string ) $ jsonPointer, $ paths );
89
- $ this ->unionSchemas ($ refSchema , $ toResolveSchema , $ fileName, $ paths );
79
+ $ refSchema = $ this ->resolve ((string ) $ jsonPointer );
80
+ $ this ->unionSchemas ($ refSchema , $ toResolveSchema , $ fileName );
90
81
}
91
82
}
92
83
}
@@ -120,14 +111,13 @@ private function getRefSchema(JsonPointer $jsonPointer, $refSchema)
120
111
* @param object $refSchema
121
112
* @param object $schema
122
113
* @param string $fileName
123
- * @param array $paths
124
114
*/
125
- private function unionSchemas ($ refSchema , $ schema , $ fileName, array $ paths )
115
+ private function unionSchemas ($ refSchema , $ schema , $ fileName )
126
116
{
127
117
if (property_exists ($ refSchema , '$ref ' )) {
128
118
$ jsonPointer = new JsonPointer ($ this ->uriResolver ->resolve ($ refSchema ->{'$ref ' }, $ fileName ));
129
- $ newSchema = $ this ->resolveCached ((string ) $ jsonPointer, $ paths );
130
- $ this ->unionSchemas ($ newSchema , $ refSchema , $ fileName, $ paths );
119
+ $ newSchema = $ this ->resolve ((string ) $ jsonPointer );
120
+ $ this ->unionSchemas ($ newSchema , $ refSchema , $ fileName );
131
121
}
132
122
133
123
unset($ schema ->{'$ref ' });
0 commit comments