ngmy/typed-array
Composer 安装命令:
composer require ngmy/typed-array
包简介
The typed array for PHP
关键字:
README 文档
README
PHP Typed Array is the typed array for PHP.
- Can create the typed array with the specified key and value type
- Can specify the bool, float, int, object, resource, or string type, or the specified class type, or the class type that implements the specified interface, or the class type that uses the specified trait for the key type
- Can specify the array, bool, float, int, object, resource, or string type, or the specified class type, or the class type that implements the specified interface, or the class type that uses the specified trait for the value type
- Implements the
ArrayAccess,Countable, andIteratorAggregateinterfaces - Supports the static analysis like PHPStan and Psalm. Please see examples
// Returns a new instance of the typed array with the int type value $intArray = Ngmy\TypedArray\TypedArray::new()->withIntValue(); // TypedArray<mixed, int> $intArray[] = 1; // Good // $intArray[] = '2'; // No good. The InvalidArgumentException exception is thrown // Returns a new instance of the typed array with the class type value that implements the DateTimeInterface interface $dateTimeInterfaceArray = Ngmy\TypedArray\TypedArray::new() ->withInterfaceValue(DateTimeInterface::class); // TypedArray<mixed, DateTimeInterface> $dateTimeInterfaceArray[] = new DateTime(); // Good $dateTimeInterfaceArray[] = new DateTimeImmutable(); // Good // $dateTimeInterfaceArray[] = new stdClass(); // No good. The InvalidArgumentException exception is thrown foreach ($dateTimeInterfaceArray as $dateTime) { echo $dateTime->format('Y-m-d H:i:s') . PHP_EOL; } // Determines if the typed array is empty or not echo var_export($dateTimeInterfaceArray->isEmpty(), true) . PHP_EOL; // false // Gets the typed array of items as a plain array print_r($dateTimeInterfaceArray->toArray()); // Array // ( // [0] => DateTime Object // ... // [1] => DateTimeImmutable Object // ... // ) // You can also specify the type of the key $stringKeyArray = Ngmy\TypedArray\TypedArray::new()->withStringKey(); // TypedArray<string, mixed> $stringKeyArray['foo'] = 1; // Good // $stringKeyArray[] = 2; // No good. The InvalidArgumentException exception is thrown // Of course, you can also specify the type of both the key and the value $intStringArray = Ngmy\TypedArray\TypedArray::new()->withIntKey()->withStringValue(); // TypedArray<int, string>
Requirements
PHP Typed Array has the following requirements:
- PHP >= 7.3
Installation
Execute the Composer require command:
composer require ngmy/typed-array
Documentation
Please see the API documentation.
License
PHP Typed Array is open-sourced software licensed under the MIT license.
ngmy/typed-array 适用场景与选型建议
ngmy/typed-array 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.59k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 02 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「array」 「type」 「Typed Array」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ngmy/typed-array 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ngmy/typed-array 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ngmy/typed-array 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A bundle providing fields for image upload with jquery upload and image cropping with jcrop for symfony2
A set of useful PHP classes.
A simple Symfony bundle that adds boolean form field type.
A PHP Abstract Enum Class
Linna Typed Array, typed arrays for PHP
This package provides type-safe extension of the laravel collection, forcing a single type of object.
统计信息
- 总下载量: 1.59k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-02-16