Merge pull request #621 from Zae/feature/fix-callable-macros

Support php's array callable format for macro's.
This commit is contained in:
Barry vd. Heuvel
2018-05-07 11:15:49 +02:00
committed by GitHub
2 changed files with 23 additions and 5 deletions
+15 -2
View File
@@ -331,10 +331,9 @@ class Alias
$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->getMacroFunction($macro_func),
$this->alias,
$reflection,
$macro_name,
@@ -346,6 +345,20 @@ class Alias
}
/**
* @param $macro_func
*
* @return \ReflectionFunctionAbstract
* @throws \ReflectionException
*/
protected function getMacroFunction($macro_func)
{
if (is_array($macro_func) && is_callable($macro_func)) {
return new \ReflectionMethod($macro_func[0], $macro_func[1]);
}
return new \ReflectionFunction($macro_func);
}
* Get the docblock for this alias
*
* @param string $prefix
+8 -3
View File
@@ -10,14 +10,19 @@ class Macro extends Method
/**
* Macro constructor.
*
* @param \ReflectionFunction $method
* @param \ReflectionFunctionAbstract $method
* @param string $alias
* @param \ReflectionClass $class
* @param null $methodName
* @param array $interfaces
*/
public function __construct(\ReflectionFunction $method, $alias, $class, $methodName = null, $interfaces = array())
{
public function __construct(
\ReflectionFunctionAbstract $method,
$alias,
$class,
$methodName = null,
$interfaces = array()
) {
$this->method = $method;
$this->interfaces = $interfaces;
$this->name = $methodName ?: $method->name;