Jelajahi Sumber

Tweak const visibility, refs #1228

Jordi Boggiano 7 tahun lalu
induk
melakukan
bb99e4c699

+ 1 - 1
src/Monolog/Formatter/GelfMessageFormatter.php

@@ -22,7 +22,7 @@ use Gelf\Message;
  */
 class GelfMessageFormatter extends NormalizerFormatter
 {
-    public const DEFAULT_MAX_LENGTH = 32766;
+    protected const DEFAULT_MAX_LENGTH = 32766;
 
     /**
      * @var string the name of the system for the Gelf log message

+ 2 - 2
src/Monolog/Formatter/LogmaticFormatter.php

@@ -18,7 +18,7 @@ namespace Monolog\Formatter;
  */
 class LogmaticFormatter extends JsonFormatter
 {
-    public const MARKERS = ["sourcecode", "php"];
+    protected const MARKERS = ["sourcecode", "php"];
 
     /**
      * @var string
@@ -59,7 +59,7 @@ class LogmaticFormatter extends JsonFormatter
             $record["appname"] = $this->appname;
         }
 
-        $record["@marker"] = self::MARKERS;
+        $record["@marker"] = static::MARKERS;
 
         return parent::format($record);
     }

+ 2 - 4
src/Monolog/Formatter/WildfireFormatter.php

@@ -22,8 +22,6 @@ use Monolog\Logger;
  */
 class WildfireFormatter extends NormalizerFormatter
 {
-    public const TABLE = 'table';
-
     /**
      * Translates Monolog log levels to Wildfire levels.
      */
@@ -69,10 +67,10 @@ class WildfireFormatter extends NormalizerFormatter
             $message = reset($message);
         }
 
-        if (isset($record['context'][self::TABLE])) {
+        if (isset($record['context']['table'])) {
             $type  = 'TABLE';
             $label = $record['channel'] .': '. $record['message'];
-            $message = $record['context'][self::TABLE];
+            $message = $record['context']['table'];
         } else {
             $type  = $this->logLevels[$record['level']];
             $label = $record['channel'];

+ 5 - 5
src/Monolog/Handler/ChromePHPHandler.php

@@ -29,17 +29,17 @@ class ChromePHPHandler extends AbstractProcessingHandler
     /**
      * Version of the extension
      */
-    public const VERSION = '4.0';
+    protected const VERSION = '4.0';
 
     /**
      * Header name
      */
-    public const HEADER_NAME = 'X-ChromeLogger-Data';
+    protected const HEADER_NAME = 'X-ChromeLogger-Data';
 
     /**
      * Regular expression to detect supported browsers (matches any Chrome, or Firefox 43+)
      */
-    public const USER_AGENT_REGEX = '{\b(?:Chrome/\d+(?:\.\d+)*|HeadlessChrome|Firefox/(?:4[3-9]|[5-9]\d|\d{3,})(?:\.\d)*)\b}';
+    protected const USER_AGENT_REGEX = '{\b(?:Chrome/\d+(?:\.\d+)*|HeadlessChrome|Firefox/(?:4[3-9]|[5-9]\d|\d{3,})(?:\.\d)*)\b}';
 
     protected static $initialized = false;
 
@@ -164,7 +164,7 @@ class ChromePHPHandler extends AbstractProcessingHandler
         }
 
         if (trim($data) !== '') {
-            $this->sendHeader(self::HEADER_NAME, $data);
+            $this->sendHeader(static::HEADER_NAME, $data);
         }
     }
 
@@ -187,6 +187,6 @@ class ChromePHPHandler extends AbstractProcessingHandler
             return false;
         }
 
-        return preg_match(self::USER_AGENT_REGEX, $_SERVER['HTTP_USER_AGENT']) === 1;
+        return preg_match(static::USER_AGENT_REGEX, $_SERVER['HTTP_USER_AGENT']) === 1;
     }
 }

+ 8 - 8
src/Monolog/Handler/FirePHPHandler.php

@@ -26,22 +26,22 @@ class FirePHPHandler extends AbstractProcessingHandler
     /**
      * WildFire JSON header message format
      */
-    public const PROTOCOL_URI = 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2';
+    protected const PROTOCOL_URI = 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2';
 
     /**
      * FirePHP structure for parsing messages & their presentation
      */
-    public const STRUCTURE_URI = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1';
+    protected const STRUCTURE_URI = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1';
 
     /**
      * Must reference a "known" plugin, otherwise headers won't display in FirePHP
      */
-    public const PLUGIN_URI = 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3';
+    protected const PLUGIN_URI = 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3';
 
     /**
      * Header prefix for Wildfire to recognize & parse headers
      */
-    public const HEADER_PREFIX = 'X-Wf';
+    protected const HEADER_PREFIX = 'X-Wf';
 
     /**
      * Whether or not Wildfire vendor-specific headers have been generated & sent yet
@@ -65,7 +65,7 @@ class FirePHPHandler extends AbstractProcessingHandler
      */
     protected function createHeader(array $meta, string $message): array
     {
-        $header = sprintf('%s-%s', self::HEADER_PREFIX, join('-', $meta));
+        $header = sprintf('%s-%s', static::HEADER_PREFIX, join('-', $meta));
 
         return [$header => $message];
     }
@@ -103,9 +103,9 @@ class FirePHPHandler extends AbstractProcessingHandler
     {
         // Initial payload consists of required headers for Wildfire
         return array_merge(
-            $this->createHeader(['Protocol', 1], self::PROTOCOL_URI),
-            $this->createHeader([1, 'Structure', 1], self::STRUCTURE_URI),
-            $this->createHeader([1, 'Plugin', 1], self::PLUGIN_URI)
+            $this->createHeader(['Protocol', 1], static::PROTOCOL_URI),
+            $this->createHeader([1, 'Structure', 1], static::STRUCTURE_URI),
+            $this->createHeader([1, 'Plugin', 1], static::PLUGIN_URI)
         );
     }
 

+ 5 - 5
src/Monolog/Handler/FleepHookHandler.php

@@ -25,9 +25,9 @@ use Monolog\Logger;
  */
 class FleepHookHandler extends SocketHandler
 {
-    public const FLEEP_HOST = 'fleep.io';
+    protected const FLEEP_HOST = 'fleep.io';
 
-    public const FLEEP_HOOK_URI = '/hook/';
+    protected const FLEEP_HOOK_URI = '/hook/';
 
     /**
      * @var string Webhook token (specifies the conversation where logs are sent)
@@ -53,7 +53,7 @@ class FleepHookHandler extends SocketHandler
 
         $this->token = $token;
 
-        $connectionString = 'ssl://' . self::FLEEP_HOST . ':443';
+        $connectionString = 'ssl://' . static::FLEEP_HOST . ':443';
         parent::__construct($connectionString, $level, $bubble);
     }
 
@@ -93,8 +93,8 @@ class FleepHookHandler extends SocketHandler
      */
     private function buildHeader(string $content): string
     {
-        $header = "POST " . self::FLEEP_HOOK_URI . $this->token . " HTTP/1.1\r\n";
-        $header .= "Host: " . self::FLEEP_HOST . "\r\n";
+        $header = "POST " . static::FLEEP_HOOK_URI . $this->token . " HTTP/1.1\r\n";
+        $header .= "Host: " . static::FLEEP_HOST . "\r\n";
         $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
         $header .= "Content-Length: " . strlen($content) . "\r\n";
         $header .= "\r\n";

+ 1 - 6
src/Monolog/Handler/HipChatHandler.php

@@ -29,15 +29,10 @@ use Monolog\Logger;
  */
 class HipChatHandler extends SocketHandler
 {
-    /**
-     * The maximum allowed length for the name used in the "from" field.
-     */
-    public const MAXIMUM_NAME_LENGTH = 15;
-
     /**
      * The maximum allowed length for the message.
      */
-    public const MAXIMUM_MESSAGE_LENGTH = 9500;
+    protected const MAXIMUM_MESSAGE_LENGTH = 9500;
 
     /**
      * @var string

+ 6 - 6
src/Monolog/Handler/LogglyHandler.php

@@ -24,9 +24,9 @@ use Monolog\Formatter\LogglyFormatter;
  */
 class LogglyHandler extends AbstractProcessingHandler
 {
-    public const HOST = 'logs-01.loggly.com';
-    public const ENDPOINT_SINGLE = 'inputs';
-    public const ENDPOINT_BATCH = 'bulk';
+    protected const HOST = 'logs-01.loggly.com';
+    protected const ENDPOINT_SINGLE = 'inputs';
+    protected const ENDPOINT_BATCH = 'bulk';
 
     protected $token;
 
@@ -76,7 +76,7 @@ class LogglyHandler extends AbstractProcessingHandler
 
     protected function write(array $record): void
     {
-        $this->send($record["formatted"], self::ENDPOINT_SINGLE);
+        $this->send($record["formatted"], static::ENDPOINT_SINGLE);
     }
 
     public function handleBatch(array $records): void
@@ -88,13 +88,13 @@ class LogglyHandler extends AbstractProcessingHandler
         });
 
         if ($records) {
-            $this->send($this->getFormatter()->formatBatch($records), self::ENDPOINT_BATCH);
+            $this->send($this->getFormatter()->formatBatch($records), static::ENDPOINT_BATCH);
         }
     }
 
     protected function send(string $data, string $endpoint): void
     {
-        $url = sprintf("https://%s/%s/%s/", self::HOST, $endpoint, $this->token);
+        $url = sprintf("https://%s/%s/%s/", static::HOST, $endpoint, $this->token);
 
         $headers = ['Content-Type: application/json'];
 

+ 2 - 2
src/Monolog/Handler/ProcessHandler.php

@@ -51,7 +51,7 @@ class ProcessHandler extends AbstractProcessingHandler
     /**
      * @var array
      */
-    public const DESCRIPTOR_SPEC = [
+    protected const DESCRIPTOR_SPEC = [
         0 => ['pipe', 'r'],  // STDIN is a pipe that the child will read from
         1 => ['pipe', 'w'],  // STDOUT is a pipe that the child will write to
         2 => ['pipe', 'w'],  // STDERR is a pipe to catch the any errors
@@ -115,7 +115,7 @@ class ProcessHandler extends AbstractProcessingHandler
      */
     private function startProcess(): void
     {
-        $this->process = proc_open($this->command, self::DESCRIPTOR_SPEC, $this->pipes, $this->cwd);
+        $this->process = proc_open($this->command, static::DESCRIPTOR_SPEC, $this->pipes, $this->cwd);
 
         foreach ($this->pipes as $pipe) {
             stream_set_blocking($pipe, false);

+ 1 - 1
src/Monolog/Handler/RotatingFileHandler.php

@@ -50,7 +50,7 @@ class RotatingFileHandler extends StreamHandler
         $this->maxFiles = (int) $maxFiles;
         $this->nextRotation = new \DateTimeImmutable('tomorrow');
         $this->filenameFormat = '{filename}-{date}';
-        $this->dateFormat = self::FILE_PER_DAY;
+        $this->dateFormat = static::FILE_PER_DAY;
 
         parent::__construct($this->getTimedFilename(), $level, $bubble, $filePermission, $useLocking);
     }

+ 4 - 4
src/Monolog/Handler/Slack/SlackRecord.php

@@ -182,13 +182,13 @@ class SlackRecord
     {
         switch (true) {
             case $level >= Logger::ERROR:
-                return self::COLOR_DANGER;
+                return static::COLOR_DANGER;
             case $level >= Logger::WARNING:
-                return self::COLOR_WARNING;
+                return static::COLOR_WARNING;
             case $level >= Logger::INFO:
-                return self::COLOR_GOOD;
+                return static::COLOR_GOOD;
             default:
-                return self::COLOR_DEFAULT;
+                return static::COLOR_DEFAULT;
         }
     }
 

+ 4 - 4
src/Monolog/Handler/SqsHandler.php

@@ -22,9 +22,9 @@ use Monolog\Logger;
 class SqsHandler extends AbstractProcessingHandler
 {
     /** 256 KB in bytes - maximum message size in SQS */
-    public const MAX_MESSAGE_SIZE = 262144;
+    protected const MAX_MESSAGE_SIZE = 262144;
     /** 100 KB in bytes - head message size for new error log */
-    public const HEAD_MESSAGE_SIZE = 102400;
+    protected const HEAD_MESSAGE_SIZE = 102400;
 
     /** @var SqsClient */
     private $client;
@@ -51,8 +51,8 @@ class SqsHandler extends AbstractProcessingHandler
         }
 
         $messageBody = $record['formatted'];
-        if (strlen($messageBody) >= self::MAX_MESSAGE_SIZE) {
-            $messageBody = substr($messageBody, 0, self::HEAD_MESSAGE_SIZE);
+        if (strlen($messageBody) >= static::MAX_MESSAGE_SIZE) {
+            $messageBody = substr($messageBody, 0, static::HEAD_MESSAGE_SIZE);
         }
 
         $this->client->sendMessage([

+ 2 - 2
src/Monolog/Handler/SyslogUdp/UdpSocket.php

@@ -13,7 +13,7 @@ namespace Monolog\Handler\SyslogUdp;
 
 class UdpSocket
 {
-    public const DATAGRAM_MAX_LENGTH = 65023;
+    protected const DATAGRAM_MAX_LENGTH = 65023;
 
     /** @var string */
     protected $ip;
@@ -52,7 +52,7 @@ class UdpSocket
 
     protected function assembleMessage(string $line, string $header): string
     {
-        $chunkSize = self::DATAGRAM_MAX_LENGTH - strlen($header);
+        $chunkSize = static::DATAGRAM_MAX_LENGTH - strlen($header);
 
         return $header . substr($line, 0, $chunkSize);
     }

+ 1 - 1
tests/Monolog/Formatter/WildfireFormatterTest.php

@@ -120,7 +120,7 @@ class WildfireFormatterTest extends \PHPUnit\Framework\TestCase
             'level_name' => 'ERROR',
             'channel' => 'table-channel',
             'context' => [
-            WildfireFormatter::TABLE => [
+                'table' => [
                     ['col1', 'col2', 'col3'],
                     ['val1', 'val2', 'val3'],
                     ['foo1', 'foo2', 'foo3'],

+ 3 - 3
tests/Monolog/Handler/ChromePHPHandlerTest.php

@@ -39,7 +39,7 @@ class ChromePHPHandlerTest extends TestCase
 
         $expected = [
             'X-ChromeLogger-Data'   => base64_encode(utf8_encode(json_encode([
-                'version' => ChromePHPHandler::VERSION,
+                'version' => '4.0',
                 'columns' => ['label', 'log', 'backtrace', 'type'],
                 'rows' => [
                     'test',
@@ -73,7 +73,7 @@ class ChromePHPHandlerTest extends TestCase
 
         $expected = [
             'X-ChromeLogger-Data'   => base64_encode(utf8_encode(json_encode([
-                'version' => ChromePHPHandler::VERSION,
+                'version' => '4.0',
                 'columns' => ['label', 'log', 'backtrace', 'type'],
                 'rows' => [
                     [
@@ -116,7 +116,7 @@ class ChromePHPHandlerTest extends TestCase
 
         $expected = [
             'X-ChromeLogger-Data'   => base64_encode(utf8_encode(json_encode([
-                'version' => ChromePHPHandler::VERSION,
+                'version' => '4.0',
                 'columns' => ['label', 'log', 'backtrace', 'type'],
                 'rows' => [
                     'test',

+ 1 - 1
tests/Monolog/Handler/FleepHookHandlerTest.php

@@ -80,6 +80,6 @@ class FleepHookHandlerTest extends TestCase
      */
     public function testConnectionStringisConstructedCorrectly()
     {
-        $this->assertEquals('ssl://' . FleepHookHandler::FLEEP_HOST . ':443', $this->handler->getConnectionString());
+        $this->assertEquals('ssl://fleep.io:443', $this->handler->getConnectionString());
     }
 }