Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [4.8.0] - 2026-11-25
### Changed
- JSON-LD is read by a small built-in expander. The unmaintained `ml/json-ld` dependency is no longer used. Remote `@context` URLs are still never fetched; schema.org contexts stay bundled. `$info->getLinkedData()` (`get`, `getAll`, `all`) is unchanged [#554] [#582]

### Fixed
- PHP 8.4 and 8.5 no longer emit deprecations while reading JSON-LD [#554] [#582]

## [4.7.0] - 2026-11-23
### Added
- YouTube: `$info->image` is `maxresdefault.jpg` when the video page links it in `og:image`, instead of the oEmbed `hqdefault.jpg` with black bars [#535]
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
"oscarotero/html-parser": "^0.1.6",
"psr/http-message": "^1.0|^2.0",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
"ml/json-ld": "^1.1"
"psr/http-factory": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
Expand Down
44 changes: 22 additions & 22 deletions src/JsonLd/DocumentLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,15 @@

namespace Embed\JsonLd;

use ML\JsonLD\DocumentLoaderInterface;
use ML\JsonLD\Exception\JsonLdException;
use ML\JsonLD\Processor;
use ML\JsonLD\RemoteDocument;

/**
* JSON-LD document loader that never touches the network or the filesystem.
*
* LinkedData passes this as the documentLoader option. The global
* JsonLD::setDefaultDocumentLoader() is not used, so a host application
* keeps its own loader.
*
* schema.org context URLs are answered with a bundled vocabulary of
* {"@context":{"@vocab":"http://schema.org/"}}. Every other remote URL or
* path raises JsonLdException, which LinkedData already catches.
* The expander uses this when a document names a remote `@context`. schema.org
* context URLs are answered with a bundled vocabulary of
* {"@context":{"@vocab":"http://schema.org/"}}. Every other remote URL or path
* raises JsonLdException, which LinkedData already catches.
*/
final class DocumentLoader implements DocumentLoaderInterface
final class DocumentLoader
{
private const SCHEMA_CONTEXT = '{"@context":{"@vocab":"http://schema.org/"}}';

Expand All @@ -34,24 +26,32 @@ final class DocumentLoader implements DocumentLoaderInterface
* @param string $url
*
* @throws JsonLdException
*
* @return RemoteDocument
*/
public function loadDocument($url)
public function loadDocument(string $url): RemoteDocument
{
$trimmed = trim($url);
if (isset($trimmed[0]) && ($trimmed[0] === '{' || $trimmed[0] === '[')) {
return new RemoteDocument($url, Processor::parse($trimmed));
return new RemoteDocument($url, self::parseJson($trimmed));
}

if ($this->isSchemaOrgContext($trimmed)) {
return new RemoteDocument($url, Processor::parse(self::SCHEMA_CONTEXT), 'application/ld+json');
return new RemoteDocument($url, self::parseJson(self::SCHEMA_CONTEXT));
}

throw new JsonLdException('Remote JSON-LD documents are not loaded.');
}

/**
* @return mixed
*/
private static function parseJson(string $json)
{
$document = json_decode($json);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new JsonLdException('Invalid JSON-LD document: '.json_last_error_msg());
}

throw new JsonLdException(
JsonLdException::LOADING_REMOTE_CONTEXT_FAILED,
'Remote JSON-LD documents are not loaded.'
);
return $document;
}

private function isSchemaOrgContext(string $url): bool
Expand Down
Loading