-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Proper PHP support (#74) * Create index.php * Added autoloader entry * Removed Emoji functions due to PHP complexity issues * Updated code style to match library * Added PHPUnit * Added basic test implementation * ci: check php-actions/phpunit@v2 * ci: remove nodejs 10 * ci: PHP config updates * ci: nodejs 10 lives till about October '21 :) * v2.6.0 Co-authored-by: Moritz Friedrich <[email protected]>
- Loading branch information
1 parent
0932765
commit 1b85751
Showing
11 changed files
with
1,857 additions
and
3,088 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Countries PHP CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
paths: | ||
- ".github/workflows/*.yml" | ||
- "data/**" | ||
- "dist/*.php" | ||
- "test/*.php" | ||
- "*.js" | ||
- "*.json" | ||
- "*.ts" | ||
- "!.editorconfig" | ||
- "!.travis.yml" | ||
- "!**LICENSE*" | ||
- "!**README*" | ||
|
||
jobs: | ||
build-test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: php-actions/composer@v5 | ||
|
||
- name: PHPUnit Tests | ||
uses: php-actions/phpunit@v2 | ||
with: | ||
configuration: phpunit.xml | ||
args: --coverage-text |
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
*.lock | ||
|
||
coverage | ||
.phpunit.cache | ||
|
||
composer.phar | ||
|
||
|
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
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
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Annexare\Countries; | ||
|
||
use JsonException; | ||
|
||
use function file_get_contents; | ||
use function json_decode; | ||
|
||
use const JSON_THROW_ON_ERROR; | ||
|
||
/** | ||
* Loads a JSON file relative to the current directory. | ||
* | ||
* @param string $path | ||
* | ||
* @return array | ||
* @throws JsonException | ||
* @internal | ||
*/ | ||
function load(string $path): array | ||
{ | ||
static $cache = []; | ||
|
||
if (isset($cache[$path])) { | ||
return $cache[$path]; | ||
} | ||
|
||
return $cache[$path] = json_decode( | ||
file_get_contents(__DIR__ . '/' . $path), | ||
true, | ||
512, | ||
JSON_THROW_ON_ERROR | ||
); | ||
} | ||
|
||
/** | ||
* Continents, key-value object (key is alpha-2 code). | ||
* | ||
* @return array | ||
* @throws JsonException | ||
*/ | ||
function continents(): array | ||
{ | ||
return load('continents.min.json'); | ||
} | ||
|
||
/** | ||
* Countries, key-value object (key is alpha-2 code, uppercase). | ||
* | ||
* @return array | ||
* @throws JsonException | ||
*/ | ||
function countries(): array | ||
{ | ||
return load('countries.min.json'); | ||
} | ||
|
||
/** | ||
* Languages in use only, key-value object (key is alpha-2 code). | ||
* | ||
* @return array | ||
* @throws JsonException | ||
*/ | ||
function languages(): array | ||
{ | ||
return load('languages.min.json'); | ||
} | ||
|
||
/** | ||
* Languages, key-value object (key is alpha-2 code). | ||
* A complete list including not used by Countries list. | ||
* | ||
* @return array | ||
* @throws JsonException | ||
*/ | ||
function languagesAll(): array | ||
{ | ||
return load('languages.all.min.json'); | ||
} |
Oops, something went wrong.