fix:更新已知bug,优化代码
This commit is contained in:
@@ -27,34 +27,34 @@ class Request extends \Webman\Http\Request
|
||||
* 用户ID
|
||||
* @var int
|
||||
*/
|
||||
public $userId = 0;
|
||||
public mixed $user_id = 0;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
public $userInfo = [];
|
||||
public mixed $userData = [];
|
||||
|
||||
/**
|
||||
* 管理员ID
|
||||
* @var int
|
||||
*/
|
||||
public $adminId = 0;
|
||||
public mixed $admin_id = 0;
|
||||
|
||||
/**
|
||||
* 管理员信息
|
||||
* @return string
|
||||
*/
|
||||
public $adminInfo = [];
|
||||
public mixed $adminData = [];
|
||||
|
||||
/**
|
||||
* 生成请求令牌
|
||||
* @access public
|
||||
* @param string $name 令牌名称
|
||||
* @param mixed $type 令牌生成方法
|
||||
* @param string $type 令牌生成方法
|
||||
* @return string
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
*/
|
||||
public function buildToken(string $name = '__token__', $type = 'md5'): string
|
||||
public function buildToken(string $name = '__token__',string $type = 'md5'): string
|
||||
{
|
||||
$type = is_callable($type) ? $type : 'md5';
|
||||
$token = call_user_func($type, Random::alpha(32));
|
||||
@@ -89,7 +89,7 @@ class Request extends \Webman\Http\Request
|
||||
}
|
||||
|
||||
if (empty($data)) {
|
||||
$data = request()->all();
|
||||
$data = request()->session()->all();
|
||||
}
|
||||
|
||||
// 令牌验证
|
||||
|
||||
37
support/Template.php
Normal file
37
support/Template.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace support;
|
||||
|
||||
use Psr\SimpleCache\InvalidArgumentException;
|
||||
use support\view\ThinkPHP;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
|
||||
/**
|
||||
* 模板类
|
||||
* Class Template
|
||||
* @package support
|
||||
* @method static string fetch(string $template = '', array $vars = [], array $config = [])
|
||||
*/
|
||||
class Template extends ThinkPHP
|
||||
{
|
||||
/**
|
||||
* @param string $template
|
||||
* @param array $vars
|
||||
* @param string|null $app
|
||||
* @return array|false|string|string[]|null
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws InvalidArgumentException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public static function render(string $template, array $vars, string $app = null)
|
||||
{
|
||||
$content = parent::render($template, $vars, $app);
|
||||
if (saenv('minify_page')) {
|
||||
$content = preg_replace('/\s+/i', ' ', $content);
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
@@ -22,10 +22,6 @@ use Webman\Util;
|
||||
|
||||
$worker = $worker ?? null;
|
||||
|
||||
if ($timezone = config('app.default_timezone')) {
|
||||
date_default_timezone_set($timezone);
|
||||
}
|
||||
|
||||
set_error_handler(function ($level, $message, $file = '', $line = 0) {
|
||||
if (error_reporting() & $level) {
|
||||
throw new ErrorException($message, 0, $level, $file, $line);
|
||||
@@ -48,7 +44,11 @@ if (class_exists('Dotenv\Dotenv') && file_exists(base_path() . '/.env')) {
|
||||
}
|
||||
}
|
||||
|
||||
Support\App::loadAllConfig(['route']);
|
||||
Config::clear();
|
||||
support\App::loadAllConfig(['route']);
|
||||
if ($timezone = config('app.default_timezone')) {
|
||||
date_default_timezone_set($timezone);
|
||||
}
|
||||
|
||||
foreach (config('autoload.files', []) as $file) {
|
||||
include_once $file;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of webman.
|
||||
*
|
||||
@@ -12,10 +13,10 @@
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
use support\Container;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use support\Translation;
|
||||
use support\Container;
|
||||
use support\view\Raw;
|
||||
use support\view\Blade;
|
||||
use support\view\ThinkPHP;
|
||||
@@ -25,68 +26,95 @@ use Webman\App;
|
||||
use Webman\Config;
|
||||
use Webman\Route;
|
||||
|
||||
// Phar support.
|
||||
if (\is_phar()) {
|
||||
\define('BASE_PATH', dirname(__DIR__));
|
||||
} else {
|
||||
\define('BASE_PATH', realpath(__DIR__ . '/../'));
|
||||
}
|
||||
\define('WEBMAN_VERSION', '1.4');
|
||||
// Webman version
|
||||
define('WEBMAN_VERSION', '1.4');
|
||||
|
||||
// Project base path
|
||||
define('BASE_PATH', dirname(__DIR__));
|
||||
|
||||
/**
|
||||
* @param $return_phar
|
||||
* Generate paths based on given information
|
||||
* @param string $front
|
||||
* @param string $back
|
||||
* @return string
|
||||
*/
|
||||
function path_combine(string $front, string $back)
|
||||
{
|
||||
return $front . ($back ? (DIRECTORY_SEPARATOR . ltrim($back, DIRECTORY_SEPARATOR)) : $back);
|
||||
}
|
||||
|
||||
/**
|
||||
* return the program execute directory
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
function run_path(string $path = '')
|
||||
{
|
||||
static $run_path = '';
|
||||
if (!$run_path) {
|
||||
$run_path = \is_phar() ? \dirname(\Phar::running(false)) : BASE_PATH;
|
||||
}
|
||||
return \path_combine($run_path, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* if the param $path equal false,will return this program current execute directory
|
||||
* @param string|false $path
|
||||
* @return false|string
|
||||
*/
|
||||
function base_path(bool $return_phar = true)
|
||||
function base_path($path = '')
|
||||
{
|
||||
static $real_path = '';
|
||||
if (!$real_path) {
|
||||
$real_path = \is_phar() ? \dirname(Phar::running(false)) : BASE_PATH;
|
||||
if (false === $path) {
|
||||
return \run_path();
|
||||
}
|
||||
return $return_phar ? BASE_PATH : $real_path;
|
||||
|
||||
return \path_combine(BASE_PATH, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
function app_path()
|
||||
function app_path(string $path = '')
|
||||
{
|
||||
return BASE_PATH . DIRECTORY_SEPARATOR . 'app';
|
||||
return \path_combine(BASE_PATH . DIRECTORY_SEPARATOR . 'app', $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
function public_path()
|
||||
function public_path(string $path = '')
|
||||
{
|
||||
static $path = '';
|
||||
if (!$path) {
|
||||
$path = \config('app.public_path', BASE_PATH . DIRECTORY_SEPARATOR . 'public');
|
||||
static $public_path = '';
|
||||
if (!$public_path) {
|
||||
$public_path = \config('app.public_path') ? : \run_path('public');
|
||||
}
|
||||
return $path;
|
||||
return \path_combine($public_path, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
function config_path()
|
||||
function config_path(string $path = '')
|
||||
{
|
||||
return BASE_PATH . DIRECTORY_SEPARATOR . 'config';
|
||||
return \path_combine(BASE_PATH . DIRECTORY_SEPARATOR . 'config', $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Phar support.
|
||||
* Compatible with the 'realpath' function in the phar file.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
function runtime_path()
|
||||
function runtime_path(string $path = '')
|
||||
{
|
||||
static $path = '';
|
||||
if (!$path) {
|
||||
$path = \config('app.runtime_path', BASE_PATH . DIRECTORY_SEPARATOR . 'runtime');
|
||||
static $runtime_path = '';
|
||||
if (!$runtime_path) {
|
||||
$runtime_path = \config('app.runtime_path') ? : \run_path('runtime');
|
||||
}
|
||||
return $path;
|
||||
return \path_combine($runtime_path, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,7 +238,7 @@ function twig_view(string $template, array $vars = [], string $app = null)
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Request
|
||||
* @return \Webman\Http\Request|Request|null
|
||||
*/
|
||||
function request()
|
||||
{
|
||||
@@ -379,7 +407,7 @@ function worker_bind($worker, $class)
|
||||
}
|
||||
}
|
||||
if (\method_exists($class, 'onWorkerStart')) {
|
||||
[$class, 'onWorkerStart']($worker);
|
||||
\call_user_func([$class, 'onWorkerStart'], $worker);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -433,7 +461,6 @@ function worker_start($process_name, $config)
|
||||
$instance = Container::make($config['handler'], $config['constructor'] ?? []);
|
||||
\worker_bind($worker, $instance);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user