Issues

ZF2-532: ClassMapAutoloader::realPharPath() rejects valid phar scheme

Issue Type: Bug Created: 2012-09-08T14:00:59.000+0000 Last Updated: 2012-10-08T20:14:37.000+0000 Status: Closed Fix version(s): Reporter: Robert Fisher (fwrmedia) Assignee: Matthew Weier O'Phinney (matthew) Tags: -

Related issues: Attachments:

Description

While testing phar based modules I ran into the following: - System: Apache/2.4.2 (Win32) PHP/5.4.5

Errors: Warning: include(): Filename cannot be empty in C:\SOME_PATH\vendor\ZF2\library\Zend\Loader\ClassMapAutoloader.php on line 185

Warning: include(): Failed opening '' for inclusion (include_path='phar://C:\SOME_PATH\module\Album.phar;.;C:\php\pear') in C:\SOME_PATH\vendor\ZF2\library\Zend\Loader\ClassMapAutoloader.php on line 185

Fatal error: Uncaught exception 'Zend\Loader\Exception\InvalidArgumentException' with message 'Map file provided does not return a map.

The path injected into ClassMapAutoloader::realPharPath() was: -

phar://C/SOME_PATH/module/…

This the function returns void as phar:/// does not exist at strpos position 0.

With the strpos adjusted as a test the substr length is then incorrect.

The following seems to work as intended: -

<pre class="highlight">
    public static function realPharPath($path)
    {
        // If phar:// does not exist in the string at position 0 then return
        if (strpos($path, 'phar://') !== 0) {
            return;
        }
        // We need the correct substr length for phar:// | <a>phar:///</a>
        $substr_length = (strpos($path, '<a>phar:///</a>') === false) ? 7 : 8;
        $parts = explode('/', str_replace(array('/','\\'), '/', substr($path, $substr_length)));
        $parts = array_values(array_filter($parts, function($p) { return ($p !== '' && $p !== '.'); }));

        array_walk($parts, function ($value, $key) use(&$parts) {
            if ($value === '..') {
                unset($parts[$key], $parts[$key-1]);
                $parts = array_values($parts);
            }
        });
        // Adjust phar scheme for full path or alias
        $phar_scheme = ($substr_length === 8) ? '<a>phar:///</a>' : 'phar://';
        if (file_exists($realPath = $phar_scheme . implode('/', $parts))) {
            return $realPath;
        }
    }

Comments

Posted by Ralph Schindler (ralph) on 2012-10-08T20:14:37.000+0000

This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit: https://github.com/zendframework/zf2/issues/2566

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts