private function resolveReferences() { if (!empty($this->references)) { foreach (array_keys($this->references) as $ref) { $keys = Utils::pathDecode($ref); if ($schema = $this->find($this->data, $keys)) { $this->references[$ref] = $schema; } else { throw new \RuntimeException('Unable to find ref ' . $ref); } } foreach ($this->references as $ref => $schema) { $this->references[$ref] = $this->resolve($schema); } $this->data = Utils::dataCopy($this->data, array($this, 'resolveCallback')); $this->references = array(); } }
public function testObjectWithEmptyElements() { $data = new \stdClass(); $data->prop1 = new \stdClass(); $data->prop2 = 'none'; $data->prop3 = null; $data->prop4 = array(); $data->prop5 = array(7); $data->prop6 = array('Bloggs', 'firstName' => 'Fred', 9); $result = Utils::dataCopy($data); $expected = '{ "prop1": {}, "prop2": "none", "prop3": null, "prop4": [], "prop5": [7], "prop6": { "0": "Bloggs", "firstName": "Fred", "1": 9 } }'; $expected = $this->fromJson($expected); $this->assertEquals($expected, $result); }