Skip to content

Commit 1b85751

Browse files
dmythroRadiergummi
andauthored
Proper PHP support + CI (#77)
* 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]>
1 parent 0932765 commit 1b85751

File tree

11 files changed

+1857
-3088
lines changed

11 files changed

+1857
-3088
lines changed

.github/workflows/phpunit.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Countries PHP CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
paths:
11+
- ".github/workflows/*.yml"
12+
- "data/**"
13+
- "dist/*.php"
14+
- "test/*.php"
15+
- "*.js"
16+
- "*.json"
17+
- "*.ts"
18+
- "!.editorconfig"
19+
- "!.travis.yml"
20+
- "!**LICENSE*"
21+
- "!**README*"
22+
23+
jobs:
24+
build-test:
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- uses: actions/checkout@v2
29+
30+
- uses: php-actions/composer@v5
31+
32+
- name: PHPUnit Tests
33+
uses: php-actions/phpunit@v2
34+
with:
35+
configuration: phpunit.xml
36+
args: --coverage-text

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*.lock
77

88
coverage
9+
.phpunit.cache
910

1011
composer.phar
1112

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Countries",
3-
"version": "2.5.6",
3+
"version": "2.6.0",
44
"homepage": "http://annexare.github.io/Countries/",
55
"author": {
66
"name": "Dmytro",

composer.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "annexare/countries-list",
3-
"version": "2.5.6",
3+
"version": "2.6.0",
44
"description": "Continents & countries: ISO 3166-1 alpha-2 code, name, ISO 639-1 languages, capital, currency, native name, phone. JSON, CSV and SQL.",
55
"type": "library",
66
"keywords": [
@@ -32,5 +32,13 @@
3232
"issues": "https://github.com/annexare/Countries/issues"
3333
},
3434
"require": {},
35-
"homepage": "http://annexare.github.io/Countries/"
35+
"autoload": {
36+
"files": [
37+
"dist/index.php"
38+
]
39+
},
40+
"homepage": "http://annexare.github.io/Countries/",
41+
"require-dev": {
42+
"phpunit/phpunit": "^9.5"
43+
}
3644
}

dist/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Type definitions for countries-list 2.5
1+
// Type definitions for countries-list 2.6
22
// Project: https://github.com/annexare/Countries
33
// Definitions by: Dmytro <https://github.com/z-ax>
44
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

dist/index.es5.min.js

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Annexare\Countries;
6+
7+
use JsonException;
8+
9+
use function file_get_contents;
10+
use function json_decode;
11+
12+
use const JSON_THROW_ON_ERROR;
13+
14+
/**
15+
* Loads a JSON file relative to the current directory.
16+
*
17+
* @param string $path
18+
*
19+
* @return array
20+
* @throws JsonException
21+
* @internal
22+
*/
23+
function load(string $path): array
24+
{
25+
static $cache = [];
26+
27+
if (isset($cache[$path])) {
28+
return $cache[$path];
29+
}
30+
31+
return $cache[$path] = json_decode(
32+
file_get_contents(__DIR__ . '/' . $path),
33+
true,
34+
512,
35+
JSON_THROW_ON_ERROR
36+
);
37+
}
38+
39+
/**
40+
* Continents, key-value object (key is alpha-2 code).
41+
*
42+
* @return array
43+
* @throws JsonException
44+
*/
45+
function continents(): array
46+
{
47+
return load('continents.min.json');
48+
}
49+
50+
/**
51+
* Countries, key-value object (key is alpha-2 code, uppercase).
52+
*
53+
* @return array
54+
* @throws JsonException
55+
*/
56+
function countries(): array
57+
{
58+
return load('countries.min.json');
59+
}
60+
61+
/**
62+
* Languages in use only, key-value object (key is alpha-2 code).
63+
*
64+
* @return array
65+
* @throws JsonException
66+
*/
67+
function languages(): array
68+
{
69+
return load('languages.min.json');
70+
}
71+
72+
/**
73+
* Languages, key-value object (key is alpha-2 code).
74+
* A complete list including not used by Countries list.
75+
*
76+
* @return array
77+
* @throws JsonException
78+
*/
79+
function languagesAll(): array
80+
{
81+
return load('languages.all.min.json');
82+
}

0 commit comments

Comments
 (0)