Skip to content

Commit

Permalink
Merge pull request #2 from bopoda/master
Browse files Browse the repository at this point in the history
Fix getMasterRequest deprecation warning
  • Loading branch information
tattali authored Mar 29, 2022
2 parents f6b7b8b + 7ddfb88 commit 136bc4a
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ php:
- 7.2
- 7.3
- 7.4
- 8.0

env:
matrix:
Expand Down
7 changes: 4 additions & 3 deletions src/EventListener/RequestResponseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function handleRequest(RequestEvent $event)
{
// only handle master request, do not handle sub request like esi includes
// If the device view is "not the mobile view" (e.g. we're not in the request context)
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType() || $this->deviceView->isNotMobileView()) {
if (HttpKernelInterface::MAIN_REQUEST !== $event->getRequestType() || $this->deviceView->isNotMobileView()) {
return;
}

Expand All @@ -119,9 +119,10 @@ public function handleRequest(RequestEvent $event)
}
}

$viewType = $this->deviceView->getViewType();
// Check if we must redirect to the target view and do so if needed
if ($this->mustRedirect($request, $this->deviceView->getViewType())) {
if (($response = $this->getRedirectResponse($request, $this->deviceView->getViewType()))) {
if ($viewType && $this->mustRedirect($request, $viewType)) {
if ($response = $this->getRedirectResponse($request, $viewType)) {
$event->setResponse($response);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Helper/DeviceView.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class DeviceView

public function __construct(RequestStack $requestStack = null)
{
if (!$requestStack || !$this->request = $requestStack->getMasterRequest()) {
if (!$requestStack || !$this->request = $requestStack->getMainRequest()) {
$this->viewType = self::VIEW_NOT_MOBILE;

return;
Expand Down
2 changes: 1 addition & 1 deletion src/Twig/Extension/MobileDetectExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public function isAndroidOS()
public function setRequestByRequestStack(RequestStack $requestStack = null)
{
if (null !== $requestStack) {
$this->request = $requestStack->getMasterRequest();
$this->request = $requestStack->getMainRequest();
}
}
}
2 changes: 1 addition & 1 deletion tests/DataCollector/DeviceDataCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function setUp(): void

$this->requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->disableOriginalConstructor()->getMock();
$this->requestStack->expects($this->any())
->method('getMasterRequest')
->method('getMainRequest')
->willReturn($this->request)
;

Expand Down
6 changes: 3 additions & 3 deletions tests/EventListener/RequestResponseListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function setUp(): void

$this->requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->disableOriginalConstructor()->getMock();
$this->requestStack->expects($this->any())
->method('getMasterRequest')
->method('getMainRequest')
->willReturn($this->request)
;

Expand Down Expand Up @@ -624,7 +624,7 @@ private function createGetResponseEvent(string $content, string $method = 'GET',
$event = new ViewEvent(
$this->createMock(HttpKernelInterface::class),
$this->request,
HttpKernelInterface::MASTER_REQUEST,
HttpKernelInterface::MAIN_REQUEST,
$content
);
$event->getRequest()->headers = new HeaderBag($headers);
Expand All @@ -646,7 +646,7 @@ private function createResponseEvent($response, $method = 'GET', $headers = [])
$event = new ResponseEvent(
$this->createMock(HttpKernelInterface::class),
$this->request,
HttpKernelInterface::MASTER_REQUEST,
HttpKernelInterface::MAIN_REQUEST,
$response
);
$event->getRequest()->headers = new HeaderBag($headers);
Expand Down
2 changes: 1 addition & 1 deletion tests/Helper/DeviceViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function setUp(): void
$this->request->cookies = new ParameterBag();

$this->requestStack->expects($this->any())
->method('getMasterRequest')
->method('getMainRequest')
->willReturn($this->request)
;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Twig/Extension/MobileDetectExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function setUp(): void
$this->request->cookies = new ParameterBag();

$this->requestStack->expects($this->any())
->method('getMasterRequest')
->method('getMainRequest')
->willReturn($this->request)
;

Expand Down

0 comments on commit 136bc4a

Please sign in to comment.