[WIP] first draft to guess dependencies from composer's autoloader#91
[WIP] first draft to guess dependencies from composer's autoloader#91
Conversation
8f6addc to
f4e79b1
Compare
f4e79b1 to
326308f
Compare
8386810 to
266391f
Compare
| public function __construct(GuesserInterface ...$guessers) | ||
| { | ||
| $this->guessers[] = new GuessFromLoadedExtensions(); | ||
| foreach ($guessers as $guesser) { |
There was a problem hiding this comment.
$this->guessers = array_merge([new GuessFromLoadedExtensions(), $guessers])
| */ | ||
| private $composerAutoloader; | ||
|
|
||
| private $configVendorDir; |
|
|
||
| public function __construct(string $composerJsonPath) | ||
| { | ||
| $composerJson = json_decode(file_get_contents($composerJsonPath), true); |
There was a problem hiding this comment.
Probably better to require the composer DSL to already be in array shape, instead of adding I/O and nullability in here
| { | ||
| $composerJson = json_decode(file_get_contents($composerJsonPath), true); | ||
| $this->configVendorDir = $this->normalizePath(dirname($composerJsonPath) . '/' . ($composerJson['config']['vendor-dir'] ?? 'vendor')); | ||
| $this->composerAutoloader = include $this->configVendorDir . '/autoload.php'; |
There was a problem hiding this comment.
This is very risky, and it can lead to pre-loading analysed code. So far, the library limited itself to using the AST.
If you need to add composer-based file location, maybe check Roave/BackwardCompatibilityCheck#102, where I implemented an abstraction for PSR-4, PSR-0, classmap and files loading via BetterReflection. Still extremely slow, but since we need such an abstraction in BetterReflection itself, putting efforts there would be better.
Ocramius
left a comment
There was a problem hiding this comment.
Requires rebase rather than merge
This adresses #52
ClassLoader::findFile($class)does not even include the file, it just checks if the Loader finds a file within the configured autoloader config.