Skip to content

Commit 045e04f

Browse files
committed
BUGFIX: Fix rendering of enums and objects in proxied methods attributes
This is done by using the method Compiler::renderAttribute instead of a local implementation
1 parent 14be8b7 commit 045e04f

File tree

1 file changed

+1
-70
lines changed

1 file changed

+1
-70
lines changed

Neos.Flow/Classes/ObjectManagement/Proxy/ProxyMethodGenerator.php

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Laminas\Code\Generator\DocBlockGenerator;
1515
use Laminas\Code\Generator\MethodGenerator;
1616
use Laminas\Code\Generator\ParameterGenerator;
17-
use Neos\Flow\ObjectManagement\Exception\UnsupportedAttributeException;
1817

1918
/**
2019
* Class ProxyMethodGenerator
@@ -260,77 +259,9 @@ protected function buildAttributesCode(\ReflectionMethod $reflectionMethod): str
260259
$attributesCode = "";
261260

262261
foreach ($reflectionMethod->getAttributes() as $attribute) {
263-
$attributeName = "\\" . ltrim($attribute->getName(), '\\');
264-
$argumentsString = $this->formatAttributesArguments($attribute->getArguments(), $reflectionMethod->name);
265-
$attributesCode .= "{$indent}#[{$attributeName}({$argumentsString})]" . self::LINE_FEED;
262+
$attributesCode .= $indent . Compiler::renderAttribute($attribute) . self::LINE_FEED;
266263
}
267264

268265
return $attributesCode;
269266
}
270-
271-
/**
272-
* Formats the arguments of attributes into a string.
273-
*
274-
* @param array $arguments An array of arguments for attributes.
275-
* @param string $methodName The current method name the proxy code is built for.
276-
* @return string The formatted arguments as a string.
277-
* @throws UnsupportedAttributeException
278-
*/
279-
private function formatAttributesArguments(array $arguments, string $methodName): string
280-
{
281-
$formattedArguments = [];
282-
283-
foreach ($arguments as $key => $value) {
284-
if (is_int($key)) {
285-
$formattedArguments[] = $this->formatAttributeValue($value, $methodName);
286-
} else {
287-
$formattedArguments[] = "{$key}: " . $this->formatAttributeValue($value, $methodName);
288-
}
289-
}
290-
291-
return implode(', ', $formattedArguments);
292-
}
293-
294-
/**
295-
* Formats the given attribute value.
296-
*
297-
* @param mixed $value The value to be formatted.
298-
* @param string $methodName The current method name the proxy code is built for.
299-
* @return string The formatted attribute value.
300-
*/
301-
private function formatAttributeValue(mixed $value, string $methodName): string
302-
{
303-
if (is_string($value)) {
304-
return "\"$value\"";
305-
}
306-
if (is_bool($value)) {
307-
return $value ? 'true' : 'false';
308-
}
309-
if (is_int($value)) {
310-
return (string)$value;
311-
}
312-
if (is_float($value)) {
313-
return (string)$value;
314-
}
315-
if ($value === null) {
316-
return 'null';
317-
}
318-
if (is_array($value)) {
319-
$formattedArrayElements = implode(', ', array_map(function ($key, $value) use ($methodName) {
320-
return is_int($key)
321-
? $this->formatAttributeValue($value, $methodName)
322-
: "\"{$key}\" => " . $this->formatAttributeValue($value, $methodName);
323-
}, array_keys($value), $value));
324-
return "[{$formattedArrayElements}]";
325-
}
326-
throw new UnsupportedAttributeException(
327-
sprintf(
328-
'Failed rendering proxy method %s::%s because an attribute contained an unsupported value type (%s)',
329-
$this->getFullOriginalClassName(),
330-
$methodName,
331-
get_debug_type($value)
332-
),
333-
1705501433
334-
);
335-
}
336267
}

0 commit comments

Comments
 (0)