Skip to content

Commit

Permalink
feat: support Symfony 7
Browse files Browse the repository at this point in the history
  • Loading branch information
Natalia committed Nov 13, 2024
1 parent 2c61360 commit 75b9350
Show file tree
Hide file tree
Showing 8 changed files with 400 additions and 549 deletions.
24 changes: 6 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ jobs:
strategy:
matrix:
include:
- symfony: '4.4.*'
php: '8.0'
- symfony: '4.4.*'
php: '8.1'
- symfony: '4.4.*'
php: '8.2'
- symfony: '5.4.*'
php: '8.0'
- symfony: '5.4.*'
php: '8.1'
- symfony: '5.4.*'
Expand All @@ -37,9 +29,11 @@ jobs:
php: '8.1'
- symfony: '6.2.*'
php: '8.2'
- symfony: '7.1.*'
php: '8.2'
steps:
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup PHP Action
uses: shivammathur/setup-php@v2
with:
Expand Down Expand Up @@ -71,14 +65,6 @@ jobs:
strategy:
matrix:
include:
- symfony: '4.4.*'
php: '8.0'
- symfony: '4.4.*'
php: '8.1'
- symfony: '4.4.*'
php: '8.2'
- symfony: '5.4.*'
php: '8.0'
- symfony: '5.4.*'
php: '8.1'
- symfony: '5.4.*'
Expand All @@ -87,9 +73,11 @@ jobs:
php: '8.1'
- symfony: '6.2.*'
php: '8.2'
- symfony: '7.1.*'
php: '8.2'
steps:
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup PHP Action
uses: shivammathur/setup-php@v2
with:
Expand Down
22 changes: 4 additions & 18 deletions EventListener/FinishRootSpanSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,17 @@ public static function getSubscribedEvents(): array

public function onFinishRequest(KernelEvent $event): void
{
# TODO: when Symfony 4.4 is unmaintained (November 2023), remove outer if-block in favor of isMainRequest()
if (method_exists($event, 'isMainRequest')) {
if (!$event->isMainRequest()) {
return;
}
} elseif (method_exists($event, 'isMasterRequest')) {
if (!$event->isMasterRequest()) {
return;
}
if (!$event->isMainRequest()) {
return;
}

$this->tracing->finishActiveSpan();
}

public function onTerminate(KernelEvent $event): void
{
# TODO: when Symfony 4.4 is unmaintained (November 2023), remove outer if-block in favor of isMainRequest()
if (method_exists($event, 'isMainRequest')) {
if (!$event->isMainRequest()) {
return;
}
} elseif (method_exists($event, 'isMasterRequest')) {
if (!$event->isMasterRequest()) {
return;
}
if (!$event->isMainRequest()) {
return;
}

$this->persistence->flush();
Expand Down
11 changes: 2 additions & 9 deletions EventListener/StartRootSpanSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,8 @@ public static function getSubscribedEvents(): array

public function onRequest(KernelEvent $event): void
{
# TODO: when Symfony 4.4 is unmaintained (November 2023), remove outer if-block in favor of isMainRequest()
if (method_exists($event, 'isMainRequest')) {
if (!$event->isMainRequest()) {
return;
}
} elseif (method_exists($event, 'isMasterRequest')) {
if (!$event->isMasterRequest()) {
return;
}
if (!$event->isMainRequest()) {
return;
}

$request = $event->getRequest();
Expand Down
7 changes: 2 additions & 5 deletions Tests/EventListener/FinishRootSpanSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public function testGetSubscribedEvents(): void

public function testOnFinishRequestIsMainRequest(): void
{
# TODO: when Symfony 4.4 is unmaintained (November 2023), replace HttpKernelInterface::MASTER_REQUEST with HttpKernelInterface::MAIN_REQUEST
$event = new KernelEvent($this->kernel->reveal(), $this->request->reveal(), HttpKernelInterface::MASTER_REQUEST);
$event = new KernelEvent($this->kernel->reveal(), $this->request->reveal(), HttpKernelInterface::MAIN_REQUEST);

$this->tracing->finishActiveSpan()->shouldBeCalledOnce();
$this->persistence->flush()->shouldNotBeCalled();
Expand All @@ -63,8 +62,7 @@ public function testOnFinishRequestIsNotMainRequest(): void

public function testOnTerminateIsMainRequest(): void
{
# TODO: when Symfony 4.4 is unmaintained (November 2023), replace HttpKernelInterface::MASTER_REQUEST with HttpKernelInterface::MAIN_REQUEST
$event = new KernelEvent($this->kernel->reveal(), $this->request->reveal(), HttpKernelInterface::MASTER_REQUEST);
$event = new KernelEvent($this->kernel->reveal(), $this->request->reveal(), HttpKernelInterface::MAIN_REQUEST);

$this->tracing->finishActiveSpan()->shouldNotBeCalled();
$this->persistence->flush()->shouldBeCalledOnce();
Expand All @@ -74,7 +72,6 @@ public function testOnTerminateIsMainRequest(): void

public function testOnTerminateIsNotMainRequest(): void
{
# TODO: when Symfony 4.4 is unmaintained (November 2023), replace HttpKernelInterface::MASTER_REQUEST with HttpKernelInterface::MAIN_REQUEST
$event = new KernelEvent($this->kernel->reveal(), $this->request->reveal(), HttpKernelInterface::SUB_REQUEST);

$this->tracing->finishActiveSpan()->shouldNotBeCalled();
Expand Down
3 changes: 1 addition & 2 deletions Tests/EventListener/StartRootSpanSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public function testGetSubscribedEvents(): void
public function testOnRequestIsMasterRequest(): void
{
$request = Request::create('http://some.uri.test/');
# TODO: when Symfony 4.4 is unmaintained (November 2023), replace HttpKernelInterface::MASTER_REQUEST with HttpKernelInterface::MAIN_REQUEST
$event = new KernelEvent($this->kernel->reveal(), $request, HttpKernelInterface::MASTER_REQUEST);
$event = new KernelEvent($this->kernel->reveal(), $request, HttpKernelInterface::MAIN_REQUEST);

$this->spanOptionsFactory->createSpanOptions($request)->willReturn(['some' => 'options']);
$this->tracing->startActiveSpan(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(Opentracing $opentracing)
$this->opentracing = $opentracing;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$carrier = [];
$this->opentracing->getTracerInstance()->inject($this->opentracing->getTracerInstance()->getActiveSpan()->getContext(), TEXT_MAP, $carrier);
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
"type": "library",
"license": "MIT",
"require": {
"php": "^8.0",
"php": "^8.1",
"ext-json": "*",
"psr/log": "^1.1|^2.0|^3.0",
"psr/http-message": "^1.0",
"psr/http-client": "^1.0",
"opentracing/opentracing": "^1.0.1",
"composer/package-versions-deprecated": "^1.11.99",
"symfony/http-kernel": "^4.4|^5.4|^6.2",
"symfony/dependency-injection": "^4.4|^5.4|^6.2",
"symfony/config": "^4.4|^5.4|^6.2",
"symfony/console": "^4.4|^5.4|^6.2",
"symfony/yaml": "^4.4|^5.4|^6.2"
"symfony/http-kernel": "^5.4|^6.2|^7.1",
"symfony/dependency-injection": "^5.4|^6.2|^7.1",
"symfony/config": "^5.4|^6.2|^7.1",
"symfony/console": "^5.4|^6.2|^7.1",
"symfony/yaml": "^5.4|^6.2|^7.1"
},
"require-dev": {
"roave/security-advisories": "dev-latest",
Expand Down
Loading

0 comments on commit 75b9350

Please sign in to comment.