thybag/pseudo-model

PseudoModel 是一个优雅的类似模型基础,用于支撑自定义数据结构。

0.2.0 2023-05-31 15:26 UTC

This package is auto-updated.

Last update: 2024-08-30 01:26:05 UTC


README

PseudoModel 是一个类似于 Laravel 的基础模型,旨在反映 Laravel 大部分基本模型的功能。

使用 PseudoModel,您可以以类似于正常模型的方式表示和交互非数据库数据,有望简化您需要编写的代码。过去我曾使用这种方法来映射 LDAP 以及第三方 API。

为了提供标准的 eloquent 事件行为,您可以使用 persist 方法来定义您的保存逻辑。该方法将根据更改是创建、更新还是删除而改变。

    /**
     * Persist model changes. Called on save & delete.
     *
     * @param  string $action  create|update|delete
     * @param  array  $options
     * @return boolean true|false
     */
    protected function persist($action, array $options = []): bool
    {
        return true;
    }

这个库仍在开发中,因此不建议在生产环境中使用。