Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 7 additions & 19 deletions .github/workflows/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,16 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '8.1', '8.2', '8.3', '8.4' ]
typo3: [ '11', '12', '13' ]
php: [ '8.2', '8.3', '8.4' ]
typo3: [ '13', '14' ]
sentry: [ false, true ]
exclude:
- php: '8.1'
typo3: '13'
sentry: true
- php: '8.1'
typo3: '13'
sentry: false
steps:
- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
# - uses: mirromutth/mysql-action@v1.1
# with:
# mysql version: '5.7'
# mysql database: 'typo3_test'
# mysql root password: 'root'
- uses: actions/checkout@v4
- uses: actions/cache@v4
- uses: actions/checkout@v6
- uses: actions/cache@v5
with:
path: ~/.composer/cache/files
key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
Expand All @@ -46,7 +34,7 @@ jobs:
- run: composer test
- run: jq 'del(.logs.html)' infection.json > infection.json.new && mv infection.json.new infection.json
- run: composer infection
- uses: codecov/codecov-action@v5
- uses: codecov/codecov-action@v6
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: Resources/Public/test-result/clover.xml
Expand All @@ -64,15 +52,15 @@ jobs:
TYPO3_API_PASSWORD: ${{ secrets.TYPO3_API_PASSWORD }}

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.4'
extensions: intl, mbstring, xml, soap, zip, curl

- name: Install typo3/tailor
Expand Down
48 changes: 11 additions & 37 deletions Classes/DataProcessor/XClassContentDataProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,19 @@

namespace Kanti\ServerTiming\DataProcessor;

use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;

final class XClassContentDataProcessor extends ContentDataProcessor
{
/**
* @param array<array-key, mixed> $configuration
* @param array<array-key, mixed> $variables
* @return array<array-key, mixed>
*/
public function process(ContentObjectRenderer $cObject, array $configuration, array $variables)
{
$processors = $configuration['dataProcessing.'] ?? [];
if (!$processors) {
return $variables;
}

$processorKeys = ArrayUtility::filterAndSortByNumericKeys($processors);
$index = 1;
$newDataProcessing = [];
foreach ($processorKeys as $key) {
$processorClassOrAlias = $processors[$key];

$uniqId = uniqId();

$newDataProcessing[$index] = TrackingDataProcessor::class;
$newDataProcessing[$index . '.'] = ['key' => $key, 'processorOrAlias' => $processorClassOrAlias, 'type' => 'start', 'id' => $uniqId, 'for' => $cObject->getCurrentTable() . ':' . $cObject->data['uid']];
$index++;
$newDataProcessing[$index] = $processorClassOrAlias;
$newDataProcessing[$index . '.'] = $processors[$key . '.'] ?? [];
$index++;
$newDataProcessing[$index] = TrackingDataProcessor::class;
$newDataProcessing[$index . '.'] = ['type' => 'stop', 'id' => $uniqId];
$index++;
}
// phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses

$configuration['dataProcessing.'] = $newDataProcessing;

return parent::process($cObject, $configuration, $variables);
if ((new Typo3Version())->getMajorVersion() <= 13) {
final class XClassContentDataProcessor extends ContentDataProcessor
{
use XClassContentDataProcessorTrait;
}
} else {
final readonly class XClassContentDataProcessor extends ContentDataProcessor
{
use XClassContentDataProcessorTrait;
}
}
48 changes: 48 additions & 0 deletions Classes/DataProcessor/XClassContentDataProcessorTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace Kanti\ServerTiming\DataProcessor;

use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;

trait XClassContentDataProcessorTrait
{
/**
* @param array<array-key, mixed> $configuration
* @param array<array-key, mixed> $variables
* @return array<array-key, mixed>
*/
public function process(ContentObjectRenderer $cObject, array $configuration, array $variables)
{
$processors = $configuration['dataProcessing.'] ?? [];
if (!$processors) {
return $variables;
}

$processorKeys = ArrayUtility::filterAndSortByNumericKeys($processors);
$index = 1;
$newDataProcessing = [];
foreach ($processorKeys as $key) {
$processorClassOrAlias = $processors[$key];

$uniqId = uniqId();

$newDataProcessing[$index] = TrackingDataProcessor::class;
$newDataProcessing[$index . '.'] = ['key' => $key, 'processorOrAlias' => $processorClassOrAlias, 'type' => 'start', 'id' => $uniqId, 'for' => $cObject->getCurrentTable() . ':' . $cObject->data['uid']];
$index++;
$newDataProcessing[$index] = $processorClassOrAlias;
$newDataProcessing[$index . '.'] = $processors[$key . '.'] ?? [];
$index++;
$newDataProcessing[$index] = TrackingDataProcessor::class;
$newDataProcessing[$index . '.'] = ['type' => 'stop', 'id' => $uniqId];
$index++;
}

$configuration['dataProcessing.'] = $newDataProcessing;

return parent::process($cObject, $configuration, $variables);
}
}
9 changes: 6 additions & 3 deletions Classes/Dto/ScriptResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Http\ServerRequestFactory;

final class ScriptResult
final readonly class ScriptResult
{
private function __construct(public readonly ?ServerRequestInterface $request, public readonly ?ResponseInterface $response, public readonly ?int $cliExitCode)
{
private function __construct(
public ?ServerRequestInterface $request,
public ?ResponseInterface $response,
public ?int $cliExitCode,
) {
}

public static function fromRequest(ServerRequestInterface $request, ?ResponseInterface $response = null): ScriptResult
Expand Down
4 changes: 2 additions & 2 deletions Classes/EventListener/BootCompletedEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

namespace Kanti\ServerTiming\EventListener;

use Kanti\ServerTiming\SqlLogging\SqlLoggerCore11;
use Kanti\ServerTiming\Utility\TimingUtility;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Core\Event\BootCompletedEvent;

final class BootCompletedEventListener
{
#[AsEventListener('kanti/server-timing/boot-completed-event-listener')]
public function __invoke(BootCompletedEvent $event): void
{
// we initialize TimingUtility here
// in the install tool, (eg. DB compare)
// at this point, the TimingUtility is found in the container, but at the shutdown state the TimingUtility is not found in the container.
// so if we initialize it right here and save it inside a static variable, then everything works as expected. (not the sentry part :/ )
TimingUtility::getInstance();
SqlLoggerCore11::registerSqlLogger();
}
}
15 changes: 14 additions & 1 deletion Classes/EventListener/ConsoleCommandEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@

use Exception;
use Kanti\ServerTiming\Dto\ScriptResult;
use Kanti\ServerTiming\Dto\StopWatch;
use Kanti\ServerTiming\Utility\TimingUtility;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Kanti\ServerTiming\Dto\StopWatch;
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Core\Attribute\AsEventListener;

final class ConsoleCommandEventListener
{
/** @var StopWatch[] */
private array $stopWatches = [];

#[AsEventListener('kanti/server-timing/console-command-event-listener')]
public function start(ConsoleCommandEvent $event): void
{
$this->stopWatches[] = TimingUtility::stopWatch('console.command', (string)$event->getCommand()?->getName());
}

#[AsEventListener('kanti/server-timing/console-terminate-event-listener')]
public function stop(ConsoleTerminateEvent $event): void
{
$stopWatch = array_pop($this->stopWatches);
Expand All @@ -32,5 +36,14 @@ public function stop(ConsoleTerminateEvent $event): void
if (!$this->stopWatches) {
TimingUtility::getInstance()->shutdown(ScriptResult::fromCli($event->getExitCode()));
}

$event->getOutput()->writeln(
sprintf(
'<info>server_timing:</info> Command "%s" took %.4fs',
(string)$event->getCommand()?->getName(),
$stopWatch->getDuration(),
),
OutputInterface::VERBOSITY_VERBOSE,
);
}
}
3 changes: 3 additions & 0 deletions Classes/EventListener/FileProcessingEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

use Kanti\ServerTiming\Dto\StopWatch;
use Kanti\ServerTiming\Utility\TimingUtility;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Resource\Event\AfterFileProcessingEvent;
use TYPO3\CMS\Core\Resource\Event\BeforeFileProcessingEvent;

final class FileProcessingEventListener
{
public StopWatch|null $stopWatch = null;

#[AsEventListener('kanti/server-timing/file-processing')]
public function before(BeforeFileProcessingEvent $event): void
{
if (!$event->getProcessedFile()->isProcessed()) {
Expand All @@ -21,6 +23,7 @@ public function before(BeforeFileProcessingEvent $event): void
}
}

#[AsEventListener('kanti/server-timing/file-processing')]
public function after(AfterFileProcessingEvent $event): void
{
$this->stopWatch?->stopIfNot();
Expand Down
6 changes: 5 additions & 1 deletion Classes/EventListener/MailEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,33 @@

namespace Kanti\ServerTiming\EventListener;

use Symfony\Component\Mime\Address;
use Kanti\ServerTiming\Dto\StopWatch;
use Kanti\ServerTiming\Utility\TimingUtility;
use Symfony\Component\Mime\Email;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Mail\Event\AfterMailerSentMessageEvent;
use TYPO3\CMS\Core\Mail\Event\BeforeMailerSentMessageEvent;

final class MailEventListener
{
public ?StopWatch $stopWatch = null;

#[AsEventListener('kanti/server-timing/mail-event-listener')]
public function start(BeforeMailerSentMessageEvent $event): void
{
$info = '';
$message = $event->getMessage();
if ($message instanceof Email) {
$emails = implode(', ', array_map(static fn($address): string => $address->getAddress(), $message->getTo()));
$emails = implode(', ', array_map(static fn(Address $address): string => $address->getAddress(), $message->getTo()));
$info = $message->getSubject() . ' -> ' . $emails;
}

$this->stopWatch?->stopIfNot();
$this->stopWatch = TimingUtility::stopWatch('mail', $info);
}

#[AsEventListener('kanti/server-timing/mail-event-listener')]
public function stop(AfterMailerSentMessageEvent $event): void
{
$this->stopWatch?->stopIfNot();
Expand Down
44 changes: 0 additions & 44 deletions Classes/Middleware/AdminpanelSqlLoggingMiddleware.php

This file was deleted.

6 changes: 0 additions & 6 deletions Classes/Middleware/WrapMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,9 @@ public function handle(ServerRequestInterface $request): ResponseInterface
self::$middlewareIn?->stopIfNot();
self::$middlewareIn = TimingUtility::stopWatch($this->isKernel ? 'requestHandler' : 'middleware.in', $this->info);

if ($this->isKernel) {
$request->getAttribute('middleware.in.total')?->stop();
}

$response = $this->requestHandler->handle($request);

if ($this->isKernel) {
TimingUtility::start('middleware.out.total');
}

// if it was the requestHandler:
self::$middlewareIn?->stopIfNot();
Expand Down
6 changes: 0 additions & 6 deletions Classes/Middleware/XClassMiddlewareDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$stop->startTime = $_SERVER["REQUEST_TIME_FLOAT"];
$stop->stop();

$request = $request->withAttribute('middleware.in.total', TimingUtility::stopWatch('middleware.in.total'));
if ($this->tip instanceof WrapMiddleware) {
$this->tip->isFirst();
}
Expand All @@ -46,11 +45,6 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$response = $immediateResponseException->getResponse();
}

try {
TimingUtility::end('middleware.out.total');
} catch (Exception) {
}

return TimingUtility::getInstance()->shutdown(ScriptResult::fromRequest($request, $response)) ?? $response;
}

Expand Down
Loading
Loading