mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-17 17:47:13 +00:00
Add magic methods
This commit is contained in:
+31
-8
@@ -16,18 +16,20 @@ class Alias
|
||||
protected $alias;
|
||||
protected $facade;
|
||||
protected $extends = null;
|
||||
protected $classTYpe = 'class';
|
||||
protected $classType = 'class';
|
||||
protected $namespace = '__root';
|
||||
protected $root = null;
|
||||
protected $classes = array();
|
||||
protected $methods = array();
|
||||
protected $used_methods = array();
|
||||
protected $usedMethods = array();
|
||||
protected $valid = false;
|
||||
protected $magicMethods = array();
|
||||
protected $interfaces = array();
|
||||
|
||||
public function __construct($alias, $facade, $interfaces = array())
|
||||
public function __construct($alias, $facade, $magicMethods = array(), $interfaces = array())
|
||||
{
|
||||
$this->alias = $alias;
|
||||
$this->magicMethods = $magicMethods;
|
||||
$this->interfaces = $interfaces;
|
||||
|
||||
// Make the class absolute
|
||||
@@ -61,6 +63,8 @@ class Alias
|
||||
foreach ($classes as $class) {
|
||||
if (class_exists($class) || interface_exists($class)) {
|
||||
$this->classes[] = $class;
|
||||
}else{
|
||||
echo "Class not exists: $class\r\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,6 +126,7 @@ class Alias
|
||||
*/
|
||||
public function getMethods()
|
||||
{
|
||||
$this->addMagicMethods();
|
||||
$this->detectMethods();
|
||||
return $this->methods;
|
||||
|
||||
@@ -207,6 +212,24 @@ class Alias
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function addMagicMethods(){
|
||||
|
||||
foreach($this->magicMethods as $magic => $real){
|
||||
list($className, $name) = explode('::', $real);
|
||||
if(!class_exists($className) && !interface_exists($className)){
|
||||
continue;
|
||||
}
|
||||
$method = new \ReflectionMethod($className, $name);
|
||||
$class = new \ReflectionClass($className);
|
||||
|
||||
if(!in_array($method->name, $this->usedMethods)){
|
||||
if($class !== $this->root){
|
||||
$this->methods[] = new Method($method, $this->alias, $class, $magic, $this->interfaces);
|
||||
}
|
||||
$this->usedMethods[] = $magic;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the methods for one or multiple classes.
|
||||
*
|
||||
@@ -221,13 +244,13 @@ class Alias
|
||||
$methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
|
||||
if ($methods) {
|
||||
foreach ($methods as $method) {
|
||||
if (!in_array($method->name, $this->used_methods)) {
|
||||
// Only add the methods to the output when the root is not the same as the facade.
|
||||
if (!in_array($method->name, $this->usedMethods)) {
|
||||
// Only add the methods to the output when the root is not the same as the class.
|
||||
// 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->interfaces);
|
||||
if ($this->extends !== $class && $method->name !== '__clone') {
|
||||
$this->methods[] = new Method($method, $this->alias, $reflection, $method->name, $this->interfaces);
|
||||
}
|
||||
$this->used_methods[] = $method->name;
|
||||
$this->usedMethods[] = $method->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-7
@@ -40,7 +40,6 @@ class Generator
|
||||
$this->magic = $this->config->get('laravel-ide-helper::magic');
|
||||
$this->interfaces = $this->config->get('laravel-ide-helper::interfaces');
|
||||
$this->helpers = $helpers;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,7 +67,8 @@ class Generator
|
||||
|
||||
// Get all aliases
|
||||
foreach (AliasLoader::getInstance()->getAliases() as $name => $facade) {
|
||||
$alias = new Alias($name, $facade, $this->interfaces);
|
||||
$magicMethods = array_key_exists($name, $this->magic) ? $this->magic[$name] : array();
|
||||
$alias = new Alias($name, $facade, $magicMethods, $this->interfaces);
|
||||
|
||||
if ($alias->isValid()) {
|
||||
|
||||
@@ -82,11 +82,6 @@ class Generator
|
||||
$alias->addClass($this->extra[$name]);
|
||||
}
|
||||
|
||||
//Add extra methods, from other classes (magic static calls)
|
||||
if (array_key_exists($name, $this->magic)) {
|
||||
$alias->addClass($this->magic[$name]);
|
||||
}
|
||||
|
||||
$namespace = $alias->getNamespace();
|
||||
if (!isset($namespaces[$namespace])) {
|
||||
$namespaces[$namespace] = array();
|
||||
|
||||
+2
-2
@@ -26,10 +26,10 @@ class Method
|
||||
protected $params_with_default = array();
|
||||
protected $interfaces = array();
|
||||
|
||||
public function __construct($method, $alias, $class, $interfaces = array())
|
||||
public function __construct($method, $alias, $class, $methodName = null, $interfaces = array())
|
||||
{
|
||||
$this->interfaces = $interfaces;
|
||||
$this->name = $method->name;
|
||||
$this->name = $methodName ?: $method->name;
|
||||
$this->namespace = $method->getDeclaringClass()->getNamespaceName();
|
||||
|
||||
//Create a DocBlock and serializer instance
|
||||
|
||||
Reference in New Issue
Block a user