mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 01:57:13 +00:00
Work on interfaces
This commit is contained in:
+4
-2
@@ -23,10 +23,12 @@ class Alias
|
||||
protected $methods = array();
|
||||
protected $used_methods = array();
|
||||
protected $valid = false;
|
||||
protected $interfaces = array();
|
||||
|
||||
public function __construct($alias, $facade)
|
||||
public function __construct($alias, $facade, $interfaces = array())
|
||||
{
|
||||
$this->alias = $alias;
|
||||
$this->interfaces = $interfaces;
|
||||
|
||||
// Make the class absolute
|
||||
$facade = '\\' . ltrim($facade, '\\');
|
||||
@@ -223,7 +225,7 @@ class Alias
|
||||
// Only add the methods to the output when the root is not the same as the facade.
|
||||
// And don't add the __*() methods
|
||||
if ($this->facade !== $this->root && substr($method->name, 0, 2) !== '__') {
|
||||
$this->methods[] = new Method($method, $this->alias, $reflection);
|
||||
$this->methods[] = new Method($method, $this->alias, $reflection, $this->interfaces);
|
||||
}
|
||||
$this->used_methods[] = $method->name;
|
||||
}
|
||||
|
||||
@@ -53,10 +53,7 @@ class GeneratorCommand extends Command
|
||||
/** @var \Illuminate\View\Factory */
|
||||
protected $view;
|
||||
|
||||
protected $extra;
|
||||
protected $onlyExtend;
|
||||
protected $helpers;
|
||||
protected $magic;
|
||||
|
||||
|
||||
/**
|
||||
@@ -94,8 +91,7 @@ class GeneratorCommand extends Command
|
||||
$this->useMemoryDriver();
|
||||
}
|
||||
|
||||
$extra = $this->config->get('laravel-ide-helper::extra');
|
||||
$magic = $this->config->get('laravel-ide-helper::magic');
|
||||
|
||||
$helpers = '';
|
||||
if ($this->option('helpers') || ($this->config->get('laravel-ide-helper::include_helpers'))) {
|
||||
foreach ($this->config->get('laravel-ide-helper::helper_files', array()) as $helper) {
|
||||
@@ -107,7 +103,7 @@ class GeneratorCommand extends Command
|
||||
$helpers = '';
|
||||
}
|
||||
|
||||
$generator = new Generator($this->view, $extra, $magic, $helpers);
|
||||
$generator = new Generator($this->config, $this->view, $helpers);
|
||||
$output = $generator->generate();
|
||||
|
||||
|
||||
|
||||
+11
-9
@@ -15,6 +15,8 @@ use Illuminate\Config\Repository as ConfigRepository;
|
||||
|
||||
class Generator
|
||||
{
|
||||
/** @var \Illuminate\Config\Repository */
|
||||
protected $config;
|
||||
|
||||
/** @var \Illuminate\View\Factory */
|
||||
protected $view;
|
||||
@@ -24,21 +26,21 @@ class Generator
|
||||
protected $helpers;
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Config\Repository $config
|
||||
* @param \Illuminate\View\Factory $view
|
||||
* @param array $extra
|
||||
* @param array $magic
|
||||
* @param string $helpers
|
||||
*/
|
||||
public function __construct( /* Illuminate\View\Factory */
|
||||
$view,
|
||||
$extra = array(),
|
||||
$magic = array(),
|
||||
public function __construct(ConfigRepository $config,
|
||||
/* Illuminate\View\Factory */ $view,
|
||||
$helpers = ''
|
||||
) {
|
||||
$this->config = $config;
|
||||
$this->view = $view;
|
||||
$this->extra = $extra;
|
||||
$this->magic = $magic;
|
||||
$this->extra = $this->config->get('laravel-ide-helper::extra');
|
||||
$this->magic = $this->config->get('laravel-ide-helper::magic');
|
||||
$this->interfaces = $this->config->get('laravel-ide-helper::interfaces');
|
||||
$this->helpers = $helpers;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +68,7 @@ class Generator
|
||||
|
||||
// Get all aliases
|
||||
foreach (AliasLoader::getInstance()->getAliases() as $name => $facade) {
|
||||
$alias = new Alias($name, $facade);
|
||||
$alias = new Alias($name, $facade, $this->interfaces);
|
||||
|
||||
if ($alias->isValid()) {
|
||||
|
||||
|
||||
+12
-5
@@ -24,11 +24,12 @@ class Method
|
||||
protected $phpdoc;
|
||||
protected $params = array();
|
||||
protected $params_with_default = array();
|
||||
protected $interfaces = array();
|
||||
|
||||
public function __construct($method, $alias, $class, $methodName = null)
|
||||
public function __construct($method, $alias, $class, $interfaces = array())
|
||||
{
|
||||
|
||||
$this->name = $methodName ?: $method->name;
|
||||
$this->interfaces = $interfaces;
|
||||
$this->name = $method->name;
|
||||
$this->namespace = $method->getDeclaringClass()->getNamespaceName();
|
||||
|
||||
//Create a DocBlock and serializer instance
|
||||
@@ -38,7 +39,7 @@ class Method
|
||||
try {
|
||||
$this->normalizeDescription($method);
|
||||
} catch (\Exception $e) {
|
||||
$this->info("Cannot normalize method $alias::$methodName..");
|
||||
$this->info("Cannot normalize method $alias::{$this->name}..");
|
||||
}
|
||||
|
||||
//Get the parameters, including formatted default values
|
||||
@@ -173,12 +174,18 @@ class Method
|
||||
//Get the return type and adjust them for beter autocomplete
|
||||
$returnTags = $this->phpdoc->getTagsByName('return');
|
||||
if ($returnTags) {
|
||||
/** @var $tag */
|
||||
/** @var Tag $tag */
|
||||
$tag = reset($returnTags);
|
||||
$returnValue = $tag->getType();
|
||||
|
||||
foreach($this->interfaces as $interface => $real){
|
||||
$returnValue = str_replace($interface, $real, $returnValue);
|
||||
}
|
||||
$tag->setContent($returnValue);
|
||||
} else {
|
||||
$returnValue = null;
|
||||
}
|
||||
|
||||
return $returnValue;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,9 @@ return array(
|
||||
'alert' => 'Monolog\Logger::addAlert',
|
||||
'emergency' => 'Monolog\Logger::addEmergency',
|
||||
)
|
||||
),
|
||||
'interfaces' => array(
|
||||
'\Illuminate\Auth\UserInterface' => '\User',
|
||||
)
|
||||
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user