mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-08-26 14:49:44 +08:00
80 lines
1.9 KiB
PHP
80 lines
1.9 KiB
PHP
<?php
|
||
|
||
// +----------------------------------------------------------------------
|
||
// | Library for ThinkAdmin
|
||
// +----------------------------------------------------------------------
|
||
// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
|
||
// +----------------------------------------------------------------------
|
||
// | 官方网站: https://gitee.com/zoujingli/ThinkLibrary
|
||
// +----------------------------------------------------------------------
|
||
// | 开源协议 ( https://mit-license.org )
|
||
// +----------------------------------------------------------------------
|
||
// | gitee 仓库地址 :https://gitee.com/zoujingli/ThinkLibrary
|
||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||
// +----------------------------------------------------------------------
|
||
|
||
declare (strict_types=1);
|
||
|
||
namespace think\admin;
|
||
|
||
use think\App;
|
||
use think\Container;
|
||
use think\Db;
|
||
use think\db\Query;
|
||
|
||
/**
|
||
* 控制器挂件
|
||
* Class Helper
|
||
* @package think\admin
|
||
*/
|
||
abstract class Helper
|
||
{
|
||
/**
|
||
* 应用容器
|
||
* @var App
|
||
*/
|
||
public $app;
|
||
|
||
/**
|
||
* 数据库实例
|
||
* @var Db|Query
|
||
*/
|
||
public $query;
|
||
|
||
/**
|
||
* 控制器实例
|
||
* @var Controller
|
||
*/
|
||
public $class;
|
||
|
||
/**
|
||
* Helper constructor.
|
||
* @param App $app
|
||
* @param Controller $class
|
||
*/
|
||
public function __construct(Controller $class, App $app)
|
||
{
|
||
$this->app = $app;
|
||
$this->class = $class;
|
||
}
|
||
|
||
/**
|
||
* 获取数据库对象
|
||
* @param string|Db|Query $dbQuery
|
||
* @return Db|Query
|
||
*/
|
||
protected function buildQuery($dbQuery)
|
||
{
|
||
return is_string($dbQuery) ? $this->app->db->name($dbQuery) : $dbQuery;
|
||
}
|
||
|
||
/**
|
||
* 实例对象反射
|
||
* @param array $args
|
||
* @return static
|
||
*/
|
||
public static function instance(...$args): Helper
|
||
{
|
||
return Container::getInstance()->invokeClass(static::class, $args);
|
||
}
|
||
} |