Skip to content

Commit

Permalink
fix: dont use ReflectionClass directly
Browse files Browse the repository at this point in the history
  • Loading branch information
canvural committed Jun 4, 2022
1 parent 086b665 commit 2404fa8
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/Methods/Pipes/Macros.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,26 @@ public function handle(PassableContract $passable, Closure $next): void

if ($className !== null && $macroTraitProperty) {
$classReflection = $passable->getReflectionProvider()->getClass($className);
$refObject = new \ReflectionClass($className);
$refProperty = $refObject->getProperty($macroTraitProperty);
$refProperty->setAccessible(true);

$found = $className === Builder::class
? $className::hasGlobalMacro($passable->getMethodName())
: $className::hasMacro($passable->getMethodName());
if ($classReflection->getNativeReflection()->hasProperty($macroTraitProperty)) {
$refProperty = $classReflection->getNativeReflection()->getProperty($macroTraitProperty);
$refProperty->setAccessible(true);

if ($found) {
$reflectionFunction = new \ReflectionFunction($refProperty->getValue()[$passable->getMethodName()]);
$found = $className === Builder::class
? $className::hasGlobalMacro($passable->getMethodName())
: $className::hasMacro($passable->getMethodName());

$methodReflection = new Macro(
$classReflection, $passable->getMethodName(), $reflectionFunction
);
if ($found) {
$reflectionFunction = new \ReflectionFunction($refProperty->getValue()[$passable->getMethodName()]);

$methodReflection->setIsStatic(true);
$methodReflection = new Macro(
$classReflection, $passable->getMethodName(), $reflectionFunction
);

$passable->setMethodReflection($methodReflection);
$methodReflection->setIsStatic(true);

$passable->setMethodReflection($methodReflection);
}
}
}

Expand Down

0 comments on commit 2404fa8

Please sign in to comment.