支持更改项目命名空间

This commit is contained in:
TOP糯米 2019-06-13 16:46:10 +08:00
parent 0dadd1dba6
commit be9a922391
5 changed files with 27 additions and 6 deletions

View File

@ -23,16 +23,21 @@ class Framework {
/**
* 执行
*/
public static function startApp() {
public static function startApp($callable = '') {
header('content-type: text/html; charset=utf-8');
if (is_callable($callable)) {
$callable(self::class);
}
// 指定时区
date_default_timezone_set('PRC');
self::debug();
self::frameworkPath();
self::appPath();
self::appNameSpace();
self::resourcePath();
self::frameworkPath();
require 'library/App.php';
App::start(self::$type, self::$defaultModule);
@ -74,6 +79,15 @@ class Framework {
}
}
public static function appNameSpace($namespace = '') {
if (!defined('APP_NS')) {
if (!$namespace) {
$namespace = 'app';
}
define('APP_NS', $namespace);
}
}
/**
* 指定Resource目录
* @param string $path

View File

@ -16,7 +16,7 @@ class App {
require 'Loader.php';
$loader = new Loader();
$loader->set('top', FRAMEWORK_PATH);
$loader->set('app', APP_PATH);
$loader->set(APP_NS, APP_PATH);
$loader->register();
// composer自动加载

View File

@ -1,4 +1,5 @@
<?php
namespace top\library\route;
use top\library\route\ifs\RouteIfs;
@ -8,12 +9,18 @@ class Command implements RouteIfs {
// 模块
public $module = '';
// 类名
public $class = '';
// 控制器
public $ctrl = '';
// 动作
public $action = '';
// 参数
public $param = [];
/**
* 暂时就这样吧(逃...
*/
@ -21,7 +28,7 @@ class Command implements RouteIfs {
// TODO Auto-generated method stub
$this->module = $this->module();
$this->ctrl = $this->ctrl();
$this->className = APPNS . '\\' . $this->module . '\\controller\\' . $this->ctrl;
$this->class = '\\' . APP_NS . '\\' . $this->module . '\\controller\\' . $this->ctrl;
$this->action = $this->action();
$this->param = $this->param();
}
@ -39,7 +46,7 @@ class Command implements RouteIfs {
*/
public function ctrl() {
// TODO Auto-generated method stub
return 'index';
return 'Index';
}
/**

View File

@ -169,7 +169,7 @@ class Pathinfo implements RouteIfs {
$this->uriArray = $this->processUriArray();
$this->module = $this->module();
$this->ctrl = $this->ctrl();
$this->class = '\app\\' . $this->module . '\\controller\\' . $this->ctrl;
$this->class = '\\' . APP_NS . '\\' . $this->module . '\\controller\\' . $this->ctrl;
$this->action = $this->action();
$this->param = $this->param();
unset($this->uriArray);