larastan: Larastan is not auto-registering service providers in packages.
- Larastan Version: v2.2.0
Description
Upon investigation i found the getVendorDir static method here:
https://github.com/nunomaduro/larastan/blob/master/src/ApplicationResolver.php#L39
When i do
/**
* Creates an application and registers service providers found.
*
* @return \Illuminate\Contracts\Foundation\Application
*
* @throws \ReflectionException
*/
public static function resolve(): Application
{
$app = (new self)->createApplication();
$vendorDir = self::getVendorDir() ?? getcwd().DIRECTORY_SEPARATOR.'vendor';
$composerConfigPath = dirname($vendorDir).DIRECTORY_SEPARATOR.'composer.json';
var_dump($composerConfigPath, $app->basePath());
// ...
i get this output:
string(101) "phar:///home/brad/code/esb-workspace/esb-foundation/vendor/phpstan/phpstan/phpstan.phar/composer.json"
string(84) "/home/brad/code/esb-workspace/esb-foundation/vendor/orchestra/testbench-core/laravel"
it appears that getVendorDir is returning the vendor dir of the PHPStan phar, rather than the local project. This causes larastan to read the composer.json from there, and fail to auto-register service providers.
This package used to work in the past (i’m not sure what version of phpstan / larastan) so along the way a change to phpstan / larastan has caused this to happen.
I suspect this is the root of my view-string issue i posted a while ago.
Not sure how you’d go about fixing this as i’m not super familiar with the bootstrapping of larastan (yet)
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 33 (15 by maintainers)
Just an idea, I added a ComposerHelper class to PHPStan a while back: https://github.com/phpstan/phpstan-src/blob/5cf39bc960b4b9dbc01be6906cbc1d71285118f7/src/Internal/ComposerHelper.php
Could we use the same logic here also?
@crynobone We are trying to find the service provider of the root package and register it.
In the Testbench documentation it’s stated that
Do you have any advice for that? Our current solution is really hacky and involves reading the
composer.jsongetting the autoloaders, creating class maps from that, then trying to find the service providers 🤢yeah it does: