AssetReferenceExtractor
in package
Extract asset references from HTML and structured iDevice properties.
Tags
Table of Contents
Constants
- ASSET_PATTERN : mixed = '/(?:\{\{context_path\}\}\/)?' . '([^\s"\'<>(),...
Properties
- $archiveLookup : array<string, string>
- $resolutionCache : array<string, string|null>
Methods
- __construct() : mixed
- detectAssetType() : string
- Return the logical asset type for a path.
- extract() : array<int, array<string, mixed>>
- Extract unique referenced assets with their page/iDevice origins.
- findBrokenReferences() : array<int, array<string, mixed>>
- Find asset references that cannot be resolved to archive entries.
- collectStringValues() : void
- Recursively collect string values from decoded JSON properties.
- extractCandidatesFromString() : array<int, string>
- Extract package-like asset reference candidates from arbitrary text.
- extractPathsFromString() : array<int, string>
- Extract canonical package paths from a string.
- normalizePath() : string|null
- Normalize a package path without allowing it to move above the archive root.
- resolveArchivePath() : string|null
- Resolve a reference to the canonical path stored in the archive.
- resolveArchivePathUncached() : string|null
- Resolve an uncached asset reference against archive entries.
Constants
ASSET_PATTERN
private
mixed
ASSET_PATTERN
= '/(?:\{\{context_path\}\}\/)?' . '([^\s"\'<>(),]+\.(?:png|jpe?g|gif|svg|webp|bmp|mp3|wav|ogg|m4a|mp4|webm|ogv|' . 'pdf|docx?|xlsx?|pptx?|odt|ods|odp|zip)(?:[?#][^\s"\'<>(),]*)?)/iu'
Properties
$archiveLookup
private
array<string, string>
$archiveLookup
= []
$resolutionCache
private
array<string, string|null>
$resolutionCache
= []
Methods
__construct()
public
__construct(array<int, string> $archiveEntries) : mixed
Parameters
- $archiveEntries : array<int, string>
-
Archive entry names.
detectAssetType()
Return the logical asset type for a path.
public
detectAssetType(string $path) : string
Parameters
- $path : string
-
Asset path.
Return values
stringextract()
Extract unique referenced assets with their page/iDevice origins.
public
extract(array<int, array<string, mixed>> $pages) : array<int, array<string, mixed>>
Parameters
- $pages : array<int, array<string, mixed>>
-
Parsed pages.
Return values
array<int, array<string, mixed>>findBrokenReferences()
Find asset references that cannot be resolved to archive entries.
public
findBrokenReferences(array<int, array<string, mixed>> $pages) : array<int, array<string, mixed>>
Parameters
- $pages : array<int, array<string, mixed>>
-
Parsed pages.
Return values
array<int, array<string, mixed>>collectStringValues()
Recursively collect string values from decoded JSON properties.
private
collectStringValues(mixed $value, array<int, string> &$strings) : void
Parameters
- $value : mixed
-
Value to inspect.
- $strings : array<int, string>
-
Collected strings.
extractCandidatesFromString()
Extract package-like asset reference candidates from arbitrary text.
private
extractCandidatesFromString(string $source) : array<int, string>
Parameters
- $source : string
-
HTML, CSS, JSON value, or other text.
Return values
array<int, string>extractPathsFromString()
Extract canonical package paths from a string.
private
extractPathsFromString(string $source) : array<int, string>
Parameters
- $source : string
-
HTML, CSS, JSON value, or other text.
Return values
array<int, string>normalizePath()
Normalize a package path without allowing it to move above the archive root.
private
normalizePath(string $path) : string|null
Parameters
- $path : string
-
Raw path.
Return values
string|nullresolveArchivePath()
Resolve a reference to the canonical path stored in the archive.
private
resolveArchivePath(string $candidate) : string|null
Parameters
- $candidate : string
-
Raw asset reference.
Return values
string|nullresolveArchivePathUncached()
Resolve an uncached asset reference against archive entries.
private
resolveArchivePathUncached(string $candidate) : string|null
Parameters
- $candidate : string
-
Raw asset reference.