generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb25f1f
commit a2a467e
Showing
8 changed files
with
91 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,47 @@ | ||
<?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 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