2021-05-18 14:32:53 +08:00

80 lines
1.9 KiB
PHP
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
// +----------------------------------------------------------------------
// | 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);
}
}