PHPackages                             hoa-math-community/consistency - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. hoa-math-community/consistency

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hoa-math-community/consistency
==============================

The Hoa\\Consistency library.

v3.0.0(3y ago)01.2k↓25%12BSD-3-ClausePHPPHP ~8.0

Since Jan 6Pushed 3y agoCompare

[ Source](https://github.com/hoa-math-community/Consistency)[ Packagist](https://packagist.org/packages/hoa-math-community/consistency)[ Docs](https://hoa-project.net/)[ RSS](/packages/hoa-math-community-consistency/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (10)Used By (12)

 [![Hoa](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)

---

 [![Build status](https://camo.githubusercontent.com/9c697d5f6d57dc7ee526a2ca5f06efe9bc9b7843362c6ab7819c85bf88cf3b83/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f686f6170726f6a6563742f436f6e73697374656e63792f6d61737465722e737667)](https://travis-ci.org/hoaproject/Consistency) [![Code coverage](https://camo.githubusercontent.com/49a6dbc114b4e20de09ff9882123cc2113285fbcf3502301481c8a9e63238945/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f686f6170726f6a6563742f436f6e73697374656e63792f6d61737465722e737667)](https://coveralls.io/github/hoaproject/Consistency?branch=master) [![Packagist](https://camo.githubusercontent.com/9770baa3f0f173d702cf481fa7b597ae9031131786bf93acc4bb963f9c8aec76/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f686f612f636f6e73697374656e63792e737667)](https://packagist.org/packages/hoa/consistency) [![License](https://camo.githubusercontent.com/28ef63fafb830f69bb80bdc18d9808c78ac8d2f74f57891d6862958d410de42c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f686f612f636f6e73697374656e63792e737667)](https://hoa-project.net/LICENSE)

 Hoa is a **modular**, **extensible** and **structured** set of PHP libraries.
 Moreover, Hoa aims at being a bridge between industrial and research worlds.

Hoa\\Consistency
================

[](#hoaconsistency)

[![Help on IRC](https://camo.githubusercontent.com/4dbc9c9d28c30cf1ab591f4bb8212fe4dbddc734145df532a9bb86b09878d4c6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d253233686f6170726f6a6563742d6666303036362e737667)](https://webchat.freenode.net/?channels=#hoaproject)[![Help on Gitter](https://camo.githubusercontent.com/8c4c85951788ff606b1268cb3dd946be05e3054795455d0a7b9250711bc2ac05/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d6769747465722d6666303036362e737667)](https://gitter.im/hoaproject/central)[![Documentation](https://camo.githubusercontent.com/7059ad5f1a363f9098686c59d432f01d7330aed9d4b6c8111d985fd64cfc6c60/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63756d656e746174696f6e2d6861636b5f626f6f6b2d6666303036362e737667)](https://central.hoa-project.net/Documentation/Library/Consistency)[![Board](https://camo.githubusercontent.com/fd81654ba14b3aca3a713e1b471bc3fc3ba7b5bb3761ccffd6eea2e2ed1fa5ca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6f7267616e69736174696f6e2d626f6172642d6666303036362e737667)](https://waffle.io/hoaproject/consistency)

This library provides a thin layer between PHP VMs and libraries to ensure consistency accross VM versions and library versions.

[Learn more](https://central.hoa-project.net/Documentation/Library/Consistency).

Installation
------------

[](#installation)

With [Composer](https://getcomposer.org/), to include this library into your dependencies, you need to require [`hoa/consistency`](https://packagist.org/packages/hoa/consistency):

```
$ composer require hoa/consistency '~2.0'
```

For more installation procedures, please read [the Source page](https://hoa-project.net/Source.html).

Testing
-------

[](#testing)

Before running the test suites, the development dependencies must be installed:

```
$ composer install
```

Then, to run all the test suites:

```
$ vendor/bin/hoa test:run
```

For more information, please read the [contributor guide](https://hoa-project.net/Literature/Contributor/Guide.html).

Quick usage
-----------

[](#quick-usage)

We propose a quick overview of how the consistency API ensures foreward and backward compatibility, also an overview of the [PSR-4 autoloader](http://www.php-fig.org/psr/psr-4/) and the xcallable API.

### Foreward and backward compatibility

[](#foreward-and-backward-compatibility)

The `Hoa\Consistency\Consistency` class ensures foreward and backward compatibility.

#### Example with keywords

[](#example-with-keywords)

The `Hoa\Consistency\Consistency::isKeyword` checks whether a specific word is reserved by PHP or not. Let's say your current PHP version does not support the `callable` keyword or type declarations such as `int`, `float`, `string` etc., the `isKeyword` method will tell you if they are reserved keywords: Not only for your current PHP version, but maybe in an incoming version.

```
$isKeyword = Hoa\Consistency\Consistency::isKeyword('yield');
```

It avoids to write algorithms that might break in the future or for your users living on the edge.

#### Example with identifiers

[](#example-with-identifiers)

PHP identifiers are defined by a regular expression. It might change in the future. To prevent breaking your algorithms, you can use the `Hoa\Consistency\Consistency::isIdentifier` method to check an identifier is correct regarding current PHP version:

```
$isValidIdentifier = Hoa\Consistency\Consistency::isIdentifier('foo');
```

#### Flexible entities

[](#flexible-entities)

Flexible entities are very simple. If we declare `Foo\Bar\Bar` as a flexible entity, we will be able to access it with the `Foo\Bar\Bar` name or `Foo\Bar`. This is very useful if your architecture evolves but you want to keep the backward compatibility. For instance, it often happens that you create a `Foo\Bar\Exception` class in the `Foo/Bar/Exception.php` file. But after few versions, you realise other exceptions need to be introduced, so you need an `Exception` directory. In this case, `Foo\Bar\Exception` should move as `Foo\Bar\Exception\Exception`. If this latter is declared as a flexible entity, backward compatibility will be kept.

```
Hoa\Consistency\Consistency::flexEntity('Foo\Bar\Exception\Exception');
```

Another example is the “entry-class” (informal naming). `Hoa\Consistency\Consistency` is a good example. This is more convenient to write `Hoa\Consistency` instead of `Hoa\Consistency\Consistency`. This is possible because this is a flexible entity.

#### Throwable &amp; co.

[](#throwable--co)

The `Throwable` interface has been introduced to represent a whole new exception architecture in PHP. Thus, to be compatible with incoming PHP versions, you might want to use this interface in some cases. Hopefully, the `Throwable`interface will be created for you if it does not exists.

```
try {
    …
} catch (Throwable $e) {
    …
}
```

### Autoloader

[](#autoloader)

`Hoa\Consistency\Autoloader` is a [PSR-4 compatible](http://www.php-fig.org/psr/psr-4/) autoloader. It simply works as follows:

- `addNamespace` is used to map a namespace prefix to a directory,
- `register` is used to register the autoloader.

The API also provides the `load` method to force the load of an entity, `unregister` to unregister the autoloader, `getRegisteredAutoloaders` to get a list of all registered autoloaders etc.

For instance, to map the `Foo\Bar` namespace to the `Source/` directory:

```
$autoloader = new Hoa\Consistency\Autoloader();
$autoloader->addNamespace('Foo\Bar', 'Source');
$autoloader->register();

$baz = new Foo\Bar\Baz(); // automatically loaded!
```

### Xcallable

[](#xcallable)

Xcallables are “extended callables”. It is a unified API to invoke callables of any kinds, and also extends some Hoa's API (like [`Hoa\Event`](https://central.hoa-project.net/Resource/Library/Event)or [`Hoa\Stream`](https://central.hoa-project.net/Resource/Library/Stream)). It understands the following kinds:

- `'function'` as a string,
- `'class::method'` as a string,
- `'class', 'method'` as 2 string arguments,
- `$object, 'method'` as 2 arguments,
- `$object, ''` as 2 arguments, the “able” is unknown,
- `function (…) { … }` as a closure,
- `['class', 'method']` as an array of strings,
- `[$object, 'method']` as an array.

To use it, simply instanciate the `Hoa\Consistency\Xcallable` class and use it as a function:

```
$xcallable = new Hoa\Consistency\Xcallable('strtoupper');
var_dump($xcallable('foo'));

/**
 * Will output:
 *     string(3) "FOO"
 */
```

The `Hoa\Consistency\Xcallable::distributeArguments` method invokes the callable but the arguments are passed as an array:

```
$xcallable->distributeArguments(['foo']);
```

This is also possible to get a unique hash of the callable:

```
var_dump($xcallable->getHash());

/**
 * Will output:
 *     string(19) "function#strtoupper"
 */
```

Finally, this is possible to get a reflection instance of the current callable (can be of kind [`ReflectionFunction`](http://php.net/ReflectionFunction), [`ReflectionClass`](http://php.net/ReflectionClass), [`ReflectionMethod`](http://php.net/ReflectionMethod) or [`ReflectionObject`](http://php.net/ReflectionObject)):

```
var_dump($xcallable->getReflection());

/**
 * Will output:
 *     object(ReflectionFunction)#42 (1) {
 *       ["name"]=>
 *       string(10) "strtoupper"
 *     }
 */
```

When the object is set but not the method, the latter will be deduced if possible. If the object is of kind [`Hoa\Stream`](http://central.hoa-project.net/Resource/Library/Stream), then according to the type of the arguments given to the callable, the `writeInteger`, `writeString`, `writeArray` etc. method will be used. If the argument is of kind `Hoa\Event\Bucket`, then the method name will be deduced based on the data contained inside the event bucket. This is very handy. For instance, the following example will work seamlessly:

```
Hoa\Event\Event::getEvent('hoa://Event/Exception')
    ->attach(new Hoa\File\Write('Exceptions.log'));
```

The `attach` method on `Hoa\Event\Event` transforms its argument as an xcallable. In this particular case, the method to call is unknown, we only have an object (of kind `Hoa\File\Write`). However, because this is a stream, the method will be deduced according to the data contained in the event bucket fired on the `hoa://Event/Exception` event channel.

Documentation
-------------

[](#documentation)

The [hack book of `Hoa\Consistency`](https://central.hoa-project.net/Documentation/Library/Consistency)contains detailed information about how to use this library and how it works.

To generate the documentation locally, execute the following commands:

```
$ composer require --dev hoa/devtools
$ vendor/bin/hoa devtools:documentation --open
```

More documentation can be found on the project's website: [hoa-project.net](https://hoa-project.net/).

Getting help
------------

[](#getting-help)

There are mainly two ways to get help:

- On the [`#hoaproject`](https://webchat.freenode.net/?channels=#hoaproject)IRC channel,
- On the forum at [users.hoa-project.net](https://users.hoa-project.net).

Contribution
------------

[](#contribution)

Do you want to contribute? Thanks! A detailed [contributor guide](https://hoa-project.net/Literature/Contributor/Guide.html) explains everything you need to know.

License
-------

[](#license)

Hoa is under the New BSD License (BSD-3-Clause). Please, see [`LICENSE`](https://hoa-project.net/LICENSE) for details.

###  Health Score

36

—

LowBetter than 81% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 89.2% 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

Every ~362 days

Recently: every ~620 days

Total

8

Last Release

1239d ago

Major Versions

0.16.01.06 → 1.16.01.112016-01-11

1.17.05.02 → 2.17.08.292017-08-29

2.17.08.29 → v3.0.02022-12-17

PHP version history (3 changes)1.16.01.11PHP &gt;=5.5.0

2.17.08.29PHP &gt;=7.1

v3.0.0PHP ~8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/14144958f1893ddd81dafbd4df8583e38792ccc089462e3cb14b80eeba32cef3?d=identicon)[hubipe](/maintainers/hubipe)

---

Top Contributors

[![Hywan](https://avatars.githubusercontent.com/u/946104?v=4)](https://github.com/Hywan "Hywan (58 commits)")[![Metalaka](https://avatars.githubusercontent.com/u/5406767?v=4)](https://github.com/Metalaka "Metalaka (2 commits)")[![vonglasow](https://avatars.githubusercontent.com/u/1275202?v=4)](https://github.com/vonglasow "vonglasow (2 commits)")[![Grummfy](https://avatars.githubusercontent.com/u/668804?v=4)](https://github.com/Grummfy "Grummfy (1 commits)")[![hubipe](https://avatars.githubusercontent.com/u/617880?v=4)](https://github.com/hubipe "hubipe (1 commits)")[![mathroc](https://avatars.githubusercontent.com/u/291531?v=4)](https://github.com/mathroc "mathroc (1 commits)")

---

Tags

callablelibraryentityautoloaderkeywordconsistencyflex

### Embed Badge

![Health badge](/badges/hoa-math-community-consistency/health.svg)

```
[![Health](https://phpackages.com/badges/hoa-math-community-consistency/health.svg)](https://phpackages.com/packages/hoa-math-community-consistency)
```

###  Alternatives

[league/iso3166

ISO 3166-1 PHP Library

69536.3M116](/packages/league-iso3166)[php-di/invoker

Generic and extensible callable invoker

26857.8M56](/packages/php-di-invoker)[dekor/php-array-table

PHP Library for printing associative arrays as text table (similar to mysql terminal console)

296.6M2](/packages/dekor-php-array-table)

PHPackages © 2026

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