73 lines
1.8 KiB
PHP
Executable File
73 lines
1.8 KiB
PHP
Executable File
<?php
|
||
|
||
/**
|
||
* Author: ykxiao
|
||
* Date: 2024/12/24
|
||
* Time: 下午3:04
|
||
* Description:
|
||
*
|
||
* (c) ykxiao <yk_9001@hotmail.com>
|
||
*
|
||
* This source file is subject to the MIT license that is bundled
|
||
* with this source code in the file LICENSE.
|
||
*/
|
||
|
||
declare(strict_types=1);
|
||
/**
|
||
* This file is part of Hyperf.
|
||
*
|
||
* @link https://www.hyperf.io
|
||
* @document https://hyperf.wiki
|
||
* @contact group@hyperf.io
|
||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||
*/
|
||
|
||
namespace App\Repository;
|
||
|
||
use App\Service\Trait\ColumnConfigTrait;
|
||
|
||
/**
|
||
* Author: ykxiao
|
||
* Date: 2024/12/24
|
||
* Time: 下午3:06
|
||
* Description: BaseRepository类用于提供一个基本的仓库模式实现。它包含一个DAO(数据访问对象)属性,并允许通过魔术方法动态调用DAO上的方法。
|
||
*
|
||
* (c) ykxiao <yk_9001@hotmail.com>
|
||
*
|
||
* This source file is subject to the MIT license that is bundled
|
||
* with this source code in the file LICENSE.
|
||
*/
|
||
class AbstractRepository
|
||
{
|
||
use ColumnConfigTrait;
|
||
|
||
/**
|
||
* 存储数据访问对象的属性。
|
||
* @var string
|
||
*/
|
||
protected mixed $dao;
|
||
|
||
/**
|
||
* 当尝试调用不存在的实例方法时,自动调用此方法。
|
||
* 允许通过对象的动态方法调用DAO上的相应方法。
|
||
* @param string $name 被调用的方法名
|
||
* @param array $arguments 被调用方法的参数数组
|
||
* @return mixed 返回DAO方法的执行结果
|
||
*/
|
||
public function __call(string $name, array $arguments)
|
||
{
|
||
// 动态调用DAO上的方法。
|
||
return call_user_func_array([$this->dao, $name], $arguments);
|
||
}
|
||
|
||
/**
|
||
* 设置DAO对象。
|
||
* 用于设置存储数据访问对象的属性。
|
||
* @param string $dao 数据访问对象的实例
|
||
*/
|
||
public function setDao(string $dao): void
|
||
{
|
||
$this->dao = $dao;
|
||
}
|
||
}
|