Skip to content

Commit 09623f2

Browse files
Add extends declaration for Macroable classes to fix missing inherited methods (#1674)
1 parent 3d4e377 commit 09623f2

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

resources/views/helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<?php foreach ($namespaces_by_extends_ns as $namespace => $aliases) : ?>
3030
namespace <?= $namespace === '__root' ? '' : trim($namespace, '\\') ?> {
3131
<?php foreach ($aliases as $alias) : ?>
32-
<?php echo trim($alias->getDocComment($s1)) . "\n{$s1}" . $alias->getClassType() ?> <?= $alias->getExtendsClass() ?> {
32+
<?php echo trim($alias->getDocComment($s1)) . "\n{$s1}" . $alias->getClassType() ?> <?= $alias->getExtendsClass() ?><?php if($alias->shouldExtendParentClass()): ?> extends <?= $alias->getParentClass() ?><?php endif; ?> {
3333
<?php foreach ($alias->getMethods() as $method) : ?>
3434
<?= trim($method->getDocComment($s2)) . "\n{$s2}" ?>public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>)
3535
{<?php if ($method->getDeclaringClass() !== $method->getRoot()) : ?>

src/Alias.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Alias
3636
protected $classType = 'class';
3737
protected $short;
3838
protected $namespace = '__root';
39+
protected $parentClass;
3940
protected $root = null;
4041
protected $classes = [];
4142
protected $methods = [];
@@ -87,6 +88,7 @@ public function __construct($config, $alias, $facade, $magicMethods = [], $inter
8788
$this->detectNamespace();
8889
$this->detectClassType();
8990
$this->detectExtendsNamespace();
91+
$this->detectParentClass();
9092

9193
if (!empty($this->namespace)) {
9294
try {
@@ -171,6 +173,25 @@ public function getExtendsNamespace()
171173
return $this->extendsNamespace;
172174
}
173175

176+
/**
177+
* Get the parent class of the class which this alias extends
178+
*
179+
* @return null|string
180+
*/
181+
public function getParentClass()
182+
{
183+
return $this->parentClass;
184+
}
185+
186+
/**
187+
* Check if this class should extend the parent class
188+
*/
189+
public function shouldExtendParentClass()
190+
{
191+
return $this->parentClass
192+
&& $this->getExtendsNamespace() !== '\\Illuminate\\Support\\Facades';
193+
}
194+
174195
/**
175196
* Get the Alias by which this class is called
176197
*
@@ -268,6 +289,18 @@ protected function detectExtendsNamespace()
268289
}
269290
}
270291

292+
/**
293+
* Detect the parent class
294+
*/
295+
protected function detectParentClass()
296+
{
297+
$reflection = new ReflectionClass($this->root);
298+
299+
$parentClass = $reflection->getParentClass();
300+
301+
$this->parentClass = $parentClass ? '\\' . $parentClass->getName() : null;
302+
}
303+
271304
/**
272305
* Detect the class type
273306
*/

0 commit comments

Comments
 (0)