PHPackages                             oihana/php-standards - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. oihana/php-standards

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

oihana/php-standards
====================

The Oihana PHP Standards library

1.0.0(9mo ago)0766MPL-2.0PHPPHP &gt;=8.4

Since Aug 13Pushed 4mo agoCompare

[ Source](https://github.com/BcommeBois/oihana-php-standards)[ Packagist](https://packagist.org/packages/oihana/php-standards)[ Docs](https://github.com/BcommeBois/oihana-php-schema)[ RSS](/packages/oihana-php-standards/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (2)Used By (6)

Oihana PHP – Standards
======================

[](#oihana-php--standards)

[![Oihana PHP System](https://raw.githubusercontent.com/BcommeBois/oihana-php-standards/main/assets/images/oihana-php-standards-logo-inline-512x160.png)](https://raw.githubusercontent.com/BcommeBois/oihana-php-standards/main/assets/images/oihana-php-standards-logo-inline-512x160.png)

**Oihana PHP – Standards** is a library of **constants**, **enumerations**, and **helpers** based on major international standards (ISO, UN, UN/CEFACT, etc.).

It is designed for **strong typing**, **validation**, and **easy lookups** in your PHP applications.

[![Latest Version](https://camo.githubusercontent.com/f726f9986cca262bae718374e846c1be87660fe41866b6e044d939d0968855d0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f6968616e612f7068702d7374616e64617264732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/oihana/php-standards)
[![Total Downloads](https://camo.githubusercontent.com/1a389591d3e096700136c897839a6efe6b75f8e73a4ebf6256ad3361c623d4bc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f6968616e612f7068702d7374616e64617264732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/oihana/php-standards)
[![License](https://camo.githubusercontent.com/3bf654f65b235f2877a8530159abd118fc42e38af14b1f8b8ea96ddadc760e47/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6f6968616e612f7068702d7374616e64617264732e7376673f7374796c653d666c61742d737175617265)](LICENSE)

---

📑 Table of Contents
-------------------

[](#-table-of-contents)

1. [Installation](#-installation)
2. [Features](#-features)
    - [Namespace Overview](#-namespace-overview)
    - [Available Enumerations](#-available-enumerations)
3. [Core Helper Methods](#-core-helper-methods-constantstrait)
4. [Usage Examples](#-usage-examples)
5. [License](#-license)
6. [Author](#-author)

---

📦 Installation
--------------

[](#-installation)

> **Requires [PHP 8.4+](https://php.net/releases/)**

Install via [Composer](https://getcomposer.org):

```
composer require oihana/php-standards
```

---

✨ Features
----------

[](#-features)

- **Ready-to-use enumerations** for currencies, languages, scripts, country codes, measurement units, package types, and more.
- **Built-in helpers** for validation, lookups, and cross-conversions (e.g., code ↔ name ↔ symbol).
- **Clear namespace organization** for quick navigation and maintainability.

### 🗂 Namespace Overview

[](#-namespace-overview)

NamespaceDescription`org\iso`ISO-related enumerations (currencies, languages, scripts).`org\unstats`United Nations M49 country and area codes (alpha-3).`org\unece\uncefact`UN/CEFACT recommendations (units of measure, package types) with cross lookups.---

📚 Available Enumerations
------------------------

[](#-available-enumerations)

ClassDescriptionExample`org\iso\ISO4217`ISO 4217 currency codes (alpha-3)`ISO4217::USD // 'USD'``org\iso\ISO639_1`ISO 639-1 language codes (alpha-2)`ISO639_1::EN // 'en'``org\iso\ISO15924`ISO 15924 script codes`ISO15924::LATN // 'Latn'``org\iso\ISO3166_1`ISO 3166-1 country codes (alpha-2)`ISO3166_1::FR // 'FR'``org\unstats\UNM49`UN M49 country/area codes (alpha-3)`UNM49::FRA // 'FRA'``org\unece\uncefact\MeasureCode`UN/CEFACT Rec. 20 unit codes`MeasureCode::KILOGRAM // 'KGM'``org\unece\uncefact\MeasureName`UN/CEFACT unit names`MeasureName::KILOGRAM // 'Kilogram'``org\unece\uncefact\MeasureSymbol`UN/CEFACT unit symbols`MeasureSymbol::KILOGRAM // 'kg'``org\unece\uncefact\PackageCode`UN/CEFACT Rec. 21 package type codes`PackageCode::BOX // 'BX'``org\unece\uncefact\PackageName`UN/CEFACT package type names`PackageName::BOX // 'Box'`---

🔧 Core Helper Methods (`ConstantsTrait`)
----------------------------------------

[](#-core-helper-methods-constantstrait)

All constant classes use `oihana\reflections\traits\ConstantsTrait`, which provides:

MethodDescription`getAll()`Returns a `[name => value]` map of constants.`enums(int $flags = SORT_STRING)`Returns unique sorted values.`includes(mixed $value, bool $strict = false, ?string $separator = null)`Checks if a value exists.`get(mixed $value, mixed $default = null)`Returns the value if valid, otherwise `$default`.`validate(mixed $value, bool $strict = true, ?string $separator = null)`Validates or throws an exception.`getConstant(string $value, arraystring`resetCaches()`Clears internal caches.---

💡 Usage Examples
----------------

[](#-usage-examples)

### Basic Enum Access

[](#basic-enum-access)

```
use org\iso\ISO4217;
use org\iso\ISO639_1;

$usd = ISO4217::USD; // 'USD'
$en  = ISO639_1::EN;  // 'en'
```

### Validation &amp; Listing

[](#validation--listing)

```
use org\iso\ISO4217;

ISO4217::validate('EUR');             // OK
$isValid = ISO4217::includes('JPY');  // true
$all     = ISO4217::getAll();         // ['AED' => 'AED', ...]
$values  = ISO4217::enums();          // ['AED', 'AFN', ...]
```

### UN/CEFACT Unit Cross-Lookups

[](#uncefact-unit-cross-lookups)

```
use org\unece\uncefact\MeasureCode;
use org\unece\uncefact\MeasureName;
use org\unece\uncefact\MeasureSymbol;

$code   = MeasureCode::KILOGRAM;        // 'KGM'
$name   = MeasureCode::getName($code);  // 'Kilogram'
$symbol = MeasureCode::getSymbol($code);// 'kg'

// Reverse lookups
$fromName   = MeasureCode::getFromName('Kilogram'); // 'KGM'
$fromSymbol = MeasureCode::getFromSymbol('kg');     // 'KGM'
```

### UN/CEFACT Package Conversion

[](#uncefact-package-conversion)

```
use org\unece\uncefact\PackageCode;
use org\unece\uncefact\PackageName;

$bx   = PackageCode::BOX;            // 'BX'
$name = PackageCode::getName($bx);   // 'Box'
$code = PackageName::getCode('Box'); // 'BX'
```

### ISO 3166-1 Country Codes

[](#iso-3166-1-country-codes)

```
use org\iso\ISO3166_1;

$fr = ISO3166_1::FR;        // 'FR'
ISO3166_1::validate('US');  // OK
$all = ISO3166_1::getAll(); // ['FR' => 'FR', ...]
```

### UN M49 Country Codes

[](#un-m49-country-codes)

```
use org\unstats\UNM49;

$fr = UNM49::FRA; // 'FRA'
```

### Utility: ISO 8601 Durations

[](#utility-iso-8601-durations)

The `Iso8601Duration` class (PHP 8.4+) provides robust handling of duration strings using property hooks.

```
use org\iso\Iso8601Duration;
use DateTime;

// 1. Create a duration
$duration = new Iso8601Duration('P1M5D'); // 1 Month and 5 Days

// 2. Use helper methods to add/subtract
$date = new DateTime('2024-01-10');
$newDate = $duration->addTo($date);

echo $newDate->format('Y-m-d'); // '2024-02-15'

// 3. Properties are synchronized
$duration->iso = 'PT2H30M'; // Change duration to 2 hours 30 minutes
echo $duration->toSeconds(); // 9000

$date2 = new DateTime('2024-01-01 10:00:00');
echo $duration->subtractFrom($date2)->format('Y-m-d H:i:s'); // '2024-01-01 07:30:00'

// 4. Create from DateInterval
$interval = $date->diff($newDate);
$durationFromInterval = new Iso8601Duration($interval);
echo $durationFromInterval->iso; // 'P1M5D'
```

### Utility: ISO 8601 Times

[](#utility-iso-8601-times)

The `Iso8601Time` class (PHP 8.4+) provides robust handling of time-only strings.

```
use org\iso\Iso8601Time;
use DateTimeImmutable;
use DateTimeZone;

// 1. Create from an ISO string
$time = new Iso8601Time('T14:30:00Z');

// 2. Access properties
echo $time->hours;   // 14
echo $time->minutes; // 30
echo $time->iso;     // "T14:30:00Z"

// 3. Properties are synchronized
$time->iso = 'T08:15:00+02:00';
echo $time->hours; // 8
echo $time->time->getTimezone()->getName(); // '+02:00'

// 4. Create from DateTimeInterface
$dt = new DateTimeImmutable('23:59:59', new DateTimeZone('-05:00'));
$timeFromDt = new Iso8601Time($dt);
echo $timeFromDt->iso; // 'T23:59:59-05:00'
```

### Helper: ISO 8601 Conversion &amp; Validation

[](#helper-iso-8601-conversion--validation)

#### toIso8601Duration()

[](#toiso8601duration)

Converts a `DateInterval` object directly into a normalized ISO 8601 string.

```
use function org\iso\helpers\toIso8601Duration;
use DateTime;
use DateInterval;

// From a diff
$start = new DateTime('2024-01-01');
$end = new DateTime('2024-03-15');
$interval = $start->diff($end);

echo toIso8601Duration($interval); // 'P2M14D'

// From a new interval
$interval = new DateInterval('PT1H30M');
echo toIso8601Duration($interval); // 'PT1H30M'
```

#### toIso8601Time()

[](#toiso8601time)

Converts a `DateTimeInterface` object into a normalized ISO 8601 time string.

```
use function org\iso\helpers\toIso8601Time;
use DateTimeImmutable;
use DateTimeZone;

$dt_utc = new DateTimeImmutable('14:30:00', new DateTimeZone('UTC'));
echo toIso8601Time($dt_utc); // "T14:30:00Z"

$dt_offset = new DateTimeImmutable('08:15:30', new DateTimeZone('+02:00'));
echo toIso8601Time($dt_offset); // "T08:15:30+02:00"
```

#### isIso8601Duration() and isIso8601Time()

[](#isiso8601duration-and-isiso8601time)

Validates if a string conforms to the ISO 8601 specification.

```
use function org\iso\helpers\isIso8601Time;
use function org\iso\helpers\isIso8601Duration;

// Time Validation
isIso8601Time('T14:30:00Z');      // true
isIso8601Time('T14:30:00', true); // true (strict)
isIso8601Time('14:30:00', true); // false (strict requires 'T')
isIso8601Time('T25:00:00');      // false (invalid hour)
isIso8601Time('T12:60:00');      // false (invalid minute)

// Duration Validation
isIso8601Duration('P1Y2M3D');  // true
isIso8601Duration('PT4H30M');  // true
isIso8601Duration('P1YT');     // false (strict mode)
isIso8601Duration('P');        // false
isIso8601Duration('INVALID');  // false
```

---

📜 License
---------

[](#-license)

**MPL 2.0** — Mozilla Public License Version 2.0

---

👤 Author
--------

[](#-author)

- **Marc ALCARAZ** (aka *eKameleon*)
- 📧
- 🌐

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance68

Regular maintenance activity

Popularity10

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

278d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d234506e51778dd3d1d61b6c2af6f294ff963651b4aa509b595d3d2a77b7d89b?d=identicon)[ooop](/maintainers/ooop)

---

Top Contributors

[![ekameleon](https://avatars.githubusercontent.com/u/749032?v=4)](https://github.com/ekameleon "ekameleon (22 commits)")

---

Tags

phpisouncefactunm49

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/oihana-php-standards/health.svg)

```
[![Health](https://phpackages.com/badges/oihana-php-standards/health.svg)](https://phpackages.com/packages/oihana-php-standards)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
