Skip to content

Various fixes #12285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,18 @@ public function removeListener($eventName, $listener)
{
$this->lazyLoad($eventName);

if (isset($this->listeners[$eventName])) {
foreach ($this->listeners[$eventName] as $key => $l) {
foreach ($this->listenerIds[$eventName] as $i => $args) {
list($serviceId, $method, $priority) = $args;
if ($key === $serviceId.'.'.$method) {
if ($listener === array($l, $method)) {
unset($this->listeners[$eventName][$key]);
if (empty($this->listeners[$eventName])) {
unset($this->listeners[$eventName]);
}
unset($this->listenerIds[$eventName][$i]);
if (empty($this->listenerIds[$eventName])) {
unset($this->listenerIds[$eventName]);
}
}
if (isset($this->listenerIds[$eventName])) {
foreach ($this->listenerIds[$eventName] as $i => $args) {
list($serviceId, $method, $priority) = $args;
$key = $serviceId.'.'.$method;
if (isset($this->listeners[$eventName][$key]) && $listener === array($this->listeners[$eventName][$key], $method)) {
unset($this->listeners[$eventName][$key]);
if (empty($this->listeners[$eventName])) {
unset($this->listeners[$eventName]);
}
unset($this->listenerIds[$eventName][$i]);
if (empty($this->listenerIds[$eventName])) {
unset($this->listenerIds[$eventName]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ class SubscriberService implements EventSubscriberInterface
public static function getSubscribedEvents()
{
return array(
'onEvent' => 'onEvent',
'onEvent' => array('onEvent', 10),
'onEvent' => array('onEvent'),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Symfony\Component\Debug\ErrorHandler;
use Symfony\Component\Debug\ExceptionHandler;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\KernelEvent;
use Symfony\Component\HttpKernel\KernelEvents;
Expand All @@ -36,6 +35,7 @@ class DebugHandlersListener implements EventSubscriberInterface
private $throwAt;
private $scream;
private $fileLinkFormat;
private $firstCall = true;

/**
* @param callable|null $exceptionHandler A handler that will be called on Exception
Expand All @@ -58,38 +58,37 @@ public function __construct($exceptionHandler, LoggerInterface $logger = null, $
/**
* Configures the error handler.
*
* @param Event|null $event The triggering event
* @param string|null $eventName The triggering event name
* @param EventDispatcherInterface|null $eventDispatcher The dispatcher used to trigger $event
* @param Event|null $event The triggering event
*/
public function configure(Event $event = null, $eventName = null, EventDispatcherInterface $eventDispatcher = null)
public function configure(Event $event = null)
{
if (null !== $eventDispatcher) {
foreach (array_keys(static::getSubscribedEvents()) as $name) {
$eventDispatcher->removeListener($name, array($this, 'configure'));
}
if (!$this->firstCall) {
return;
}
$handler = set_error_handler('var_dump', 0);
$handler = is_array($handler) ? $handler[0] : null;
restore_error_handler();
if ($handler instanceof ErrorHandler) {
if ($this->logger) {
$handler->setDefaultLogger($this->logger, $this->levels);
if (is_array($this->levels)) {
$scream = 0;
foreach ($this->levels as $type => $log) {
$scream |= $type;
$this->firstCall = false;
if ($this->logger || null !== $this->throwAt) {
$handler = set_error_handler('var_dump', 0);
$handler = is_array($handler) ? $handler[0] : null;
restore_error_handler();
if ($handler instanceof ErrorHandler) {
if ($this->logger) {
$handler->setDefaultLogger($this->logger, $this->levels);
if (is_array($this->levels)) {
$scream = 0;
foreach ($this->levels as $type => $log) {
$scream |= $type;
}
} else {
$scream = null === $this->levels ? E_ALL | E_STRICT : $this->levels;
}
} else {
$scream = null === $this->levels ? E_ALL | E_STRICT : $this->levels;
if ($this->scream) {
$handler->screamAt($scream);
}
$this->logger = $this->levels = null;
}
if ($this->scream) {
$handler->screamAt($scream);
if (null !== $this->throwAt) {
$handler->throwAt($this->throwAt, true);
}
$this->logger = $this->levels = null;
}
if (null !== $this->throwAt) {
$handler->throwAt($this->throwAt, true);
}
}
if (!$this->exceptionHandler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ public function testConsoleEvent()
throw $exception;
}

$this->assertSame(array(), $dispatcher->getListeners());

$xHandler = $eHandler->setExceptionHandler('var_dump');
$this->assertInstanceOf('Closure', $xHandler);

Expand Down
10 changes: 3 additions & 7 deletions src/Symfony/Component/VarDumper/Dumper/CliDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CliDumper extends AbstractDumper
'meta' => '38;5;27',
);

protected static $controlCharsRx = "/\\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x7F/";
protected static $controlCharsRx = '/[\x00-\x1F\x7F]/';

/**
* Enables/disables colored output.
Expand Down Expand Up @@ -321,17 +321,13 @@ protected function style($style, $value, $attr = array())
$this->colors = $this->supportsColors($this->outputStream);
}

if (!$this->colors || '' === $value) {
return $value;
}

$style = $this->styles[$style];
$cchr = "\033[m\033[{$style};{$this->styles['cchr']}m%s\033[m\033[{$style}m";
$cchr = $this->colors ? "\033[m\033[{$style};{$this->styles['cchr']}m%s\033[m\033[{$style}m" : '%s';
$value = preg_replace_callback(self::$controlCharsRx, function ($r) use ($cchr) {
return sprintf($cchr, "\x7F" === $r[0] ? '?' : chr(64 + ord($r[0])));
}, $value);

return sprintf("\033[%sm%s\033[m", $style, $value);
return $this->colors ? sprintf("\033[%sm%s\033[m", $style, $value) : $value;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/VarDumper/Tests/CliDumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function testGet()
5 => -INF
6 => {$intMax}
"str" => "déjà"
7 => b"é"
7 => b"é@"
"[]" => []
"res" => :stream {@{$res1}
wrapper_type: "plainfile"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DumbFoo
$var = array(
'number' => 1, null,
'const' => 1.1, true, false, NAN, INF, -INF, PHP_INT_MAX,
'str' => "déjà", "\xE9",
'str' => "déjà", "\xE9\x00",
'[]' => array(),
'res' => $g,
$h,
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testGet()
<span class=sf-dump-meta>5</span> => <span class=sf-dump-num>-INF</span>
<span class=sf-dump-meta>6</span> => <span class=sf-dump-num>{$intMax}</span>
"<span class=sf-dump-meta>str</span>" => "<span class=sf-dump-str title="4 characters">d&#233;j&#224;</span>"
<span class=sf-dump-meta>7</span> => b"<span class=sf-dump-str>&#233;</span>"
<span class=sf-dump-meta>7</span> => b"<span class=sf-dump-str title="2 binary or non-UTF-8 characters">&#233;<span class=sf-dump-cchr title=\\x00>@</span></span>"
"<span class=sf-dump-meta>[]</span>" => []
"<span class=sf-dump-meta>res</span>" => <abbr title="`stream` resource" class=sf-dump-note>:stream</abbr> {<a class=sf-dump-solo-ref>@{$res1}</a><samp>
<span class=sf-dump-meta>wrapper_type</span>: "<span class=sf-dump-str title="9 characters">plainfile</span>"
Expand Down