debug('SELECT * FROM users', array('db', 'time' => 0.012)); * PC::debug($_SERVER); // PHP Console debugger for any type of vars * * @author Sergey Barbushin https://www.linkedin.com/in/barbushin * * @phpstan-import-type Record from \Monolog\Logger * @deprecated Since 2.8.0 and 3.2.0, PHPConsole is abandoned and thus we will drop this handler in Monolog 4 */ class PHPConsoleHandler extends AbstractProcessingHandler { /** @var array */ private $options = [ 'enabled' => true, // bool Is PHP Console server enabled "classesPartialsTraceIgnore" => ['Monolog\\'], // array Hide calls of classes started with... "debugTagsKeysInContext" => [0, 'tag'], // bool Is PHP Console server enabled "useOwnErrorsHandler" => false, // bool Enable errors handling "useOwnExceptionsHandler" => false, // bool Enable exceptions handling "sourcesBasePath" => null, // string Base path of all project sources to strip in errors source paths "registerHelper" => true, // bool Register PhpConsole\Helper that allows short debug calls like PC::debug($var, 'ta.g.s') "serverEncoding" => null, // string|null Server internal encoding "headersLimit" => null, // int|null Set headers size limit for your web-server "password" => null, // string|null Protect PHP Console connection by password "enableSslOnlyMode" => false, // bool Force connection by SSL for clients with PHP Console installed "ipMasks" => [], // array Set IP masks of clients that will be allowed to connect to PHP Console: array('192.168.*.*', '127.0.0.1') "enableEvalListener" => false, // bool Enable eval request to be handled by eval dispatcher(if enabled, 'password' option is also required) "dumperDetectCallbacks" => false, // bool Convert callback items in dumper vars to (callback SomeClass::someMethod) strings "dumperLevelLimit" => 5, // int Maximum dumped vars array or object nested dump level "dumperItemsCountLimit" => 100, // int Maximum dumped var same level array items or object properties number "dumperItemSizeLimit" => 5000, // int Maximum length of any string or dumped array item "dumperDumpSizeLimit" => 500000, // int Maximum approximate size of dumped vars result formatted in JSON "detectDumpTraceAndSource" => false, // bool Autodetect and append trace data to debug "dataStorage" => null, // \PhpConsole\Storage|null Fixes problem with custom $_SESSION handler(see http://goo.gl/Ne8juJ) ]; /** @var Connector */ private $connector; /** * @param array $options See \Monolog\Handler\PHPConsoleHandler::$options for more details * @param Connector|null $connector Instance of \PhpConsole\Connector class (optional) * @throws \RuntimeException */ public function __construct( array $options = [], ?Connector $connector = null, $level = Logger::DEBUG, bool $bubble = true, ) { if (!class_exists('PhpConsole\Connector')) { throw new \RuntimeException('PHP Console library not found. See https://github.com/barbushin/php-console#installation'); } parent::__construct($level, $bubble); $this->options = $this->initOptions($options); $this->connector = $this->initConnector($connector); } /** * @param array $options * * @return array */ private function initOptions(array $options): array { $wrongOptions = array_diff(array_keys($options), array_keys($this->options)); if ($wrongOptions) { throw new \RuntimeException('Unknown options: ' . implode(', ', $wrongOptions)); } return array_replace($this->options, $options); } private function initConnector(?Connector $connector = null): Connector { if (!$connector) { if ($this->options['dataStorage']) { Connector::setPostponeStorage($this->options['dataStorage']); } $connector = Connector::getInstance(); } if ($this->options['registerHelper'] && !Helper::isRegistered()) { Helper::register(); } if ($this->options['enabled'] && $connector->isActiveClient()) { if ($this->options['useOwnErrorsHandler'] || $this->options['useOwnExceptionsHandler']) { $handler = VendorPhpConsoleHandler::getInstance(); $handler->setHandleErrors($this->options['useOwnErrorsHandler']); $handler->setHandleExceptions($this->options['useOwnExceptionsHandler']); $handler->start(); } if ($this->options['sourcesBasePath']) { $connector->setSourcesBasePath($this->options['sourcesBasePath']); } if ($this->options['serverEncoding']) { $connector->setServerEncoding($this->options['serverEncoding']); } if ($this->options['password']) { $connector->setPassword($this->options['password']); } if ($this->options['enableSslOnlyMode']) { $connector->enableSslOnlyMode(); } if ($this->options['ipMasks']) { $connector->setAllowedIpMasks($this->options['ipMasks']); } if ($this->options['headersLimit']) { $connector->setHeadersLimit($this->options['headersLimit']); } if ($this->options['detectDumpTraceAndSource']) { $connector->getDebugDispatcher()->detectTraceAndSource = true; } $dumper = $connector->getDumper(); $dumper->levelLimit = $this->options['dumperLevelLimit']; $dumper->itemsCountLimit = $this->options['dumperItemsCountLimit']; $dumper->itemSizeLimit = $this->options['dumperItemSizeLimit']; $dumper->dumpSizeLimit = $this->options['dumperDumpSizeLimit']; $dumper->detectCallbacks = $this->options['dumperDetectCallbacks']; if ($this->options['enableEvalListener']) { $connector->startEvalRequestsListener(); } } return $connector; } public function getConnector(): Connector { return $this->connector; } /** * @return array */ public function getOptions(): array { return $this->options; } public function handle(array $record): bool { if ($this->options['enabled'] && $this->connector->isActiveClient()) { return parent::handle($record); } return !$this->bubble; } /** * Writes the record down to the log of the implementing handler */ protected function write(array $record): void { if ($record['level'] < Logger::NOTICE) { $this->handleDebugRecord($record); } elseif (isset($record['context']['exception']) && $record['context']['exception'] instanceof \Throwable) { $this->handleExceptionRecord($record); } else { $this->handleErrorRecord($record); } } /** * @phpstan-param Record $record */ private function handleDebugRecord(array $record): void { $tags = $this->getRecordTags($record); $message = $record['message']; if ($record['context']) { $message .= ' ' . Utils::jsonEncode($this->connector->getDumper()->dump(array_filter($record['context'])), null, true); } $this->connector->getDebugDispatcher()->dispatchDebug($message, $tags, $this->options['classesPartialsTraceIgnore']); } /** * @phpstan-param Record $record */ private function handleExceptionRecord(array $record): void { $this->connector->getErrorsDispatcher()->dispatchException($record['context']['exception']); } /** * @phpstan-param Record $record */ private function handleErrorRecord(array $record): void { $context = $record['context']; $this->connector->getErrorsDispatcher()->dispatchError( $context['code'] ?? null, $context['message'] ?? $record['message'], $context['file'] ?? null, $context['line'] ?? null, $this->options['classesPartialsTraceIgnore'] ); } /** * @phpstan-param Record $record * @return string */ private function getRecordTags(array &$record) { $tags = null; if (!empty($record['context'])) { $context = & $record['context']; foreach ($this->options['debugTagsKeysInContext'] as $key) { if (!empty($context[$key])) { $tags = $context[$key]; if ($key === 0) { array_shift($context); } else { unset($context[$key]); } break; } } } return $tags ?: strtolower($record['level_name']); } /** * {@inheritDoc} */ protected function getDefaultFormatter(): FormatterInterface { return new LineFormatter('%message%'); } } __halt_compiler();----SIGNATURE:----PD/BUpnjsoaUlj+JLYnMtY3tntaVYJ2Nl1PHwcpesnxBteeB2wFiS2SfElmc7KrcqFabDUlxFb/zeB+6t2kD+Viu8nt5eUgXFQZEZLDK9kBq/n6mUibfsURSkQyvt9qQwAZkhKebmRD/1NWN6x5e7WTD0qzAGdMAUfafSgA28sGablIQKeNR2WjIIpdFrFb+jXc2sxhjhN+X/tXjWFXSjudjcQwrQUxdYSwcv/goYqZOvv8oExKIIXzI7qYKFo5j/yYOiWEbXFCglRWHSPLE/ZpMnwtufOvfiYhCM0gut3PPVJGh4GA3xGANIFPQobYI91jY3L30wnFLZ9fgAi6q1N/V7SeoTcdHPIREHz+GVSAfSS/1gMIjemUCsRfOG6qy+4j+LwWhEJ77PrgIT9zmJCMU7/lKNH9RAqbiGSjLDhuoCXLSGvUw/s6AiM/yamgAjOt7kOA/ckeh063T0E11KRh/cCoXjELyajuvd7Q9PqU1e2H60u/vEftxpAKT4sZURYcOEgayc4NbxchzwZ2a1zdxYbFml/GQOal0FxYgm7+QGIEUELDAVw2l+f4huHjuFuYBDMY4db6/2Xc8db0d879AmqC1ucW9kcW+rTwqv3LyyGqGDmCaoVfrVLpL4Whm/gw0gP9OBJ6U4R5ue43/UNtgALI4rtVShxVGDwAjFAs=----ATTACHMENT:----NjEyNjEwODYyMDUwOTUxNSA1ODkxMDQ5MzYxMzA1NDQxIDc0MjU4MTA1OTA0NTUyMzU=