Pass original class name in AspectContext

This commit is contained in:
icefox 2026-01-07 12:13:27 -03:00
parent 6946059f07
commit 0c34664aef
No known key found for this signature in database

View file

@ -179,12 +179,13 @@ class AspectWeaver
array $methodAspectsMap, array $methodAspectsMap,
string $modifiedSource string $modifiedSource
): string { ): string {
$originalClassName = $namespace ? "{$namespace}\\{$shortName}" : $shortName;
$code = "<?php\n\n"; $code = "<?php\n\n";
$code .= trim($modifiedSource) . "\n\n"; $code .= trim($modifiedSource) . "\n\n";
$code .= "class {$shortName} extends {$renamedClassName}\n{\n"; $code .= "class {$shortName} extends {$renamedClassName}\n{\n";
foreach ($methodAspectsMap as $methodMetadata) { foreach ($methodAspectsMap as $methodMetadata) {
$code .= $this->generateProxyMethodFromReflection($methodMetadata->method, $methodMetadata->aspects); $code .= $this->generateProxyMethodFromReflection($methodMetadata->method, $methodMetadata->aspects, $originalClassName);
} }
$code .= "}\n"; $code .= "}\n";
@ -201,6 +202,7 @@ class AspectWeaver
string $renamedClassName, string $renamedClassName,
array $methodAspectsMap array $methodAspectsMap
): string { ): string {
$originalClassName = $namespace ? "{$namespace}\\{$shortName}" : $shortName;
$code = ''; $code = '';
if ($namespace) { if ($namespace) {
@ -210,7 +212,7 @@ class AspectWeaver
$code .= "class {$shortName} extends {$renamedClassName}\n{\n"; $code .= "class {$shortName} extends {$renamedClassName}\n{\n";
foreach ($methodAspectsMap as $methodMetadata) { foreach ($methodAspectsMap as $methodMetadata) {
$code .= $this->generateProxyMethodFromReflection($methodMetadata->method, $methodMetadata->aspects); $code .= $this->generateProxyMethodFromReflection($methodMetadata->method, $methodMetadata->aspects, $originalClassName);
} }
$code .= "}\n"; $code .= "}\n";
@ -221,13 +223,12 @@ class AspectWeaver
/** /**
* @param array<int, AttributeMetadata> $aspects * @param array<int, AttributeMetadata> $aspects
*/ */
private function generateProxyMethodFromReflection(ReflectionMethod $method, array $aspects): string private function generateProxyMethodFromReflection(ReflectionMethod $method, array $aspects, string $className): string
{ {
$visibility = $method->isPublic() ? 'public' : 'protected'; $visibility = $method->isPublic() ? 'public' : 'protected';
$static = $method->isStatic() ? 'static ' : ''; $static = $method->isStatic() ? 'static ' : '';
$isStatic = $method->isStatic(); $isStatic = $method->isStatic();
$name = $method->getName(); $name = $method->getName();
$className = $method->getDeclaringClass()->getName();
$this->logger->info('Generating proxy method', [ $this->logger->info('Generating proxy method', [
'class' => $className, 'class' => $className,