bug #22422 [FrameworkBundle][Console][EventDispatcher] Fixed debug:event command (lyrixx)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[FrameworkBundle][Console][EventDispatcher] Fixed debug:event command

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

---

before:

![screenshot5](https://cloud.githubusercontent.com/assets/408368/25013888/bcd561ba-2075-11e7-8538-b977420640d2.png)

after:

![screenshot6](https://cloud.githubusercontent.com/assets/408368/25013894/c2bc9332-2075-11e7-97f6-ebfcca70b23b.png)

Commits
-------

9960b7e [FrameworkBundle][Console][EventDispatcher] Fixed debug:event command
This commit is contained in:
Nicolas Grekas 2017-04-18 17:38:19 +02:00
commit 1674f9218b
5 changed files with 22 additions and 4 deletions

View File

@ -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';
}
}

View File

@ -363,7 +363,7 @@ class JsonDescriptor extends Descriptor
}
if ($callable instanceof \Closure) {
$data['type'] = 'closure';
$data['type'] = $this->formatClosure($callable);
return $data;
}

View File

@ -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");
}

View File

@ -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')) {

View File

@ -593,7 +593,7 @@ class XmlDescriptor extends Descriptor
}
if ($callable instanceof \Closure) {
$callableXML->setAttribute('type', 'closure');
$callableXML->setAttribute('type', $this->formatClosure($callable));
return $dom;
}