Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Valitron doesn't work in phar #314

Open
Moult opened this issue May 24, 2020 · 2 comments
Open

Valitron doesn't work in phar #314

Moult opened this issue May 24, 2020 · 2 comments

Comments

@Moult
Copy link

Moult commented May 24, 2020

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?

@willemwollebrants
Copy link
Collaborator

Can you check if it works when you replace

if (stream_resolve_include_path($langFile)) {

with

if (stream_resolve_include_path(realpath($langFile))) {

?

@Moult
Copy link
Author

Moult commented May 26, 2020

@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/" 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants