mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-06-18 10:59:14 +08:00
76 lines
1.9 KiB
PHP
76 lines
1.9 KiB
PHP
<?php
|
||
|
||
// +----------------------------------------------------------------------
|
||
// | Library for ThinkAdmin
|
||
// +----------------------------------------------------------------------
|
||
// | 版权所有 2014~2020 广州楚才信息科技有限公司 [ 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
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace think\admin;
|
||
|
||
use think\App;
|
||
use think\Container;
|
||
use think\db\Query;
|
||
|
||
/**
|
||
* 控制器挂件
|
||
* Class Helper
|
||
* @package think\admin
|
||
*/
|
||
abstract class Helper
|
||
{
|
||
/**
|
||
* 当前应用容器
|
||
* @var App
|
||
*/
|
||
public $app;
|
||
|
||
/**
|
||
* 数据库实例
|
||
* @var Query
|
||
*/
|
||
public $query;
|
||
|
||
/**
|
||
* 当前控制器实例
|
||
* @var Controller
|
||
*/
|
||
public $controller;
|
||
|
||
/**
|
||
* Helper constructor.
|
||
* @param App $app
|
||
* @param Controller $controller
|
||
*/
|
||
public function __construct(Controller $controller, App $app)
|
||
{
|
||
$this->app = $app;
|
||
$this->controller = $controller;
|
||
}
|
||
|
||
/**
|
||
* 获取数据库对象
|
||
* @param string|Query $dbQuery
|
||
* @return Query
|
||
*/
|
||
protected function buildQuery($dbQuery): Query
|
||
{
|
||
return is_string($dbQuery) ? $this->app->db->name($dbQuery) : $dbQuery;
|
||
}
|
||
|
||
/**
|
||
* 实例对象反射
|
||
* @return static
|
||
*/
|
||
public static function instance(): Helper
|
||
{
|
||
return Container::getInstance()->invokeClass(static::class);
|
||
}
|
||
} |