Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Php 8.0 support #23

Merged
merged 12 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
fail-fast: false
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.3', '7.4']
php-versions: ['7.3', '7.4', '8.0']
composer:
- {name: "lowest", flags: " --prefer-dist --prefer-lowest"}
- {name: "stable", flags: " --prefer-dist --prefer-stable"}
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
extensions: mbstring,intl
tools: composer:v2
- name: Get composer cache directory
Expand All @@ -70,7 +70,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
extensions: mbstring,intl
tools: composer:v2
- name: Get composer cache directory
Expand Down
1 change: 1 addition & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ return PhpCsFixer\Config::create()
'native_function_invocation' => [
'include' => ['@compiler_optimized']
],
'php_unit_method_casing' => false,
])
;
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
},
"require": {
"php": ">=7.3",
"php": ">=7.3 || >= 8.0",
hugochinchilla marked this conversation as resolved.
Show resolved Hide resolved
"symfony/config": "^4.4 || ^5.0",
"symfony/dependency-injection": "^4.4 || ^5.0",
"symfony/http-kernel": "^4.4 || ^5.0",
Expand All @@ -28,7 +28,7 @@
"psr/http-factory": "^1.0",
"psr/http-server-handler": "^1.0",
"psr/http-server-middleware": "^1.0",
"dflydev/fig-cookies": "^2.0",
"dflydev/fig-cookies": "^3.0",
"php-http/discovery": "^1.9",
"psr/http-factory-implementation": "1.0.0",
"psr/log": "^1.1"
Expand All @@ -44,10 +44,10 @@
"phpspec/prophecy-phpunit": "^2.0",
"friendsofphp/php-cs-fixer": "^2.16",
"phpstan/phpstan": "^0.12.2",
"sentry/sentry-symfony": "^3.4",
"sentry/sentry-symfony": "^4.0",
"symfony/framework-bundle": "^4.0||^5.0",
"nyholm/psr7": "^1.2",
"doctrine/mongodb-odm-bundle": "^4.1",
"doctrine/mongodb-odm": "dev-master#fa967eadf9e226923a97b145e8018f94d6580f09",
hugochinchilla marked this conversation as resolved.
Show resolved Hide resolved
"blackfire/php-sdk": "^1.21",
"doctrine/doctrine-bundle": "^2.0",
"doctrine/orm": "^2.7.3",
Expand Down
6 changes: 3 additions & 3 deletions src/EventListener/SentryListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Baldinof\RoadRunnerBundle\Event\WorkerExceptionEvent;
use Baldinof\RoadRunnerBundle\Event\WorkerStopEvent;
use Sentry\FlushableClientInterface;
use Sentry\ClientInterface;
use Sentry\State\HubInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

Expand All @@ -21,8 +21,8 @@ public function onWorkerStop(WorkerStopEvent $event): void
{
$client = $this->hub->getClient();

if ($client instanceof FlushableClientInterface) {
$client->flush();
if ($client instanceof ClientInterface) {
hugochinchilla marked this conversation as resolved.
Show resolved Hide resolved
$client->flush()->wait();
}
}

Expand Down
16 changes: 13 additions & 3 deletions src/Http/Middleware/NativeSessionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface

unset($_SESSION);

$oldId = FigRequestCookies::get($request, session_name())->getValue() ?: '';
$sessionName = session_name();
if ($sessionName) {
$oldId = FigRequestCookies::get($request, $sessionName)->getValue() ?: '';
} else {
$oldId = '';
}

session_id($oldId); // Set to current session or reset to nothing

Expand All @@ -31,7 +36,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface

$newId = session_id();

if ($newId !== $oldId) {
if ($newId && $newId !== $oldId) {
// A session has been started or the id has changed: send the cookie again
$response = $this->addSessionCookie($response, $newId);
}
Expand All @@ -47,8 +52,13 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
private function addSessionCookie(ResponseInterface $response, string $sessionId): ResponseInterface
{
$params = session_get_cookie_params();
$sessionName = session_name();

if (!$sessionName) {
return $response;
}

$setCookie = SetCookie::create(session_name())
$setCookie = SetCookie::create($sessionName)
->withValue($sessionId)
->withPath($params['path'])
->withDomain($params['domain'])
Expand Down
16 changes: 10 additions & 6 deletions src/Http/Middleware/SentryMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
use Psr\Http\Server\RequestHandlerInterface;
use Sentry\ClientInterface;
use Sentry\Event;
use Sentry\FlushableClientInterface;
use Sentry\Options;
use Sentry\State\HubInterface;
use Sentry\State\Scope;
use Sentry\UserDataBag;

/**
* This middleware is mostly a copy of the the Sentry RequestIntegration.
Expand Down Expand Up @@ -49,8 +49,8 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface

yield $next->handle($request);

if ($currentClient instanceof FlushableClientInterface) {
$currentClient->flush();
if ($currentClient instanceof ClientInterface) {
$currentClient->flush()->wait(false);
}
}

Expand Down Expand Up @@ -93,10 +93,14 @@ private function processEvent(Event $event, Options $options, ServerRequestInter
$requestData['cookies'] = $request->getCookieParams();
$requestData['headers'] = $request->getHeaders();

$userContext = $event->getUserContext();
$userDataBag = $event->getUser();
if (null === $userDataBag) {
$userDataBag = new UserDataBag();
$event->setUser($userDataBag);
}

if (null === $userContext->getIpAddress() && isset($serverParams['REMOTE_ADDR'])) {
$userContext->setIpAddress($serverParams['REMOTE_ADDR']);
if (null === $userDataBag->getIpAddress() && isset($serverParams['REMOTE_ADDR'])) {
$userDataBag->setIpAddress($serverParams['REMOTE_ADDR']);
}
} else {
$requestData['headers'] = $this->removePiiFromHeaders($request->getHeaders());
Expand Down
15 changes: 12 additions & 3 deletions tests/Http/Middleware/SentryMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use function Baldinof\RoadRunnerBundle\consumes;
use Baldinof\RoadRunnerBundle\Http\Middleware\SentryMiddleware;
use GuzzleHttp\Promise\Promise;
use GuzzleHttp\Promise\PromiseInterface;
use Nyholm\Psr7\Response;
use Nyholm\Psr7\ServerRequest;
use Nyholm\Psr7\UploadedFile;
Expand Down Expand Up @@ -38,7 +40,7 @@ public function setUp(): void
$this->handler = new class() implements RequestHandlerInterface {
public function handle(ServerRequestInterface $request): ResponseInterface
{
SentrySdk::getCurrentHub()->captureEvent([]);
SentrySdk::getCurrentHub()->captureMessage('Oops, there was an error');

return new Response();
}
Expand All @@ -54,11 +56,18 @@ public function getHub(array $options)
public function create(Options $options): TransportInterface
{
return new class() implements TransportInterface {
public function send(Event $event): ?string
public function send(Event $event): PromiseInterface
{
SentryMiddlewareTest::$collectedEvents->push($event);

return $event->getId();
return new Promise(function () use ($event) {
return $event->getId();
}, null);
}

public function close(?int $timeout = null): PromiseInterface
{
return new Promise(null, null);
}
};
}
Expand Down