sevaske/support
最新稳定版本:1.0.0
Composer 安装命令:
composer require sevaske/support
包简介
Reusable traits and utility helpers for PHP
README 文档
README
PHP Support
Lightweight and minimalistic PHP library providing a set of foundational tools for development.
Designed to be practical, extendable, and easy to integrate into projects, offering a flexible base for building more complex functionality.
Installation
composer require sevaske/support
Features
Dynamic Attributes (HasAttributes)
- Store attributes dynamically with magic methods:
__get,__set,__isset,__unset. - Supports array-style access via
ArrayAccess. - Utility methods:
fill(array $attributes)— bulk set attributes.has(string $key)— check if an attribute exists.keys()— list all attribute keys.replicate()— clone object with same attributes.toArray(),jsonSerialize()— export attributes.
Example:
use Sevaske\Support\Traits\HasAttributes; class User { use HasAttributes; } $user = new User(); $user->fill(['name' => 'John', 'age' => 30]); $user->age = 31; $user->age; // 31 $user['age']; // 31 unset($user->name); $copy = $user->replicate();
Read-Only Attributes (HasReadOnlyAttributesContract)
- Implements a contract to define read-only behavior.
readOnlyAttributescan betrue(all) or an array of keys.- Modifying locked attributes throws
LogicException.
Example:
class User implements HasReadOnlyAttributesContract { use HasAttributes; public function getReadOnlyAttributes(): bool|array { return ['age']; } } $user = new User(); $user->fill(['name' => 'John', 'age' => 30]); $user->name = 'Alice'; // allowed $user->age = 32; // throws LogicException
Contextable Exceptions (HasContext + ContextableException)
- Attach metadata to exceptions.
- Fluent
withContext()method andcontext()retrieval.
Example:
use Sevaske\Support\Exceptions\ContextableException; $ex = new ContextableException('Error', ['user_id' => 123]); $ex->withContext(['ip' => '127.0.0.1']); print_r($ex->context());
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.
Please follow PSR-12 coding standards and include tests for any new features or fixes.
License
This project is licensed under the MIT License. See the LICENSE file for details.
统计信息
- 总下载量: 97
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-04