Skip to content

Commit

Permalink
complete http module
Browse files Browse the repository at this point in the history
  • Loading branch information
yangjian committed Nov 18, 2014
1 parent 5798ee3 commit a289a0c
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 187 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 3,5 @@
.svn/
.git/
.htaccess
runtime/
runtime/views/

3 changes: 3 additions & 0 deletions framework/herosphp/Heros.const.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 15,7 @@
//定义请求访问模式
define('__PATH_INFO_REQUEST__', 1); //pathinfo 访问模式
define('__NORMAL_REQUEST__', 2); //常规访问模式
define('__CLIENT_REQUEST__', 3); //客户端请求模式
define('__REQUEST_MODE__', __PATH_INFO_REQUEST__);

//定义编译路径
Expand All @@ -32,4 33,6 @@

define('EXT_PHP', '.class.php'); //加载php文件
define('EXT_HTML', '.html'); //加载html文件

define('URI_EXT', '.html'); //uri 伪静态路径后缀
?>
9 changes: 6 additions & 3 deletions framework/herosphp/Herosphp.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 11,9 @@

include APP_FRAME_PATH.'functions.php'; //包含框架全局函数
include APP_FRAME_PATH.'core/Loader.class.php'; //包含资源加载器

use herosphp\core\Loader;
use herosphp\core\WebApplication;

class Herosphp {

Expand Down Expand Up @@ -40,7 42,8 @@ public static function run() {
}

$configs = Loader::config(); //加载系统全局配置
__print($configs);
$application = WebApplication::getInstance();
$application->execute($configs);

}

Expand All @@ -50,8 53,8 @@ public static function run() {
*/
private static function _loadBaseLib() {
self::$LIB_CLASS = array(
'herosphp\core\HttpRequest' => 'core.HttpRequest',
'herosphp\core\Webapplication' => 'core.Webapplication',
'herosphp\http\HttpRequest' => 'http.HttpRequest',
'herosphp\core\WebApplication' => 'core.WebApplication',
'herosphp\core\Debug' => 'core.Debug',
'herosphp\core\Loader' => 'core.Loader',
'HomecommonAction' => 'core.HomecommonAction',
Expand Down
172 changes: 0 additions & 172 deletions framework/herosphp/core/HttpRequest.class.php

This file was deleted.

25 changes: 18 additions & 7 deletions framework/herosphp/core/Loader.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 19,12 @@ class Loader {
*/
private static $IMPORTED_FILES = array();

/**
* 已经导入的配置文档
* @var array
*/
private static $CONFIGS = array();

/**
* 加载一个类或者加载一个包
* 如果加载的包中有子文件夹不进行循环加载
Expand Down Expand Up @@ -80,17 86,20 @@ public static function import( $classPath, $type = IMPORT_APP, $extension=EXT_PH

/**
* 加载配置信息
* @param string $key 配置文件名称key
* @param string $section 配置文档所属片区|模块
* @param string $key 配置文件名称key, 如果没有指定则加载所有配置文档
* @param string $section 配置文档所属片区|模块,如果没有指定则加载配置文档根目录的所有文件
* @return array
*/
public static function config( $key=null, $section=null ) {
public static function config( $key='*', $section='root' ) {

if ( isset(self::$CONFIGS[$section][$key]) ) {
return self::$CONFIGS[$section][$key];
}
$configDir = APP_CONFIG_PATH;
if ( $section != null ) $configDir .= $section.'/';
if ( $key != null ) {
if ( $section != 'root' ) $configDir .= $section.'/'; //默认加载配置根目录的配置文档
if ( $key != '*' ) {
$configFile = $configDir.$key.'.config.php';
return include $configFile;
self::$CONFIGS[$section][$key] = include $configFile;
} else {
chdir($configDir);
$configFiles = glob("*.config.php");
Expand All @@ -99,7 108,9 @@ public static function config( $key=null, $section=null ) {
$tempConfig = include APP_CONFIG_PATH.$file;
$configs = array_merge($configs, $tempConfig);
}
return $configs;
self::$CONFIGS[$section][$key] = &$configs;
}

return self::$CONFIGS[$section][$key];
}
}
61 changes: 57 additions & 4 deletions framework/herosphp/core/WebApplication.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 13,15 @@
namespace herosphp\core;

use herosphp\core\interfaces\IApplication;
use herosphp\http\HttpRequest;

Loader::import('core.interfaces.IApplication', IMPORT_FRAME);

class WebApplication implements IApplication {

/**
* http 请求对象
* @var \herosphp\core\HttpRequest
* @var \herosphp\http\HttpRequest
*/
private $httpRequest;

Expand All @@ -38,8 41,18 @@ private function __construct() {}

/**
* 执行应用程序
* @param array 系统配置信息
*/
public function execute() {
public function execute( $configs ) {

$this->setConfigs($configs);
$this->requestInit();

//invoker 方法调用
$this->actionInvoke();

//发送响应
$this->sendResponse();

}

Expand All @@ -56,7 69,8 @@ public static function getInstance() {
*/
public function requestInit()
{

$this->httpRequest = new HttpRequest();
$this->httpRequest->parseURL();
}

/**
Expand All @@ -75,5 89,44 @@ public function sendResponse()
// TODO: Implement sendResponse() method.
}

/**
* @param array $configs
*/
public function setConfigs($configs)
{
$this->configs = $configs;
}

/**
* @return array
*/
public function getConfigs()
{
return $this->configs;
}

/**
* 获取指定key的配置值
* @param $key 配置key
*/
public function getConfig( $key ) {
return $this->configs[$key];
}

/**
* @param \herosphp\http\HttpRequest $httpRequest
*/
public function setHttpRequest($httpRequest)
{
$this->httpRequest = $httpRequest;
}

/**
* @return \herosphp\http\HttpRequest
*/
public function getHttpRequest()
{
return $this->httpRequest;
}

}
}
Loading

0 comments on commit a289a0c

Please sign in to comment.