-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1261 from dpfaffenbauer/issue/1260
[Country] don't call the request based resolvers every time
- Loading branch information
Showing
3 changed files
with
123 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/CoreShop/Component/Address/Context/RequestBased/CachedCountryContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* CoreShop. | ||
* | ||
* This source file is subject to the GNU General Public License version 3 (GPLv3) | ||
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt | ||
* files that are distributed with this source code. | ||
* | ||
* @copyright Copyright (c) 2015-2020 Dominik Pfaffenbauer (https://www.pfaffenbauer.at) | ||
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3) | ||
*/ | ||
|
||
namespace CoreShop\Component\Address\Context\RequestBased; | ||
|
||
use CoreShop\Component\Address\Context\RequestBased\RequestResolverInterface; | ||
use CoreShop\Component\Address\Model\CountryInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
final class CachedCountryContext implements RequestResolverInterface | ||
{ | ||
/** | ||
* @var RequestResolverInterface | ||
*/ | ||
private $inner; | ||
|
||
/** | ||
* @var CountryInterface | ||
*/ | ||
private $country; | ||
|
||
/** | ||
* @param RequestResolverInterface $inner | ||
*/ | ||
public function __construct(RequestResolverInterface $inner) | ||
{ | ||
$this->inner = $inner; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function findCountry(Request $request) | ||
{ | ||
if (null === $this->country) { | ||
$this->country = $this->inner->findCountry($request); | ||
} | ||
|
||
return $this->country; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters