Files
wh-api/app/Repository/AbstractRepository.php
ykxiao 0b2299c427
Some checks failed
Build Docker / build (push) Has been cancelled
协程版仓库后端项目
2025-07-08 14:59:47 +08:00

73 lines
1.8 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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;
}
}