Skip to content

Commit

Permalink
Merge pull request #4 from psalm/resolve-ide-helper-dep
Browse files Browse the repository at this point in the history
Resolving an issue in the plugin where it isn't always bootstrapped.
  • Loading branch information
muglug authored Mar 6, 2019
2 parents a700c89 + e69051b commit 33850a7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
totallyTyped="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config file:///Users/matthewbrown/Desktop/vimeo/git/laravel-psalm-plugin/vendor/vimeo/psalm/config.xsd"
xsi:schemaLocation="https://getpsalm.org/schema/config"
>
<projectFiles>
<directory name="src" />
Expand Down
19 changes: 14 additions & 5 deletions src/Plugin.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php
namespace Psalm\LaravelPlugin;

use Psalm\Plugin\PluginEntryPointInterface;
use Psalm\Plugin\RegistrationInterface;
use SimpleXMLElement;
use Illuminate\Support\ServiceProvider;
use Illuminate\View\Engines\EngineResolver;
use Illuminate\View\Engines\PhpEngine;
use Illuminate\View\Factory;
use Illuminate\View\FileViewFinder;
use Orchestra\Testbench\Concerns\CreatesApplication;
use Psalm\Plugin\PluginEntryPointInterface;
use Psalm\Plugin\RegistrationInterface;
use SimpleXMLElement;

class Plugin implements PluginEntryPointInterface
{
Expand All @@ -20,19 +19,29 @@ class Plugin implements PluginEntryPointInterface
*/
public function __invoke(RegistrationInterface $registration, ?SimpleXMLElement $config = null)
{
$ide_helper_provider = \Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class;

if (file_exists($applicationPath = __DIR__.'/../../../../bootstrap/app.php')) { // Applications
$app = require $applicationPath;
} elseif (file_exists($applicationPath = getcwd().'/bootstrap/app.php')) { // Local Dev
$app = require $applicationPath;
} else { // Packages
$app = (new self)->createApplication();
$app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
$app->register($ide_helper_provider);
}

if ($app instanceof \Illuminate\Contracts\Foundation\Application) {
/** @var \Illuminate\Contracts\Http\Kernel $kernel */
$kernel = $app->make(\Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();

// If we're running a Laravel container, let's see if we need to register the IDE helper if it isn't
// already. If we don't do this, the plugin will crash out because the IDE helper doesn't have configs
// it bootstraps present in the app container.

if (!$app->getProvider($ide_helper_provider)) {
$app->register($ide_helper_provider);
}
}

$fake_filesystem = new FakeFilesystem();
Expand Down

0 comments on commit 33850a7

Please sign in to comment.