<?php
/**
* The router class file of ZenTaoPHP.
*
* ZenTaoPHP is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* ZenTaoPHP is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZenTaoPHP. If not, see <http://www.gnu.org/licenses/>.
*
* @copyright Copyright: 2009 Chunsheng Wang
* @author Chunsheng Wang <[email protected]>
* @package ZenTaoPHP
* @version $Id: router.class.php 1176 2009-05-24 15:09:00Z wwccss $
* @link http://www.zentao.cn
*/
class router
{
private $pathFix = ''; // 文件系统的路径分隔符。
private $basePath = ''; // 框架的基准路径。
private $frameRoot = ''; // 框架基类路径。
private $coreLibRoot = ''; // 框架所带的library目录。
private $appRoot = ''; // 当前应用程序所在的目录。
private $appLibRoot = ''; // 应用程序的libraray目录。
private $cacheRoot = ''; // 缓存文件所在的根目录。
private $configRoot = ''; // 配置文件所在的根目录。
private $moduleRoot = ''; // 模块文件所在的根目录。
private $themeRoot = ''; // 主题文件所在的根目录。
private $clientLang = ''; // 用户所使用的语言。
private $clientTheme = ''; // 用户所使用的主题。
private $moduleName = ''; // 当前需要加载的模块名称。
private $controlFile = ''; // 当前模块对应的control文件。
private $methodName = ''; // 需要调用的controlFile的方法。
private $URI = ''; // 当前请求的URI。
private $params = array(); // 传递的参数。
private $viewType = ''; // 视图格式。html|json|xml|txt
private $config = ''; // config对象。
private $lang = ''; // lang对象。
private $dbh = ''; // dbh对象。
/* 构造函数。*/
private function __construct($appName = 'demo', $appRoot = '')
{
$this->setPathFix();
$this->setBasePath();
$this->setFrameRoot();
$this->setCoreLibRoot();
$this->setAppRoot($appName, $appRoot);
$this->setAppLibRoot();
$this->setCacheRoot();
$this->setConfigRoot();
$this->setModuleRoot();
$this->setThemeRoot();
}
/* 生成一个应用。*/
public static function createApp($appName = 'demo', $appRoot = '')
{
return new router($appName, $appRoot);
}
//-------------------- 路径相关的方法。--------------------//
/* 设置路径分隔符。*/
protected function setPathFix()
{
$this->pathFix = DIRECTORY_SEPARATOR;
}
/* 设置整个框架所在的根目录。*/
protected function setBasePath()
{
$this->basePath = realpath(dirname(dirname(__FILE__))) . $this->pathFix;
}
/* 设置框架核心类文件所在的根目录。*/
protected function setFrameRoot()
{
$this->frameRoot = $this->basePath . 'framework' . $this->pathFix;
}
/* 设置coreLib文件的根目录。*/
protected function setCoreLibRoot()
{
$this->coreLibRoot = $this->basePath . 'lib' . $this->pathFix;
}
/* 设置应用程序所在的根目录。默认情况下面根据appName来进行计算,如果指定了appRoot,直接用之。*/
protected function setAppRoot($appName = 'demo', $appRoot = '')
{
if(empty($appRoot))
{
$this->appRoot = $this->basePath . 'app' . $this->pathFix . $appName . $this->pathFix;
}
else
{
$this->appRoot = realpath($appRoot) . $this->pathFix;
}
if(!is_dir($this->appRoot)) $this->error("The app you call not noud in {$this->appRoot}", __FILE__, __LINE__, $exit = true);
}
/* 设置appLib文件的根目录。*/
protected function setAppLibRoot()
{
$this->appLibRoot = $this->appRoot . 'lib' . $this->pathFix;
}
/* 设置缓存文件所在的根目录。*/
protected function setCacheRoot()
{
$this->cacheRoot = $this->appRoot . 'cache' . $this->pathFix;
}
/* 设置配置文件所在的根目录。*/
protected function setConfigRoot()
{
$this->configRoot = $this->appRoot . 'config' . $this->pathFix;
}
/* 设置module所在的根目录。*/
protected function setModuleRoot()
{
$this->moduleRoot = $this->appRoot . 'module' . $this->pathFix;
}
/* 设置客户端主题文件所在的根目录。*/
protected function setThemeRoot()
{
$this->themeRoot = $this->appRoot . 'www' . $this->pathFix . 'theme' . $this->pathFix;
}
/* 返回路径分隔符。*/
public function getPathFix()
{
return $this->pathFix;
}
/* 返回整个框架的所在的目录。*/
public function getBasePath()
{
return $this->basePath;
}
/* 返回框架核心类文件所在的根目录。*/
public function getFrameRoot()
{
return $this->frameRoot;
}
/* 返回lib文件所在的根目录。*/
public function getCoreLibRoot()
{
return $this->coreLibRoot;
}
/* 返回应用程序所在的根目录。*/
public function getAppRoot()
{
return $this->appRoot;
}
/* 返回appLib文件所在的根目录。*/
public function getAppLibRoot()
{
return $this->appLibRoot;
}
/* 返回缓存文件所在的根目录。*/
public function getCacheRoot()
{
return $this->cacheRoot;
}
/* 返回配置文件所在的根目录。*/
public function getConfigRoot()
{
return $this->configRoot;
}
/* 返回模块文件所在的根目录。*/
public function getModuleRoot()
{
return $this->moduleRoot;
}
/* 返回主题文件所在的根目录。*/
public function getThemeRoot()
{
return $this->themeRoot;
}
//-------------------- 客户端环境设置。--------------------//
/* 设置客户端所使用的语言。*/
public function setClientLang($lang = '')
{
if(!empty($lang))
{
$this->clientLang = $lang;
}
elseif(isset($_SESSION['lang']))
{
$this->clientLang = $_SESSION['lang'];
}
elseif(isset($_COOKIE['lang']))
{
$this->clientLang = $_COOKIE['lang'];
}
elseif(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
{
$this->clientLang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, strpos($_SERVER['HTTP_ACCEPT_LANGUAGE'], ','));
}
if(!empty($this->clientLang))
{
$this->clientLang = strtolower($this->clientLang);
if(strpos($this->config->langs, $this->clientLang) === false)
{
$this->clientLang = $this->config->default->lang;
}
}
else
{
$this->clientLang = $this->config->default->lang;
}
setcookie('lang', $this->clientLang, $this->config->cookieLife, $this->config->cookiePath);
}
/* 返回客户端使用的语言。*/
public function getClientLang()
{
return $this->clientLang;
}
/* 设置客户端所使用的主题。*/
public function setClientTheme($theme = '')
{
if(!empty($theme))
{
$this->clientTheme = $theme;
}
elseif(isset($_SESSION['theme']))
{
$this->clientTheme = $_SESSION['theme'];
}
elseif(isset($_COOKIE['theme']))
{
$this->clientTheme = $_COOKIE['theme'];
}
if(!empty($this->clientTheme))
{
$this->clientTheme = strtolower($this->clientTheme);
if(strpos($this->config->themes, $this->clientTheme) === false)
{
$this->clientTheme = $this->config->default->theme
没有合适的资源?快使用搜索试试~ 我知道了~
PHP实例开发源码—MVC开发框架 zentaophp框架.zip
共52个文件
php:44个
copying:1个
bat:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 131 浏览量
2022-11-11
22:38:56
上传
评论
收藏 74KB ZIP 举报
温馨提示
PHP实例开发源码—MVC开发框架 zentaophp框架.zip
资源推荐
资源详情
资源评论
收起资源包目录
PHP实例开发源码—MVC开发框架 zentaophp框架.zip (52个子文件)
132684871418157584
zentaophp
app
demo
config
config.php 3KB
config.devel.php 3KB
config.product.php 3KB
www
index.php 2KB
data
js
theme
default
style.css 176B
cache
module
index
lang
zh-cn.php 1KB
en.php 1000B
model.php 1KB
view
index.html.php 1KB
control.php 1KB
hello
lang
zh-cn.php 1KB
en.php 1KB
db
blog.sql 584B
model.php 2KB
view
index.html.php 2KB
view.html.php 1KB
add.html.php 1KB
edit.html.php 2KB
control.php 3KB
common
header.html.php 652B
lang
zh-cn.php 1KB
en.php 1KB
error.html.php 19B
footer.html.php 16B
cli
config
config.php 2KB
ztphp 3KB
ztphp.bat 38B
ztphp.sh 38B
module
generator
model.php 2KB
view
createrouter.html.php 2KB
createconfig.html.php 3KB
createcontrol.html.php 1KB
createlang.html.php 903B
createread.html.php 406B
createcreate.html.php 479B
createclaim.html.php 169B
createindex.html.php 409B
createmodel.html.php 560B
createupdate.html.php 479B
createdelete.html.php 404B
claim.test.php 156B
control.php 9KB
common
lang
en.php 1KB
compress
model.php 1KB
control.php 2KB
framework
model.class.php 3KB
helper.class.php 3KB
router.class.php 21KB
control.class.php 5KB
README 3KB
COPYING.LESSER 7KB
COPYING 34KB
共 52 条
- 1
资源评论
毕业_设计
- 粉丝: 1935
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功