forked from barryvdh/laravel-ide-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
/** | ||
* Laravel IDE Helper Generator | ||
* | ||
* @author Barry vd. Heuvel <[email protected]> | ||
* @copyright 2015 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl) | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT | ||
* @link https://github.com/barryvdh/laravel-ide-helper | ||
*/ | ||
|
||
namespace Barryvdh\LaravelIdeHelper\Console; | ||
|
||
use Illuminate\Console\Command; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
/** | ||
* A command to generate phpstorm meta data | ||
* | ||
* @author Barry vd. Heuvel <[email protected]> | ||
*/ | ||
class MetaCommand extends Command { | ||
|
||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'ide-helper:meta'; | ||
protected $filename = '.phpstorm.meta.php'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Generate metadata for PhpStorm'; | ||
|
||
/** @var \Illuminate\Filesystem\Filesystem */ | ||
protected $files; | ||
|
||
/** @var \Illuminate\View\Factory */ | ||
protected $view; | ||
|
||
/** | ||
* | ||
* @param \Illuminate\Filesystem\Filesystem $files | ||
* @param \Illuminate\View\Factory $view | ||
*/ | ||
public function __construct($files, $view) { | ||
$this->files = $files; | ||
$this->view = $view; | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function fire() | ||
{ | ||
$filename = $this->option('filename'); | ||
|
||
$bindings = array(); | ||
|
||
foreach ($this->laravel->getBindings() as $abstract => $options) { | ||
try { | ||
$concrete = $this->laravel->make($abstract); | ||
if (is_object($concrete)) { | ||
$bindings[$abstract] = get_class($concrete); | ||
} | ||
}catch (\Exception $e) { | ||
$this->error("Cannot make $abstract: ".$e->getMessage()); | ||
} | ||
} | ||
$content = $this->view->make('laravel-ide-helper::meta', ['bindings' => $bindings])->render(); | ||
$written = $this->files->put($filename, $content); | ||
|
||
if ($written !== false) { | ||
$this->info("A new meta file was written to $filename"); | ||
} else { | ||
$this->error("The meta file could not be created at $filename"); | ||
} | ||
} | ||
|
||
/** | ||
* Get the console command options. | ||
* | ||
* @return array | ||
*/ | ||
protected function getOptions() | ||
{ | ||
return array( | ||
array('filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the meta file', $this->filename), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?= '<?php' ?> namespace PHPSTORM_META { | ||
|
||
/** | ||
* PhpStorm Meta file, to provide autocomplete information for PhpStorm | ||
* Generated on <?= date("Y-m-d") ?>. | ||
* | ||
* @author Barry vd. Heuvel <[email protected]> | ||
* @see https://github.com/barryvdh/laravel-ide-helper | ||
*/ | ||
|
||
/** @noinspection PhpUnusedLocalVariableInspection */ | ||
/** @noinspection PhpIllegalArrayKeyTypeInspection */ | ||
$STATIC_METHOD_TYPES = [ | ||
\App::make('') => [ | ||
<?php foreach($bindings as $abstract => $class): ?> | ||
'<?= $abstract ?>' instanceof \<?= $class ?>, | ||
<?php endforeach ?> ], | ||
app('') => [ | ||
<?php foreach($bindings as $abstract => $class): ?> | ||
'<?= $abstract ?>' instanceof \<?= $class ?>, | ||
<?php endforeach ?> ], | ||
]; | ||
|
||
} |