# dot **Repository Path**: zms-code/dot ## Basic Information - **Project Name**: dot - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-10 - **Last Updated**: 2026-06-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # dot #### 介绍 Zms\Dot 是一个基于 PHP 8+ 特性构建的轻量级、高安全性的数据模型(DTO/Entity)基础组件。它充分利用了 PHP 的 Attributes(注解)和 Reflection(反射)机制,将数据验证、类型转换、默认值填充等逻辑高度内聚,帮助开发者以“声明式”的方式快速构建健壮的数据传输对象。 #### 安装教程 ` composer require zms/dot ` #### DOT定义 ```php //赋值请通过初始化或赋值方法赋值,不要直接赋值 '3', 'max' => '10'], [Type::STRING, 'min' => '3', 'max' => '10'], ])] protected string $name; #[Dot(default: 18, fill: true)] protected int $sex; } ``` #### 使用Dot ```php '', // 空值将被替换为配置的 empty 值: '' 'name' => '张三', // 触发验证规则,长度符合 3-10 // 'sex' 未传入,但因为配置了 fill: true,会自动填充为 18 ]; // 批量注入数据 $news = new NewsDot($data); //或者通过setPropertys赋值 //$news->setPropertys($data); // 安全读取数据 echo $news->get('title'); // 输出: '' echo $news->get('sex'); // 输出: 18 // 获取全部合法数据 $data = $news->data(); } catch (\Zms\Exception\ValidateException $e) { // 捕获验证异常 echo $e->getMessage(); } ``` #### 注解属性 (`#[Dot]`) | 参数 | 类型 | 默认值 | 描述 | | :--- | :--- | :--- | :--- | | `empty` | mixed | `null` | 当写入的数据为空(如 `''`, `[]`, `null`)时,以此值替换。 | | `default` | mixed | `null` | 数据的默认值。当值为空且未配置 `empty` 时生效,或用于自动填充。 | | `label` | string | `''` | 字段业务名称。用于验证失败时生成友好的错误提示。 | | `fill` | bool | `false` | 是否自动填充。为 `true` 时,初始化会自动注入 `default` 或 `empty` 值。 | | `validate` | array | `[]` | 验证规则数组。对接 `Zms\Validate` 验证器。 |