TYPO3 v15 dev-main snapshot ()

This commit is contained in:
2026-08-10 22:31:09 +02:00
commit af8cc155b5
6818 changed files with 642608 additions and 0 deletions
@@ -0,0 +1,81 @@
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Log\Processor;
/**
* Common memory processor methods.
*/
abstract class AbstractMemoryProcessor extends AbstractProcessor
{
/**
* Allocated memory usage type to use
* If set, the real size of memory allocated from system is used.
* Otherwise the memory used by emalloc() is used.
*
* @var bool
* @see memory_get_usage()
* @see memory_get_peak_usage()
*/
protected $realMemoryUsage = true;
/**
* Whether the size is formatted, e.g. in megabytes
*
* @var bool
* @see \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize()
*/
protected $formatSize = true;
/**
* Sets the allocated memory usage type
*
* @param bool $realMemoryUsage Which allocated memory type to use
*/
public function setRealMemoryUsage($realMemoryUsage)
{
$this->realMemoryUsage = (bool)$realMemoryUsage;
}
/**
* Returns the allocated memory usage type
*
* @return bool
*/
public function getRealMemoryUsage()
{
return $this->realMemoryUsage;
}
/**
* Sets whether size should be formatted
*
* @param bool $formatSize
*/
public function setFormatSize($formatSize)
{
$this->formatSize = (bool)$formatSize;
}
/**
* Returns whether size should be formatted
*
* @return bool
*/
public function getFormatSize()
{
return $this->formatSize;
}
}
@@ -0,0 +1,42 @@
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Log\Processor;
use TYPO3\CMS\Core\Log\Exception\InvalidLogProcessorConfigurationException;
/**
* Abstract implementation of a log processor
*/
abstract class AbstractProcessor implements ProcessorInterface
{
/**
* Constructs this log processor
*
* @param array $options Configuration options - depends on the actual processor
* @throws \TYPO3\CMS\Core\Log\Exception\InvalidLogProcessorConfigurationException
*/
public function __construct(array $options = [])
{
foreach ($options as $optionKey => $optionValue) {
$methodName = 'set' . ucfirst($optionKey);
if (method_exists($this, $methodName)) {
$this->{$methodName}($optionValue);
} else {
throw new InvalidLogProcessorConfigurationException('Invalid LogProcessor configuration option "' . $optionKey . '" for log processor of type "' . static::class . '"', 1321696151);
}
}
}
}
@@ -0,0 +1,161 @@
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Log\Processor;
use TYPO3\CMS\Core\Log\LogRecord;
/**
* Introspection processor to automatically add where the log record came from.
*/
class IntrospectionProcessor extends AbstractProcessor
{
/**
* Add the full backtrace to the log entry or
* just the last entry of the backtrace
*
* @var bool
*/
protected $appendFullBackTrace = false;
/**
* Number of entries to shift from the backtrace
*
* @var int
*/
protected $shiftBackTraceLevel = 0;
/**
* Temporary storage of the preceding backtrace line number
*
* @var string
*/
private $precedingBacktraceLine = '';
/**
* Temporary storage of the preceding backtrace file
*
* @var string
*/
private $precedingBacktraceFile = '';
/**
* Set the number of levels to be shift from the backtrace
*
* @param int $shiftBackTraceLevel Numbers of levels to shift
* @return IntrospectionProcessor
*/
public function setShiftBackTraceLevel($shiftBackTraceLevel)
{
$this->shiftBackTraceLevel = (int)$shiftBackTraceLevel;
return $this;
}
/**
* Set if the full backtrace should be added to the log or just the last item
*
* @param bool $appendFullBackTrace If the full backtrace should be added
* @return IntrospectionProcessor
*/
public function setAppendFullBackTrace($appendFullBackTrace)
{
$this->appendFullBackTrace = (bool)$appendFullBackTrace;
return $this;
}
/**
* Add debug backtrace information to logRecord
* It adds: filepath, line number, class and function name
*
* @param LogRecord $logRecord The log record to process
* @return LogRecord The processed log record with additional data
* @see debug_backtrace()
*/
public function processLogRecord(LogRecord $logRecord)
{
$trace = $this->getDebugBacktrace();
// skip TYPO3\CMS\Core\Log classes
foreach ($trace as $traceEntry) {
if (isset($traceEntry['class']) && str_contains($traceEntry['class'], 'TYPO3\\CMS\\Core\\Log')) {
$trace = $this->shiftBacktraceLevel($trace);
} else {
break;
}
}
// shift a given number of entries from the trace
for ($i = 0; $i < $this->shiftBackTraceLevel; $i++) {
// shift only if afterwards there is at least one entry left after.
if (count($trace) > 1) {
$trace = $this->shiftBacktraceLevel($trace);
}
}
if ($this->appendFullBackTrace) {
// Add the line and file of the last entry that has these information
// to the first backtrace entry if it does not have this information.
// This is required in case we have shifted entries and the first entry
// is now a call_user_func that does not contain the line and file information.
if (!isset($trace[0]['line'])) {
$trace[0] = ['line' => $this->precedingBacktraceLine] + $trace[0];
}
if (!isset($trace[0]['file'])) {
$trace[0] = ['file' => $this->precedingBacktraceFile] + $trace[0];
}
$logRecord->addData([
'backtrace' => $trace,
]);
} else {
$logRecord->addData([
'file' => $trace[0]['file'] ?? null,
'line' => $trace[0]['line'] ?? null,
'class' => $trace[0]['class'] ?? null,
'function' => $trace[0]['function'] ?? null,
]);
}
return $logRecord;
}
/**
* Shift the first item from the backtrace
*
* @return array
*/
protected function shiftBacktraceLevel(array $backtrace)
{
if (isset($backtrace[0]['file'])) {
$this->precedingBacktraceFile = $backtrace[0]['file'];
}
if (isset($backtrace[0]['line'])) {
$this->precedingBacktraceLine = $backtrace[0]['line'];
}
array_shift($backtrace);
return $backtrace;
}
/**
* Get the debug backtrace
*
* @return array
*/
protected function getDebugBacktrace()
{
return debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
}
}
@@ -0,0 +1,46 @@
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Log\Processor;
use TYPO3\CMS\Core\Log\LogRecord;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Memory peak usage processor methods.
*/
class MemoryPeakUsageProcessor extends AbstractMemoryProcessor
{
/**
* Processes a log record and adds memory peak usage information.
*
* @param \TYPO3\CMS\Core\Log\LogRecord $logRecord The log record to process
* @return \TYPO3\CMS\Core\Log\LogRecord The processed log record with additional data
* @see memory_get_peak_usage()
*/
public function processLogRecord(LogRecord $logRecord)
{
$bytes = memory_get_peak_usage($this->getRealMemoryUsage());
if ($this->formatSize) {
$size = GeneralUtility::formatSize($bytes);
} else {
$size = $bytes;
}
$logRecord->addData([
'memoryPeakUsage' => $size,
]);
return $logRecord;
}
}
@@ -0,0 +1,46 @@
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Log\Processor;
use TYPO3\CMS\Core\Log\LogRecord;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Memory usage processor methods.
*/
class MemoryUsageProcessor extends AbstractMemoryProcessor
{
/**
* Processes a log record and adds memory usage information.
*
* @param \TYPO3\CMS\Core\Log\LogRecord $logRecord The log record to process
* @return \TYPO3\CMS\Core\Log\LogRecord The processed log record with additional data
* @see memory_get_usage()
*/
public function processLogRecord(LogRecord $logRecord)
{
$bytes = memory_get_usage($this->getRealMemoryUsage());
if ($this->formatSize) {
$size = GeneralUtility::formatSize($bytes);
} else {
$size = $bytes;
}
$logRecord->addData([
'memoryUsage' => $size,
]);
return $logRecord;
}
}
+35
View File
@@ -0,0 +1,35 @@
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Log\Processor;
use TYPO3\CMS\Core\Log\LogRecord;
/**
* A log processor that does nothing. Used in unit tests.
*/
class NullProcessor extends AbstractProcessor
{
/**
* Processes a log record and returns the same.
*
* @param \TYPO3\CMS\Core\Log\LogRecord $logRecord The log record to process
* @return \TYPO3\CMS\Core\Log\LogRecord The processed log record with additional data
*/
public function processLogRecord(LogRecord $logRecord)
{
return $logRecord;
}
}
@@ -0,0 +1,35 @@
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Log\Processor;
use TYPO3\CMS\Core\Log\LogRecord;
/**
* Log processor interface
*
* Processors provide additional data in an automatic way, without having to
* collect that data yourself.
*/
interface ProcessorInterface
{
/**
* Processes a log record and adds additional data.
*
* @param \TYPO3\CMS\Core\Log\LogRecord $logRecord The log record to process
* @return \TYPO3\CMS\Core\Log\LogRecord The processed log record with additional data
*/
public function processLogRecord(LogRecord $logRecord);
}
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Log\Processor;
use TYPO3\CMS\Core\Core\RequestId;
use TYPO3\CMS\Core\Log\LogRecord;
/**
* Adds the unique ID of the current request to log records, in order
* to correlate all log entries written during a single request.
*/
final class RequestIdProcessor implements ProcessorInterface
{
public function __construct(private readonly RequestId $requestId) {}
public function processLogRecord(LogRecord $logRecord): LogRecord
{
return $logRecord->setRequestId((string)$this->requestId);
}
}
+60
View File
@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Log\Processor;
use TYPO3\CMS\Core\Http\NormalizedParams;
use TYPO3\CMS\Core\Log\LogRecord;
/**
* Web log processor to automatically add web request related data to a log
* record.
*/
class WebProcessor extends AbstractProcessor
{
public function processLogRecord(LogRecord $logRecord): LogRecord
{
$normalizedParams = ($GLOBALS['TYPO3_REQUEST'] ?? null)?->getAttribute('normalizedParams');
if ($normalizedParams instanceof NormalizedParams) {
$logRecord->addData([
'HTTP_HOST' => $normalizedParams->getHttpHost(),
'TYPO3_HOST_ONLY' => $normalizedParams->getRequestHostOnly(),
'TYPO3_PORT' => $normalizedParams->getRequestPort(),
'PATH_INFO' => $normalizedParams->getPathInfo(),
'QUERY_STRING' => $normalizedParams->getQueryString(),
'REQUEST_URI' => $normalizedParams->getRequestUri(),
'HTTP_REFERER' => $normalizedParams->getHttpReferer(),
'TYPO3_REQUEST_HOST' => $normalizedParams->getRequestHost(),
'TYPO3_REQUEST_URL' => $normalizedParams->getRequestUrl(),
'TYPO3_REQUEST_SCRIPT' => $normalizedParams->getRequestScript(),
'TYPO3_REQUEST_DIR' => $normalizedParams->getRequestDir(),
'TYPO3_SITE_URL' => $normalizedParams->getSiteUrl(),
'TYPO3_SITE_SCRIPT' => $normalizedParams->getSiteScript(),
'TYPO3_SSL' => $normalizedParams->isHttps(),
'TYPO3_REV_PROXY' => $normalizedParams->isBehindReverseProxy(),
'SCRIPT_NAME' => $normalizedParams->getScriptName(),
'TYPO3_DOCUMENT_ROOT' => $normalizedParams->getDocumentRoot(),
'SCRIPT_FILENAME' => $normalizedParams->getScriptFilename(),
'REMOTE_ADDR' => $normalizedParams->getRemoteAddress(),
'REMOTE_HOST' => $normalizedParams->getRemoteHost(),
'HTTP_USER_AGENT' => $normalizedParams->getHttpUserAgent(),
'HTTP_ACCEPT_LANGUAGE' => $normalizedParams->getHttpAcceptLanguage(),
]);
}
return $logRecord;
}
}