Remove dependent dangling embeds.
This commit is contained in:
parent
ac210d60e3
commit
fb11cb945f
26
jsonld.php
26
jsonld.php
|
@ -2622,6 +2622,26 @@ function _isDuckType($input, $frame)
|
||||||
return $rval;
|
return $rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively removes dependent dangling embeds.
|
||||||
|
*
|
||||||
|
* @param iri the iri of the parent to remove embeds for.
|
||||||
|
* @param embeds the embeds map.
|
||||||
|
*/
|
||||||
|
function removeDependentEmbeds($iri, $embeds)
|
||||||
|
{
|
||||||
|
$iris = get_object_vars($embeds);
|
||||||
|
foreach($iris as $i => $embed)
|
||||||
|
{
|
||||||
|
if($embed->parent !== null and
|
||||||
|
$embed->parent->{'@subject'}->{'@iri'} === $iri)
|
||||||
|
{
|
||||||
|
unset($embeds->$i);
|
||||||
|
removeDependentEmbeds($i, $embeds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subframes a value.
|
* Subframes a value.
|
||||||
*
|
*
|
||||||
|
@ -2672,12 +2692,13 @@ function _subframe(
|
||||||
{
|
{
|
||||||
if(is_array($embed->parent->{$embed->key}))
|
if(is_array($embed->parent->{$embed->key}))
|
||||||
{
|
{
|
||||||
|
// find and replace embed in array
|
||||||
$arrLen = count($embed->parent->{$embed->key});
|
$arrLen = count($embed->parent->{$embed->key});
|
||||||
for($i = 0; $i < $arrLen; ++$i)
|
for($i = 0; $i < $arrLen; ++$i)
|
||||||
{
|
{
|
||||||
$obj = $embed->parent->{$embed->key}[$i];
|
$obj = $embed->parent->{$embed->key}[$i];
|
||||||
if(is_object($obj) and property_exists($obj, '@subject') and
|
if(is_object($obj) and property_exists($obj, '@subject') and
|
||||||
$obj['@iri'] === $iri)
|
$obj->{'@subject'}->{'@iri'} === $iri)
|
||||||
{
|
{
|
||||||
$embed->parent->{$embed->key}[$i] = $value->{'@subject'};
|
$embed->parent->{$embed->key}[$i] = $value->{'@subject'};
|
||||||
break;
|
break;
|
||||||
|
@ -2688,6 +2709,9 @@ function _subframe(
|
||||||
{
|
{
|
||||||
$embed->parent->{$embed->key} = $value->{'@subject'};
|
$embed->parent->{$embed->key} = $value->{'@subject'};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// recursively remove any dependent dangling embeds
|
||||||
|
removeDependentEmbeds($iri, $embeds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update embed entry
|
// update embed entry
|
||||||
|
|
Loading…
Reference in a new issue