Skip to content

Commit

Permalink
Fix support for symfony 4.4 in SymfonyProfiler+ProfilerMiddleware (#15)
Browse files Browse the repository at this point in the history
Symfony 4.4 uses the older method `getMasterRequest()` instead of `getMainRequest()`.   Since 4.4 is supported by this library at this time, I propose this change so it correctly works using symfony 4.4.
  • Loading branch information
Zombaya authored Jan 3, 2023
1 parent f2754a6 commit 03e6b33
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ parameters:
- '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::#'
- '#[Ff]unction (dd_?trace|DDTrace\\)\S+ (is )?not found#'
- '#Call to static method [^(]+\(\) on an unknown class Tideways\\Profiler.#'
- message: '#Call to function method_exists\(\) with Symfony\\Component\\HttpFoundation\\RequestStack and .getMainRequest. will always evaluate to true#'
reportUnmatched: false
- message: '#Call to an undefined method Symfony\\Component\\HttpFoundation\\RequestStack::getMasterRequest\(\).#'
reportUnmatched: false
- message: '#Call to deprecated method getMasterRequest\(\) of class Symfony\\Component\\HttpFoundation\\RequestStack#'
reportUnmatched: false

# See https://github.com/phpstan/phpstan-deprecation-rules/issues/76#issuecomment-1319808544
- '#^Call to deprecated method prophesize\(\) of class Sourceability\\Instrumentation\\Test\\#'
Expand Down
5 changes: 4 additions & 1 deletion src/Messenger/ProfilerMiddleware.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public function handle(Envelope $envelope, StackInterface $stack): Envelope

$skip = false;
if (null !== $this->requestStack
&& null !== $this->requestStack->getMainRequest()
&& null !== (method_exists(
$this->requestStack,
'getMainRequest'
) ? $this->requestStack->getMainRequest() : $this->requestStack->getMasterRequest())
) {
$skip = true;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Profiler/SymfonyProfiler.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ public function stop(?Throwable $exception = null): void

$requestStackToCleanUp = null;
if (null !== $this->requestStack
&& null === $this->requestStack->getMainRequest()
&& null === (method_exists(
$this->requestStack,
'getMainRequest'
) ? $this->requestStack->getMainRequest() : $this->requestStack->getMasterRequest())
) {
// Fixes: Notice: Trying to get property 'attributes' of non-object
// See https://github.com/symfony/symfony/blob/e34cd7dd2c6d0b30d24cad443b8f964daa841d71/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php#L109
Expand Down

0 comments on commit 03e6b33

Please sign in to comment.