integrate laravel framework

This commit is contained in:
xiaomlove
2021-04-02 19:48:41 +08:00
parent fe8c7683b8
commit e48461546f
96 changed files with 10107 additions and 207 deletions
-1
View File
@@ -11,7 +11,6 @@ $rootpath= dirname(__DIR__);
set_include_path(get_include_path() . PATH_SEPARATOR . $rootpath);
$rootpath .= "/";
require $rootpath . 'include/functions.php';
require $rootpath . 'include/globalfunctions.php';
require $rootpath . 'classes/class_advertisement.php';
require $rootpath . 'classes/class_attendance.php';
require $rootpath . 'include/core.php';
-1
View File
@@ -4,5 +4,4 @@ define('NEXUS_START', microtime(true));
define('IN_TRACKER', true);
$rootpath= dirname(__DIR__) . '/';
require $rootpath . 'include/functions_announce.php';
require $rootpath . 'include/globalfunctions.php';
require $rootpath . 'include/core.php';
+1 -1
View File
@@ -405,7 +405,7 @@ $SUBSPATH = "subs";
//Make sure you have wget installed on your OS
//replace "http://www.nexusphp.com/" with your own site address
$useCronTriggerCleanUp = config('nexus.use_cron_trigger_cleanup', false);
$useCronTriggerCleanUp = nexus_config('nexus.use_cron_trigger_cleanup', false);
//some promotion rules
//$promotionrules_torrent = array(0 => array("mediumid" => array(1), "promotion" => 5), 1 => array("mediumid" => array(3), "promotion" => 5), 2 => array("catid" => array(402), "standardid" => array(3), "promotion" => 4), 3 => array("catid" => array(403), "standardid" => array(3), "promotion" => 4));
$promotionrules_torrent = array();
+5 -4
View File
@@ -14,14 +14,15 @@ if (!file_exists($rootpath . '.env')) {
redirect($installScriptRelativePath);
}
}
ini_set('date.timezone', config('nexus.timezone'));
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 0);
require $rootpath . 'vendor/autoload.php';
require $rootpath . 'nexus/Database/helpers.php';
require $rootpath . 'classes/class_cache_redis.php';
require $rootpath . 'include/config.php';
ini_set('date.timezone', nexus_config('nexus.timezone'));
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 0);
if (!in_array(CURRENT_SCRIPT, ['announce', 'scrape'])) {
require $rootpath . get_langfile_path("functions.php");
checkGuestVisit();
+105 -36
View File
@@ -135,16 +135,17 @@ function printLine($line, $exist = false)
}
}
function dd($vars)
function nexus_dd($vars)
{
echo '<pre>';
array_map(function ($var) {
var_dump($var);
}, func_get_args());
echo '</pre>';
exit(0);
echo '<pre>';
array_map(function ($var) {
var_dump($var);
}, func_get_args());
echo '</pre>';
exit(0);
}
function do_log($log, $level = 'info')
{
global $CURUSER;
@@ -177,7 +178,7 @@ function getLogFile()
if (!is_null($logFile)) {
return $logFile;
}
$config = config('nexus');
$config = nexus_config('nexus');
$logFile = sys_get_temp_dir() . '/nexus_' . date('Y-m-d') . '.log';
if (!empty($config['log_file'])) {
$logFile = $config['log_file'];
@@ -208,26 +209,30 @@ function getLogFile()
}
function config($key, $default = null)
function nexus_config($key, $default = null)
{
static $configs;
if (is_null($configs)) {
//get all configuration from config file
$files = glob(ROOT_PATH . 'config/*.php');
foreach ($files as $file) {
$basename = basename($file);
if ($basename == 'allconfig.php') {
//exclude the NexusPHP default config file
continue;
}
$values = require $file;
$configPrefix = strstr($basename, '.php', true);
$configs[$configPrefix] = $values;
}
}
return arr_get($configs, $key, $default);
static $configs;
if (is_null($configs)) {
//get all configuration from config file
// $files = glob(ROOT_PATH . 'config/*.php');
$files = [
ROOT_PATH . 'config/nexus.php',
];
foreach ($files as $file) {
$basename = basename($file);
if ($basename == 'allconfig.php') {
//exclude the NexusPHP default config file
continue;
}
$values = require $file;
$configPrefix = strstr($basename, '.php', true);
$configs[$configPrefix] = $values;
}
}
return arr_get($configs, $key, $default);
}
/**
* get setting for given name and prefix
*
@@ -257,24 +262,23 @@ function get_setting($name = null)
return arr_get($settings, $name);
}
function env($key = null, $default = null)
function nexus_env($key = null, $default = null)
{
static $env;
if (is_null($env)) {
$envFile = ROOT_PATH . '.env';
$env = readEnvFile($envFile);
}
if (is_null($key)) {
return $env;
static $env;
if (is_null($env)) {
$envFile = defined('ROOT_PATH') ? ROOT_PATH . '.env' : base_path('.env');
$env = readEnvFile($envFile);
}
return $env[$key] ?? $default;
if (is_null($key)) {
return $env;
}
return $env[$key] ?? $default;
}
function readEnvFile($envFile)
{
if (!file_exists($envFile)) {
throw new \RuntimeException("env file is not exists in the root path.");
throw new \RuntimeException("env file : $envFile is not exists in the root path.");
}
$env = [];
$fp = fopen($envFile, 'r');
@@ -423,3 +427,68 @@ function getBaseUrl()
}
return trim($url, '/');
}
function api(...$args)
{
if (!isset($args[2])) {
//参数少于3个时,默认为错误状态。
$ret = -1;
$msg = isset($args[0]) ? $args[0] : 'ERROR';
$data = isset($args[1]) ? $args[1] : [];
} else {
$ret = $args[0];
$msg = $args[1];
$data = $args[2];
}
if (defined('LARAVEL_START')) {
$start = LARAVEL_START;
if ($data instanceof \Illuminate\Http\Resources\Json\ResourceCollection || $data instanceof \Illuminate\Http\Resources\Json\JsonResource) {
$data = $data->response()->getData(true);
if (isset($data['data']) && count($data) == 1) {
//单纯的集合,无分页等其数据
$data = $data['data'];
}
}
} elseif (defined('NEXUS_START')) {
$start = NEXUS_START;
} else {
throw new \RuntimeException("no constant START is defined.");
}
return [
'ret' => (int)$ret,
'msg' => (string)$msg,
'data' => $data,
'timeuse' => (float)number_format(microtime(true) - $start, 3),
];
}
function success(...$args)
{
$ret = 0;
$msg = 'OK';
$data = [];
$argumentCount = func_num_args();
if ($argumentCount == 1) {
$data = $args[0];
} elseif ($argumentCount == 2) {
$msg = $args[0];
$data = $args[1];
}
return api($ret, $msg, $data);
}
function fail(...$args)
{
$ret = -1;
$msg = 'ERROR';
$data = [];
$argumentCount = func_num_args();
if ($argumentCount == 1) {
$data = $args[0];
} elseif ($argumentCount == 2) {
$msg = $args[0];
$data = $args[1];
}
return api($ret, $msg, $data);
}