Skip to content
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

Integrate BrowserConsoleHandler in Symfony #43065

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/Symfony/Bridge/Monolog/Handler/BrowserConsoleHandler.php
@@ -0,0 +1,59 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Monolog\Handler;

use Monolog\Handler\BrowserConsoleHandler as BaseBrowserConsoleHandler;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class BrowserConsoleHandler extends BaseBrowserConsoleHandler implements EventSubscriberInterface
{
/** @var string */
private static $responseFormat;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this a static property ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because everything else in this class is static.


public static function getSubscribedEvents(): array
{
return [KernelEvents::RESPONSE => 'onResponse'];
}

private static function determineResponseFormatFromContentType(?string $contentType): string
{
if (null === $contentType) {
return 'unknown';
}
if (stripos($contentType, 'application/javascript') !== false || stripos($contentType, 'text/javascript') !== false) {
return 'js';
}
if (stripos($contentType, 'text/html') === false) {
return 'unknown';
}

return 'html';
}

public static function onResponse(ResponseEvent $responseEvent): void
{
$contentType = $responseEvent->getResponse()->headers->get('Content-Type');
static::$responseFormat = static::determineResponseFormatFromContentType($contentType);
static::send();
}

protected static function getResponseFormat(): string
{
return static::$responseFormat;
}

protected function registerShutdownFunction(): void
{
}
}