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