AssetPathResolver
in package
Converts a relative (public) asset path to an absolute path on disk, so that the {@see \App\Core\Base\Shared\System\Models\Entities\Asset} entity can check that the file exists ({@see \App\Core\Base\Shared\System\Models\ValueObjects\AssetVariant::exists()}).
The entity has no DI, so this is a static helper initialized once at boot (init()).
Without initialization toAbsolute() returns null (and exists() safely false).
The logic mirrors relToAbs in the asset backfill services (appWwwDir.rel prefix
/www/ to appWwwDir.abs %wwwDir%/).
Table of Contents
Constants
- PRIVATE_PDF_REL : string = '/www/private/pdf/'
- Root of private invoice PDFs (relative, as the `invoice.pdf` value in the DB).
Properties
- $wwwDirAbs : string|null
- $wwwDirRel : string
Methods
- init() : void
- toAbsolute() : string|null
- Relative path (from `appWwwDir.rel`, e.g. `/www/modules/...`) to an absolute path on disk.
- toAbsoluteWithin() : string|null
- Like {@see toAbsolute()}, but the file must exist and, after canonicalization (`realpath`, symlinks resolved), lie inside `$baseRel` (see {@see \App\UI\Api\Eshop\Models\Import\ImportFilePath}).
- toPrivatePdfAbsolute() : string|null
- Private invoice PDFs (`/www/private/pdf/...`): {@see toAbsoluteWithin()} with a fixed root.
- __construct() : mixed
- hasTraversal() : bool
Constants
PRIVATE_PDF_REL
Root of private invoice PDFs (relative, as the `invoice.pdf` value in the DB).
public
string
PRIVATE_PDF_REL
= '/www/private/pdf/'
Properties
$wwwDirAbs
private
static string|null
$wwwDirAbs
= null
$wwwDirRel
private
static string
$wwwDirRel
= '/www/'
Methods
init()
public
static init(string $wwwDirAbs, string $wwwDirRel) : void
Parameters
- $wwwDirAbs : string
- $wwwDirRel : string
toAbsolute()
Relative path (from `appWwwDir.rel`, e.g. `/www/modules/...`) to an absolute path on disk.
public
static toAbsolute(string $rel) : string|null
Returns null when the helper is not initialized or the path is empty.
Parameters
- $rel : string
Return values
string|nulltoAbsoluteWithin()
Like {@see toAbsolute()}, but the file must exist and, after canonicalization (`realpath`, symlinks resolved), lie inside `$baseRel` (see {@see \App\UI\Api\Eshop\Models\Import\ImportFilePath}).
public
static toAbsoluteWithin(string $rel, string $baseRel) : string|null
For private files served through a proxy (invoice PDFs, attachments), so that a DB value cannot point to configuration or a foreign file outside the dedicated folder.
Returns null when the path is invalid, the file does not exist or lies outside $baseRel.
Parameters
- $rel : string
- $baseRel : string
Return values
string|nulltoPrivatePdfAbsolute()
Private invoice PDFs (`/www/private/pdf/...`): {@see toAbsoluteWithin()} with a fixed root.
public
static toPrivatePdfAbsolute(string $rel) : string|null
Parameters
- $rel : string
Return values
string|null__construct()
private
__construct() : mixed
hasTraversal()
private
static hasTraversal(string $rel) : bool
Parameters
- $rel : string