Skip to content

Commit

Permalink
Merge pull request #47 from Kanti/typo3-13
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanti authored Aug 2, 2024
2 parents 59445ff + 9f3bd39 commit 5391b9b
Show file tree
Hide file tree
Showing 18 changed files with 455 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
{
$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
{
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),
);
}

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),
);
}

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;
}

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 (int)$query;
}
}
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;
}

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

public function connect(array $params): DriverInterface\Connection
{
return new LoggingConnection(parent::connect($params), $this->logger);
}
}
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;
}

final class LoggingMiddleware implements MiddlewareInterface
{
public function wrap(DriverInterface $driver): DriverInterface
{
return new LoggingDriver($driver, new DoctrineSqlLogger());
}
}
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;
}

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;
}
}
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;
}

$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) {
// 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) {
throw $responseOrException;
}

Expand Down
Loading

0 comments on commit 5391b9b

Please sign in to comment.