Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Errors when installing package that defines multiple Paths for a PSR-4 Autoload #40

Closed
wants to merge 1 commit into from

Conversation

Mezzle
Copy link
Contributor

@Mezzle Mezzle commented Nov 2, 2017

In the file

https://github.com/zendframework/zend-component-installer/blob/master/src/ComponentInstaller.php#L256

This assumes that each PSR-4 Autoload item mentioned in the composer config is a singular item - so they are defined as such:-

{
    "autoload": {
        "psr-4": {
            "Monolog\\": "src/",
            "Vendor\\Namespace\\": ""
        }
    }
}

However, the Composer configuration allows that the path for the code be able to be both a string, and an array - e.g.

{
    "autoload": {
        "psr-4": { "Monolog\\": ["src/", "lib/"] }
    }
}

When defined with an array of paths, and a config provider, this causes the code to error out and the installation to fail.

Whilst this can be fixed in the package (e.g. Mezzle/queuejitsu@17f17a7 ) - this isn't always going to be possible, and should allow for any valid composer configuration to work.

@Ocramius
Copy link
Member

Hah, I didn't even know that multiple paths were valid there. An (array) cast on each psr-4 entry should deal with this.

@Mezzle
Copy link
Contributor Author

Mezzle commented Oct 19, 2017

Yeah, it's pretty much changing

foreach ($map as $namespace => $path) {

to something like

foreach ($map as $namespace => $paths) {
    $paths = (array)$paths;
    foreach ($paths as $path) {

@weierophinney
Copy link
Member

@Mezzle Would you be willing to create a pull request for this change?

@Mezzle
Copy link
Contributor Author

Mezzle commented Nov 2, 2017

@weierophinney converted.

@michalbundyra
Copy link
Member

@Mezzle @weierophinney I think it will be nice to have some tests for it as well...

@Mezzle
Copy link
Contributor Author

Mezzle commented Nov 2, 2017

I've not the time to write them at the moment - don't know when I'll be able to get round to writing some - so if in the meantime anyone wants to - feel free!

weierophinney added a commit to weierophinney/zend-component-installer that referenced this pull request Nov 6, 2017
This patch adds tests to cover zendframework#40. Specifically, it ensures that the
installer will loop through all paths for each autoloader namespace
entry, whether it's a single path or multiple paths, in order to
determine if it has any module dependencies.
weierophinney added a commit that referenced this pull request Nov 6, 2017
Also removes empty 1.0.1 stub as it will not be used.
@weierophinney
Copy link
Member

Thanks, @Mezzle. I added tests and did some refactoring, which I pushed as #44. The fix will release with 1.1.0.

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

Successfully merging this pull request may close these issues.

4 participants