|
1 | 1 | # ImmutableBase |
2 | 2 |
|
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +[](https://app.fossa.com/projects/custom%2B57865%2Fgithub.com%2FReallifeKip%2FImmutableBase?ref=badge_small) |
| 8 | + |
| 9 | + |
| 10 | +[](https://sonarcloud.io/summary/new_code?id=ReallifeKip_ImmutableBase) |
| 11 | +[](https://sonarcloud.io/summary/new_code?id=ReallifeKip_ImmutableBase) |
| 12 | +[](https://sonarcloud.io/summary/new_code?id=ReallifeKip_ImmutableBase) |
| 13 | +[](https://sonarcloud.io/summary/new_code?id=ReallifeKip_ImmutableBase) |
| 14 | +[](https://sonarcloud.io/summary/new_code?id=ReallifeKip_ImmutableBase) |
| 15 | +[](https://sonarcloud.io/summary/new_code?id=ReallifeKip_ImmutableBase) |
| 16 | +[](https://sonarcloud.io/summary/new_code?id=ReallifeKip_ImmutableBase) |
| 17 | +[](https://sonarcloud.io/summary/new_code?id=ReallifeKip_ImmutableBase) |
| 18 | +[](https://sonarcloud.io/summary/new_code?id=ReallifeKip_ImmutableBase) |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
3 | 23 | 一個專為 **不可變物件(Immutable Object)** 設計的抽象基底類別,適用於 **DTO(Data Transfer Object)**、**VO(Value Object)** 等需要「一次初始化、不可更改」的場景。 |
4 | 24 |
|
5 | 25 | 此類別強調資料的**不可變性(Immutability)**、**類型安全(Type Safety)**,並可透過建構式快速初始化、內建型別自動轉換機制、淺層複製 (`with`) 以及自動序列化支援 (`toArray`, `jsonSerialize`)。 |
|
20 | 40 |
|
21 | 41 | --- |
22 | 42 |
|
| 43 | +## 測試 |
| 44 | + |
| 45 | +### 單元測試 |
| 46 | +```bash |
| 47 | +vendor/bin/phpunit tests |
| 48 | +``` |
| 49 | +### 效能測試 |
| 50 | +```bash |
| 51 | +vendor/bin/phpbench run |
| 52 | +``` |
| 53 | + |
23 | 54 | ## 使用方式 |
24 | 55 |
|
25 | 56 | ### 1. 建立你的不可變物件類別 |
@@ -177,7 +208,7 @@ $userList = new UserListDTO([ |
177 | 208 | ]); |
178 | 209 |
|
179 | 210 | // users 和 tags 陣列中的每個元素都會自動轉換為對應的 DTO 實例 |
180 | | -```` |
| 211 | +``` |
181 | 212 |
|
182 | 213 | --- |
183 | 214 |
|
|
0 commit comments