protected function insertReference($path, $reference)
{
if (!isset($this->json[$path])) {
// Store first entries as simple reference
$this->json[$path] = $reference;
return;
}
if ($reference === $this->json[$path]) {
// Reference is already set
return;
}
if (!is_array($this->json[$path])) {
// Convert existing entries to arrays for follow ups
$this->json[$path] = array($this->json[$path]);
}
if (!in_array($reference, $this->json[$path], true)) {
// Insert at the beginning of the array
array_unshift($this->json[$path], $reference);
}
}