diff --git a/src/Alias.php b/src/Alias.php index 3112491..4902f80 100644 --- a/src/Alias.php +++ b/src/Alias.php @@ -312,6 +312,24 @@ class Alias } } } + + // Check if the class is macroable + $traits = collect($reflection->getTraitNames()); + if ($traits->contains('Illuminate\Support\Traits\Macroable')) { + $properties = $reflection->getStaticProperties(); + $macros = isset($properties['macros']) ? $properties['macros'] : []; + foreach ($macros as $macro_name => $macro_func) { + $function = new \ReflectionFunction($macro_func); + // Add macros + $this->methods[] = new Macro( + $function, + $this->alias, + $reflection, + $macro_name, + $this->interfaces + ); + } + } } } diff --git a/src/Macro.php b/src/Macro.php new file mode 100644 index 0000000..521a3f0 --- /dev/null +++ b/src/Macro.php @@ -0,0 +1,47 @@ +method = $method; + $this->interfaces = $interfaces; + $this->name = $methodName ?: $method->name; + $this->namespace = $class->getNamespaceName(); + + //Create a DocBlock and serializer instance + $this->phpdoc = new DocBlock($method); + + //Normalize the description and inherit the docs from parents/interfaces + try { + $this->normalizeParams($this->phpdoc); + $this->normalizeReturn($this->phpdoc); + $this->normalizeDescription($this->phpdoc); + } catch (\Exception $e) { + } + + //Get the parameters, including formatted default values + $this->getParameters($method); + + //Make the method static + $this->phpdoc->appendTag(Tag::createInstance('@static', $this->phpdoc)); + + //Reference the 'real' function in the declaringclass + $this->declaringClassName = '\\' . ltrim($class->name, '\\'); + $this->root = '\\' . ltrim($class->getName(), '\\'); + } +}