From f518de4ae19be0e727f5e6ab29973b5f74ab58a9 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Tue, 17 Mar 2015 08:57:14 +0100 Subject: [PATCH] Filter abstracts for common errors Fixes #184 --- src/Console/MetaCommand.php | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/Console/MetaCommand.php b/src/Console/MetaCommand.php index 349aeab..7735014 100644 --- a/src/Console/MetaCommand.php +++ b/src/Console/MetaCommand.php @@ -35,10 +35,10 @@ class MetaCommand extends Command { */ protected $description = 'Generate metadata for PhpStorm'; - /** @var \Illuminate\Filesystem\Filesystem */ + /** @var \Illuminate\Contracts\Filesystem\Filesystem */ protected $files; - /** @var \Illuminate\View\Factory */ + /** @var \Illuminate\Contracts\View\Factory */ protected $view; protected $methods = [ @@ -52,8 +52,8 @@ class MetaCommand extends Command { /** * - * @param \Illuminate\Filesystem\Filesystem $files - * @param \Illuminate\View\Factory $view + * @param \Illuminate\Contracts\Filesystem\Filesystem $files + * @param \Illuminate\Contracts\View\Factory $view */ public function __construct($files, $view) { $this->files = $files; @@ -68,11 +68,8 @@ class MetaCommand extends Command { */ public function fire() { - $filename = $this->option('filename'); - $bindings = array(); - - foreach ($this->laravel->getBindings() as $abstract => $options) { + foreach ($this->getAbstracts() as $abstract) { try { $concrete = $this->laravel->make($abstract); if (is_object($concrete)) { @@ -88,6 +85,7 @@ class MetaCommand extends Command { 'methods' => $this->methods, ])->render(); + $filename = $this->option('filename'); $written = $this->files->put($filename, $content); if ($written !== false) { @@ -97,6 +95,29 @@ class MetaCommand extends Command { } } + /** + * Get a filtered list of abstracts from the Laravel Application. + * + * @return array + */ + protected function getAbstracts() + { + $abstracts = $this->laravel->getBindings(); + + // Remove the S3 cloud driver when not available + if (config('filesystems.cloud') === 's3' && !class_exists('League\Flysystem\AwsS3v2\AwsS3Adapter')) { + unset($abstracts['filesystem.cloud']); + } + + // Remove Redis when not available + if (isset($abstracts['redis']) && !class_exists('Predis\Client')) { + unset($abstracts['redis']); + } + + // Return the abstract names only + return array_keys($abstracts); + } + /** * Get the console command options. *