oihana/php-traits
Composer 安装命令:
composer require oihana/php-traits
包简介
The Oihana PHP Traits library
README 文档
README
Reusable, composable object traits for PHP 8.4+.
📚 Documentation
User guides (FR + EN), with narrative explanations and examples:
| 🇬🇧 English documentation | 🇫🇷 Documentation française |
|---|---|
| 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):
👉 https://bcommebois.github.io/oihana-php-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
- 🧩 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
Requires PHP 8.4+
Install via Composer:
composer require oihana/php-traits
✅ 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
This project is licensed under the Mozilla Public License 2.0 (MPL-2.0).
👤 About the author
- Author : Marc ALCARAZ (aka eKameleon)
- Mail : marc@ooop.fr
- Website : http://www.ooop.fr
🛠️ Generate the Documentation
We use phpDocumentor to generate the documentation into the ./docs folder.
Usage
Run the command :
composer doc
🔗 Related packages
- oihana/php-core – core helpers and utilities used by this library.
- oihana/php-enums – a collection of strongly-typed constant enumerations for PHP.
- oihana/php-reflect – reflection and hydration utilities.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MPL-2.0
- 更新时间: 2026-06-19
