Skip to content

Load from the composer autoload - #4

Open
marc-jan wants to merge 3 commits into
thecodingmachine:1.1from
gekvansoftware:autoload
Open

Load from the composer autoload#4
marc-jan wants to merge 3 commits into
thecodingmachine:1.1from
gekvansoftware:autoload

Conversation

@marc-jan

Copy link
Copy Markdown

I created an extra method createFromComposerAutoload to load the ClassNameMapper with data of the composer autoloader.

If you use the createFromComposerFile method you only get the specific information of your custom added autoloading. With the new loading option you can also get information of namespaces in vendor packages.

I hope you like it.

@coveralls

coveralls commented Oct 4, 2019

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.8%) to 73.016% when pulling ded017c on gek-van-software:autoload into fa32a0e on thecodingmachine:1.0.

@fezfez

fezfez commented Nov 14, 2019

Copy link
Copy Markdown

+1 i need this for cause i publish shared package that use location of class (https://github.com/thecodingmachine/graphqlite). (ci fail not related)

@fezfez

Copy link
Copy Markdown

@moufmouf : can you check this ?

@marc-jan

Copy link
Copy Markdown
Author

@moufmouf Can you please check this? Same as @fezfez I'm creating shared composer packages where I plugin a package to graphqlite.

@moufmouf

Copy link
Copy Markdown
Member

Hey guys! I'm absolutely sorry, I don't know how I missed this PR. I'm having a look at it right now!

@moufmouf

Copy link
Copy Markdown
Member

Ok, I was worried that the new code might break when Composer 2 is released.
Looking at the code base for Composer 2, so far, the autoloader has the same methods in Composer 2:
https://github.com/composer/composer/blob/2.0/src/Composer/Autoload/ClassLoader.php

So this PR looks great!

@moufmouf
moufmouf changed the base branch from 1.0 to 1.1January 22, 2020 17:23
@moufmouf

Copy link
Copy Markdown
Member

I did a few more tests and this PR still needs some work I think.

In particular, it will fail if the composer autoloader is generated with an authoritative classmap:

composer dumpautoload --classmap-authoritative

In this case, every reference to PSR-0 or PSR-4 is stripped from the Composer autoloader. I'm sure we kind find a workaround around this, but this is still to be developed.

@marc-jan

Copy link
Copy Markdown
Author

@moufmouf Good one. I will have a look at it.

@marc-jan

Copy link
Copy Markdown
Author

@moufmouf Also did some tests with --classmap-authoritative enabled and disabled in several projects and I'm always getting good/same results. Am I missing something?

@moufmouf

Copy link
Copy Markdown
Member

Hey @marc-jangvs ,

Thanks a lot for your reactivity.

Ok. I'm not 100% sure that classmap-authoritative is having an impact.

Actually, I'm having trouble making this work. The Composer autoloader seems to behave in a weird way.

I changed your unit test to load the "real" autoloader from Composer (rather than the test autoloader you wrote).

ee76481

This should work, but it fails. Having a look at what is going on, I realize that (in my case), the $loader->getPrefixesPsr4() method returns only the Psr4 namespaces from dependencies (and not from composer.json).

Did you manage to have this working for dependencies AND for project files?

@marc-jan

Copy link
Copy Markdown
Author

@moufmouf Hm that is strange. I'm using it in combination with the GraphqLite package and for example I have a simple PingController in a generic package inside vendor. Also I have some controllers inside my project that I configured inside my composer.json in the autoload section with:

{ "autoload": { "psr-4": { "App\\": "src/App/src/" } } }

$loader->getPrefixesPsr4() returns both namespaces with or without --classmap-authoritative.

Didn't do anything else to make it work.

@fezfez

Copy link
Copy Markdown

Any news on this?

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@marc-jan@coveralls@fezfez@moufmouf