SplBean 过滤表结构

最后更新于:2022-04-02 02:21:53

[TOC] ## 概述 用于定义表结构,过滤掉无效字段数据。 ### 简单 demo ``` class Apple extends \EasySwoole\Spl\SplBean { protected $name; protected $price; protected $number; protected function setKeyMapping(): array { return ['price' => 'as']; } } $apple = new Apple(['name' => 'test', 'price' => 12, 'number' => 12, 'age' => 2], true); print_r($apple->toArray()); print_r($apple->toArrayWithMapping()); echo '---------------------------------------'.PHP_EOL; $apple->restore(['name' => 'blank', 'price' => 12, 'number' => 12]); print_r($apple->toArray()); print_r($apple->toArrayWithMapping()); ``` ## 配合 Model 使用 Model/user/user.php ``` ```
';