Fix #1 by improving plugin initialisation

This commit is contained in:
Matthew Brown 2019-02-20 01:33:01 -05:00
parent c6175bb1db
commit fa8b578101
3 changed files with 47 additions and 45 deletions

2
.gitignore vendored
View File

@ -1,5 +1,5 @@
composer.phar
/vendor/
composer.lock
/cache/*.php
src/cache/*.php
.DS_Store

View File

@ -7,7 +7,8 @@
"symfony/psr-http-message-bridge": "^1.0",
"vimeo/psalm": "^3.0.17 || ^3.1",
"league/flysystem-aws-s3-v3": "^1.0",
"orchestra/testbench": "^3.7"
"orchestra/testbench": "^3.7",
"predis/predis": "^1.0",
},
"license": "MIT",
"authors": [

View File

@ -13,70 +13,71 @@ use Orchestra\Testbench\Concerns\CreatesApplication;
class Plugin implements PluginEntryPointInterface
{
use CreatesApplication;
use CreatesApplication;
/**
* @return void
*/
public function __invoke(RegistrationInterface $registration, ?SimpleXMLElement $config = null)
{
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();
}
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);
}
if ($app instanceof \Illuminate\Contracts\Foundation\Application) {
if ($app instanceof \Illuminate\Contracts\Foundation\Application) {
/** @var \Illuminate\Contracts\Http\Kernel $kernel */
$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(
$app['config'],
$fake_filesystem,
$view_factory
);
$stubs_generator_command = new \Barryvdh\LaravelIdeHelper\Console\GeneratorCommand(
$app['config'],
$fake_filesystem,
$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(
new \Symfony\Component\Console\Input\ArrayInput([]),
new \Symfony\Component\Console\Output\NullOutput()
);
$stubs_generator_command->run(
new \Symfony\Component\Console\Input\ArrayInput([]),
new \Symfony\Component\Console\Output\NullOutput()
);
/** @psalm-suppress InvalidArgument */
$meta_generator_command = new FakeMetaCommand(
$fake_filesystem,
$view_factory,
$app['config']
);
$meta_generator_command = new FakeMetaCommand(
$fake_filesystem,
$view_factory,
$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(
new \Symfony\Component\Console\Input\ArrayInput([]),
new \Symfony\Component\Console\Output\NullOutput()
);
$meta_generator_command->run(
new \Symfony\Component\Console\Input\ArrayInput([]),
new \Symfony\Component\Console\Output\NullOutput()
);
$registration->addStubFile($cache_dir . 'stubs.php');
$registration->addStubFile($cache_dir . 'meta.php');
$registration->addStubFile($cache_dir . 'stubs.php');
$registration->addStubFile($cache_dir . 'meta.php');
require_once 'ReturnTypeProvider/AuthReturnTypeProvider.php';
$registration->registerHooksFromClass(ReturnTypeProvider\AuthReturnTypeProvider::class);
require_once 'ReturnTypeProvider/TransReturnTypeProvider.php';
$registration->registerHooksFromClass(ReturnTypeProvider\AuthReturnTypeProvider::class);
require_once 'ReturnTypeProvider/TransReturnTypeProvider.php';
$registration->registerHooksFromClass(ReturnTypeProvider\TransReturnTypeProvider::class);
require_once 'ReturnTypeProvider/ViewReturnTypeProvider.php';
$registration->registerHooksFromClass(ReturnTypeProvider\ViewReturnTypeProvider::class);
@ -86,15 +87,15 @@ class Plugin implements PluginEntryPointInterface
\Illuminate\Contracts\Foundation\Application $app,
FakeFilesystem $fake_filesystem
) : 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) {
throw new \UnexpectedValueException('Service helper should have a file path');
}
$resolver = new EngineResolver();
$resolver = new EngineResolver();
$resolver->register('php', function () : PhpEngine {
return new PhpEngine();
});