shahmal1yev/gcollection
Composer 安装命令:
composer require shahmal1yev/gcollection
包简介
GenericCollection is a versatile PHP library that provides a type-safe collection class for managing various data types. Simplify your data management with intuitive methods and strong type constraints.
README 文档
README
GenericCollection is a PHP library for handling collections with support for various primitive types. It allows for flexible type validation and manipulation of collections.
Features
- Flexible Type Handling: Supports various primitive types such as
int,string,float,bool, and more. - Type Validation: Provides methods to validate if an item in the collection adheres to the specified type.
- Extensible: Easily extendable to support custom types and validation logic.
Dependencies
{
"require": {
"php": ">=7.4"
},
"require-dev": {
"phpunit/phpunit": "9.6.20"
}
}
Installation
You can install GenericCollection via Composer. If you don't have Composer installed, you can get it from getcomposer.org.
Run the following command to install GenericCollection:
composer require shahmal1yev/gcollection
Usage
Here is a basic example of how to use the GenericCollection:
<?php require 'vendor/autoload.php'; use GenericCollection\GenericCollection; use GenericCollection\Types\Primitive\StringType; class Foo { public function __toString(): string { return "Foo as string"; } } // Create a new collection with Foo validation $collection = new GenericCollection(Foo::class); // Add items to the collection $collection[] = new Foo; $collection->add(1, new Foo); // Retrieve items from the collection echo $collection[0]; echo $collection->get(1); // Outputs: Foo as string // Validate an item var_dump($collection->validate(new Foo)); // Outputs: bool(true)
<?php require 'vendor/autoload.php'; use GenericCollection\GenericCollection; use GenericCollection\Types\Primitive\StringType; // Create a new collection with StringType validation $collection = new GenericCollection(new StringType()); // Add items to the collection $collection[] = "Hello"; $collection->add(1, "World"); // Retrieve items from the collection echo $collection[1]; echo $collection->get(0); // Outputs: Hello // Validate an item var_dump($collection->validate("Test")); // Outputs: bool(true)
Available Primitive Types
GenericCollection includes the following primitive types:
- IntType: Validates integer values.
- StringType: Validates string values.
- FloatType: Validates float values.
- BoolType: Validates boolean values.
- ObjectType: Validates object values.
- CallableType: Validates callable values.
- ResourceType: Validates resource values.
- IterableType: Validates iterable values.
Contributing
Contributions are welcome! Please follow these steps to contribute to the project:
- Fork the Repository: Create a personal copy of the repository by forking it on GitHub.
- Create a Branch: Create a new branch for your changes.
- Make Changes: Implement your changes or fix issues.
- Submit a Pull Request: Push your changes and submit a pull request for review.
Running Tests
To run the tests, make sure you have PHPUnit installed. You can install it via Composer:
composer require --dev phpunit/phpunit:9.6.20
Run the tests with the following command:
vendor/bin/phpunit ./tests
License
This project is licensed under the MIT License. For more information, see the LICENSE.
Contact
For any questions or feedback, please contact us at LinkedIn.
shahmal1yev/gcollection 适用场景与选型建议
shahmal1yev/gcollection 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.31k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 07 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 shahmal1yev/gcollection 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 shahmal1yev/gcollection 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2024-07-27