mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 07:02:47 +08:00
去除 MODULE_NAME CONTROLLER_NAME ACTION_NAME 常量
This commit is contained in:
7
base.php
7
base.php
@@ -19,17 +19,16 @@ define('LIB_PATH', THINK_PATH . 'library' . DS);
|
|||||||
define('MODE_PATH', THINK_PATH . 'mode' . DS); // 系统应用模式目录
|
define('MODE_PATH', THINK_PATH . 'mode' . DS); // 系统应用模式目录
|
||||||
define('CORE_PATH', LIB_PATH . 'think' . DS);
|
define('CORE_PATH', LIB_PATH . 'think' . DS);
|
||||||
define('TRAIT_PATH', LIB_PATH . 'traits' . DS);
|
define('TRAIT_PATH', LIB_PATH . 'traits' . DS);
|
||||||
|
|
||||||
defined('APP_PATH') or define('APP_PATH', dirname($_SERVER['SCRIPT_FILENAME']) . DS);
|
defined('APP_PATH') or define('APP_PATH', dirname($_SERVER['SCRIPT_FILENAME']) . DS);
|
||||||
defined('ROOT_PATH') or define('ROOT_PATH', dirname(APP_PATH) . DS);
|
defined('ROOT_PATH') or define('ROOT_PATH', dirname(APP_PATH) . DS);
|
||||||
defined('EXTEND_PATH') or define('EXTEND_PATH', ROOT_PATH . 'extend' . DS);
|
defined('EXTEND_PATH') or define('EXTEND_PATH', ROOT_PATH . 'extend' . DS);
|
||||||
defined('APP_NAMESPACE') or define('APP_NAMESPACE', 'app');
|
defined('VENDOR_PATH') or define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS);
|
||||||
defined('COMMON_MODULE') or define('COMMON_MODULE', 'common');
|
|
||||||
defined('RUNTIME_PATH') or define('RUNTIME_PATH', ROOT_PATH . 'runtime' . DS);
|
defined('RUNTIME_PATH') or define('RUNTIME_PATH', ROOT_PATH . 'runtime' . DS);
|
||||||
defined('LOG_PATH') or define('LOG_PATH', RUNTIME_PATH . 'log' . DS);
|
defined('LOG_PATH') or define('LOG_PATH', RUNTIME_PATH . 'log' . DS);
|
||||||
defined('CACHE_PATH') or define('CACHE_PATH', RUNTIME_PATH . 'cache' . DS);
|
defined('CACHE_PATH') or define('CACHE_PATH', RUNTIME_PATH . 'cache' . DS);
|
||||||
defined('TEMP_PATH') or define('TEMP_PATH', RUNTIME_PATH . 'temp' . DS);
|
defined('TEMP_PATH') or define('TEMP_PATH', RUNTIME_PATH . 'temp' . DS);
|
||||||
defined('VENDOR_PATH') or define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS);
|
defined('APP_NAMESPACE') or define('APP_NAMESPACE', 'app');
|
||||||
|
defined('COMMON_MODULE') or define('COMMON_MODULE', 'common');
|
||||||
defined('CONF_PATH') or define('CONF_PATH', APP_PATH); // 配置文件目录
|
defined('CONF_PATH') or define('CONF_PATH', APP_PATH); // 配置文件目录
|
||||||
defined('CONF_EXT') or define('CONF_EXT', EXT); // 配置文件后缀
|
defined('CONF_EXT') or define('CONF_EXT', EXT); // 配置文件后缀
|
||||||
defined('APP_MULTI_MODULE') or define('APP_MULTI_MODULE', true); // 是否多模块
|
defined('APP_MULTI_MODULE') or define('APP_MULTI_MODULE', true); // 是否多模块
|
||||||
|
|||||||
@@ -228,63 +228,68 @@ class App
|
|||||||
}
|
}
|
||||||
if (APP_MULTI_MODULE) {
|
if (APP_MULTI_MODULE) {
|
||||||
// 多模块部署
|
// 多模块部署
|
||||||
$module = strtolower($result[0] ?: $config['default_module']);
|
$module = strip_tags(strtolower($result[0] ?: $config['default_module']));
|
||||||
// 获取模块名称
|
|
||||||
define('MODULE_NAME', strip_tags($module));
|
|
||||||
$bind = Route::bind('module');
|
$bind = Route::bind('module');
|
||||||
$available = false;
|
$available = false;
|
||||||
if ($bind) {
|
if ($bind) {
|
||||||
// 绑定模块
|
// 绑定模块
|
||||||
list($bindModule) = explode('/', $bind);
|
list($bindModule) = explode('/', $bind);
|
||||||
if (MODULE_NAME == $bindModule) {
|
if ($module == $bindModule) {
|
||||||
$available = true;
|
$available = true;
|
||||||
}
|
}
|
||||||
} elseif (!in_array(MODULE_NAME, $config['deny_module_list']) && is_dir(APP_PATH . MODULE_NAME)) {
|
} elseif (!in_array($module, $config['deny_module_list']) && is_dir(APP_PATH . $module)) {
|
||||||
$available = true;
|
$available = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 模块初始化
|
// 模块初始化
|
||||||
if (MODULE_NAME && $available) {
|
if ($module && $available) {
|
||||||
define('MODULE_PATH', APP_PATH . MODULE_NAME . DS);
|
define('MODULE_PATH', APP_PATH . $module . DS);
|
||||||
define('VIEW_PATH', MODULE_PATH . 'view' . DS);
|
define('VIEW_PATH', MODULE_PATH . 'view' . DS);
|
||||||
// 初始化模块
|
// 初始化模块
|
||||||
$config = self::initModule(MODULE_NAME, $config);
|
$config = self::initModule($module, $config);
|
||||||
} else {
|
} else {
|
||||||
throw new HttpException(404, 'module [ ' . MODULE_NAME . ' ] not exists ');
|
throw new HttpException(404, 'module [ ' . $module . ' ] not exists ');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 单一模块部署
|
// 单一模块部署
|
||||||
define('MODULE_NAME', '');
|
$module = '';
|
||||||
define('MODULE_PATH', APP_PATH);
|
define('MODULE_PATH', APP_PATH);
|
||||||
define('VIEW_PATH', MODULE_PATH . 'view' . DS);
|
define('VIEW_PATH', MODULE_PATH . 'view' . DS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取控制器名
|
// 获取控制器名
|
||||||
$controllerName = strip_tags($result[1] ?: $config['default_controller']);
|
$controller = strip_tags($result[1] ?: $config['default_controller']);
|
||||||
defined('CONTROLLER_NAME') or define('CONTROLLER_NAME', $config['url_controller_convert'] ? strtolower($controllerName) : $controllerName);
|
$controller = $config['url_controller_convert'] ? strtolower($controller) : $controller;
|
||||||
|
|
||||||
// 获取操作名
|
// 获取操作名
|
||||||
$actionName = strip_tags($result[2] ?: $config['default_action']);
|
$actionName = strip_tags($result[2] ?: $config['default_action']);
|
||||||
defined('ACTION_NAME') or define('ACTION_NAME', $config['url_action_convert'] ? strtolower($actionName) : $actionName);
|
$actionName = $config['url_action_convert'] ? strtolower($actionName) : $actionName;
|
||||||
|
|
||||||
// 执行操作
|
// 执行操作
|
||||||
if (!preg_match('/^[A-Za-z](\/|\.|\w)*$/', CONTROLLER_NAME)) {
|
if (!preg_match('/^[A-Za-z](\/|\.|\w)*$/', $controller)) {
|
||||||
// 安全检测
|
// 安全检测
|
||||||
throw new Exception('illegal controller name:' . CONTROLLER_NAME, 10000);
|
throw new Exception('illegal controller name:' . $controller, 10000);
|
||||||
}
|
}
|
||||||
$instance = Loader::controller(CONTROLLER_NAME, $config['url_controller_layer'], $config['use_controller_suffix'], $config['empty_controller']);
|
|
||||||
// 获取当前操作名
|
// 设置当前请求的模块、控制器、操作
|
||||||
$action = ACTION_NAME . $config['action_suffix'];
|
$request = Request::instance();
|
||||||
|
$request->module($module);
|
||||||
|
$request->controller($controller);
|
||||||
|
$request->action($actionName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 操作方法开始监听
|
// 获取当前操作名
|
||||||
$call = [$instance, $action];
|
$action = $actionName . $config['action_suffix'];
|
||||||
Hook::listen('action_begin', $call);
|
|
||||||
if (!preg_match('/^[A-Za-z](\w)*$/', $action)) {
|
if (!preg_match('/^[A-Za-z](\w)*$/', $action)) {
|
||||||
// 非法操作
|
// 非法操作
|
||||||
throw new \ReflectionException('illegal action name :' . ACTION_NAME);
|
throw new \ReflectionException('illegal action name :' . $actionName);
|
||||||
}
|
}
|
||||||
|
$instance = Loader::controller($controller, $config['url_controller_layer'], $config['use_controller_suffix'], $config['empty_controller']);
|
||||||
|
|
||||||
// 执行操作方法
|
// 执行操作方法
|
||||||
|
$call = [$instance, $action];
|
||||||
|
Hook::listen('action_begin', $call);
|
||||||
|
|
||||||
$data = self::invokeMethod($call);
|
$data = self::invokeMethod($call);
|
||||||
} catch (\ReflectionException $e) {
|
} catch (\ReflectionException $e) {
|
||||||
// 操作不存在
|
// 操作不存在
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class Console
|
|||||||
private $runningCommand;
|
private $runningCommand;
|
||||||
|
|
||||||
private $catchExceptions = true;
|
private $catchExceptions = true;
|
||||||
private $autoExit = true;
|
private $autoExit = true;
|
||||||
private $definition;
|
private $definition;
|
||||||
private $helperSet;
|
private $helperSet;
|
||||||
private $terminalDimensions;
|
private $terminalDimensions;
|
||||||
@@ -49,7 +49,7 @@ class Console
|
|||||||
"think\\console\\command\\Lists",
|
"think\\console\\command\\Lists",
|
||||||
"think\\console\\command\\Build",
|
"think\\console\\command\\Build",
|
||||||
"think\\console\\command\\make\\Controller",
|
"think\\console\\command\\make\\Controller",
|
||||||
"think\\console\\command\\make\\Model"
|
"think\\console\\command\\make\\Model",
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
|
public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
|
||||||
@@ -90,7 +90,7 @@ class Console
|
|||||||
|
|
||||||
$exitCode = $e->getCode();
|
$exitCode = $e->getCode();
|
||||||
if (is_numeric($exitCode)) {
|
if (is_numeric($exitCode)) {
|
||||||
$exitCode = (int)$exitCode;
|
$exitCode = (int) $exitCode;
|
||||||
if (0 === $exitCode) {
|
if (0 === $exitCode) {
|
||||||
$exitCode = 1;
|
$exitCode = 1;
|
||||||
}
|
}
|
||||||
@@ -201,7 +201,7 @@ class Console
|
|||||||
*/
|
*/
|
||||||
public function setCatchExceptions($boolean)
|
public function setCatchExceptions($boolean)
|
||||||
{
|
{
|
||||||
$this->catchExceptions = (bool)$boolean;
|
$this->catchExceptions = (bool) $boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -211,7 +211,7 @@ class Console
|
|||||||
*/
|
*/
|
||||||
public function setAutoExit($boolean)
|
public function setAutoExit($boolean)
|
||||||
{
|
{
|
||||||
$this->autoExit = (bool)$boolean;
|
$this->autoExit = (bool) $boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -379,7 +379,7 @@ class Console
|
|||||||
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) {
|
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) {
|
||||||
return preg_quote($matches[1]) . '[^:]*';
|
return preg_quote($matches[1]) . '[^:]*';
|
||||||
}, $namespace);
|
}, $namespace);
|
||||||
$namespaces = preg_grep('{^' . $expr . '}', $allNamespaces);
|
$namespaces = preg_grep('{^' . $expr . '}', $allNamespaces);
|
||||||
|
|
||||||
if (empty($namespaces)) {
|
if (empty($namespaces)) {
|
||||||
$message = sprintf('There are no commands defined in the "%s" namespace.', $namespace);
|
$message = sprintf('There are no commands defined in the "%s" namespace.', $namespace);
|
||||||
@@ -417,7 +417,7 @@ class Console
|
|||||||
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) {
|
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) {
|
||||||
return preg_quote($matches[1]) . '[^:]*';
|
return preg_quote($matches[1]) . '[^:]*';
|
||||||
}, $name);
|
}, $name);
|
||||||
$commands = preg_grep('{^' . $expr . '}', $allCommands);
|
$commands = preg_grep('{^' . $expr . '}', $allCommands);
|
||||||
|
|
||||||
if (empty($commands) || count(preg_grep('{^' . $expr . '$}', $commands)) < 1) {
|
if (empty($commands) || count(preg_grep('{^' . $expr . '$}', $commands)) < 1) {
|
||||||
if (false !== $pos = strrpos($name, ':')) {
|
if (false !== $pos = strrpos($name, ':')) {
|
||||||
@@ -606,19 +606,19 @@ class Console
|
|||||||
|
|
||||||
if ('\\' === DS) {
|
if ('\\' === DS) {
|
||||||
if (preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', trim(getenv('ANSICON')), $matches)) {
|
if (preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', trim(getenv('ANSICON')), $matches)) {
|
||||||
return [(int)$matches[1], (int)$matches[2]];
|
return [(int) $matches[1], (int) $matches[2]];
|
||||||
}
|
}
|
||||||
if (preg_match('/^(\d+)x(\d+)$/', $this->getConsoleMode(), $matches)) {
|
if (preg_match('/^(\d+)x(\d+)$/', $this->getConsoleMode(), $matches)) {
|
||||||
return [(int)$matches[1], (int)$matches[2]];
|
return [(int) $matches[1], (int) $matches[2]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($sttyString = $this->getSttyColumns()) {
|
if ($sttyString = $this->getSttyColumns()) {
|
||||||
if (preg_match('/rows.(\d+);.columns.(\d+);/i', $sttyString, $matches)) {
|
if (preg_match('/rows.(\d+);.columns.(\d+);/i', $sttyString, $matches)) {
|
||||||
return [(int)$matches[2], (int)$matches[1]];
|
return [(int) $matches[2], (int) $matches[1]];
|
||||||
}
|
}
|
||||||
if (preg_match('/;.(\d+).rows;.(\d+).columns/i', $sttyString, $matches)) {
|
if (preg_match('/;.(\d+).rows;.(\d+).columns/i', $sttyString, $matches)) {
|
||||||
return [(int)$matches[2], (int)$matches[1]];
|
return [(int) $matches[2], (int) $matches[1]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,14 +69,14 @@ class Controller
|
|||||||
if (is_string($options['only'])) {
|
if (is_string($options['only'])) {
|
||||||
$options['only'] = explode(',', $options['only']);
|
$options['only'] = explode(',', $options['only']);
|
||||||
}
|
}
|
||||||
if (!in_array(ACTION_NAME, $options['only'])) {
|
if (!in_array($this->request->action(), $options['only'])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} elseif (isset($options['except'])) {
|
} elseif (isset($options['except'])) {
|
||||||
if (is_string($options['except'])) {
|
if (is_string($options['except'])) {
|
||||||
$options['except'] = explode(',', $options['except']);
|
$options['except'] = explode(',', $options['except']);
|
||||||
}
|
}
|
||||||
if (in_array(ACTION_NAME, $options['except'])) {
|
if (in_array($this->request->action(), $options['except'])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
namespace think;
|
namespace think;
|
||||||
|
|
||||||
use think\exception\HttpException;
|
use think\exception\HttpException;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
class Loader
|
class Loader
|
||||||
{
|
{
|
||||||
@@ -276,7 +277,7 @@ class Loader
|
|||||||
if (strpos($name, '/')) {
|
if (strpos($name, '/')) {
|
||||||
list($module, $name) = explode('/', $name, 2);
|
list($module, $name) = explode('/', $name, 2);
|
||||||
} else {
|
} else {
|
||||||
$module = APP_MULTI_MODULE ? MODULE_NAME : '';
|
$module = APP_MULTI_MODULE ? Request::instance()->module() : '';
|
||||||
}
|
}
|
||||||
$class = self::parseClass($module, $layer, $name, $appendSuffix);
|
$class = self::parseClass($module, $layer, $name, $appendSuffix);
|
||||||
if (class_exists($class)) {
|
if (class_exists($class)) {
|
||||||
@@ -311,7 +312,7 @@ class Loader
|
|||||||
if (strpos($name, '/')) {
|
if (strpos($name, '/')) {
|
||||||
list($module, $name) = explode('/', $name);
|
list($module, $name) = explode('/', $name);
|
||||||
} else {
|
} else {
|
||||||
$module = APP_MULTI_MODULE ? MODULE_NAME : '';
|
$module = APP_MULTI_MODULE ? Request::instance()->module() : '';
|
||||||
}
|
}
|
||||||
$class = self::parseClass($module, $layer, $name, $appendSuffix);
|
$class = self::parseClass($module, $layer, $name, $appendSuffix);
|
||||||
if (class_exists($class)) {
|
if (class_exists($class)) {
|
||||||
@@ -346,7 +347,7 @@ class Loader
|
|||||||
if (strpos($name, '/')) {
|
if (strpos($name, '/')) {
|
||||||
list($module, $name) = explode('/', $name);
|
list($module, $name) = explode('/', $name);
|
||||||
} else {
|
} else {
|
||||||
$module = APP_MULTI_MODULE ? MODULE_NAME : '';
|
$module = APP_MULTI_MODULE ? Request::instance()->module() : '';
|
||||||
}
|
}
|
||||||
$class = self::parseClass($module, $layer, $name, $appendSuffix);
|
$class = self::parseClass($module, $layer, $name, $appendSuffix);
|
||||||
if (class_exists($class)) {
|
if (class_exists($class)) {
|
||||||
@@ -385,7 +386,7 @@ class Loader
|
|||||||
{
|
{
|
||||||
$info = pathinfo($url);
|
$info = pathinfo($url);
|
||||||
$action = $info['basename'];
|
$action = $info['basename'];
|
||||||
$module = '.' != $info['dirname'] ? $info['dirname'] : CONTROLLER_NAME;
|
$module = '.' != $info['dirname'] ? $info['dirname'] : Request::instance()->controller();
|
||||||
$class = self::controller($module, $layer, $appendSuffix);
|
$class = self::controller($module, $layer, $appendSuffix);
|
||||||
if ($class) {
|
if ($class) {
|
||||||
if (is_scalar($vars)) {
|
if (is_scalar($vars)) {
|
||||||
|
|||||||
@@ -67,6 +67,10 @@ class Request
|
|||||||
*/
|
*/
|
||||||
protected $dispatch = [];
|
protected $dispatch = [];
|
||||||
|
|
||||||
|
protected $module;
|
||||||
|
protected $controller;
|
||||||
|
protected $action;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array 请求参数
|
* @var array 请求参数
|
||||||
*/
|
*/
|
||||||
@@ -908,4 +912,48 @@ class Request
|
|||||||
return $this->dispatch;
|
return $this->dispatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置或者获取当前的模块名
|
||||||
|
* @access public
|
||||||
|
* @param string $module 模块名
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function module($module = null)
|
||||||
|
{
|
||||||
|
if (!is_null($module)) {
|
||||||
|
$this->module = $module;
|
||||||
|
} else {
|
||||||
|
return $this->module ?: '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置或者获取当前的控制器名
|
||||||
|
* @access public
|
||||||
|
* @param string $controller 控制器名
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function controller($controller = null)
|
||||||
|
{
|
||||||
|
if (!is_null($controller)) {
|
||||||
|
$this->controller = $controller;
|
||||||
|
} else {
|
||||||
|
return $this->controller ?: '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置或者获取当前的操作名
|
||||||
|
* @access public
|
||||||
|
* @param string $action 操作名
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function action($action = null)
|
||||||
|
{
|
||||||
|
if (!is_null($action)) {
|
||||||
|
$this->action = $action;
|
||||||
|
} else {
|
||||||
|
return $this->action ?: '';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace think;
|
|||||||
|
|
||||||
use think\Cache;
|
use think\Cache;
|
||||||
use think\Config;
|
use think\Config;
|
||||||
|
use think\Request;
|
||||||
use think\Route;
|
use think\Route;
|
||||||
|
|
||||||
class Url
|
class Url
|
||||||
@@ -118,6 +119,7 @@ class Url
|
|||||||
// 直接解析URL地址
|
// 直接解析URL地址
|
||||||
protected static function parseUrl($url)
|
protected static function parseUrl($url)
|
||||||
{
|
{
|
||||||
|
$request = Request::instance();
|
||||||
if (0 === strpos($url, '/')) {
|
if (0 === strpos($url, '/')) {
|
||||||
// 直接作为路由地址解析
|
// 直接作为路由地址解析
|
||||||
$url = substr($url, 1);
|
$url = substr($url, 1);
|
||||||
@@ -129,14 +131,16 @@ class Url
|
|||||||
$url = substr($url, 1);
|
$url = substr($url, 1);
|
||||||
} else {
|
} else {
|
||||||
// 解析到 模块/控制器/操作
|
// 解析到 模块/控制器/操作
|
||||||
$module = MODULE_NAME ? MODULE_NAME . '/' : '';
|
$module = $request->module();
|
||||||
|
$module = $module ? $module . '/' : '';
|
||||||
|
$controller = $request->controller();
|
||||||
if ('' == $url) {
|
if ('' == $url) {
|
||||||
// 空字符串输出当前的 模块/控制器/操作
|
// 空字符串输出当前的 模块/控制器/操作
|
||||||
$url = $module . CONTROLLER_NAME . '/' . ACTION_NAME;
|
$url = $module . $controller . '/' . $request->action();
|
||||||
} else {
|
} else {
|
||||||
$path = explode('/', $url);
|
$path = explode('/', $url);
|
||||||
$action = array_pop($path);
|
$action = array_pop($path);
|
||||||
$controller = empty($path) ? CONTROLLER_NAME : (Config::get('url_controller_convert') ? Loader::parseName(array_pop($path)) : array_pop($path));
|
$controller = empty($path) ? $controller : (Config::get('url_controller_convert') ? Loader::parseName(array_pop($path)) : array_pop($path));
|
||||||
$module = empty($path) ? $module : array_pop($path) . '/';
|
$module = empty($path) ? $module : array_pop($path) . '/';
|
||||||
$url = $module . $controller . '/' . $action;
|
$url = $module . $controller . '/' . $action;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ abstract class Rest
|
|||||||
return $this->$fun();
|
return $this->$fun();
|
||||||
} else {
|
} else {
|
||||||
// 抛出异常
|
// 抛出异常
|
||||||
throw new \Exception('error action :' . ACTION_NAME);
|
throw new \Exception('error action :' . $method);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace think\view\driver;
|
|||||||
|
|
||||||
use think\Exception;
|
use think\Exception;
|
||||||
use think\Log;
|
use think\Log;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
class Php
|
class Php
|
||||||
{
|
{
|
||||||
@@ -102,14 +103,16 @@ class Php
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 分析模板文件规则
|
// 分析模板文件规则
|
||||||
if (defined('CONTROLLER_NAME') && 0 !== strpos($template, '/')) {
|
$request = Request::instance();
|
||||||
|
$controller = $request->controller();
|
||||||
|
if ($controller && 0 !== strpos($template, '/')) {
|
||||||
$depr = $this->config['view_depr'];
|
$depr = $this->config['view_depr'];
|
||||||
$template = str_replace(['/', ':'], $depr, $template);
|
$template = str_replace(['/', ':'], $depr, $template);
|
||||||
if ('' == $template) {
|
if ('' == $template) {
|
||||||
// 如果模板文件名为空 按照默认规则定位
|
// 如果模板文件名为空 按照默认规则定位
|
||||||
$template = str_replace('.', DS, CONTROLLER_NAME) . $depr . ACTION_NAME;
|
$template = str_replace('.', DS, $controller) . $depr . $request->action();
|
||||||
} elseif (false === strpos($template, $depr)) {
|
} elseif (false === strpos($template, $depr)) {
|
||||||
$template = str_replace('.', DS, CONTROLLER_NAME) . $depr . $template;
|
$template = str_replace('.', DS, $controller) . $depr . $template;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $path . ltrim($template, '/') . '.' . ltrim($this->config['view_suffix'], '.');
|
return $path . ltrim($template, '/') . '.' . ltrim($this->config['view_suffix'], '.');
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace think\view\driver;
|
|||||||
|
|
||||||
use think\Exception;
|
use think\Exception;
|
||||||
use think\Log;
|
use think\Log;
|
||||||
|
use think\Request;
|
||||||
use think\Template;
|
use think\Template;
|
||||||
|
|
||||||
class Think
|
class Think
|
||||||
@@ -110,14 +111,16 @@ class Think
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 分析模板文件规则
|
// 分析模板文件规则
|
||||||
if (defined('CONTROLLER_NAME') && 0 !== strpos($template, '/')) {
|
$request = Request::instance();
|
||||||
|
$controller = $request->controller();
|
||||||
|
if ($controller && 0 !== strpos($template, '/')) {
|
||||||
$depr = $this->config['view_depr'];
|
$depr = $this->config['view_depr'];
|
||||||
$template = str_replace(['/', ':'], $depr, $template);
|
$template = str_replace(['/', ':'], $depr, $template);
|
||||||
if ('' == $template) {
|
if ('' == $template) {
|
||||||
// 如果模板文件名为空 按照默认规则定位
|
// 如果模板文件名为空 按照默认规则定位
|
||||||
$template = str_replace('.', DS, CONTROLLER_NAME) . $depr . ACTION_NAME;
|
$template = str_replace('.', DS, $controller) . $depr . $request->action();
|
||||||
} elseif (false === strpos($template, $depr)) {
|
} elseif (false === strpos($template, $depr)) {
|
||||||
$template = str_replace('.', DS, CONTROLLER_NAME) . $depr . $template;
|
$template = str_replace('.', DS, $controller) . $depr . $template;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $path . ltrim($template, '/') . '.' . ltrim($this->config['view_suffix'], '.');
|
return $path . ltrim($template, '/') . '.' . ltrim($this->config['view_suffix'], '.');
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ namespace tests\thinkphp\library\think;
|
|||||||
|
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
use think\Controller;
|
use think\Controller;
|
||||||
|
use think\Request;
|
||||||
use think\View;
|
use think\View;
|
||||||
|
|
||||||
require_once CORE_PATH . '../../helper.php';
|
require_once CORE_PATH . '../../helper.php';
|
||||||
@@ -93,16 +94,16 @@ class controllerTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
public function testInitialize()
|
public function testInitialize()
|
||||||
{
|
{
|
||||||
$foo = new Foo;
|
$foo = new Foo(Request::instance());
|
||||||
$this->assertEquals('abcd', $foo->test);
|
$this->assertEquals('abcd', $foo->test);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testBeforeAction()
|
public function testBeforeAction()
|
||||||
{
|
{
|
||||||
$obj = new Bar;
|
$obj = new Bar(Request::instance());
|
||||||
$this->assertEquals(7, $obj->test);
|
$this->assertEquals(7, $obj->test);
|
||||||
|
|
||||||
$obj = new Baz;
|
$obj = new Baz(Request::instance());
|
||||||
$this->assertEquals(19, $obj->test);
|
$this->assertEquals(19, $obj->test);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +119,7 @@ class controllerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testFetch()
|
public function testFetch()
|
||||||
{
|
{
|
||||||
$controller = new Foo;
|
$controller = new Foo(Request::instance());
|
||||||
$view = $this->getView($controller);
|
$view = $this->getView($controller);
|
||||||
$template = dirname(__FILE__) . '/display.html';
|
$template = dirname(__FILE__) . '/display.html';
|
||||||
$viewFetch = $view->fetch($template, ['name' => 'ThinkPHP']);
|
$viewFetch = $view->fetch($template, ['name' => 'ThinkPHP']);
|
||||||
@@ -138,7 +139,7 @@ class controllerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testAssign()
|
public function testAssign()
|
||||||
{
|
{
|
||||||
$controller = new Foo;
|
$controller = new Foo(Request::instance());
|
||||||
$view = $this->getView($controller);
|
$view = $this->getView($controller);
|
||||||
$controller->assign('abcd', 'dcba');
|
$controller->assign('abcd', 'dcba');
|
||||||
$controller->assign(['key1' => 'value1', 'key2' => 'value2']);
|
$controller->assign(['key1' => 'value1', 'key2' => 'value2']);
|
||||||
@@ -148,7 +149,7 @@ class controllerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testValidate()
|
public function testValidate()
|
||||||
{
|
{
|
||||||
$controller = new Foo;
|
$controller = new Foo(Request::instance());
|
||||||
$data = [
|
$data = [
|
||||||
'username' => 'username',
|
'username' => 'username',
|
||||||
'nickname' => 'nickname',
|
'nickname' => 'nickname',
|
||||||
|
|||||||
Reference in New Issue
Block a user