From 9960b7e1d43301aff32d8a15918486b014244bd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Thu, 13 Apr 2017 18:04:25 +0200 Subject: [PATCH] [FrameworkBundle][Console][EventDispatcher] Fixed debug:event command --- .../FrameworkBundle/Console/Descriptor/Descriptor.php | 11 +++++++++++ .../Console/Descriptor/JsonDescriptor.php | 2 +- .../Console/Descriptor/MarkdownDescriptor.php | 3 ++- .../Console/Descriptor/TextDescriptor.php | 8 +++++++- .../Console/Descriptor/XmlDescriptor.php | 2 +- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php index 547c17b2f7..c081dfc6e9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php @@ -311,4 +311,15 @@ abstract class Descriptor implements DescriptorInterface return $serviceIds; } + + protected function formatClosure(\Closure $closure) + { + $r = new \ReflectionFunction($closure); + + if (preg_match('#^/\*\* @closure-proxy ([^: ]++)::([^: ]++) \*/$#', $r->getDocComment(), $m)) { + return sprintf('%s::%s', $m[1], $m[2]); + } + + return 'closure'; + } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php index 81d7233811..8052a9114b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php @@ -363,7 +363,7 @@ class JsonDescriptor extends Descriptor } if ($callable instanceof \Closure) { - $data['type'] = 'closure'; + $data['type'] = $this->formatClosure($callable); return $data; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php index c0319aad6b..b5c285dee7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php @@ -343,7 +343,8 @@ class MarkdownDescriptor extends Descriptor } if ($callable instanceof \Closure) { - $string .= "\n- Type: `closure`"; + $formatted = $this->formatClosure($callable); + $string .= "\n- Type: `$formatted`"; return $this->write($string."\n"); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php index 2481b15375..7aae3d3c19 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php @@ -466,7 +466,13 @@ class TextDescriptor extends Descriptor } if ($callable instanceof \Closure) { - return '\Closure()'; + $formatted = $this->formatClosure($callable); + + if ('closure' === $formatted) { + return '\Closure()'; + } + + return $formatted.'()'; } if (method_exists($callable, '__invoke')) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php index 40e749aa6a..bc1cc9eba0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php @@ -593,7 +593,7 @@ class XmlDescriptor extends Descriptor } if ($callable instanceof \Closure) { - $callableXML->setAttribute('type', 'closure'); + $callableXML->setAttribute('type', $this->formatClosure($callable)); return $dom; }