Allow blank nodes in JSON-LD#956
Conversation
e3decb3 to
d064f7f
Compare
d064f7f to
30a9715
Compare
| private $propertyAccessor; | ||
| private $itemIdentifiersExtractor; | ||
|
|
||
| public function __construct(PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, ItemDataProviderInterface $itemDataProvider, RouteNameResolverInterface $routeNameResolver, RouterInterface $router, PropertyAccessorInterface $propertyAccessor = null) |
There was a problem hiding this comment.
We should put a reminder somewhere that (when we can break things again) we need to remove those injections and rather directly inject ItemIdentifiersExtractor.
| $data['@id'] = $this->iriConverter->getIriFromItem($object); | ||
| $identifiers = $this->itemIdentifiersExtractor->getIdentifiersFromItem($object); | ||
|
|
||
| $data['@id'] = count(array_filter($identifiers)) > 0 ? $this->iriConverter->getIriFromItem($relatedObject) : $this->blankNodeIdentifiersGenerator->getBlankNodeIdentifier($relatedObject, $context['jsonld_document_root']); |
There was a problem hiding this comment.
Shouldn't we add a method that takes identifiers and resolves to one of those to avoid repetition?
Is $context['jsonld_document_root'] used only to cache the spl_object_hash?
There was a problem hiding this comment.
count(array_filter($identifiers)) > 0 can be replaced by array_filter($identifiers) (faster, easier to read).
There was a problem hiding this comment.
Shouldn't we add a method that takes identifiers and resolves to one of those to avoid repetition?
Sure. I'll move it to a private method.
Is $context['jsonld_document_root'] used only to cache the spl_object_hash?
We need to keep track of which JSON-LD document we're in. But of course there are many ways of doing it. I agree this is not ideal.
There was a problem hiding this comment.
Yeah, nothing wrong with how you did it, just wanted to make sure I understood ;)
| $data['@id'] = $this->iriConverter->getIriFromItem($object); | ||
| $identifiers = $this->itemIdentifiersExtractor->getIdentifiersFromItem($object); | ||
|
|
||
| $data['@id'] = count(array_filter($identifiers)) > 0 ? $this->iriConverter->getIriFromItem($relatedObject) : $this->blankNodeIdentifiersGenerator->getBlankNodeIdentifier($relatedObject, $context['jsonld_document_root']); |
There was a problem hiding this comment.
count(array_filter($identifiers)) > 0 can be replaced by array_filter($identifiers) (faster, easier to read).
|
|
||
| $identifiers = $this->itemIdentifiersExtractor->getIdentifiersFromItem($relatedObject); | ||
|
|
||
| return count(array_filter($identifiers)) > 0 ? $this->iriConverter->getIriFromItem($relatedObject) : $this->blankNodeIdentifiersGenerator->getBlankNodeIdentifier($relatedObject, $context['jsonld_document_root']); |
There was a problem hiding this comment.
Same here array_filter($identifiers) is enough.
| */ | ||
| public function getBlankNodeIdentifier($object, string $documentRootHash): string | ||
| { | ||
| $objectHash = spl_object_hash($object); |
There was a problem hiding this comment.
I'm not a fond of exposing such low level data from the system publicly. Is it really safe? Another potential problem is that this ID will be reused later by PHP. WDYT about using a UUID instead?
There was a problem hiding this comment.
It's not being exposed in any way. The hash is only used to keep track of which objects we've already generated a blank node identifier for, and always return that same identifier for the same object (the scope is the JSON-LD document).
We cannot use UUID for this, as the point is to detect the same object instance.
| * @return string|array | ||
| */ | ||
| private function normalizeRelation(PropertyMetadata $propertyMetadata, $relatedObject, string $resourceClass, string $format = null, array $context) | ||
| protected function normalizeRelation(PropertyMetadata $propertyMetadata, $relatedObject, string $resourceClass, string $format = null, array $context) |
There was a problem hiding this comment.
Can you mark this method as @internal?
30a9715 to
0648775
Compare
|
Can you rebase? It should be ok to be merged. |
|
@dunglas There are no tests yet. |
|
You do you own tests 😈 Joking, if you don't have the time lmk |
effd916 to
8d12b1b
Compare
|
@dunglas I need some help rebasing this... There seems to have been a proliferation of |
f74f04f to
58d7297
Compare
|
|
||
| if (isset($context['resources'])) { | ||
| if (isset($context['resources']) && $this->hasIri($object)) { | ||
| $resource = $context['iri'] ?? $this->iriConverter->getIriFromItem($object); |
There was a problem hiding this comment.
Is the condition still needed? if it hasIri context['iri'] is defined no?
There was a problem hiding this comment.
No. $context['iri'] is only set from the JsonLd ItemNormalizer (I think). I don't know what's the reasoning behind, but I did not change it...
58d7297 to
56b76f4
Compare
56b76f4 to
4c6d144
Compare
|
kinda fixed by #2495 |
TODO: