arshidkv12/traitify
最新稳定版本:v1.0.0
Composer 安装命令:
pie install arshidkv12/traitify
包简介
Traitify is a native PHP extension that provides commonly used traits
README 文档
README
Traitify is a native PHP extension that provides commonly used traits such as Singleton, implemented in C for optimal performance and better memory efficiency.
🧩 Features
- ✅ Native
Traitify\Singletontrait - ✅ Automatic singleton management (
getInstance()) - ✅ Proper support for
__construct() - 🚀 Built for speed — skips PHP overhead
- 🧠 Extendable for more traits like
Macroable,Loggable, etc.
📦 Installation
1. Clone and build
git clone https://github.com/yourname/traitify.git
cd traitify
phpize
./configure --enable-traitify
make
sudo make install
2. Enable in php.ini
extension=traitify.so
✨ Example Usage
Singleton Trait
<?php use Traitify\Singleton; class MyService { use Traitify\Singleton; public function __construct() { echo "Constructing...\n"; } public function hello() { return "Hello World"; } } $a = MyService::getInstance(); $b = MyService::getInstance(); var_dump($a === $b); // true echo $a->hello(); // Hello World
Macroable Trait
<?php use Traitify\Macroable; class Tool { use Macroable; } Tool::macro('greet', fn($name) => "Hello, $name!"); $t = new Tool(); echo $t->greet("Arshid"); // Hello, Arshid
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: PHP-3.01
- 更新时间: 2025-08-08