Encode an individual LogEntry in ChromeLogger-compatible format

@param array $entry

@return array log entry in ChromeLogger row-format
540946
protected function createEntryData(array $entry): array
    {
        // NOTE: "log" level type is deliberately omitted from the following map, since
        //       it's the default entry-type in ChromeLogger, and can be omitted.

        static $LEVELS = [
            LogLevel::DEBUG => self::LOG,
            LogLevel::INFO => self::INFO,
            LogLevel::NOTICE => self::INFO,
            LogLevel::WARNING => self::WARN,
            LogLevel::ERROR => self::ERROR,
            LogLevel::CRITICAL => self::ERROR,
            LogLevel::ALERT => self::ERROR,
            LogLevel::EMERGENCY => self::ERROR,
        ];

        $row = [];

        [$level, $message, $context] = $entry;

        $data = [
            \str_replace('%', '%%', Dumper::interpolate($message, $context)),
        ];

        if (\count($context)) {
            $context = $this->sanitize($context);

            $data = \array_merge($data, $context);
        }

        $row[] = $data;

        $row[] = $LEVELS[$level] ?? self::LOG;

        if (isset($context['exception'])) {
            // NOTE: per PSR-3, this reserved key could be anything, but if it is an Exception, we
            //       can use that Exception to obtain a stack-trace for output in ChromeLogger.
            $exception = $context['exception'];

            if ($exception instanceof \Throwable) {
                $row[] = $exception->__toString();
            }
        }

        // Optimization: ChromeLogger defaults to "log" if no entry-type is specified.
        if ($row[1] === self::LOG) {
            if (\count($row) === 2) {
                unset($row[1]);
            } else {
                $row[1] = '';
            }
        }

        return $row;
    }
894154
private function isEntryOutOfScope(array $entry)
    {
        if (empty($entry['path']) && $entry['path'] !== '0') {
            return false;
        }

        if ($this->recursive) {
            return $this->residesInDirectory($entry);
        }

        return $this->isDirectChild($entry);
    }
1286349
protected function encodeArray(array $value)
    {
        $text = '';
        foreach ($value as $key => $value) {
            $value = (string) $value;
            $value = trim($value);

            $text .= "\n\t" . ucfirst($key) . ': ' . str_replace("\n", "\n\t\t", $value);
        }

        return $text;
    }
850486
public function getEntry($Entry)
    {
        if ($this->Using === 'APCu') {
            return $this->unserializeEntry(apcu_fetch($Entry));
        }
        if ($this->Using === 'Memcached' || $this->Using === 'Redis') {
            return $this->unserializeEntry($this->WorkingData->get($Entry));
        }
        if ($this->Using === 'PDO') {
            if ($this->clearExpiredPDO()) {
                $this->Modified = true;
            }
            $PDO = $this->WorkingData->prepare(self::getQuery);
            if ($PDO !== false && $PDO->execute(['key' => $Entry])) {
                $Data = $PDO->fetch(\PDO::FETCH_ASSOC);
                return isset($Data['Data']) ? $this->unserializeEntry($Data['Data']) : false;
            }
            return false;
        }
        if (is_array($this->WorkingData) && isset($this->WorkingData[$Entry])) {
            if (isset($this->WorkingData[$Entry]['Data']) && !empty($this->WorkingData[$Entry]['Time'])) {
                if ($this->WorkingData[$Entry]['Time'] <= 0 || $this->WorkingData[$Entry]['Time'] > time()) {
                    return $this->unserializeEntry($this->WorkingData[$Entry]['Data']);
                }
                unset($this->WorkingData[$Entry]);
                $this->Modified = true;
                return false;
            }
            return $this->unserializeEntry($this->WorkingData[$Entry]);
        }
        return false;
    }
1146258
private function sanitizeEntryDateValue(array $entry, $key)
    {
        $date = '';
        if (!empty($entry[$key])) {
            $date = DateTime::createFromFormat(API::DateFormat_Iso, $entry[$key]);
            if ($date instanceof DateTime) {
                $date = $date->format(Api::DateFormat_Iso);
            } else {
                $date = '';
            }
        }
        return $date;
    }
123543
protected function newLogEntry(
        /*# string */ $channel,
        /*# string */ $level,
        /*# string */ $message,
        array $context = []
    )/*# : EventInterface */ {
        if (is_null($this->entry_proto)) {
            return new LogEntry($channel, $level, $message, $context);
        } else {
            $entry = clone $this->entry_proto;
            return $entry
                ->setChannel($channel)
                ->setLevel($level)
                ->setMessage($message)
                ->setContext($context)
                ->setTimestamp();
        }
    }
580942
public static function transformObject(&$entry)
    {
        $filters = [
            'transformFilterAmounts',
            'transformFilterTimestamp'
        ];

        foreach ($filters as $filter) {
            if (method_exists(__CLASS__, $filter)) {
                $result = call_user_func([__CLASS__, $filter], $entry);

                if ($result) {
                    $entry = $result;
                }
            }
        }
    }
124788
public static function log($entry, $markName = '...', $params = array())
    {
        if (!self::isDebug()) {
            return false;
        }

        // emulate normal class
        $_this = self::i();

        // check var type
        if (is_bool($entry)) {
            $entry = ($entry) ? 'TRUE' : 'FALSE';
        } elseif (is_null($entry)) {
            $entry = 'NULL';
        } elseif (is_resource($entry)) {
            $entry = 'resource of "' . get_resource_type($entry) . '"';
        }

        // serialize type
        if (self::$_config['log']['serialize'] == 'formats') {
            // don't change log entry

        } elseif (self::$_config['log']['serialize'] == 'none') {
            $entry = array('jbdump_message' => $entry);

        } elseif (self::$_config['log']['serialize'] == 'json') {
            $entry = array('jbdump_message' => @json_encode($entry));

        } elseif (self::$_config['log']['serialize'] == 'serialize') {
            $entry = array('jbdump_message' => serialize($entry));

        } elseif (self::$_config['log']['serialize'] == 'print_r') {
            $entry = array('jbdump_message' => print_r($entry, true));

        } elseif (self::$_config['log']['serialize'] == 'php_array') {
            $markName = (empty($markName) || $markName == '...') ? 'dumpVar' : $markName;
            $entry    = array('jbdump_message' => JBDump_array2php::toString($entry, $markName));

        } elseif (self::$_config['log']['serialize'] == 'var_dump') {
            ob_start();
            var_dump($entry);
            $entry = ob_get_clean();
            $entry = array('jbdump_message' => var_dump($entry, true));
        }

        if (isset($params['trace'])) {
            $_this->_trace = $params['trace'];
        } else {
            $_this->_trace = debug_backtrace();
        }

        $entry['name']      = $markName;
        $entry['datetime']  = date(self::DATE_FORMAT);
        $entry['client_ip'] = self::getClientIP();
        $entry['file']      = $_this->_getSourcePath($_this->_trace, true);
        $entry              = array_change_key_case($entry, CASE_UPPER);

        $fields = array();
        $format = isset($params['format']) ? $params['format'] : self::$_config['log']['format'];
        preg_match_all("/{(.*?)}/i", $format, $fields);

        // Fill in the field data
        $line = $format;
        for ($i = 0; $i < count($fields[0]); $i++) {
            $line = str_replace($fields[0][$i], (isset ($entry[$fields[1][$i]])) ? $entry[$fields[1][$i]] : "-", $line);
        }

        // Write the log entry line
        if ($_this->_openLog()) {
            error_log($line . PHP_EOL, 3, $_this->_logfile);
        }

        return $_this;
    }
40378
protected function parseFeedbackEntry(array $entry)
    {
        $entry['message'] = (string)$entry['message'];

        if (!isset($entry['dismissible'])) {
            $entry['dismissible'] = $this->isFeedbackDismissable($entry['level']);
        } else {
            $entry['dismissible'] = (bool)$entry['dismissible'];
        }

        return $entry;
    }
651860
protected function transformValues( \stdClass $entry )
	{
		if( isset( $entry->{'product.datestart'} ) && $entry->{'product.datestart'} != '' ) {
			$entry->{'product.datestart'} = str_replace( 'T', ' ', $entry->{'product.datestart'} );
		} else {
			$entry->{'product.datestart'} = null;
		}

		if( isset( $entry->{'product.dateend'} ) && $entry->{'product.dateend'} != '' ) {
			$entry->{'product.dateend'} = str_replace( 'T', ' ', $entry->{'product.dateend'} );
		} else {
			$entry->{'product.dateend'} = null;
		}

		if( isset( $entry->{'product.config'} ) ) {
			$entry->{'product.config'} = (array) $entry->{'product.config'};
		}

		return $entry;
	}
816551
protected function castLoadedEntry(array $entry)
    {
        $entry['valid_until'] = (int)$entry['valid_until'];
        $entry['outside'] = (int)$entry['outside'];
        $entry['plain'] = (int)$entry['plain'];

        if ((bool)$entry['outside']) {
            return $entry;
        }

        if (!(bool)$entry['plain']) {
            $entry['payload'] = $this->serializer->deserialize($entry['payload']);
            $entry['plain'] = 1;
        }

        return $entry;
    }
304811
protected function convertValuesFromLdap(array $entry)
    {
        if (!$this->schema) {
            return $entry;
        }
        $valueResolver = BaseValueResolver::getInstance(
            $this->schema,
            $entry,
            $this->type
        );
        $this->configureValueResolver($valueResolver, isset($entry['dn']) ? $entry['dn'] : null);

        return $valueResolver->fromLdap();
    }
497333
public function deleteEntry($Entry)
    {
        if ($this->Using === 'APCu') {
            if (apcu_delete($Entry)) {
                return $this->Modified = true;
            }
            return false;
        }
        if ($this->Using === 'Memcached' || $this->Using === 'Redis') {
            if ($this->WorkingData->delete($Entry)) {
                return $this->Modified = true;
            }
            return false;
        }
        if ($this->Using === 'PDO') {
            $PDO = $this->WorkingData->prepare(self::deleteQuery);
            if ($PDO !== false && $PDO->execute(['key' => $Entry])) {
                return ($PDO->rowCount() > 0 && $this->Modified = true);
            }
            return false;
        }
        if (is_array($this->WorkingData)) {
            if (isset($this->WorkingData[$Entry])) {
                unset($this->WorkingData[$Entry]);
                return $this->Modified = true;
            }
        }
        return false;
    }
282510
protected static function export(array $arr)
	{
		$exportKeys = (array_keys($arr) !== range(0, count($arr) - 1));
		ksort($arr);

		$entries = [];
		foreach ($arr as $k => $v)
		{
			$entries[] = (($exportKeys) ? var_export($k, true) . '=>' : '')
			           . ((is_array($v)) ? self::export($v) : var_export($v, true));
		}

		return '[' . implode(',', $entries) . ']';
	}
1077348
protected function normalize(array $entry)
    {
        if (isset($entry['name']) && is_array($entry['name'])) {
            $files = [];
            foreach ($entry['name'] as $index => $name) {
                if ($entry['error'][$index] === UPLOAD_ERR_NO_FILE) {
                    continue;
                }

                $files[$index] = [
                    'name' => $name,
                    'tmp_name' => $entry['tmp_name'][$index],
                    'size' => $entry['size'][$index],
                    'type' => $entry['type'][$index],
                    'error' => $entry['error'][$index]
                ];
            }

            return new self($files);
        }

        return new self($entry);
    }
866362
private function formatLogChannel(array $record)
    {
        if (!isset($record['channel'])) {
            return '';
        }

        if ($this->isDeprecationLog($record)) {
            return '** DEPRECATION **';
        }

        if ($this->isEventNotificationLog($record)) {
            return 'NOTIFIED EVENTS';
        }

        $channel = $record['channel'];
        $channelIcons = array(
            '_event_stop' => '[!] ',
            'security' => '(!) ',
        );
        $channelIcon = array_key_exists($channel, $channelIcons) ? $channelIcons[$channel] : '';

        return sprintf('%s%s', $channelIcon, strtoupper($channel));
    }
1016517
public static function create(array $entry): self
    {
        $events = [];

        foreach (self::CHANNELS as $channel) {
            if (isset($entry[$channel])) {
                foreach ($entry[$channel] as $event) {
                    $events[] = EventFactory::create($event);
                }
            }
        }

        return new self($entry['id'], $entry['time'], $events);
    }