DictionaryImportFileResolver
in package
Resolves a dictionary upload to the file an importer should consume.
Web uploads land in a single PHP temp file with no extension, but multi-file
formats like StarDict need their .idx/.dict siblings alongside the
.ifo. Users therefore upload an archive (.zip / .tar.gz / ...), and
this service extracts it, locates the entry-point file by extension, and
hands the importer back a real path it can open.
The service is stateful: each call to resolve() that extracts an
archive registers a temp directory which the caller MUST release via
cleanup() (typically in a finally block). One resolver instance
per request.
Table of Contents
Properties
- $extractor : ArchiveExtractor
- $tempDirs : array<int, string>
Methods
- __construct() : mixed
- cleanup() : void
- Release any temp directories created during resolve() calls.
- resolve() : array{path: string, name: string}
- Resolve the upload to a path/name pair the importer can use.
- expectedExtensionsForFormat() : array<int, string>
- Entry-point file extensions inside an extracted archive, by format.
Properties
$extractor
private
ArchiveExtractor
$extractor
$tempDirs
private
array<int, string>
$tempDirs
= []
Methods
__construct()
public
__construct([ArchiveExtractor|null $extractor = null ]) : mixed
Parameters
- $extractor : ArchiveExtractor|null = null
cleanup()
Release any temp directories created during resolve() calls.
public
cleanup() : void
Idempotent — safe to call multiple times.
resolve()
Resolve the upload to a path/name pair the importer can use.
public
resolve(string $tmpPath, string $originalName, string $format) : array{path: string, name: string}
Parameters
- $tmpPath : string
-
PHP upload tmp_name (e.g. /tmp/phpXXXXXX)
- $originalName : string
-
Original filename submitted by the browser
- $format : string
-
Import format: 'stardict' | 'json' | 'csv'
Tags
Return values
array{path: string, name: string} —Resolved path and display name
expectedExtensionsForFormat()
Entry-point file extensions inside an extracted archive, by format.
private
expectedExtensionsForFormat(string $format) : array<int, string>
Parameters
- $format : string