<?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 <wwccss@263.net>
* @package ZenTaoPHP
* @version $Id: router.class.php 1134 2009-03-29 11:54:45Z wwccss $
* @link http://www.zentao.cn
*/
class router
{
private $pathFix = ''; // 路径分隔符。
private $self = ''; // router自身。
private $baseRoot = ''; // 框架的基准路径。
private $frameRoot = ''; // 框架基类路径。
private $libRoot = ''; // 各种class文件所在的根目录。
private $appRoot = ''; // 当前应用程序所在的目录。
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对象。
/* 构造函数。*/
public function __construct($appName = 'demo')
{
$this->setPathFix();
$this->setSelf();
$this->setBaseRoot();
$this->setFrameRoot();
$this->setLibRoot();
$this->setAppRoot($appName);
$this->setCacheRoot();
$this->setConfigRoot();
$this->setModuleRoot();
$this->setThemeRoot();
}
//-------------------- 路径相关的方法。--------------------//
/* 设置路径分隔符。*/
protected function setPathFix()
{
$this->pathFix = DIRECTORY_SEPARATOR;
}
/* 设置router程序,即index.php的位置。*/
protected function setSelf()
{
$this->self = $_SERVER['SCRIPT_NAME'];
}
/* 设置整个框架所在的根目录。*/
protected function setBaseRoot()
{
$this->baseRoot = realpath(dirname(dirname(__FILE__))) . $this->pathFix;
}
/* 设置框架核心类文件所在的根目录。*/
protected function setFrameRoot()
{
$this->frameRoot = $this->baseRoot . 'framework' . $this->pathFix;
}
/* 设置lib文件的根目录。*/
protected function setLibRoot()
{
$this->libRoot = $this->baseRoot . 'lib' . $this->pathFix;
}
/* 设置应用程序所在的根目录。*/
protected function setAppRoot($appName = 'demo')
{
$this->appRoot = $this->baseRoot . 'app' . $this->pathFix . $appName . $this->pathFix;
if(!file_exists($this->appRoot)) $this->error("The app you call not noud in {$this->appRoot}", __FILE__, __LINE__, $exit = true);
}
/* 设置缓存文件所在的根目录。*/
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;
}
/* 返回router自身的访问路径。*/
public function getSelf()
{
return $this->self;
}
/* 返回路径分隔符。*/
public function getPathFix()
{
return $this->pathFix;
}
/* 返回整个框架的所在的目录。*/
public function getBaseRoot()
{
return $this->baseRoot;
}
/* 返回框架核心类文件所在的根目录。*/
public function getFrameRoot()
{
return $this->frameRoot;
}
/* 返回lib文件所在的根目录。*/
public function getLibRoot()
{
return $this->libRoot;
}
/* 返回应用程序所在的根目录。*/
public function getAppRoot()
{
return $this->appRoot;
}
/* 返回缓存文件所在的根目录。*/
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;
}
}
else
{
$this->clientTheme = $this->config->default->theme;
}
setcookie('theme', $this->clientTheme, $this->config->cookieLife, $this->config->cookiePath);
}
/* 返回客户端所使用的主题。*/
public function getClientTheme()
{
return $this->config->webRoot . 'theme/' . $this->clientTheme . '/';
}
//-------------------- 设置URI及其参数。--------------------//
/* 处理请求,分为PATH
没有合适的资源?快使用搜索试试~ 我知道了~
基于PHP的采用LGPL协议授权的MVC开发框架.zip
共47个文件
php:41个
readme:1个
sql:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 180 浏览量
2023-07-24
22:05:02
上传
评论
收藏 70KB ZIP 举报
温馨提示
基于PHP的采用LGPL协议授权的MVC开发框架.zip
资源推荐
资源详情
资源评论
收起资源包目录
基于PHP的采用LGPL协议授权的MVC开发框架.zip (47个子文件)
132699151284668981
zentaophp
zentaophp_1.0_alpha3_20090329
lib
README 3KB
app
demo
cache
module
index
lang
en.php 1000B
zh-cn.php 1KB
control.php 1KB
model.php 1KB
index.html.php 1KB
common
footer.html.php 16B
error.html.php 19B
lang
en.php 1KB
zh-cn.php 1KB
header.html.php 655B
hello
blog.sql 584B
lang
en.php 1KB
zh-cn.php 1KB
view.html.php 1KB
add.html.php 1KB
control.php 3KB
model.php 2KB
index.html.php 2KB
edit.html.php 2KB
www
js
data
theme
default
style.css 176B
index.php 2KB
config
config.test.php 3KB
config.php 20B
cli
call 2KB
module
common
lang
en.php 1KB
generator
createupdate.html.php 473B
control.php 8KB
model.php 2KB
createcreate.html.php 473B
createmodel.html.php 596B
createread.html.php 400B
createindex.html.php 403B
createlang.html.php 903B
createclaim.html.php 169B
createdelete.html.php 404B
createconfig.html.php 2KB
createcontrol.html.php 1KB
compress
control.php 2KB
model.php 1KB
config
config.php 2KB
COPYING.LESSER 7KB
framework
helper.class.php 2KB
control.class.php 5KB
router.class.php 19KB
model.class.php 3KB
COPYING 34KB
共 47 条
- 1
资源评论
助力毕业
- 粉丝: 2173
- 资源: 5117
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功