Skip to content

Commit

Permalink
➕ add compat for TYPO3 13
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanti committed Aug 2, 2024
1 parent 59445ff commit e8c572a
Show file tree
Hide file tree
Showing 18 changed files with 443 additions and 148 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/tasks.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Tasks

on: [push, pull_request]
on: push

jobs:
lint-php:
Expand All @@ -10,8 +10,15 @@ jobs:
fail-fast: false
matrix:
php: [ '8.1', '8.2', '8.3' ]
typo3: [ '11', '12' ]
typo3: [ '11', '12', '13' ]
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
Expand Down
2 changes: 1 addition & 1 deletion Classes/DataProcessor/TrackingDataProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class TrackingDataProcessor implements DataProcessorInterface, SingletonIn
* @param array<array-key, mixed> $processedData
* @return array<array-key, mixed>
*/
public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData): array

Check warning on line 24 in Classes/DataProcessor/TrackingDataProcessor.php

View check run for this annotation

Codecov / codecov/patch

Classes/DataProcessor/TrackingDataProcessor.php#L24

Added line #L24 was not covered by tests
{
$id = (string)$processorConfiguration['id'];
$stopWatch = $this->stopWatches[$id] ?? null;
Expand Down
19 changes: 17 additions & 2 deletions Classes/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Kanti\ServerTiming;

use Closure;
use Kanti\ServerTiming\Middleware\XClassMiddlewareDispatcher;
use Psr\Container\ContainerInterface;
use TYPO3\CMS\Backend\Http\Application as ApplicationBE;
Expand All @@ -18,7 +19,7 @@

final class ServiceProvider extends AbstractServiceProvider
{
public static function getPackagePath(): string
protected static function getPackagePath(): string

Check warning on line 22 in Classes/ServiceProvider.php

View check run for this annotation

Codecov / codecov/patch

Classes/ServiceProvider.php#L22

Added line #L22 was not covered by tests
{
return __DIR__ . '/../';
}
Expand All @@ -29,7 +30,7 @@ public static function getPackageName(): string
}

/**
* @return array<string, \Closure>
* @return array<string, Closure>
*/
public function getFactories(): array
{
Expand All @@ -46,6 +47,13 @@ public static function getApplicationFE(ContainerInterface $container): Applicat
$container->get('frontend.middlewares'),
$container,
);
if (version_compare((new Typo3Version())->getBranch(), '13.0', '>=')) {
return new ApplicationFE(
$requestHandler,
$container->get(Context::class),
);

Check warning on line 54 in Classes/ServiceProvider.php

View check run for this annotation

Codecov / codecov/patch

Classes/ServiceProvider.php#L50-L54

Added lines #L50 - L54 were not covered by tests
}

if (version_compare((new Typo3Version())->getBranch(), '12.0', '>=') && class_exists(BackendEntryPointResolver::class)) {
return new ApplicationFE(
$requestHandler,
Expand All @@ -69,6 +77,13 @@ public static function getApplicationBE(ContainerInterface $container): Applicat
$container->get('backend.middlewares'),
$container,
);
if (version_compare((new Typo3Version())->getBranch(), '13.0', '>=')) {
return new ApplicationBE(
$requestHandler,
$container->get(Context::class),
);

Check warning on line 84 in Classes/ServiceProvider.php

View check run for this annotation

Codecov / codecov/patch

Classes/ServiceProvider.php#L80-L84

Added lines #L80 - L84 were not covered by tests
}

if (version_compare((new Typo3Version())->getBranch(), '12.0', '>=') && class_exists(BackendEntryPointResolver::class)) {
return new ApplicationBE(
$requestHandler,
Expand Down
79 changes: 39 additions & 40 deletions Classes/SqlLogging/LoggingConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,42 @@

namespace Kanti\ServerTiming\SqlLogging;

//
//use Doctrine\DBAL\Driver\Connection as ConnectionInterface;
//use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware;
//use Doctrine\DBAL\Driver\Result;
//use Doctrine\DBAL\Driver\Statement as DriverStatement;
//
//if (!class_exists(AbstractConnectionMiddleware::class)) {
// return;
//}
//
//final class LoggingConnection extends AbstractConnectionMiddleware
//{
// public function __construct(ConnectionInterface $connection, private readonly DoctrineSqlLogger $logger)
// {
// parent::__construct($connection);
// }
//
// public function prepare(string $sql): DriverStatement
// {
// return new LoggingStatement(parent::prepare($sql), $this->logger, $sql);
// }
//
// public function query(string $sql): Result
// {
// $this->logger->startQuery($sql);
// $query = parent::query($sql);
// $this->logger->stopQuery();
//
// return $query;
// }
//
// public function exec(string $sql): int
// {
// $this->logger->startQuery($sql);
// $query = parent::exec($sql);
// $this->logger->stopQuery();
//
// return $query;
// }
//}
use Doctrine\DBAL\Driver\Connection as ConnectionInterface;
use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\Statement as DriverStatement;

if (!class_exists(AbstractConnectionMiddleware::class)) {
return;

Check warning on line 15 in Classes/SqlLogging/LoggingConnection.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingConnection.php#L14-L15

Added lines #L14 - L15 were not covered by tests
}

final class LoggingConnection extends AbstractConnectionMiddleware
{
public function __construct(ConnectionInterface $connection, private readonly DoctrineSqlLogger $logger)

Check warning on line 20 in Classes/SqlLogging/LoggingConnection.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingConnection.php#L20

Added line #L20 was not covered by tests
{
parent::__construct($connection);

Check warning on line 22 in Classes/SqlLogging/LoggingConnection.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingConnection.php#L22

Added line #L22 was not covered by tests
}

public function prepare(string $sql): DriverStatement

Check warning on line 25 in Classes/SqlLogging/LoggingConnection.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingConnection.php#L25

Added line #L25 was not covered by tests
{
return new LoggingStatement(parent::prepare($sql), $this->logger, $sql);

Check warning on line 27 in Classes/SqlLogging/LoggingConnection.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingConnection.php#L27

Added line #L27 was not covered by tests
}

public function query(string $sql): Result

Check warning on line 30 in Classes/SqlLogging/LoggingConnection.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingConnection.php#L30

Added line #L30 was not covered by tests
{
$this->logger->startQuery($sql);
$query = parent::query($sql);
$this->logger->stopQuery();

Check warning on line 34 in Classes/SqlLogging/LoggingConnection.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingConnection.php#L32-L34

Added lines #L32 - L34 were not covered by tests

return $query;

Check warning on line 36 in Classes/SqlLogging/LoggingConnection.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingConnection.php#L36

Added line #L36 was not covered by tests
}

public function exec(string $sql): int

Check warning on line 39 in Classes/SqlLogging/LoggingConnection.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingConnection.php#L39

Added line #L39 was not covered by tests
{
$this->logger->startQuery($sql);
$query = parent::exec($sql);
$this->logger->stopQuery();

Check warning on line 43 in Classes/SqlLogging/LoggingConnection.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingConnection.php#L41-L43

Added lines #L41 - L43 were not covered by tests

return (int)$query;

Check warning on line 45 in Classes/SqlLogging/LoggingConnection.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingConnection.php#L45

Added line #L45 was not covered by tests
}
}
40 changes: 19 additions & 21 deletions Classes/SqlLogging/LoggingDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,22 @@

namespace Kanti\ServerTiming\SqlLogging;

//
//use Doctrine\DBAL\Driver as DriverInterface;
//use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware;
//use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
//
//if (!class_exists(AbstractDriverMiddleware::class)) {
// return;
//}
//
//final class LoggingDriver extends AbstractDriverMiddleware
//{
// public function __construct(DriverInterface $driver, private readonly DoctrineSqlLogger $logger)
// {
// parent::__construct($driver);
// }
//
// public function connect(array $params)
// {
// return new LoggingConnection(parent::connect($params), $this->logger);
// }
//}
use Doctrine\DBAL\Driver as DriverInterface;
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;

if (!class_exists(AbstractDriverMiddleware::class)) {
return;

Check warning on line 13 in Classes/SqlLogging/LoggingDriver.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingDriver.php#L12-L13

Added lines #L12 - L13 were not covered by tests
}

final class LoggingDriver extends AbstractDriverMiddleware
{
public function __construct(DriverInterface $driver, private readonly DoctrineSqlLogger $logger)

Check warning on line 18 in Classes/SqlLogging/LoggingDriver.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingDriver.php#L18

Added line #L18 was not covered by tests
{
parent::__construct($driver);

Check warning on line 20 in Classes/SqlLogging/LoggingDriver.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingDriver.php#L20

Added line #L20 was not covered by tests
}

public function connect(array $params): DriverInterface\Connection

Check warning on line 23 in Classes/SqlLogging/LoggingDriver.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingDriver.php#L23

Added line #L23 was not covered by tests
{
return new LoggingConnection(parent::connect($params), $this->logger);

Check warning on line 25 in Classes/SqlLogging/LoggingDriver.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingDriver.php#L25

Added line #L25 was not covered by tests
}
}
31 changes: 15 additions & 16 deletions Classes/SqlLogging/LoggingMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@

namespace Kanti\ServerTiming\SqlLogging;

//
//use Doctrine\DBAL\Driver as DriverInterface;
//use Doctrine\DBAL\Driver\Middleware as MiddlewareInterface;
//use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
//
//if (!interface_exists(MiddlewareInterface::class)) {
// return;
//}
//
//final class LoggingMiddleware implements MiddlewareInterface
//{
// public function wrap(DriverInterface $driver): DriverInterface
// {
// return new LoggingDriver($driver, new DoctrineSqlLogger());
// }
//}
use Doctrine\DBAL\Driver as DriverInterface;
use Doctrine\DBAL\Driver\Middleware as MiddlewareInterface;
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;

if (!interface_exists(MiddlewareInterface::class)) {
return;

Check warning on line 14 in Classes/SqlLogging/LoggingMiddleware.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingMiddleware.php#L13-L14

Added lines #L13 - L14 were not covered by tests
}

final class LoggingMiddleware implements MiddlewareInterface
{
public function wrap(DriverInterface $driver): DriverInterface

Check warning on line 19 in Classes/SqlLogging/LoggingMiddleware.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingMiddleware.php#L19

Added line #L19 was not covered by tests
{
return new LoggingDriver($driver, new DoctrineSqlLogger());

Check warning on line 21 in Classes/SqlLogging/LoggingMiddleware.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingMiddleware.php#L21

Added line #L21 was not covered by tests
}
}
49 changes: 24 additions & 25 deletions Classes/SqlLogging/LoggingStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,27 @@

namespace Kanti\ServerTiming\SqlLogging;

//
//use Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware;
//use Doctrine\DBAL\Driver\Result as ResultInterface;
//use Doctrine\DBAL\Driver\Statement as StatementInterface;
//
//if (!class_exists(AbstractStatementMiddleware::class)) {
// return;
//}
//
//final class LoggingStatement extends AbstractStatementMiddleware
//{
// public function __construct(StatementInterface $statement, private readonly DoctrineSqlLogger $logger, private readonly string $sql)
// {
// parent::__construct($statement);
// }
//
// public function execute($params = null): ResultInterface
// {
// $this->logger->startQuery($this->sql);
// $result = parent::execute($params);
// $this->logger->stopQuery();
//
// return $result;
// }
//}
use Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware;
use Doctrine\DBAL\Driver\Result as ResultInterface;
use Doctrine\DBAL\Driver\Statement as StatementInterface;

if (!class_exists(AbstractStatementMiddleware::class)) {
return;

Check warning on line 14 in Classes/SqlLogging/LoggingStatement.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingStatement.php#L13-L14

Added lines #L13 - L14 were not covered by tests
}

final class LoggingStatement extends AbstractStatementMiddleware
{
public function __construct(StatementInterface $statement, private readonly DoctrineSqlLogger $logger, private readonly string $sql)

Check warning on line 19 in Classes/SqlLogging/LoggingStatement.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingStatement.php#L19

Added line #L19 was not covered by tests
{
parent::__construct($statement);

Check warning on line 21 in Classes/SqlLogging/LoggingStatement.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingStatement.php#L21

Added line #L21 was not covered by tests
}

public function execute($params = null): ResultInterface

Check warning on line 24 in Classes/SqlLogging/LoggingStatement.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingStatement.php#L24

Added line #L24 was not covered by tests
{
$this->logger->startQuery($this->sql);
$result = parent::execute($params);
$this->logger->stopQuery();

Check warning on line 28 in Classes/SqlLogging/LoggingStatement.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingStatement.php#L26-L28

Added lines #L26 - L28 were not covered by tests

return $result;

Check warning on line 30 in Classes/SqlLogging/LoggingStatement.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/LoggingStatement.php#L30

Added line #L30 was not covered by tests
}
}
5 changes: 5 additions & 0 deletions Classes/SqlLogging/SqlLoggerCore11.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Kanti\ServerTiming\Dto\StopWatch;
use Kanti\ServerTiming\Utility\TimingUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand All @@ -20,6 +21,10 @@ final class SqlLoggerCore11
*/
public static function registerSqlLogger(): void
{
if (version_compare((new Typo3Version())->getBranch(), '12.3', '>=')) {
return;

Check warning on line 25 in Classes/SqlLogging/SqlLoggerCore11.php

View check run for this annotation

Codecov / codecov/patch

Classes/SqlLogging/SqlLoggerCore11.php#L24-L25

Added lines #L24 - L25 were not covered by tests
}

$doctrineSqlLogger = new DoctrineSqlLogger();

$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
Expand Down
6 changes: 4 additions & 2 deletions Classes/Utility/GuzzleUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Kanti\ServerTiming\Utility;

use LogicException;
use Throwable;
use Closure;
use GuzzleHttp\Exception\RequestException as GuzzleRequestException;
use GuzzleHttp\Promise\PromiseInterface;
Expand All @@ -28,7 +30,7 @@ public static function getHandler(): ?Closure
return static fn(callable $handler): Closure => static function (RequestInterface $request, array $options) use ($handler): PromiseInterface {
try {
GeneralUtility::getContainer();
} catch (\LogicException) {
} catch (LogicException) {

Check warning on line 33 in Classes/Utility/GuzzleUtility.php

View check run for this annotation

Codecov / codecov/patch

Classes/Utility/GuzzleUtility.php#L33

Added line #L33 was not covered by tests
// container not found:
// than we are most likely in a subprocess (spatie/async)
// and we don't want to initialize the container here!
Expand All @@ -52,7 +54,7 @@ public static function getHandler(): ?Closure
$stop->info = $request->getMethod() . ' ' . $response->getStatusCode() . ' ' . $request->getUri()->__toString();
}

if ($responseOrException instanceof \Throwable) {
if ($responseOrException instanceof Throwable) {

Check warning on line 57 in Classes/Utility/GuzzleUtility.php

View check run for this annotation

Codecov / codecov/patch

Classes/Utility/GuzzleUtility.php#L57

Added line #L57 was not covered by tests
throw $responseOrException;
}

Expand Down
Loading

0 comments on commit e8c572a

Please sign in to comment.