nejcc / php-custom-types
一个提供自定义数据类型如i8、u8、i32、u32、f32等的Laravel包。
v1.0.3
2024-09-10 06:21 UTC
Requires
- php: ^8.1|8.2|8.3
Requires (Dev)
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-09-10 06:27:28 UTC
README
Nejcc/php-custom-types 是一个提供自定义数据类型如 i8
、u8
、i32
、u32
、f32
等的Laravel包。这些自定义类型有助于在您的Laravel应用程序中强制执行数据完整性、内存效率和验证约束。
特性
- 自定义整数类型:
i8
、u8
、i32
、u32
- 自定义浮点类型:
f32
- 自定义字符串类型:
Utf8String
- 元组和数组类型:
Pair
、FixedArray
- 易于集成: 设计成与Laravel无缝工作。
- PHP 8.3 兼容性: 利用最新的PHP特性以提高性能和安全。
安装
要安装此包,请使用Composer
composer require nejcc/php-custom-types
树状结构
CustomTypes
├── Scalar Types
│ ├── Integer Types
│ │ ├── Signed Integers
│ │ │ ├── i8 (8-bit signed)
│ │ │ ├── i16 (16-bit signed)
│ │ │ ├── i32 (32-bit signed)
│ │ │ ├── i64 (64-bit signed)
│ │ │ └── i128 (128-bit signed)
│ │ └── Unsigned Integers
│ │ ├── u8 (8-bit unsigned)
│ │ ├── u16 (16-bit unsigned)
│ │ ├── u32 (32-bit unsigned)
│ │ ├── u64 (64-bit unsigned)
│ │ └── u128 (128-bit unsigned)
│ ├── Floating-Point Types
│ │ ├── f16 (16-bit floating-point)
│ │ ├── f32 (32-bit floating-point)
│ │ ├── f64 (64-bit floating-point)
│ │ └── f128 (128-bit floating-point)
│ ├── Character Type
│ │ └── Char (Single Unicode character)
│ └── Boolean Type
│ └── Bool (Boolean, true or false)
├── Compound Types
│ ├── Tuple
│ │ └── Tuple (Fixed-size collection of heterogeneous values)
│ └── FixedArray
│ └── FixedArray (Fixed-size collection of homogeneous values)
├── String Types
│ ├── StrSlice (Immutable string slice)
│ └── OwnedString (Owned, mutable string)
├── Collection Types
│ ├── Vec (Growable array type)
│ ├── HashMap (Key-value store)
│ └── HashSet (Unordered collection of unique values)
├── Custom Types
│ ├── Structs
│ │ └── ExampleStruct (Custom user-defined data structures)
│ └── Enums
│ └── ExampleEnum (Custom enumerations)
├── Smart Pointer Types
│ ├── Box (Single ownership heap allocation)
│ ├── Rc (Reference counted pointer)
│ ├── RefCell (Single-threaded interior mutability)
│ └── Mutex (Thread-safe interior mutability)
└── Other Types
├── Unit (Represents an empty value or no value)
└── PhantomData (Marker for unused generic type parameters)
用法
自定义整数类型
i32
(32位有符号整数)
use Nejcc\CustomTypes\ScalarTypes\Integers\Signed\i32; $number = new i32(123456); echo $number->getValue(); // Output: 123456
运行测试
要运行此包的单元测试,请确保已安装PHPUnit并运行
./vendor/bin/phpunit
许可协议
此包是开源软件,根据MIT许可协议许可。