PHPackages                             oihana/php-traits - 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. oihana/php-traits

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

oihana/php-traits
=================

The Oihana PHP Traits library

00PHPCI passing

Since Jun 19Pushed todayCompare

[ Source](https://github.com/BcommeBois/oihana-php-traits)[ Packagist](https://packagist.org/packages/oihana/php-traits)[ RSS](/packages/oihana-php-traits/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Oihana PHP - Traits
===================

[](#oihana-php---traits)

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

Reusable, composable object traits for PHP 8.4+.

[![Latest Version](https://camo.githubusercontent.com/a590a7e271d61deffa90b7de22a8452c9c529bb0e747c7c6fcfd06559784fa40/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f6968616e612f7068702d7472616974732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/oihana/php-traits)
[![Total Downloads](https://camo.githubusercontent.com/68fa1e041eea8f8af94827d7fc945f98c1b71f32fe1fb269c9e2b6e5c6157e93/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f6968616e612f7068702d7472616974732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/oihana/php-traits)
[![License](https://camo.githubusercontent.com/da6c2e1d8556a34ddbc63a2aa082b3e1171f67c1215a54bb0e96ab97fb48b5e9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6f6968616e612f7068702d7472616974732e7376673f7374796c653d666c61742d737175617265)](LICENSE)

📚 Documentation
---------------

[](#-documentation)

User guides (FR + EN), with narrative explanations and examples:

🇬🇧 **[English documentation](wiki/en/README.md)**🇫🇷 **[Documentation française](wiki/fr/README.md)**Getting started, container, identifiers, key-value, lazy/lockable, URI, strings, tips.Démarrage, conteneur, identifiants, clé-valeur, lazy/lockable, URI, chaînes, astuces.Auto-generated API reference (phpDocumentor):
👉

🧠 New to traits?
----------------

[](#-new-to-traits)

A **trait** is a reusable block of methods and properties that you "mix into" a class with the `use` keyword. It is a way to **share behaviour across classes that don't share a common parent** — without copy-pasting and without inheritance.

```
trait GreetTrait
{
    public function hello(): string
    {
        return "Hi, I'm {$this->name}";
    }
}

class User
{
    use GreetTrait; // ← the class instantly gains the hello() method

    public function __construct( public string $name ) {}
}

echo ( new User('Ada') )->hello(); // Hi, I'm Ada
```

This package is a curated set of small, focused, tested traits: drop one into your class with `use` and get container access, identifiers, lazy/lockable state, key-value access, and more — for free.

🚀 Features
----------

[](#-features)

- 🧩 DI-container awareness — `ContainerTrait`.
- 💤 Lazy and 🔒 lockable state — `LazyTrait`, `LockableTrait`.
- 🆔 Identifiers — `IDTrait`, `QueryIDTrait`.
- 🗂️ Config and key-value access — `ConfigTrait`, `KeyValueTrait`, `JsonOptionsTrait`.
- 🔗 URI building, stringable and expression helpers — `UriTrait`, `ToStringTrait`, `strings\ExpressionTrait`.
- 🔢 Default sorting and unsupported-operation guards — `SortDefaultTrait`, `UnsupportedTrait`.
- 🧪 Full unit-test coverage ensuring reliability and maintainability.

💡 Designed to be lightweight, testable, and compatible with any PHP 8.4+ project.

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

[](#-installation)

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

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

```
composer require oihana/php-traits
```

✅ Tests &amp; coverage
----------------------

[](#-tests--coverage)

Run the full unit-test suite (PHPUnit, strict mode):

```
composer test
```

Run a single test case:

```
./vendor/bin/phpunit --filter ContainerTraitTest
```

Measure coverage (requires Xdebug or PCOV):

```
composer coverage        # text + Clover + HTML under build/coverage/
composer coverage:md     # readable Markdown summary (build/coverage/COVERAGE.md)
```

The suite runs in **strict mode** and targets **100% line coverage**.

🧾 License
---------

[](#-license)

This project is licensed under the [Mozilla Public License 2.0 (MPL-2.0)](https://www.mozilla.org/en-US/MPL/2.0/).

👤 About the author
------------------

[](#-about-the-author)

- Author : Marc ALCARAZ (aka eKameleon)
- Mail :
- Website :

🛠️ Generate the Documentation
-----------------------------

[](#️-generate-the-documentation)

We use [phpDocumentor](https://phpdoc.org/) to generate the documentation into the ./docs folder.

### Usage

[](#usage)

Run the command :

```
composer doc
```

🔗 Related packages
------------------

[](#-related-packages)

- [oihana/php-core](https://github.com/BcommeBois/oihana-php-core) – core helpers and utilities used by this library.
- [oihana/php-enums](https://github.com/BcommeBois/oihana-php-enums) – a collection of strongly-typed constant enumerations for PHP.
- [oihana/php-reflect](https://github.com/BcommeBois/oihana-php-reflect) – reflection and hydration utilities.

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance65

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 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.

### 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 (7 commits)")

---

Tags

dependency-injectionmixinphpphp8psr-11traits

### Embed Badge

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

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

###  Alternatives

[classpreloader/classpreloader

Helps class loading performance by generating a single PHP file containing all of the autoloaded files for a specific use case

37642.7M32](/packages/classpreloader-classpreloader)[ronanguilloux/php-gpio

GPIO-related utils &amp; toolkit PHP library

2678.0k](/packages/ronanguilloux-php-gpio)[elephox/mimey

PHP package for converting file extensions to MIME types and vice versa.

14240.0k5](/packages/elephox-mimey)[kicken/gearman-php

A PHP implementation of the Gearman protocol.

1662.8k3](/packages/kicken-gearman-php)[heyday/silverstripe-wkhtml

Provides Wkhtml functionality in SilverStripe

1539.2k1](/packages/heyday-silverstripe-wkhtml)[log1x/acf-move-wp-editor

A simple ACF Field that moves the WordPress content editor of a post or page to the location of this field.

361.1k](/packages/log1x-acf-move-wp-editor)

PHPackages © 2026

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