-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add per request in memory caching of country objects to improve perfo…
…rmance
- Loading branch information
1 parent
44adef1
commit 5d39f7c
Showing
2 changed files
with
28 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
|
||
namespace DivineOmega\LaravelAddresses\Helpers; | ||
|
||
|
||
use DivineOmega\Countries\Countries; | ||
use DivineOmega\Countries\Country; | ||
|
||
abstract class CountryHelper | ||
{ | ||
static $countriesByCode = []; | ||
|
||
static function getByIsoCode($countryCode): ?Country | ||
{ | ||
if (array_key_exists($countryCode, self::$countriesByCode)) { | ||
return self::$countriesByCode[$countryCode]; | ||
} | ||
|
||
$country = (new Countries())->getByIsoCode($countryCode); | ||
|
||
self::$countriesByCode[$countryCode] = $country; | ||
|
||
return $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