generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 197
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 #1 from spatie/simplify-countries
Simplify countries
- Loading branch information
Showing
8 changed files
with
89 additions
and
58 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,46 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Spatie\Holidays\Exceptions\InvalidYear; | ||
|
||
abstract class Country | ||
{ | ||
public static function find(string $countryCode): ?Country | ||
{ | ||
$countryCode = strtolower($countryCode); | ||
|
||
foreach (glob(__DIR__.'/../Countries/*.php') as $filename) { | ||
if (basename($filename) === 'Country.php') { | ||
continue; | ||
} | ||
|
||
// determine class name from file name | ||
$countryClass = '\\Spatie\\Holidays\\Countries\\'.basename($filename, '.php'); | ||
|
||
/** @var \Spatie\Holidays\Countries\Country $country */ | ||
$country = new $countryClass; | ||
|
||
if (strtolower($country->countryCode()) === $countryCode) { | ||
return $country; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
abstract public function countryCode(): string; | ||
|
||
abstract public function get(int $year): array; | ||
|
||
protected static function ensureYearCanBeCalculated(int $year): void | ||
{ | ||
if ($year < 1970) { | ||
throw InvalidYear::yearTooLow(); | ||
} | ||
|
||
if ($year > 2037) { | ||
throw InvalidYear::yearTooHigh(); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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,13 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Exceptions; | ||
|
||
use RuntimeException; | ||
|
||
class UnsupportedCountry extends RuntimeException | ||
{ | ||
public static function make(string $countryCode): self | ||
{ | ||
return new self("Country code `{$countryCode}` is not supported."); | ||
} | ||
} |
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
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