Skip to content

Commit

Permalink
Proper PHP support + CI (#77)
Browse files Browse the repository at this point in the history
* 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
dmythro and Radiergummi authored Jan 8, 2021
1 parent 0932765 commit 1b85751
Show file tree
Hide file tree
Showing 11 changed files with 1,857 additions and 3,088 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/phpunit.yml
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.lock

coverage
.phpunit.cache

composer.phar

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Countries",
"version": "2.5.6",
"version": "2.6.0",
"homepage": "http://annexare.github.io/Countries/",
"author": {
"name": "Dmytro",
Expand Down
12 changes: 10 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "annexare/countries-list",
"version": "2.5.6",
"version": "2.6.0",
"description": "Continents & countries: ISO 3166-1 alpha-2 code, name, ISO 639-1 languages, capital, currency, native name, phone. JSON, CSV and SQL.",
"type": "library",
"keywords": [
Expand Down Expand Up @@ -32,5 +32,13 @@
"issues": "https://github.com/annexare/Countries/issues"
},
"require": {},
"homepage": "http://annexare.github.io/Countries/"
"autoload": {
"files": [
"dist/index.php"
]
},
"homepage": "http://annexare.github.io/Countries/",
"require-dev": {
"phpunit/phpunit": "^9.5"
}
}
2 changes: 1 addition & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Type definitions for countries-list 2.5
// Type definitions for countries-list 2.6
// Project: https://github.com/annexare/Countries
// Definitions by: Dmytro <https://github.com/z-ax>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
Expand Down
5 changes: 2 additions & 3 deletions dist/index.es5.min.js

Large diffs are not rendered by default.

82 changes: 82 additions & 0 deletions dist/index.php
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');
}
Loading

0 comments on commit 1b85751

Please sign in to comment.