haeckel/generics
最新稳定版本:0.2.0
Composer 安装命令:
composer require haeckel/generics
包简介
Support for generic classes
README 文档
README
haeckel/php-generics
haeckel/generics is a php Library for dealing with generic data structures. It aims for simplicity and being fully typesafe at runtime, so unit tests will make errors visible. Uses PHPStan's generic syntax for type documentation and static analysis.
Features
- Types classes that denote php types for usage, where the native type system cannot be used, e.g. in terms of generics for parameters, because they violate the LSP rules. All type classes can be used to type check at runtime and you can get a string representation that matches the native php notation.
- Filters the filter interfaces enforce callable signatures, by specifying the __invoke() method signature. These are used to filter generic data structures (e.g. find a subset of a collection) or to remove specific elements.
- Struct contains standard data structures that support generic usage. There is always an interface and an abstract base class for these structures.
PHPStan
This project uses the max level of PHPStan and phpstan/phpstan-strict-rules to ensure the code follows a good standard. Here are the places, where @phpstan-ignore is used to step around a check (cf. unsafe mode in rust or go, where you can opt out of compiler guarantees).
- equal.notAllowed (necessary for object cmp) in method remove()
Installation
composer require haeckel/generics
Usage
See the tests Folder for runnable implementations.
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
Support
Let us know if you have issues.
License
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-or-later
- 更新时间: 2025-09-29