| Server IP : 156.238.232.47 / Your IP : 216.73.216.150 Web Server : nginx/1.25.3 System : Linux C202504152095410 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : www ( 1000) PHP Version : 8.3.25 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /www/wwwroot/2025_04_16_01/core/basic/ |
Upload File : |
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2016年11月6日
* 应用控制基类
*/
namespace core\basic;
use core\view\View;
use core\view\Paging;
class Controller
{
// 显示模板
final protected function display($file)
{
$view = View::getInstance();
$content = $view->parser($file);
$content = $this->runtime($content);
echo $this->gzip($content);
exit();
}
// 解析模板
final protected function parser($file)
{
$view = View::getInstance();
return $view->parser($file);
}
// 缓存页面内容,默认直接显示内容,可传递第二参数false返回内容
final protected function cache($content, $display = true)
{
$view = View::getInstance();
if (Config::get('tpl_html_cache')) {
$content = str_replace('{pboot:runtime}', 'Cached at ' . date('Y-m-d H:i:s'), $content);
} else {
$content = $this->runtime($content);
}
$view->cache($content); // 压缩前缓存
$content = $this->gzip($content);
if ($display) {
echo $content;
exit();
} else {
return $content;
}
}
// 设置视图主题
final protected function setTheme($themeName)
{
$view = View::getInstance();
$view->assign('theme', $themeName);
}
// 变量注入接口
final protected function assign($var, $value)
{
$view = View::getInstance();
$view->assign($var, $value);
}
// 变量获取接口
final protected function getVar($var)
{
$view = View::getInstance();
return $view->getVar($var);
}
// 手动生成分页信息,返回限制语句
final protected function page($tatal, $morePageStr = false)
{
$page = Paging::getInstance();
return $page->limit($tatal, $morePageStr);
}
// 获取配置信息
final protected function config($item = null, $array = false)
{
return Config::get($item, $array);
}
// 缓存配置信息
final protected function setConfig($itemName, array $data)
{
return Config::set($itemName, $data);
}
// 写入日志信息
final protected function log($content, $level = "info")
{
Log::write($content, $level);
}
// 解析运行时间标签
private function runtime($content)
{
return str_replace('{pboot:runtime}', 'Processed in ' . round(microtime(true) - START_TIME, 6) . ' second(s).', $content);
}
// 压缩内容
private function gzip($content)
{
if (Config::get('gzip') && ! headers_sent() && extension_loaded("zlib") && strstr($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip")) {
$content = gzencode($content, 6);
header("Content-Encoding: gzip");
header("Vary: Accept-Encoding");
header("Content-Length: " . strlen($content));
}
return $content;
}
}