|
14 | 14 | use Laminas\Code\Generator\DocBlockGenerator; |
15 | 15 | use Laminas\Code\Generator\MethodGenerator; |
16 | 16 | use Laminas\Code\Generator\ParameterGenerator; |
17 | | -use Neos\Flow\ObjectManagement\Exception\UnsupportedAttributeException; |
18 | 17 |
|
19 | 18 | /** |
20 | 19 | * Class ProxyMethodGenerator |
@@ -260,77 +259,9 @@ protected function buildAttributesCode(\ReflectionMethod $reflectionMethod): str |
260 | 259 | $attributesCode = ""; |
261 | 260 |
|
262 | 261 | 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; |
266 | 263 | } |
267 | 264 |
|
268 | 265 | return $attributesCode; |
269 | 266 | } |
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 | | - } |
336 | 267 | } |
0 commit comments