定制 oihana/php-traits 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

oihana/php-traits

Composer 安装命令:

composer require oihana/php-traits

包简介

The Oihana PHP Traits library

README 文档

README

Oihana PHP Traits

Reusable, composable object traits for PHP 8.4+.

Latest Version
Total Downloads
License

📚 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

🛠️ Generate the Documentation

We use phpDocumentor to generate the documentation into the ./docs folder.

Usage

Run the command :

composer doc

🔗 Related packages

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MPL-2.0
  • 更新时间: 2026-06-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固