valitron
valitron copied to clipboard
Valitron doesn't work in phar
When it is packaged in a phar, it gets upset.
Message: Fail to load language file 'phar:///path/to/my.phar/vendor/vlucas/valitron/lang/en.php'
File: phar:///path/to/my.phar/vendor/vlucas/valitron/src/Valitron/Validator.php
Line: 113
The lines in question:
if (stream_resolve_include_path($langFile)) {
$langMessages = include $langFile;
static::$_ruleMessages = array_merge(static::$_ruleMessages, $langMessages);
} else {
throw new \InvalidArgumentException("Fail to load language file '" . $langFile . "'");
}
It seems as though stream_resolve_include_path returns false when in a phar, because $langDir returns a phar:///path/to/lang/.
Maybe is_file is a solution?
Can you check if it works when you replace
if (stream_resolve_include_path($langFile)) {
with
if (stream_resolve_include_path(realpath($langFile))) {
?
@willemwollebrants you are correct, that'll fix it. But I'm not sure if it's the right way to fix it.
E.g.
$langFile = 'phar:///path/to/my.phar/vendor/vlucas/valitron/lang/en.php';
var_dump(realpath($langFile)); // bool(false)
var_dump(stream_resolve_include_path(realpath($langFile)); // string "phar:///path/to/my.phar/vendor/"