mirror of
https://github.com/danog/psalm-plugin-laravel.git
synced 2024-11-30 04:39:01 +01:00
Fix #1 by improving plugin initialisation
This commit is contained in:
parent
c6175bb1db
commit
fa8b578101
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,5 @@
|
|||||||
composer.phar
|
composer.phar
|
||||||
/vendor/
|
/vendor/
|
||||||
composer.lock
|
composer.lock
|
||||||
/cache/*.php
|
src/cache/*.php
|
||||||
.DS_Store
|
.DS_Store
|
@ -7,7 +7,8 @@
|
|||||||
"symfony/psr-http-message-bridge": "^1.0",
|
"symfony/psr-http-message-bridge": "^1.0",
|
||||||
"vimeo/psalm": "^3.0.17 || ^3.1",
|
"vimeo/psalm": "^3.0.17 || ^3.1",
|
||||||
"league/flysystem-aws-s3-v3": "^1.0",
|
"league/flysystem-aws-s3-v3": "^1.0",
|
||||||
"orchestra/testbench": "^3.7"
|
"orchestra/testbench": "^3.7",
|
||||||
|
"predis/predis": "^1.0",
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
|
@ -13,70 +13,71 @@ use Orchestra\Testbench\Concerns\CreatesApplication;
|
|||||||
|
|
||||||
class Plugin implements PluginEntryPointInterface
|
class Plugin implements PluginEntryPointInterface
|
||||||
{
|
{
|
||||||
use CreatesApplication;
|
use CreatesApplication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __invoke(RegistrationInterface $registration, ?SimpleXMLElement $config = null)
|
public function __invoke(RegistrationInterface $registration, ?SimpleXMLElement $config = null)
|
||||||
{
|
{
|
||||||
if (file_exists($applicationPath = __DIR__.'/../../../bootstrap/app.php')) { // Applications
|
if (file_exists($applicationPath = __DIR__.'/../../../../bootstrap/app.php')) { // Applications
|
||||||
$app = require $applicationPath;
|
$app = require $applicationPath;
|
||||||
} elseif (file_exists($applicationPath = getcwd().'/bootstrap/app.php')) { // Local Dev
|
} elseif (file_exists($applicationPath = getcwd().'/bootstrap/app.php')) { // Local Dev
|
||||||
$app = require $applicationPath;
|
$app = require $applicationPath;
|
||||||
} else { // Packages
|
} else { // Packages
|
||||||
$app = (new self)->createApplication();
|
$app = (new self)->createApplication();
|
||||||
}
|
$app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
|
||||||
|
}
|
||||||
|
|
||||||
if ($app instanceof \Illuminate\Contracts\Foundation\Application) {
|
if ($app instanceof \Illuminate\Contracts\Foundation\Application) {
|
||||||
/** @var \Illuminate\Contracts\Http\Kernel $kernel */
|
/** @var \Illuminate\Contracts\Http\Kernel $kernel */
|
||||||
$kernel = $app->make(\Illuminate\Contracts\Console\Kernel::class);
|
$kernel = $app->make(\Illuminate\Contracts\Console\Kernel::class);
|
||||||
$kernel->bootstrap();
|
$kernel->bootstrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
$fake_filesystem = new FakeFilesystem();
|
$fake_filesystem = new FakeFilesystem();
|
||||||
|
|
||||||
$view_factory = $this->getViewFactory($app, $fake_filesystem);
|
$view_factory = $this->getViewFactory($app, $fake_filesystem);
|
||||||
|
|
||||||
$stubs_generator_command = new \Barryvdh\LaravelIdeHelper\Console\GeneratorCommand(
|
$stubs_generator_command = new \Barryvdh\LaravelIdeHelper\Console\GeneratorCommand(
|
||||||
$app['config'],
|
$app['config'],
|
||||||
$fake_filesystem,
|
$fake_filesystem,
|
||||||
$view_factory
|
$view_factory
|
||||||
);
|
);
|
||||||
|
|
||||||
$stubs_generator_command->setLaravel($app);
|
$stubs_generator_command->setLaravel($app);
|
||||||
|
|
||||||
$cache_dir = __DIR__ . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
|
$cache_dir = __DIR__ . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
|
||||||
|
|
||||||
$fake_filesystem->setDestination($cache_dir . 'stubs.php');
|
$fake_filesystem->setDestination($cache_dir . 'stubs.php');
|
||||||
|
|
||||||
$stubs_generator_command->run(
|
$stubs_generator_command->run(
|
||||||
new \Symfony\Component\Console\Input\ArrayInput([]),
|
new \Symfony\Component\Console\Input\ArrayInput([]),
|
||||||
new \Symfony\Component\Console\Output\NullOutput()
|
new \Symfony\Component\Console\Output\NullOutput()
|
||||||
);
|
);
|
||||||
|
|
||||||
/** @psalm-suppress InvalidArgument */
|
/** @psalm-suppress InvalidArgument */
|
||||||
$meta_generator_command = new FakeMetaCommand(
|
$meta_generator_command = new FakeMetaCommand(
|
||||||
$fake_filesystem,
|
$fake_filesystem,
|
||||||
$view_factory,
|
$view_factory,
|
||||||
$app['config']
|
$app['config']
|
||||||
);
|
);
|
||||||
|
|
||||||
$meta_generator_command->setLaravel($app);
|
$meta_generator_command->setLaravel($app);
|
||||||
|
|
||||||
$fake_filesystem->setDestination($cache_dir . 'meta.php');
|
$fake_filesystem->setDestination($cache_dir . 'meta.php');
|
||||||
|
|
||||||
$meta_generator_command->run(
|
$meta_generator_command->run(
|
||||||
new \Symfony\Component\Console\Input\ArrayInput([]),
|
new \Symfony\Component\Console\Input\ArrayInput([]),
|
||||||
new \Symfony\Component\Console\Output\NullOutput()
|
new \Symfony\Component\Console\Output\NullOutput()
|
||||||
);
|
);
|
||||||
|
|
||||||
$registration->addStubFile($cache_dir . 'stubs.php');
|
$registration->addStubFile($cache_dir . 'stubs.php');
|
||||||
$registration->addStubFile($cache_dir . 'meta.php');
|
$registration->addStubFile($cache_dir . 'meta.php');
|
||||||
|
|
||||||
require_once 'ReturnTypeProvider/AuthReturnTypeProvider.php';
|
require_once 'ReturnTypeProvider/AuthReturnTypeProvider.php';
|
||||||
$registration->registerHooksFromClass(ReturnTypeProvider\AuthReturnTypeProvider::class);
|
$registration->registerHooksFromClass(ReturnTypeProvider\AuthReturnTypeProvider::class);
|
||||||
require_once 'ReturnTypeProvider/TransReturnTypeProvider.php';
|
require_once 'ReturnTypeProvider/TransReturnTypeProvider.php';
|
||||||
$registration->registerHooksFromClass(ReturnTypeProvider\TransReturnTypeProvider::class);
|
$registration->registerHooksFromClass(ReturnTypeProvider\TransReturnTypeProvider::class);
|
||||||
require_once 'ReturnTypeProvider/ViewReturnTypeProvider.php';
|
require_once 'ReturnTypeProvider/ViewReturnTypeProvider.php';
|
||||||
$registration->registerHooksFromClass(ReturnTypeProvider\ViewReturnTypeProvider::class);
|
$registration->registerHooksFromClass(ReturnTypeProvider\ViewReturnTypeProvider::class);
|
||||||
@ -86,15 +87,15 @@ class Plugin implements PluginEntryPointInterface
|
|||||||
\Illuminate\Contracts\Foundation\Application $app,
|
\Illuminate\Contracts\Foundation\Application $app,
|
||||||
FakeFilesystem $fake_filesystem
|
FakeFilesystem $fake_filesystem
|
||||||
) : Factory {
|
) : Factory {
|
||||||
$service_helper_reflection = new \ReflectionClass(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
|
$service_helper_reflection = new \ReflectionClass(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
|
||||||
|
|
||||||
$file_path = $service_helper_reflection->getFileName();
|
$file_path = $service_helper_reflection->getFileName();
|
||||||
|
|
||||||
if (!$file_path) {
|
if (!$file_path) {
|
||||||
throw new \UnexpectedValueException('Service helper should have a file path');
|
throw new \UnexpectedValueException('Service helper should have a file path');
|
||||||
}
|
}
|
||||||
|
|
||||||
$resolver = new EngineResolver();
|
$resolver = new EngineResolver();
|
||||||
$resolver->register('php', function () : PhpEngine {
|
$resolver->register('php', function () : PhpEngine {
|
||||||
return new PhpEngine();
|
return new PhpEngine();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user