A collection of standards as PHP Enums: ISO3166, ISO4217, ISO639...

Overview

Banner

Standards

GitHub Build Status Scrutinizer Code Quality Code Coverage PHP Version Support

A collection of standards as PHP Enums

Setup

Make sure you are running PHP 8.1 or higher to use this package

To start right away, run the following command in your composer project;

composer require prinsfrank/standards

Or for development only;

composer require prinsfrank/standards --dev

Country

ISO 3166-1 Alpha-2

$valueAlpha2 = ISO3166_1_Alpha_2::from('NL');        // ISO3166_1_Alpha_2::Netherlands
$value = $valueAlpha2->value;                        // 'NL'
$valueName = $valueAlpha2->name;                     // 'Netherlands'
$valueAlpha3 = $valueAlpha2->toISO3166_1_Alpha_3();  // ISO3166_1_Alpha_3::Netherlands
$valueNumeric = $valueAlpha2->toISO3166_1_Numeric(); // ISO3166_1_Numeric::Netherlands

ISO 3166-1 Alpha-3

$valueAlpha3 = ISO3166_1_Alpha_3::from('NLD');       // ISO3166_1_Alpha_3::Netherlands
$value = $valueAlpha3->value;                        // 'NLD'
$valueName = $valueAlpha3->name;                     // 'Netherlands'
$valueAlpha2 = $valueAlpha3->toISO3166_1_Alpha_2();  // ISO3166_1_Alpha_2::Netherlands
$valueNumeric = $valueAlpha3->toISO3166_1_Numeric(); // ISO3166_1_Numeric::Netherlands

ISO 3166-1 Numeric

$valueNumeric = ISO3166_1_Numeric::from('528');       // ISO3166_1_Numeric::Netherlands
$valueNumeric = ISO3166_1_Numeric::fromInt(528);      // ISO3166_1_Numeric::Netherlands
$value = $valueNumeric->value;                        // '528'
$valueName = $valueNumeric->name;                     // 'Netherlands'
$valueAlpha2 = $valueNumeric->toISO3166_1_Alpha_2();  // ISO3166_1_Alpha_2::Netherlands
$valueAlpha3 = $valueNumeric->toISO3166_1_Alpha_3();  // ISO3166_1_Alpha_3::Netherlands

Currency

ISO 4217 Alpha-3

$valueAlpha3 = ISO4217_Alpha3::from('EUR');        // ISO4217_Alpha3::Euro
$value = $valueAlpha3->value;                      // 'EUR'
$valueName = $valueAlpha3->name;                   // 'Euro'
$valueNumeric = $valueAlpha3->toISO4217_Numeric(); // ISO4217_Numeric::Euro

ISO 4217 Numeric

$valueNumeric = ISO4217_Numeric::from('978');     // ISO4217_Numeric::Euro
$valueNumeric = ISO4217_Numeric::fromInt(978);    // ISO4217_Numeric::Euro
$value = $valueNumeric->value;                    // '978'
$valueName = $valueNumeric->name;                 // 'Euro'
$valueAlpha3 = $valueNumeric->toISO4217_Alpha3(); // ISO4217_Alpha3::Euro

Language

ISO 639-1

$valueAlpha2 = ISO639_1_Alpha_2::from('nl');                                  // ISO639_1_Alpha_2::Dutch_Flemish
$value = $valueAlpha2->value;                                                 // 'nl'
$valueName = $valueAlpha2->name;                                              // 'Dutch_Flemish'
$valueAlpha3Bibliographic = $valueAlpha2->toISO639_2_Alpha_3_Bibliographic(); // ISO639_2_Alpha_3_Bibliographic::Dutch_Flemish
$valueAlpha3Terminology = $valueAlpha2->toISO639_2_Alpha_3_Terminology();     // ISO639_2_Alpha_3_Terminology::Dutch_Flemish

ISO 639-2 (Common, Bibliographic and Terminology)

$valueAlpha2 = ISO639_2_Alpha_3_Bibliographic::from('dut');               // ISO639_1_Alpha_2::Dutch_Flemish
$value = $valueAlpha2->value;                                             // 'dut'
$valueName = $valueAlpha2->name;                                          // 'Dutch_Flemish'
$valueAlpha2 = $valueAlpha2->toISO639_1_Alpha_2();                        // ISO639_1_Alpha_2::Dutch_Flemish
$valueAlpha3Terminology = $valueAlpha2->toISO639_2_Alpha_3_Terminology(); // ISO639_2_Alpha_3_Terminology::Dutch_Flemish

$valueAlpha2 = ISO639_2_Alpha_3_Terminology::from('nld');                     // ISO639_1_Alpha_2::Dutch_Flemish
$value = $valueAlpha2->value;                                                 // 'nld'
$valueName = $valueAlpha2->name;                                              // 'Dutch_Flemish'
$valueAlpha2 = $valueAlpha2->toISO639_1_Alpha_2();                            // ISO639_1_Alpha_2::Dutch_Flemish
$valueAlpha3Bibliographic = $valueAlpha2->toISO639_2_Alpha_3_Bibliographic(); // ISO639_2_Alpha_3_Bibliographic::Dutch_Flemish
Comments
  • Add ::names ::values ::toArray helper to BackedEnum

    Add ::names ::values ::toArray helper to BackedEnum

    This PR add static function names(), values() and toArray in the BackendEnum class.

    use PrinsFrank\Standards\BackedEnum;
    use PrinsFrank\Standards\Language\ISO639_1_Alpha_2;
    
    $array = BackedEnum::toArray(ISO639_1_Alpha_2::class);
    $values = BackedEnum::values(ISO639_1_Alpha_2::class);
    $names = BackedEnum::names(ISO639_1_Alpha_2::class);
    

    This maybe useful and maybe not. Feel free to accept or drop this PR. Cheers :clinking_glasses:


    Apart from this, @PrinsFrank what do you think instead of using it with BackedEnum class, use directly in the enum class it self. Like:

    use PrinsFrank\Standards\Language\ISO639_1_Alpha_2;
    
    $array = ISO639_1_Alpha_2::toArray();
    $values = ISO639_1_Alpha_2::values();
    $names = ISO639_1_Alpha_2::names();
    
    // and maybe add toJson too
    $json = ISO639_1_Alpha_2::toJson();
    
    opened by lakuapik 4
  • Small fixes

    Small fixes

    Fix composer phpunit test suite: no tests were running since the unit was lowercase

    Fix case convert tests when not expecting null: since those converter functions were set to not return null (since they should be one for one), if it happened it would throw a \TypeError

    Simplify Enum:fromKey: added return type to ?\BackedEnum since they all are backed, also since the filter always expects one to be found, it can be simplified to return early on the first one found or null if none

    opened by akalineskou 2
  • HTTP Status Codes (iana)

    HTTP Status Codes (iana)

    Added an enum that lists HTTP Status Codes (PrinsFrank\Standards\Http\HttpStatusCode).

    Since this is just a dumb enum, no unit tests were added (no functionality to test).

    Sources used:

    • https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
    • https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
    opened by iRealWorlds 2
  • IANA Assigned Ports and services

    IANA Assigned Ports and services

    Not an ISO standard but IANA, but ports would be a good addition;

    https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.txt

    https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv

    opened by Jellyfrog 2
  • [Feature Request] E.123 / E.124 / Country calling codes

    [Feature Request] E.123 / E.124 / Country calling codes

    opened by francoisauclair911 1
  • Add .gitattributes

    Add .gitattributes

    With this file, we can ignore files/folder that are not used for package distribution. This will save disk space when user install the package.

    image

    Before: 224KB, After: 182K. It saves around 42KB. Its not a lot, but it saves some space.

    Feel free to drop or accept this PR. Cheers :beers:

    opened by lakuapik 1
Releases(v1.5.0)
  • v1.5.0(Nov 27, 2022)

    What's Changed

    • Added HTTP Methods

    Other changes

    • Add incremental backoff to spec updating so manual retries are not ne… by @PrinsFrank in https://github.com/PrinsFrank/standards/pull/46

    Full Changelog: https://github.com/PrinsFrank/standards/compare/v1.4.0...v1.5.0

    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Sep 24, 2022)

    What's Changed

    • Add UnitEnum utility class providing similar function as BackedEnum functionality but for UnitEnums instead.
    • Update the six group datasource url for currency codes as it has been update on their website by @PrinsFrank in https://github.com/PrinsFrank/standards/pull/44

    Full Changelog: https://github.com/PrinsFrank/standards/compare/v1.3.0...v1.4.0

    Source code(tar.gz)
    Source code(zip)
  • v1.3.0(Aug 24, 2022)

    What's Changed

    • Add ::names ::values ::toArray helper to BackedEnum by @lakuapik in https://github.com/PrinsFrank/standards/pull/33

    Full Changelog: https://github.com/PrinsFrank/standards/compare/v1.2.0...v1.3.0

    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Aug 14, 2022)

    What's Changed

    • Add country calling codes enum by @PrinsFrank in https://github.com/PrinsFrank/standards/pull/32

    Full Changelog: https://github.com/PrinsFrank/standards/compare/v1.1.0...v1.2.0

    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Jul 16, 2022)

    What's Changed

    Turkey, Türkiye and BC key changes.

    A new minor version is released as Turkey has now officially been renamed to Türkiye in ISO3166.

    This brought one major challenge though; Renaming enum names are breaking changes, and releasing a new major version for every country rename is not ideal and leaves a lot of overhead for package users. Therefor, a new enum is added with the latest name for countries, currencies and languages, that can be used instead of enum keys. Keys will not change to keep this package backwards compatible:

    /**
     * @source https://www.iso.org/obp/ui/#search/code/
     */
    enum ISO3166_1_Name: string
    {
        case Turkey = 'Türkiye';
        // Enum key is unchanged to be backwards compatible
    }
    

    Methods are added to get the name corresponding to alpha2, alpha3 and numeric values:

    $turkiye = ISO3166_1_Alpha_2::fromValue('TR');
    $name = $turkiye->toISO3166_Name()->value(); // Türkiye
    

    Helper methods for casing and numeric values as integers

    All alpha2 and alpha3 values in ISO3166 and ISO4127 are uppercase, and lowercase in ISO639. You may want to get them as lowercase and uppercase respectfully. Methods to get these values are now available:

    $netherlands = ISO3166_1_Alpha_2::fromValue('NL');
    $netherlandsLowerCase = $netherlands->lowerCaseValue(); // nl
    
    $dutchFlemish = ISO639_1_Alpha_2::fromValue('nl');
    $dutchFlemishUpperCase = $dutchFlemish->upperCaseValue(): // NL
    

    Numeric enums sometimes have leading zeros that are required as their complete value. You may want to get those values as integers though;

    $euro = ISO4217_Numeric::fromValue('978');
    $euro = ISO4217_Numeric::fromInt(978);
    $euroAsInt = $euro->valueAsInt(): // 978
    

    Other changes

    Apart from these changes, a lot has been done to improve this package's stability and make this package more mature;

    • Name Composer scripts like $tool:$action by @szepeviktor in https://github.com/PrinsFrank/standards/pull/14
    • Fix Composer script in CI by @szepeviktor in https://github.com/PrinsFrank/standards/pull/16
    • Run unit tests in CI by @szepeviktor in https://github.com/PrinsFrank/standards/pull/17
    • Add phpstan by @PrinsFrank in https://github.com/PrinsFrank/standards/pull/21
    • Simplify BackedEnum by @szepeviktor in https://github.com/PrinsFrank/standards/pull/23
    • Convert key variance to new enum to prevent many major releases by @PrinsFrank in https://github.com/PrinsFrank/standards/pull/26
    • Add code coverage generation by @PrinsFrank in https://github.com/PrinsFrank/standards/pull/30

    Full Changelog: https://github.com/PrinsFrank/standards/compare/v1.0.0...v1.1.0

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Jul 10, 2022)

    What's Changed

    With version 1.0.0, this package is now stable! As the standards are now pulled daily from their respective sources, this package will be updated as soon as their counterpart spec updates! Unfortunately, when pulling from the official sources it became apparent that the 0.0.1 release contained several enum keys that were not consistent with the official spec. make sure to follow the upgrade guide to implement these changes and get up and running with this new release!

    • Add .gitattributes by @lakuapik in https://github.com/PrinsFrank/standards/pull/6
    • Small fixes by @akalineskou in https://github.com/PrinsFrank/standards/pull/5
    • Rename ISO4217_Alpha3 to ISO4217_Alpha_3 by @Wick96 in https://github.com/PrinsFrank/standards/pull/3
    • HTTP Status Codes (iana) by @iRealWorlds in https://github.com/PrinsFrank/standards/pull/4
    • Add automatic spec updating by @PrinsFrank in https://github.com/PrinsFrank/standards/pull/9, https://github.com/PrinsFrank/standards/pull/10 and https://github.com/PrinsFrank/standards/pull/11
    • Run SpecUpdater in a Composer way by @szepeviktor in https://github.com/PrinsFrank/standards/pull/13

    New Contributors

    • @lakuapik made their first contribution in https://github.com/PrinsFrank/standards/pull/6
    • @akalineskou made their first contribution in https://github.com/PrinsFrank/standards/pull/5
    • @Wick96 made their first contribution in https://github.com/PrinsFrank/standards/pull/3
    • @iRealWorlds made their first contribution in https://github.com/PrinsFrank/standards/pull/4
    • @szepeviktor made their first contribution in https://github.com/PrinsFrank/standards/pull/13

    Full Changelog: https://github.com/PrinsFrank/standards/compare/v0.0.1...v1.0.0

    Source code(tar.gz)
    Source code(zip)
  • v0.0.1(Jun 8, 2022)

Owner
Hi! I'm Frank Prins, A senior PHP developer specialized in Security.
null
Support for PHP 8.1 enums in Doctrine.

Doctrine Native Enums This library provides first-class support to PHP Enums, introduced in PHP 8.1, within your Doctrine entities. Installation compo

Beno!t POLASZEK 14 Dec 15, 2022
Helpers for making PHP enums more lovable.

Enums A collection of enum helpers for PHP. InvokableCases Names Values Options From Metadata You can read more about the idea on Twitter. I originall

ARCHTECH 212 Dec 22, 2022
This library can be used, among other things, to retrieve the classes, interfaces, traits, enums, functions and constants declared in a file

marijnvanwezel/reflection-file Library that allows reflection of files. This library can be used, among other things, to retrieve the classes, interfa

Marijn van Wezel 5 Apr 17, 2022
PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.

PHP_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second phpcbf script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent.

Squiz Labs 9.9k Jan 5, 2023
A tool to automatically fix PHP Coding Standards issues

PHP Coding Standards Fixer The PHP Coding Standards Fixer (PHP CS Fixer) tool fixes your code to follow standards; whether you want to follow PHP codi

null 11.6k Jan 1, 2023
Standards Alignment Tool

Standards Alignment Tool (SALT) [] Overview This is a prototype for testing the IMS Global Learning Consortium® CASE™ Specification and proving its us

OpenSALT 39 Dec 14, 2022
A tool to automatically fix Twig Coding Standards issues

Twig CS Fixer Installation This standard can be installed with the Composer dependency manager. Add the coding standard as a dependency of your projec

Vincent Langlet 50 Jan 6, 2023
Composer installer for PHP_CodeSniffer coding standards

PHP_CodeSniffer Standards Composer Installer Plugin This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards (r

Dealerdirect 462 Dec 22, 2022
The tool converts different error reporting standards for deep compatibility with popular CI systems (TeamCity, IntelliJ IDEA, GitHub Actions, etc).

JBZoo / CI-Report-Converter Why? Installing Using as GitHub Action Example GitHub Action workflow Available Directions Help description in terminal Co

JBZoo Toolbox 17 Jun 16, 2022
This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards

PHP_CodeSniffer Standards Composer Installer Plugin This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards (r

PHPCSStandards 393 Feb 25, 2022
Sitepackage for TYPO3 CMS that adheres to the recommended standards, maps all conceivable functional areas and contains examples for common use cases.

TYPO3 CMS Sitepackage This sitepackage sticks as closely as possible to the recommended standard and maps all conceivable functional areas. There are

Eric Bode 3 Dec 18, 2022
Collection pipeline library for PHP

Knapsack Collection pipeline library for PHP Knapsack is a collection library for PHP >= 5.6 that implements most of the sequence operations proposed

Dušan Kasan 540 Dec 17, 2022
🎓 Collection of useful PHP frequently asked questions, articles and best practices

PHP.earth documentation These files are available online at PHP.earth. Contributing and license We are always looking forward to see your contribution

PHP.earth 278 Dec 27, 2022
Collection of value objects that represent the types of the PHP type system

sebastian/type Collection of value objects that represent the types of the PHP type system. Installation You can add this library as a local, per-proj

Sebastian Bergmann 1.1k Dec 29, 2022
Collection of useful PHP functions, mini-classes, and snippets for every day.

JBZoo / Utils Collection of PHP functions, mini classes and snippets for everyday developer's routine life. Install composer require jbzoo/utils Usage

JBZoo Toolbox 786 Dec 30, 2022
A collection of samples that demonstrate how to call Google Cloud services from PHP.

PHP Docs Samples A collection of samples that demonstrate how to call Google Cloud services from PHP. See our other Google Cloud Platform github repos

Google Cloud Platform 875 Dec 29, 2022
A collection of samples that demonstrate how to call Google Cloud services from PHP.

PHP Docs Samples A collection of samples that demonstrate how to call Google Cloud services from PHP. See our other Google Cloud Platform github repos

Google Cloud Platform 796 Dec 22, 2021
A collection of command line scripts for Magento 2 code generation, and a PHP module system for organizing command line scripts.

What is Pestle? Pestle is A PHP Framework for creating and organizing command line programs An experiment in implementing python style module imports

Alan Storm 526 Dec 5, 2022
This library provides a collection of native enum utilities (traits) which you almost always need in every PHP project.

This library provides a collection of native enum utilities (traits) which you almost always need in every PHP project.

DIVE 20 Nov 11, 2022