Skip to content

Commit 8770cde

Browse files
committed
add en doc
1 parent cb99ab5 commit 8770cde

20 files changed

+470
-470
lines changed

docs/en/annotation/alisa-annotation.md

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,139 @@
1-
## 名称映射
1+
## Name Mapping
22

3-
### 基础使用
3+
### Basic Usage
44

55
```php
66
use Astral\Serialize\Attributes\InputName;
77
use Astral\Serialize\Attributes\OutputName;
88
use Astral\Serialize\Serialize;
99

1010
class User extends Serialize {
11-
// 输入时使用不同的属性名
11+
// Use a different property name for input
1212
#[InputName('user_name')]
1313
public string $name;
1414

15-
// 输出时使用不同的属性名
15+
// Use a different property name for output
1616
#[OutputName('user_id')]
1717
public int $id;
1818

19-
// 同时支持输入和输出不同名称
19+
// Support different names for both input and output
2020
#[InputName('register_time')]
2121
#[OutputName('registeredAt')]
2222
public DateTime $createdAt;
2323
}
2424

25-
// 使用不同名称的输入数据
25+
// Input data with different names
2626
$user = User::from([
27-
'user_name' => '张三', // 映射到 $name
28-
'id' => 123, // 保持不变
29-
'register_time' => '2023-01-01 10:00:00' // 映射到 $createdAt
27+
'user_name' => 'Job', // Mapped to $name
28+
'id' => 123, // Remains unchanged
29+
'register_time' => '2023-01-01 10:00:00' // Mapped to $createdAt
3030
]);
3131

32-
// 输出数据
32+
// Output data
3333
$userArray = $user->toArray();
34-
// $userArray 的内容:
34+
// $userArray toArray:
3535
// [
36-
// 'name' => '张三',
36+
// 'name' => 'Job',
3737
// 'user_id' => 123,
3838
// 'registeredAt' => '2023-01-01 10:00:00'
3939
// ]
4040
```
4141

42-
### 多输入/输出名称处理
42+
### Handling Multiple Input/Output Names
4343

4444
```php
4545
use Astral\Serialize\Attributes\InputName;
4646
use Astral\Serialize\Attributes\OutputName;
4747
use Astral\Serialize\Serialize;
4848

4949
class MultiOutputUser extends Serialize {
50-
// 多个输出名称
50+
// output multiple names
5151
#[OutputName('user_id')]
5252
#[OutputName('id')]
5353
#[OutputName('userId')]
5454
public int $id;
5555

56-
// 多个输出名称 按照声明顺序取地一个匹配的name
56+
// Multiple input names, the first matching name in declaration order will be used
5757
#[InputName('user_name')]
5858
#[InputName('other_name')]
5959
#[InputName('userName')]
6060
public int $name;
6161

6262
}
6363

64-
// 场景1:使用第一个匹配的输入名称
64+
// Scenario 1: Use the first matching input name
6565
$user1 = MultiInputUser::from([
66-
'user_name' => '张三' // 使用 'user_name'
66+
'user_name' => 'Job' // Use 'user_name'
6767
]);
68-
echo $user1->name; // 输出 '张三'
68+
echo $user1->name; // Output 'Job'
6969

70-
// 场景2:使用第二个匹配的输入名称
70+
// Scenario 2: Use the second matching input name
7171
$user2 = MultiInputUser::from([
72-
'other_name' => '李四' // 使用 'other_name'
72+
'other_name' => 'Tom' // Use 'Tom'
7373
]);
74-
echo $user2->name; // 输出 '李四'
74+
echo $user2->name; // Output 'Tom'
7575

76-
// 场景3:使用最后的输入名称
76+
// Scenario 3: Use the last input name
7777
$user3 = MultiInputUser::from([
78-
'userName' => '王五' // 使用 'userName'
78+
'userName' => 'Lin' // Use 'userName'
7979
]);
80-
echo $user3->name; // 输出 '王五'
80+
echo $user3->name; // Output 'Lin'
8181

82-
// 场景4:传入多个的时候 按照声明顺序取地一个匹配的name
82+
// Scenario 4: When multiple are passed, the first matching name in declaration order is used
8383
$user4 = MultiInputUser::from([
84-
'userName' => '王五',
85-
'other_name' => '李四',
86-
'user_name' => '张三',
84+
'userName' => 'Job',
85+
'other_name' => 'Tom',
86+
'user_name' => 'Lin',
8787
]);
88-
echo $user4->name; // 输出 '张三'
88+
echo $user4->name; // Output 'Job'
8989

90-
// 创建用户对象
90+
// Create user object
9191
$user = MultiOutputUser::from([
9292
'id' => 123,
93-
'name' => '张三'
93+
'name' => 'Job'
9494
]);
9595

96-
// 转换为数组
97-
// tips: 因为id 有多个outputname 所以输出了 ['user_id','id','userId']
96+
// Convert to array
97+
// tips: Since id has multiple output names, the output includes ['user_id','id','userId']
9898
$userArray = $user->toArray();
99-
// $userArray 的内容:
99+
// $userArray toArray:
100100
// [
101101
// 'user_id' => 123,
102102
// 'id' => 123,
103103
// 'userId' => 123,
104104
// ]
105105
```
106106

107-
### 复杂映射场景
107+
### Complex Mapping Scenarios
108108

109109
```php
110110
use Astral\Serialize\Serialize;
111111

112112
class ComplexUser extends Serialize {
113-
// 嵌套对象的名称映射
113+
// Name mapping for nested objects
114114
#[InputName('user_profile')]
115115
public UserProfile $profile;
116116

117-
// 数组元素的名称映射
117+
// Name mapping for array elements
118118
#[InputName('user_tags')]
119119
public array $tags;
120120
}
121121

122-
// 处理复杂的输入结构
122+
// Handle complex input structure
123123
$complexUser = ComplexUser::from([
124124
'user_profile' => [
125-
'nickname' => '小明',
125+
'nickname' => 'job',
126126
'age' => 25
127127
],
128128
'user_tags' => ['developer', 'programmer']
129129
]);
130130

131-
// 转换为标准数组
131+
// Convert to standard array
132132
$complexUserArray = $complexUser->toArray();
133-
// $complexUserArray 的内容:
133+
// $complexUserArray toArray:
134134
// [
135135
// 'profile' => UserProfile Object ([
136-
// 'nickname' => '小明',
136+
// 'nickname' => 'job',
137137
// 'age' => 25
138138
// ]),
139139
// 'tags' => ['developer', 'programmer']

docs/en/annotation/customer-annotation.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
### 自定义注解类实现
1+
### Custom Annotation Class Implementation
22

3-
你可以通过自定义注解类,灵活地扩展序列化库的输入输出处理逻辑。
3+
You can flexibly extend the input/output handling logic of the serialization library by defining custom annotation classes.
44

55
---
66

7-
#### 入参处理注解类
7+
#### Input Processing Annotation Class
88

9-
实现 `InputValueCastInterface` 接口,重写其中的 `match` `resolve` 方法,来自定义输入数据的转换和处理。
9+
Implement the `InputValueCastInterface` interface, and override its `match` and `resolve` methods to customize the conversion and handling of input data.
1010

11-
- **`match`**:用于判断是否对当前值进行处理,返回 `true` 表示进入 `resolve`
12-
- **`resolve`**:对匹配的输入值进行转换,并返回转换后的结果。
11+
- **`match`**: Used to determine whether to process the current value; returning `true` means `resolve` will be called.
12+
- **`resolve`**: Converts the matched input value and returns the result.
1313

14-
示例:给输入值添加自定义前缀的注解类
14+
Example: Annotation class that adds a custom prefix to the input value
1515

1616
```php
1717
use Astral\Serialize\Contracts\Attribute\InputValueCastInterface;
@@ -27,23 +27,23 @@ class CustomerInput implements InputValueCastInterface
2727

2828
public function match(mixed $value, DataCollection $collection, InputValueContext $context): bool
2929
{
30-
// 对所有输入值都生效
30+
// Applies to all input values
3131
return true;
3232
}
3333

3434
public function resolve(mixed $value, DataCollection $collection, InputValueContext $context): mixed
3535
{
36-
// 给输入值添加前缀
36+
// Add prefix to input value
3737
return $this->prefix . $value;
3838
}
3939
}
40-
````
40+
```
4141

42-
### 输出处理注解类
42+
### Output Processing Annotation Class
4343

44-
输出处理注解与输入处理注解类似,只是实现的接口不同——需要实现 `OutputValueCastInterface`,用以对序列化输出的值进行自定义转换。
44+
The output processing annotation is similar to the input processing annotation, but implements a different interface—`OutputValueCastInterface`, which is used to customize the conversion of serialized output values.
4545

46-
示例:给序列化输出的值添加自定义后缀的注解类
46+
Example: Annotation class that adds a custom suffix to the serialized output value
4747

4848
```php
4949
use Astral\Serialize\Contracts\Attribute\OutputValueCastInterface;
@@ -59,13 +59,13 @@ class CustomerOutput implements OutputValueCastInterface
5959

6060
public function match(mixed $value, DataCollection $collection, OutputValueContext $context): bool
6161
{
62-
// 对所有输出值都生效
62+
// Applies to all output values
6363
return true;
6464
}
6565

6666
public function resolve(mixed $value, DataCollection $collection, OutputValueContext $context): mixed
6767
{
68-
// 给输出值添加后缀
68+
// Add suffix to output value
6969
return $value . $this->suffix;
7070
}
7171
}

docs/en/annotation/date-annotation.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
## 时间转换
1+
## Date/Time Conversion
22

3-
1. 格式灵活性
4-
支持多种输入和输出时间格式
5-
可以轻松处理不同地区的日期表示
6-
2. 时区处理
7-
支持在不同时区间转换
8-
自动处理时间的时区偏移
9-
3. 类型安全
10-
自动将字符串转换为 DateTime 对象
11-
保证类型的一致性和正确性
3+
1. Flexible Formatting
4+
Supports multiple input and output date/time formats
5+
Easily handles date representations from different regions
6+
2. Timezone Handling
7+
Supports conversion between different timezones
8+
Automatically handles timezone offsets for times
9+
3. Type Safety
10+
Automatically converts strings to DateTime objects
11+
Ensures type consistency and correctness
1212

13-
### 基础使用
13+
### Basic Usage
1414

1515
```php
1616
use Astral\Serialize\Attributes\Input\InputDateFormat;
@@ -27,37 +27,37 @@ class TimeExample extends Serialize {
2727
#[InputDateFormat('Y-m-d')]
2828
public string $dateDateString;
2929

30-
// 输出时间格式转换
30+
// Output date format conversion
3131
#[OutputDateFormat('Y/m/d H:i')]
3232
public DateTime|string $processedAt;
3333

3434

35-
// 支持多种时间格式
35+
// Supports multiple date/time formats
3636
#[InputDateFormat('Y-m-d H:i:s')]
3737
#[OutputDateFormat('Y-m-d')]
3838
public string $createdAt;
3939
}
4040

41-
// 创建订单对象
41+
// Create order object
4242
$order = TimeExample::from([
43-
'dateTime' => new DateTime('2023-08-11'), // 输入格式:Y-m-d
44-
'dateDateString' => '2023-08-15', // 输入格式:Y-m-d
45-
'processedAt' => '2023-08-16 14:30', // 输入默认格式 也支持DateTime对象
46-
'createdAt' => '2023-08-16 14:45:30' // 输入格式:Y-m-d H:i:s
43+
'dateTime' => new DateTime('2023-08-11'), // Input format: Y-m-d
44+
'dateDateString' => '2023-08-15', // Input format: Y-m-d
45+
'processedAt' => '2023-08-16 14:30', // Default input format, also supports DateTime objects
46+
'createdAt' => '2023-08-16 14:45:30' // Input format: Y-m-d H:i:s
4747
]);
4848

49-
// 转换为数组
49+
// Convert to array
5050
$orderArray = $order->toArray();
51-
// $orderArray 的内容:
51+
// Content of $orderArray:
5252
// [
5353
// 'dateTime' => '2023-08-11',
54-
// dateDateString' => '2023-08-15',
54+
// 'dateDateString' => '2023-08-15',
5555
// 'processedAt' => '2023/08/16 14:30',
5656
// 'createdAt' => '2023-08-16'
5757
// ]
5858
```
5959

60-
### 带时区的时间转换
60+
### Time Conversion with Timezone
6161

6262
```php
6363

@@ -66,27 +66,27 @@ use Astral\Serialize\Attributes\Output\OutputDateFormat;
6666
use Astral\Serialize\Serialize;
6767

6868
class AdvancedTimeUser extends Serialize {
69-
// 支持时区转换
69+
// Supports timezone conversion
7070
#[InputDateFormat('Y-m-d H:i:s', timezone: 'UTC')]
7171
#[OutputDateFormat('Y-m-d H:i:s', timezone: 'Asia/Shanghai')]
7272
public DateTime $registeredAt;
7373

74-
// 支持不同地区的时间格式
75-
#[InputDateFormat('d/m/Y')] // 英国格式
76-
#[OutputDateFormat('Y-m-d')] // 标准格式
74+
// Supports date formats from different regions
75+
#[InputDateFormat('d/m/Y')] // UK format
76+
#[OutputDateFormat('Y-m-d')] // Standard format
7777
public DateTime $birthDate;
7878
}
7979

80-
// 使用高级时间转换
80+
// Use advanced time conversion
8181
$advancedUser = AdvancedTimeUser::from([
82-
'registeredAt' => '2023-08-16 10:00:00', // UTC 时间
83-
'birthDate' => '15/08/1990' // 英国日期格式
82+
'registeredAt' => '2023-08-16 10:00:00', // UTC time
83+
'birthDate' => '15/08/1990' // UK date format
8484
]);
8585

8686
$advancedUserArray = $advancedUser->toArray();
87-
// $advancedUserArray 的内容:
87+
// Content of $advancedUserArray:
8888
// [
89-
// 'registeredAt' => '2023-08-16 18:00:00', // 转换为上海时区
89+
// 'registeredAt' => '2023-08-16 18:00:00', // Converted to Shanghai timezone
9090
// 'birthDate' => '1990-08-15'
9191
// ]
9292
```

0 commit comments

Comments
 (0)