mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-19 02:23:11 +00:00
- Improve MetaCommand to allow to ignore some abstract names
- Auto-correct `Method` FQN type name if missing first \ - Implement unit-tests
This commit is contained in:
@@ -39,10 +39,9 @@ class MetaCommand extends Command {
|
||||
protected $view;
|
||||
|
||||
protected $methods = array(
|
||||
'\Illuminate\Foundation\Application::make',
|
||||
'new \Illuminate\Foundation\Application',
|
||||
'\Illuminate\Container\Container::make',
|
||||
//'\Illuminate\Foundation\Application::make',
|
||||
'new \Illuminate\Container\Container',
|
||||
'\Illuminate\Container\Container::make',
|
||||
'\App::make',
|
||||
'app',
|
||||
);
|
||||
@@ -67,8 +66,16 @@ class MetaCommand extends Command {
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
$bindings = array();
|
||||
$bindings = array_flip($this->getAppAliases());
|
||||
$exclude = $this->option('exclude');
|
||||
if (!empty($exclude)) {
|
||||
$exclude = '/' . str_replace('\|', '|', preg_quote($exclude, '/')) . '/';
|
||||
}
|
||||
|
||||
foreach ($this->getAbstracts() as $abstract) {
|
||||
if (!empty($exclude) && preg_match($exclude, $abstract))
|
||||
continue;
|
||||
|
||||
try {
|
||||
$concrete = $this->laravel->make($abstract);
|
||||
if (is_object($concrete)) {
|
||||
@@ -78,6 +85,7 @@ class MetaCommand extends Command {
|
||||
$this->error("Cannot make $abstract: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
asort($bindings);
|
||||
|
||||
$content = $this->view->make('laravel-ide-helper::meta', array(
|
||||
'bindings' => $bindings,
|
||||
@@ -104,6 +112,21 @@ class MetaCommand extends Command {
|
||||
return array_keys($this->laravel->getBindings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of aliases from the Laravel Application.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAppAliases()
|
||||
{
|
||||
static $aliasProp;
|
||||
if (!isset($aliasProp)) {
|
||||
$aliasProp = new \ReflectionProperty('Illuminate\Container\Container', 'aliases');
|
||||
$aliasProp->setAccessible(true);
|
||||
}
|
||||
return $aliasProp->getValue($this->laravel);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -111,6 +134,7 @@ class MetaCommand extends Command {
|
||||
{
|
||||
return array(
|
||||
array('filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the meta file', $this->filename),
|
||||
array('exclude', 'E', InputOption::VALUE_OPTIONAL, 'Laravel bindings to exclude (e.g. "bar.|.foo")'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+10
-2
@@ -24,7 +24,6 @@ class Method
|
||||
/** @var \ReflectionMethod */
|
||||
protected $method;
|
||||
|
||||
protected $output = '';
|
||||
protected $name;
|
||||
protected $namespace;
|
||||
protected $params = array();
|
||||
@@ -230,7 +229,16 @@ class Method
|
||||
*/
|
||||
protected static function convertKeywords($string)
|
||||
{
|
||||
return preg_replace(array('/(^|\|)Closure(\||$)/', '/(^|\|)dynamic(\||$)/'), array('$1\Closure$2', '$1mixed$2'), $string);
|
||||
$types = explode('|', $string);
|
||||
foreach ($types as &$type) {
|
||||
if ($type === 'Closure')
|
||||
$type = '\Closure';
|
||||
elseif ($type === 'dynamic')
|
||||
$type = 'mixed';
|
||||
elseif (strrpos($type, '\\') && $type[0] !== '\\' && (class_exists($type) || interface_exists($type)))
|
||||
$type = '\\' . $type;
|
||||
}
|
||||
return implode('|', $types);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
<?php foreach ($methods as $method): ?>
|
||||
<?= strpos($method, 'new ') === 0 ? $method : $method . '(\'\')' ?> => array(
|
||||
<?php foreach ($bindings as $abstract => $class): ?>
|
||||
'<?= $abstract ?>' instanceof \<?= $class ?>,
|
||||
<?= var_export($abstract, true) ?> instanceof \<?= $class ?>,
|
||||
<?php endforeach ?>
|
||||
),
|
||||
<?php endforeach ?>
|
||||
|
||||
Reference in New Issue
Block a user