diff --git a/composer.json b/composer.json index ad920e2..a5aa3e7 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,7 @@ "name": "firephp/firephp-core", "description": "Minimal library for sending PHP variables to browsers.", "type": "library", + "version": "0.5.4", "homepage": "https://github.com/firephp/firephp-core", "license": "MIT", "authors": [ @@ -26,7 +27,7 @@ ] }, "require-dev": { - "phpunit/phpunit": "^8" + "phpunit/phpunit": "^12" }, "scripts": { "test": "phpunit --testdox --configuration tests/phpunit.xml" diff --git a/lib/FirePHPCore/FirePHP.class.php b/lib/FirePHPCore/FirePHP.class.php index e864d47..4f2f15d 100644 --- a/lib/FirePHPCore/FirePHP.class.php +++ b/lib/FirePHPCore/FirePHP.class.php @@ -3,6 +3,7 @@ // - cadorn, Christoph Dorn , Copyright 2007, New BSD License // - qbbr, Sokolov Innokenty , Copyright 2011, New BSD License // - cadorn, Christoph Dorn , Copyright 2011, MIT License +// - marwin, Martin Winstrand , Copyright 2025, MIT License /** * *** BEGIN LICENSE BLOCK ***** @@ -37,21 +38,7 @@ * @package FirePHPCore */ -/** - * @see http://code.google.com/p/firephp/issues/detail?id=112 - */ -if (!defined('E_STRICT')) { - define('E_STRICT', 2048); -} -if (!defined('E_RECOVERABLE_ERROR')) { - define('E_RECOVERABLE_ERROR', 4096); -} -if (!defined('E_DEPRECATED')) { - define('E_DEPRECATED', 8192); -} -if (!defined('E_USER_DEPRECATED')) { - define('E_USER_DEPRECATED', 16384); -} +namespace FirePHP; /** * Sends the given data to the FirePHP Firefox Extension. @@ -72,7 +59,7 @@ class FirePHP { * * @var string */ - const VERSION = '0.3'; // @pinf replace '0.3' with '%%VERSION%%' + public const string VERSION = '0.5.4'; // @pinf replace '0.3' with '%%VERSION%%' /** * Firebug LOG level @@ -81,7 +68,7 @@ class FirePHP { * * @var string */ - const LOG = 'LOG'; + public const string LOG = 'LOG'; /** * Firebug INFO level @@ -90,7 +77,7 @@ class FirePHP { * * @var string */ - const INFO = 'INFO'; + public const string INFO = 'INFO'; /** * Firebug WARN level @@ -99,7 +86,7 @@ class FirePHP { * * @var string */ - const WARN = 'WARN'; + public const string WARN = 'WARN'; /** * Firebug ERROR level @@ -108,21 +95,21 @@ class FirePHP { * * @var string */ - const ERROR = 'ERROR'; + public const string ERROR = 'ERROR'; /** * Dumps a variable to firebug's server panel * * @var string */ - const DUMP = 'DUMP'; + public const string DUMP = 'DUMP'; /** * Displays a stack trace in firebug console * * @var string */ - const TRACE = 'TRACE'; + public const string TRACE = 'TRACE'; /** * Displays an exception in firebug console @@ -131,28 +118,28 @@ class FirePHP { * * @var string */ - const EXCEPTION = 'EXCEPTION'; + public const string EXCEPTION = 'EXCEPTION'; /** * Displays an table in firebug console * * @var string */ - const TABLE = 'TABLE'; + public const string TABLE = 'TABLE'; /** * Starts a group in firebug console * * @var string */ - const GROUP_START = 'GROUP_START'; + public const string GROUP_START = 'GROUP_START'; /** * Ends a group in firebug console * * @var string */ - const GROUP_END = 'GROUP_END'; + public const string GROUP_END = 'GROUP_END'; /** * Singleton instance of FirePHP @@ -166,42 +153,42 @@ class FirePHP { * * @var boolean */ - protected $inExceptionHandler = false; + protected bool $inExceptionHandler = false; /** * Flag whether to throw PHP errors that have been converted to ErrorExceptions * * @var boolean */ - protected $throwErrorExceptions = true; + protected bool $throwErrorExceptions = true; /** * Flag whether to convert PHP assertion errors to Exceptions * * @var boolean */ - protected $convertAssertionErrorsToExceptions = true; + protected bool $convertAssertionErrorsToExceptions = true; /** * Flag whether to throw PHP assertion errors that have been converted to Exceptions * * @var boolean */ - protected $throwAssertionExceptions = false; + protected bool $throwAssertionExceptions = false; /** * Wildfire protocol message index * * @var integer */ - protected $messageIndex = 1; + protected int $messageIndex = 1; /** * Options for the library * * @var array */ - protected $options = array( + protected array $options = array( 'maxDepth' => 10, 'maxObjectDepth' => 5, 'maxArrayDepth' => 5, @@ -215,7 +202,7 @@ class FirePHP { * * @var array */ - protected $objectFilters = array( + protected array $objectFilters = array( 'firephp' => array('objectStack', 'instance', 'json_objectStack') // 'firephp_test_class' => array('objectStack', 'instance', 'json_objectStack') ); @@ -225,7 +212,7 @@ class FirePHP { * * @var array */ - protected $ignoredInTraces = array( + protected array $ignoredInTraces = array( 'classes' => array( 'FirePHP' => true, 'FB' => true @@ -238,23 +225,23 @@ class FirePHP { * * @var object */ - protected $objectStack = array(); + protected array $objectStack = array(); /** * Flag to enable/disable logging * * @var boolean */ - protected $enabled = true; + protected bool $enabled = true; /** * The insight console to log to if applicable * * @var object */ - protected $logToInsightConsole = null; + protected mixed $logToInsightConsole = null; - function __construct () + public function __construct () { $this->ignoredInTraces['paths'][__DIR__] = true; $this->ignoredInTraces['paths'][__FILE__] = true; @@ -265,7 +252,7 @@ function __construct () * * @return array */ - public function __sleep() + public function __sleep() : array { return array('options', 'objectFilters', 'enabled'); } @@ -276,7 +263,7 @@ public function __sleep() * @param boolean $autoCreate * @return FirePHP */ - public static function getInstance($autoCreate = false) + public static function getInstance(bool $autoCreate = false) : FirePHP { if ($autoCreate === true && !self::$instance) { self::init(); @@ -289,7 +276,7 @@ public static function getInstance($autoCreate = false) * * @return FirePHP */ - public static function init() + public static function init() : FirePHP { return self::setInstance(new self()); } @@ -300,7 +287,7 @@ public static function init() * @param FirePHP $instance The FirePHP object instance * @return FirePHP */ - public static function setInstance($instance) + public static function setInstance($instance) : FirePHP { return self::$instance = $instance; } @@ -329,7 +316,7 @@ public function setLogToInsightConsole($console) * @param boolean $enabled TRUE to enable, FALSE to disable * @return void */ - public function setEnabled($enabled) + public function setEnabled(bool $enabled) { $this->enabled = $enabled; } @@ -339,7 +326,7 @@ public function setEnabled($enabled) * * @return boolean TRUE if enabled */ - public function getEnabled() + public function getEnabled() : bool { return $this->enabled; } @@ -363,7 +350,7 @@ public function setObjectFilter($class, $filter = true) * * @param string $class The class name to ignore */ - public function ignoreClassInTraces ($class) + public function ignoreClassInTraces (string $class) { $this->ignoredInTraces['classes'][$class] = true; } @@ -373,7 +360,7 @@ public function ignoreClassInTraces ($class) * * @param string $path The path prefix to ignore */ - public function ignorePathInTraces ($path) + public function ignorePathInTraces (string $path) { $this->ignoredInTraces['paths'][$path] = true; } @@ -387,7 +374,7 @@ public function ignorePathInTraces ($path) * @param string $name The property name to check * @return boolean */ - protected function _isClassPropertyInObjectFilter($class, $name) + protected function isClassPropertyInObjectFilter(string $class, string $name) : bool { $classes = class_parents($class); array_unshift($classes, $class); @@ -429,7 +416,7 @@ protected function _isClassPropertyInObjectFilter($class, $name) * @param array $options The options to be set * @return void */ - public function setOptions($options) + public function setOptions(array $options) { $this->options = array_merge($this->options, $options); } @@ -439,7 +426,7 @@ public function setOptions($options) * * @return array The currently set options */ - public function getOptions() + public function getOptions() : array { return $this->options; } @@ -452,7 +439,7 @@ public function getOptions() * @return void * @throws Exception */ - public function setOption($name, $value) + public function setOption(string $name, mixed $value) { if (!isset($this->options[$name])) { throw $this->newException('Unknown option: ' . $name); @@ -467,7 +454,7 @@ public function setOption($name, $value) * @return mixed * @throws Exception */ - public function getOption($name) + public function getOption(string $name) : mixed { if (!isset($this->options[$name])) { throw $this->newException('Unknown option: ' . $name); @@ -482,7 +469,7 @@ public function getOption($name) * * @return mixed Returns a string containing the previously defined error handler (if any) */ - public function registerErrorHandler($throwErrorExceptions = false) + public function registerErrorHandler($throwErrorExceptions = false) : mixed { //NOTE: The following errors will not be caught by this error handler: // E_ERROR, E_PARSE, E_CORE_ERROR, @@ -505,7 +492,7 @@ public function registerErrorHandler($throwErrorExceptions = false) * @param integer $errline * @param array $errcontext */ - public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) + public function errorHandler(int $errno, string $errstr, string $errfile, int $errline, array $errcontext) : mixed { // Don't throw exception if error reporting is switched off if (error_reporting() == 0) { @@ -530,7 +517,7 @@ public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) * or NULL on error. * If no previous handler was defined, NULL is also returned. */ - public function registerExceptionHandler() + public function registerExceptionHandler() : mixed { return set_exception_handler(array($this, 'exceptionHandler')); } @@ -543,7 +530,7 @@ public function registerExceptionHandler() * @param Exception $exception * @throws Exception */ - function exceptionHandler($exception) + public function exceptionHandler(\Exception $exception) { $this->inExceptionHandler = true; @@ -565,7 +552,7 @@ function exceptionHandler($exception) * @param boolean $throwAssertionExceptions * @return mixed Returns the original setting or FALSE on errors */ - public function registerAssertionHandler($convertAssertionErrorsToExceptions = true, $throwAssertionExceptions = false) + public function registerAssertionHandler(bool $convertAssertionErrorsToExceptions = true, bool $throwAssertionExceptions = false) : mixed { $this->convertAssertionErrorsToExceptions = $convertAssertionErrorsToExceptions; $this->throwAssertionExceptions = $throwAssertionExceptions; @@ -586,7 +573,7 @@ public function registerAssertionHandler($convertAssertionErrorsToExceptions = t * @param integer $line Line source of assertion * @param mixed $code Assertion code */ - public function assertionHandler($file, $line, $code) + public function assertionHandler(string $file, int $line, mixed $code) : mixed { if ($this->convertAssertionErrorsToExceptions) { @@ -615,7 +602,7 @@ public function assertionHandler($file, $line, $code) * @return true * @throws Exception */ - public function group($name, $options = null) + public function group(string $name, ?array $options = null) : bool { if ( is_null($name) || @@ -642,7 +629,7 @@ public function group($name, $options = null) * @return true * @throws Exception */ - public function groupEnd() + public function groupEnd() : bool { return $this->fb(null, null, FirePHP::GROUP_END); } @@ -656,7 +643,7 @@ public function groupEnd() * @return true * @throws Exception */ - public function log($object, $label = null, $options = array()) + public function log(mixed $object, ?string $label = null, array $options = array()) : bool { return $this->fb($object, $label, FirePHP::LOG, $options); } @@ -670,7 +657,7 @@ public function log($object, $label = null, $options = array()) * @return true * @throws Exception */ - public function info($object, $label = null, $options = array()) + public function info(mixed $object, ?string $label = null, array $options = array()) : bool { return $this->fb($object, $label, FirePHP::INFO, $options); } @@ -684,7 +671,7 @@ public function info($object, $label = null, $options = array()) * @return true * @throws Exception */ - public function warn($object, $label = null, $options = array()) + public function warn(mixed $object, ?string $label = null, array $options = array()) : bool { return $this->fb($object, $label, FirePHP::WARN, $options); } @@ -698,7 +685,7 @@ public function warn($object, $label = null, $options = array()) * @return true * @throws Exception */ - public function error($object, $label = null, $options = array()) + public function error(mixed $object, ?string $label = null, array $options = array()) : bool { return $this->fb($object, $label, FirePHP::ERROR, $options); } @@ -712,7 +699,7 @@ public function error($object, $label = null, $options = array()) * @return true * @throws Exception */ - public function dump($key, $variable, $options = array()) + public function dump(string $key, mixed $variable, array $options = array()) : bool { if (!is_string($key)) { throw $this->newException('Key passed to dump() is not a string'); @@ -734,7 +721,7 @@ public function dump($key, $variable, $options = array()) * @return true * @throws Exception */ - public function trace($label) + public function trace(string $label) : bool { return $this->fb($label, null, FirePHP::TRACE, array( 'trace' => debug_backtrace() @@ -750,7 +737,7 @@ public function trace($label) * @return true * @throws Exception */ - public function table($label, $table, $options = array()) + public function table(string $label, string $table, array $options = array()) : bool { return $this->fb($table, $label, FirePHP::TABLE, $options); } @@ -760,7 +747,7 @@ public function table($label, $table, $options = array()) * * @see Insight_Helper::to() */ - public static function to() + public static function to() : mixed { $instance = self::getInstance(); if (!method_exists($instance, '_to')) { @@ -775,7 +762,7 @@ public static function to() * * @see Insight_Helper::plugin() */ - public static function plugin() + public static function plugin() : mixed { $instance = self::getInstance(); if (!method_exists($instance, '_plugin')) { @@ -790,7 +777,7 @@ public static function plugin() * * @return boolean */ - public function detectClientExtension() + public function detectClientExtension() : bool { // Check if FirePHP is installed on client via User-Agent header if (@preg_match_all('/\sFirePHP\/([\.\d]*)\s?/si', $this->getUserAgent(), $m) && @@ -810,7 +797,8 @@ public function detectClientExtension() * * @param string $trace A debug_backtrace() trace */ - protected function filterDebugBacktrace ($trace, $offset = 0) { + protected function filterDebugBacktrace (mixed $trace, int $offset = 0) : mixed + { $discardedTrace = array(); $filteredTrace = array(); for ($i = 0; $i < sizeof($trace); $i++) { @@ -818,7 +806,7 @@ protected function filterDebugBacktrace ($trace, $offset = 0) { count($this->ignoredInTraces['classes']) && isset($trace[$i]['class']) && ( - isset($this->ignoredInTraces['classes'][$trace[$i]['class']]) || + isset($ignoredInTraces['classes'][$trace[$i]['class']]) || array_reduce( array_keys($this->ignoredInTraces['classes']), function ($carry, $class) use ($trace, $i) @@ -839,7 +827,7 @@ function ($carry, $class) use ($trace, $i) count($this->ignoredInTraces['paths']) && isset($trace[$i]['file']) && ( - isset($this->ignoredInTraces['paths'][$trace[$i]['file']]) || + isset($ignoredInTraces['paths'][$trace[$i]['file']]) || array_reduce( array_keys($this->ignoredInTraces['paths']), function ($carry, $path) use ($trace, $i) @@ -874,7 +862,7 @@ function ($carry, $path) use ($trace, $i) * @return boolean Return TRUE if message was added to headers, FALSE otherwise * @throws Exception */ - public function fb($object) + public function fb(mixed $object) : bool { if ($this instanceof FirePHP_Insight && method_exists($this, '_logUpgradeClientMessage')) { if (!FirePHP_Insight::$upgradeClientMessageLogged) { // avoid infinite recursion as _logUpgradeClientMessage() logs a message @@ -948,17 +936,17 @@ public function fb($object) } } if (isset($trace[$i]['file'])) { - $path = $this->_standardizePath($trace[$i]['file']); + $path = $this->standardizePath($trace[$i]['file']); if (substr($path, -1*$fbLength, $fbLength) == $parentFolder.'/fb.php' || substr($path, -1*$fireClassLength, $fireClassLength) == $parentFolder.'/FirePHP.class.php') { continue; } } if (isset($trace[$i]['function']) && $trace[$i]['function'] == 'fb' && - isset($trace[$i - 1]['file']) && substr($this->_standardizePath($trace[$i - 1]['file']), -1*$fbLength, $fbLength) == $parentFolder.'/fb.php') { + isset($trace[$i - 1]['file']) && substr($this->standardizePath($trace[$i - 1]['file']), -1*$fbLength, $fbLength) == $parentFolder.'/fb.php') { continue; } if (isset($trace[$i]['class']) && $trace[$i]['class'] == 'FB' && - isset($trace[$i - 1]['file']) && substr($this->_standardizePath($trace[$i - 1]['file']), -1*$fbLength, $fbLength) == $parentFolder.'/fb.php') { + isset($trace[$i - 1]['file']) && substr($this->standardizePath($trace[$i - 1]['file']), -1*$fbLength, $fbLength) == $parentFolder.'/fb.php') { continue; } break; @@ -1014,7 +1002,7 @@ public function fb($object) if ($object instanceof Exception) { - $meta['file'] = $this->_escapeTraceFile($object->getFile()); + $meta['file'] = $this->escapeTraceFile($object->getFile()); $meta['line'] = $object->getLine(); $originalTrace = $object->getTrace(); @@ -1051,10 +1039,6 @@ public function fb($object) $severity = 'E_USER_NOTICE'; break; - case E_STRICT: - $severity = 'E_STRICT'; - break; - case E_RECOVERABLE_ERROR: $severity = 'E_RECOVERABLE_ERROR'; break; @@ -1071,10 +1055,10 @@ public function fb($object) $object = array( 'Class' => get_class($object), 'Message' => $severity . ': ' . $object->getMessage(), - 'File' => $this->_escapeTraceFile($object->getFile()), + 'File' => $this->escapeTraceFile($object->getFile()), 'Line' => $object->getLine(), 'Type' => 'trigger', - 'Trace' => $this->_escapeTrace($trace, array( + 'Trace' => $this->escapeTrace($trace, array( 'maxDepth' => 2, 'includeMaxDepthProperties' => false, 'includeStaticProperties' => false, @@ -1088,10 +1072,10 @@ public function fb($object) $object = array( 'Class' => get_class($object), 'Message' => $object->getMessage(), - 'File' => $this->_escapeTraceFile($object->getFile()), + 'File' => $this->escapeTraceFile($object->getFile()), 'Line' => $object->getLine(), 'Type' => 'throw', - 'Trace' => $this->_escapeTrace($trace, array( + 'Trace' => $this->escapeTrace($trace, array( 'maxDepth' => 2, 'includeMaxDepthProperties' => false, 'includeStaticProperties' => false, @@ -1139,7 +1123,7 @@ public function fb($object) 'Type' => isset($callingFrame['type']) ? $callingFrame['type'] : '', 'Function' => isset($callingFrame['function']) ? $callingFrame['function'] : '', 'Message' => $callingFrame['args'][0], - 'File' => isset($callingFrame['file']) ? $this->_escapeTraceFile($callingFrame['file']) : '', + 'File' => isset($callingFrame['file']) ? $this->escapeTraceFile($callingFrame['file']) : '', 'Line' => isset($callingFrame['line']) ? $callingFrame['line'] : '', 'Args' => isset($callingFrame['args']) ? $this->encodeObject($callingFrame['args'], 1, 1, 1, array( 'maxDepth' => 2, @@ -1149,7 +1133,7 @@ public function fb($object) 'includeProtectedProperties' => false, 'includeUndeclaredProperties' => false )) : '', - 'Trace' => $this->_escapeTrace($trace, array( + 'Trace' => $this->escapeTrace($trace, array( 'maxDepth' => 2, 'includeMaxDepthProperties' => false, 'includeStaticProperties' => false, @@ -1160,7 +1144,7 @@ public function fb($object) ); $skipFinalObjectEncode = true; - $meta['file'] = isset($callingFrame['file']) ? $this->_escapeTraceFile($callingFrame['file']) : ''; + $meta['file'] = isset($callingFrame['file']) ? $this->escapeTraceFile($callingFrame['file']) : ''; $meta['line'] = isset($callingFrame['line']) ? $callingFrame['line'] : ''; } else @@ -1221,7 +1205,7 @@ public function fb($object) $encounteredCount += 1; continue; } - $meta['file'] = isset($trace[$i]['file']) ? $this->_escapeTraceFile($trace[$i]['file']) : ''; + $meta['file'] = isset($trace[$i]['file']) ? $this->escapeTraceFile($trace[$i]['file']) : ''; $meta['line'] = isset($trace[$i]['line']) ? $trace[$i]['line'] : ''; break; } @@ -1300,7 +1284,7 @@ public function fb($object) * @param string $path * @return string */ - protected function _standardizePath($path) + protected function standardizePath(string $path) : string { return preg_replace('/\\\\+/', '/', $path); } @@ -1311,12 +1295,12 @@ protected function _standardizePath($path) * @param array $trace * @return array */ - protected function _escapeTrace($trace, $options = array()) + protected function escapeTrace(array $trace, array $options = array()) : array { if (!$trace) return $trace; for ($i = 0; $i < sizeof($trace); $i++) { if (isset($trace[$i]['file'])) { - $trace[$i]['file'] = $this->_escapeTraceFile($trace[$i]['file']); + $trace[$i]['file'] = $this->escapeTraceFile($trace[$i]['file']); } if (isset($trace[$i]['args'])) { $trace[$i]['args'] = $this->encodeObject($trace[$i]['args'], 1, 1, 1, $options); @@ -1331,7 +1315,7 @@ protected function _escapeTrace($trace, $options = array()) * @param string $file * @return string */ - protected function _escapeTraceFile($file) + protected function escapeTraceFile(string $file) : string { /* Check if we have a windows filepath */ if (strpos($file, '\\')) { @@ -1350,7 +1334,7 @@ protected function _escapeTraceFile($file) * @param string $filename * @param integer $linenum */ - protected function headersSent(&$filename, &$linenum) + protected function headersSent(?string &$filename, ?int &$linenum) : mixed { return headers_sent($filename, $linenum); } @@ -1361,7 +1345,7 @@ protected function headersSent(&$filename, &$linenum) * @param string $name * @param string $value */ - protected function setHeader($name, $value) + protected function setHeader(string $name, string $value) : mixed { return header($name . ': ' . $value); } @@ -1371,7 +1355,7 @@ protected function setHeader($name, $value) * * @return string|false */ - protected function getUserAgent() + protected function getUserAgent() : string|false { if (!isset($_SERVER['HTTP_USER_AGENT'])) return false; return $_SERVER['HTTP_USER_AGENT']; @@ -1382,7 +1366,7 @@ protected function getUserAgent() * * @return array */ - public static function getAllRequestHeaders() + public static function getAllRequestHeaders() : array { static $_cachedHeaders = false; if ($_cachedHeaders !== false) { @@ -1408,7 +1392,7 @@ public static function getAllRequestHeaders() * * @return string|false */ - protected function getRequestHeader($name) + protected function getRequestHeader(mixed $name) : string | false { $headers = self::getAllRequestHeaders(); if (isset($headers[strtolower($name)])) { @@ -1423,7 +1407,7 @@ protected function getRequestHeader($name) * @param string $message * @return Exception */ - protected function newException($message) + protected function newException(string $message) : Exception { return new Exception($message); } @@ -1437,7 +1421,7 @@ protected function newException($message) * @param boolean $skipObjectEncode * @return string The JSON string */ - public function jsonEncode($object, $skipObjectEncode = false) + public function jsonEncode(mixed $object, bool $skipObjectEncode = false) : string { if (!$skipObjectEncode) { $object = $this->encodeObject($object); @@ -1458,7 +1442,7 @@ public function jsonEncode($object, $skipObjectEncode = false) * @param array $table The table to be encoded * @return array */ - protected function encodeTable($table, $options = array()) + protected function encodeTable(array $table, array $options = array()) : array { if (!$table) return $table; @@ -1490,7 +1474,13 @@ protected function encodeTable($table, $options = array()) * @param array $options Encoding options * @return array All members of the object */ - protected function encodeObject($object, $objectDepth = 1, $arrayDepth = 1, $maxDepth = 1, $options = array()) + protected function encodeObject( + mixed $object, + int $objectDepth = 1, + int $arrayDepth = 1, + int $maxDepth = 1, + array $options = array() + ) : mixed { if ( $maxDepth > $this->options['maxDepth'] || @@ -1533,7 +1523,7 @@ protected function encodeObject($object, $objectDepth = 1, $arrayDepth = 1, $max return '** Excluded by Filter (' . $class . ') **'; } - $reflectionClass = new ReflectionClass($class); + $reflectionClass = new \ReflectionClass($class); $properties = array(); foreach ($reflectionClass->getProperties() as $property) { $properties[$property->getName()] = $property; @@ -1566,7 +1556,7 @@ protected function encodeObject($object, $objectDepth = 1, $arrayDepth = 1, $max $rawName = "\0" . '*' . "\0" . $rawName; } - if (!$this->_isClassPropertyInObjectFilter($class, $plainName)) { + if (!$this->isClassPropertyInObjectFilter($class, $plainName)) { if (array_key_exists($rawName, $members) && !$property->isStatic()) { $return[$name] = $this->encodeObject($members[$rawName], $objectDepth + 1, 1, $maxDepth + 1, $options); } else { @@ -1613,7 +1603,7 @@ protected function encodeObject($object, $objectDepth = 1, $arrayDepth = 1, $max } $name = 'undeclared:' . $name; - if (!$this->_isClassPropertyInObjectFilter($class, $plainName)) { + if (!$this->isClassPropertyInObjectFilter($class, $plainName)) { $return[$name] = $this->encodeObject($value, $objectDepth + 1, 1, $maxDepth + 1, $options); } else { $return[$name] = '** Excluded by Filter **'; @@ -1676,12 +1666,12 @@ protected function encodeObject($object, $objectDepth = 1, $arrayDepth = 1, $max } } elseif ( is_bool($object) ) { - return $object; - } elseif ( is_null($object) ) { - return $object; - } elseif ( is_numeric($object) ) { - return $object; - } else { + return $object; + } elseif ( is_null($object) ) { + return $object; + } elseif ( is_numeric($object) ) { + return $object; + } else { if ($this->is_utf8($object)) { return $object; } else { @@ -1697,7 +1687,7 @@ protected function encodeObject($object, $objectDepth = 1, $arrayDepth = 1, $max * @param mixed $str String to be tested * @return boolean */ - protected function is_utf8($str) + protected function is_utf8(string $str) : bool { if (function_exists('mb_detect_encoding')) { return ( @@ -1791,7 +1781,7 @@ protected function is_utf8($str) /** * Keep a list of objects as we descend into the array so we can detect recursion. */ - private $json_objectStack = array(); + private array $json_objectStack = array(); /** @@ -1805,7 +1795,7 @@ protected function is_utf8($str) * @return string UTF-16 character * @access private */ - private function json_utf82utf16($utf8) + private function json_utf82utf16(string $utf8) : string { // oh please oh please oh please oh please oh please if (function_exists('mb_convert_encoding')) { @@ -1849,7 +1839,7 @@ private function json_utf82utf16($utf8) * @return mixed JSON string representation of input var or an error if a problem occurs * @access public */ - private function json_encode($var) + private function json_encode(mixed $var) : mixed { if (is_object($var)) { if (in_array($var, $this->json_objectStack)) { @@ -2063,7 +2053,7 @@ private function json_encode($var) * @return string JSON-formatted name-value pair, like '"name":value' * @access private */ - private function json_name_value($name, $value) + private function json_name_value(string $name, mixed $value) : mixed { // Encoding the $GLOBALS PHP array causes an infinite loop // if the recursion is not reset here as it contains diff --git a/lib/FirePHPCore/FirePHP_TestWrapper.class.php b/lib/FirePHPCore/FirePHP_TestWrapper.class.php index cbb86e9..d1cf623 100644 --- a/lib/FirePHPCore/FirePHP_TestWrapper.class.php +++ b/lib/FirePHPCore/FirePHP_TestWrapper.class.php @@ -2,25 +2,29 @@ class FirePHP_TestWrapper extends FirePHP { - private $_headers = array(); + private array $_headers = array(); - public function _getHeaders() { + public function _getHeaders() : mixed + { return $this->_headers; } - public function _getHeader($index) { + public function _getHeader(mixed $index) : mixed + { return $this->_headers[array_slice(array_keys($this->_headers), $index-1, 1)[0]]; } - public function _clearHeaders() { + public function _clearHeaders() : void + { $this->_headers = array(); } // ###################### // # Subclassed Methods # - // ###################### + // ###################### - protected function setHeader($Name, $Value) { + protected function setHeader(string $Name, mixed $Value) : void + { preg_match('/(\d+)\|(.+)$/', $Value, $countMatch); @@ -39,12 +43,14 @@ protected function setHeader($Name, $Value) { } } - protected function headersSent(&$Filename, &$Linenum) { + protected function headersSent(string &$Filename, int &$Linenum) : bool + { return false; } - public function detectClientExtension() { + public function detectClientExtension() : bool + { return true; } - + } diff --git a/lib/FirePHPCore/fb.php b/lib/FirePHPCore/fb.php index de32731..61a2de0 100644 --- a/lib/FirePHPCore/fb.php +++ b/lib/FirePHPCore/fb.php @@ -3,14 +3,15 @@ // - cadorn, Christoph Dorn , Copyright 2007, New BSD License // - qbbr, Sokolov Innokenty , Copyright 2011, New BSD License // - cadorn, Christoph Dorn , Copyright 2011, MIT License +// - marwin, Martin Winstrand , Copyright 2025, MIT License /** * ***** BEGIN LICENSE BLOCK ***** - * + * * [MIT License](http://www.opensource.org/licenses/mit-license.php) - * + * * Copyright (c) 2007+ [Christoph Dorn](http://www.christophdorn.com/) - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights @@ -28,15 +29,17 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. - * + * * ***** END LICENSE BLOCK ***** - * + * * @copyright Copyright (C) 2007+ Christoph Dorn * @author Christoph Dorn * @license [MIT License](http://www.opensource.org/licenses/mit-license.php) * @package FirePHPCore */ +namespace FirePHP; + if (!class_exists('FirePHP', false)) { require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'FirePHP.class.php'; } @@ -45,7 +48,7 @@ * Sends the given data to the FirePHP Firefox Extension. * The data can be displayed in the Firebug Console or in the * "Server" request tab. - * + * * @see http://www.firephp.org/Wiki/Reference/Fb * @param mixed $Object * @return true @@ -54,7 +57,7 @@ function fb() { $instance = FirePHP::getInstance(true); - + $args = func_get_args(); return call_user_func_array(array($instance, 'fb'), $args); } @@ -64,85 +67,85 @@ class FB { /** * Set an Insight console to direct all logging calls to - * + * * @param object $console The console object to log to * @return void */ - public static function setLogToInsightConsole($console) + public static function setLogToInsightConsole(mixed $console) { FirePHP::getInstance(true)->setLogToInsightConsole($console); } /** * Enable and disable logging to Firebug - * + * * @see FirePHP->setEnabled() * @param boolean $enabled TRUE to enable, FALSE to disable * @return void */ - public static function setEnabled($enabled) + public static function setEnabled(bool $enabled) { FirePHP::getInstance(true)->setEnabled($enabled); } - + /** * Check if logging is enabled - * + * * @see FirePHP->getEnabled() * @return boolean TRUE if enabled */ - public static function getEnabled() + public static function getEnabled() : bool { return FirePHP::getInstance(true)->getEnabled(); } - + /** * Specify a filter to be used when encoding an object - * + * * Filters are used to exclude object members. - * + * * @see FirePHP->setObjectFilter() * @param string $class The class name of the object * @param array $filter An array or members to exclude * @return void */ - public static function setObjectFilter($class, $filter) + public static function setObjectFilter(string $class, array $filter) { FirePHP::getInstance(true)->setObjectFilter($class, $filter); } - + /** * Set some options for the library - * + * * @see FirePHP->setOptions() * @param array $options The options to be set * @return void */ - public static function setOptions($options) + public static function setOptions(array $options) { FirePHP::getInstance(true)->setOptions($options); } /** * Get options for the library - * + * * @see FirePHP->getOptions() * @return array The options */ - public static function getOptions() + public static function getOptions() : mixed { return FirePHP::getInstance(true)->getOptions(); } /** * Log object to firebug - * + * * @see http://www.firephp.org/Wiki/Reference/Fb * @param mixed $object * @return true * @throws Exception */ - public static function send() + public static function send(): bool { $args = func_get_args(); return call_user_func_array(array(FirePHP::getInstance(true), 'fb'), $args); @@ -150,7 +153,7 @@ public static function send() /** * Start a group for following messages - * + * * Options: * Collapsed: [true|false] * Color: [#RRGGBB|ColorName] @@ -159,7 +162,7 @@ public static function send() * @param array $options OPTIONAL Instructions on how to log the group * @return true */ - public static function group($name, $options=null) + public static function group(string $name, array $options=null): bool { return FirePHP::getInstance(true)->group($name, $options); } @@ -170,7 +173,7 @@ public static function group($name, $options=null) * @return true * @throws Exception */ - public static function groupEnd() + public static function groupEnd() : bool { return self::send(null, null, FirePHP::GROUP_END); } @@ -184,7 +187,7 @@ public static function groupEnd() * @return true * @throws Exception */ - public static function log($object, $label=null) + public static function log(mixed $object, ?string $label=null) : bool { return self::send($object, $label, FirePHP::LOG); } @@ -198,7 +201,7 @@ public static function log($object, $label=null) * @return true * @throws Exception */ - public static function info($object, $label=null) + public static function info(mixed $object, ?string $label=null) : bool { return self::send($object, $label, FirePHP::INFO); } @@ -212,7 +215,7 @@ public static function info($object, $label=null) * @return true * @throws Exception */ - public static function warn($object, $label=null) + public static function warn(mixed $object, ?string $label=null) : bool { return self::send($object, $label, FirePHP::WARN); } @@ -226,7 +229,7 @@ public static function warn($object, $label=null) * @return true * @throws Exception */ - public static function error($object, $label=null) + public static function error(mixed $object, ?string $label=null) : bool { return self::send($object, $label, FirePHP::ERROR); } @@ -240,7 +243,7 @@ public static function error($object, $label=null) * @return true * @throws Exception */ - public static function dump($key, $variable) + public static function dump(string $key, mixed $variable) : bool { return self::send($variable, $key, FirePHP::DUMP); } @@ -253,7 +256,7 @@ public static function dump($key, $variable) * @return true * @throws Exception */ - public static function trace($label) + public static function trace(string $label) : bool { return self::send($label, FirePHP::TRACE); } @@ -267,7 +270,7 @@ public static function trace($label) * @return true * @throws Exception */ - public static function table($label, $table) + public static function table(string $label, string $table) : bool { return self::send($table, $label, FirePHP::TABLE); } diff --git a/package.json b/package.json index 6835b30..389bc5b 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { - "uid": "https://github.com/firephp/firephp-core/", + "uid": "https://github.com/winstrand/firephp-core/", "name": "firephp-core", "description": "Minimal library for sending PHP variables to browsers.", "repositories": [ { "type": "git", - "url": "git://github.com/firephp/firephp-core.git" + "url": "git://github.com/winstrand/firephp-core.git" } ], "maintainers": [ @@ -37,6 +37,13 @@ "alias": { "github": "qbbr" } + }, + { + "name": "Martin Winstrand", + "email": "martin.winstrand@gmail.com", + "alias": { + "github": "winstrand" + } } ], "nodemonConfig": {