diff --git a/app/app.php b/app/app.php index f1b5389..0931b58 100644 --- a/app/app.php +++ b/app/app.php @@ -7,4 +7,4 @@ */ /** Application Default Entrance */ -require __DIR__."/common.php"; +require __DIR__."/common.php"; \ No newline at end of file diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index 98fbe81..42e4a31 100644 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -8,6 +8,7 @@ namespace app\index\controller; + class Index { public function index(){ diff --git a/config/database.php b/config/database.php index edf2e41..fb935cf 100644 --- a/config/database.php +++ b/config/database.php @@ -13,7 +13,7 @@ return [ 'driver' => 'mysql', 'host' => 'localhost', - 'database' => 'mvctest', + 'database' => 'test', 'username' => 'root', 'password' => 'root', 'charset' => 'utf8', diff --git a/config/general.php b/config/general.php index 6dc6bf0..fd3c37a 100644 --- a/config/general.php +++ b/config/general.php @@ -53,7 +53,7 @@ 'xml_item_node' => 'item', 'xml_item_key' => 'id', - 'enable_servers' => true, + 'enable_servers' => false, ], /** @@ -108,7 +108,7 @@ * Task Queue System Settings */ 'task' => [ - 'enable' => true, + 'enable' => false, 'server_driver' => 'db', 'client_driver' => 'db', 'port' => 2073, diff --git a/config/vhost.php b/config/vhost.php index c72d691..c87a59a 100644 --- a/config/vhost.php +++ b/config/vhost.php @@ -10,5 +10,5 @@ * VHost Settings */ return [ - 'localhost' => 'localhost' + 'localhost,127.0.0.1' => 'localhost' ]; \ No newline at end of file diff --git a/route/localhost.php b/route/localhost.php index 9e63434..d796431 100644 --- a/route/localhost.php +++ b/route/localhost.php @@ -8,5 +8,5 @@ /** Routing rules for localhost */ return [ - '/' => 'index/Index/index', + '/' => "index/Index/index" ]; \ No newline at end of file diff --git a/start.php b/start.php index 1695f0b..c2e2bb7 100644 --- a/start.php +++ b/start.php @@ -5,9 +5,8 @@ * Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) * Author: Dizy */ - -/** Server CLI Entrance */ namespace think; define('APP_PATH', __DIR__ . '/app/'); //Define the application directory -require __DIR__ . '/thinkworker/start.php'; //Require the bootstrap file \ No newline at end of file +require __DIR__ . '/thinkworker/start.php'; //Require the bootstrap file +/** Server CLI Entrance */ diff --git a/thinkworker/common.php b/thinkworker/common.php index bd800bb..8977b14 100644 --- a/thinkworker/common.php +++ b/thinkworker/common.php @@ -172,6 +172,17 @@ function think_core_shorten_filepath($filepath) } } +if(!function_exists("think_core_clean_hostname")) { + function think_core_clean_hostname($hostname) + { + $pos = strpos($hostname, ":"); + if($pos===false){ + return $hostname; + } + return substr($hostname, 0, $pos); + } +} + if(!function_exists("think_core_form_tracing_table_filepath")) { function think_core_form_tracing_table_filepath($trace) { @@ -210,6 +221,22 @@ function think_core_get_all_extensions() } } +function think_core_rtrim($text, $niddle){ + $text = trim($text); + $len = strlen($text); + $nlen = strlen($niddle); + $pos = strrpos($text, $niddle); + if($pos!==false){ + if($len-$pos == $nlen){ + return substr($text, 0, -$nlen); + }else{ + return $text; + } + }else{ + return $text; + } +} + if(!function_exists("think_core_charset_auto_revert")) { function think_core_charset_auto_revert($msg) { @@ -289,7 +316,7 @@ function think_core_route_basic_path_match($pattern, $uri, &$isMatched, $suffix $pattern = rtrim($pattern, "/")."/"; if(substr($uri, -strlen(".".$suffix)) == ".".$suffix){ if(substr($uri, -strlen(".".$suffix) -1, 1) != "/"){ - $uri = rtrim($uri, ".".$suffix); + $uri = think_core_rtrim($uri, ".".$suffix); } } $uri = rtrim(merge_slashes($uri), "/")."/"; @@ -348,7 +375,7 @@ function think_core_route_vars_path_match($pattern, $uri, &$isMatched, $suffix = $pattern = rtrim($pattern, "/")."/"; if(substr($uri, -strlen(".".$suffix)) == ".".$suffix){ if(substr($uri, -strlen(".".$suffix) -1, 1) != "/"){ - $uri = rtrim($uri, ".".$suffix); + $uri = think_core_rtrim($uri, ".".$suffix); } } $uri = rtrim(merge_slashes($uri), "/")."/"; @@ -564,4 +591,4 @@ function think_tool_get_rand_sid() { $TW_CORE_RAND_SID = rand(); return $TW_CORE_RAND_SID; } -} \ No newline at end of file +} diff --git a/thinkworker/lib/think/Config.php b/thinkworker/lib/think/Config.php index b0ac7cb..f452592 100644 --- a/thinkworker/lib/think/Config.php +++ b/thinkworker/lib/think/Config.php @@ -23,7 +23,7 @@ public static function _init(){ { $lastDsPos = strrpos($configFile, DS); $rangeName = substr($configFile, $lastDsPos + 1); - $rangeName = strtolower(rtrim($rangeName, CONF_EXT)); + $rangeName = strtolower(think_core_rtrim($rangeName, CONF_EXT)); self::$config[$rangeName] = include($configFile); } } diff --git a/thinkworker/lib/think/Db.php b/thinkworker/lib/think/Db.php index 2559b5d..da4aa8d 100644 --- a/thinkworker/lib/think/Db.php +++ b/thinkworker/lib/think/Db.php @@ -144,7 +144,7 @@ public static function table($table) public static function query() { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->query(); + return $TW_ENV_CAPSULE::query(); } /** @@ -158,7 +158,7 @@ public static function query() public static function selectOne($query, $bindings = [], $useReadPdo = true) { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->selectOne($query, $bindings, $useReadPdo); + return $TW_ENV_CAPSULE::selectOne($query, $bindings, $useReadPdo); } /** @@ -171,7 +171,7 @@ public static function selectOne($query, $bindings = [], $useReadPdo = true) public static function selectFromWriteConnection($query, $bindings = []) { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->selectFromWriteConnection($query, $bindings); + return $TW_ENV_CAPSULE::selectFromWriteConnection($query, $bindings); } /** @@ -185,7 +185,7 @@ public static function selectFromWriteConnection($query, $bindings = []) public static function select($query, $bindings = [], $useReadPdo = true) { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->select($query, $bindings, $useReadPdo); + return $TW_ENV_CAPSULE::select($query, $bindings, $useReadPdo); } /** @@ -199,7 +199,7 @@ public static function select($query, $bindings = [], $useReadPdo = true) public static function cursor($query, $bindings = [], $useReadPdo = true) { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->cursor($query, $bindings, $useReadPdo); + return $TW_ENV_CAPSULE->connection()->cursor($query, $bindings, $useReadPdo); } /** @@ -212,7 +212,7 @@ public static function cursor($query, $bindings = [], $useReadPdo = true) public static function insert($query, $bindings = []) { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->insert($query, $bindings); + return $TW_ENV_CAPSULE->connection()->insert($query, $bindings); } /** @@ -225,7 +225,7 @@ public static function insert($query, $bindings = []) public static function update($query, $bindings = []) { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->update($query, $bindings); + return $TW_ENV_CAPSULE::update($query, $bindings); } /** @@ -238,7 +238,7 @@ public static function update($query, $bindings = []) public static function delete($query, $bindings = []) { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->delete($query, $bindings); + return $TW_ENV_CAPSULE::delete($query, $bindings); } /** @@ -251,7 +251,7 @@ public static function delete($query, $bindings = []) public static function statement($query, $bindings = []) { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->statement($query, $bindings); + return $TW_ENV_CAPSULE::statement($query, $bindings); } /** @@ -264,7 +264,7 @@ public static function statement($query, $bindings = []) public static function affectingStatement($query, $bindings = []) { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->affectingStatement($query, $bindings); + return $TW_ENV_CAPSULE::affectingStatement($query, $bindings); } /** @@ -276,7 +276,7 @@ public static function affectingStatement($query, $bindings = []) public static function unprepared($query) { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->unprepared($query); + return $TW_ENV_CAPSULE::unprepared($query); } /** @@ -288,7 +288,7 @@ public static function unprepared($query) public static function pretend(Closure $callback) { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->pretend($callback); + return $TW_ENV_CAPSULE::pretend($callback); } /** @@ -301,7 +301,7 @@ public static function pretend(Closure $callback) public static function bindValues($statement, $bindings) { global $TW_ENV_CAPSULE; - $TW_ENV_CAPSULE->bindValues($statement, $bindings); + $TW_ENV_CAPSULE::bindValues($statement, $bindings); } /** @@ -313,7 +313,7 @@ public static function bindValues($statement, $bindings) public static function prepareBindings(array $bindings) { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->prepareBindings($bindings); + return $TW_ENV_CAPSULE::prepareBindings($bindings); } /** @@ -327,7 +327,7 @@ public static function prepareBindings(array $bindings) public static function logQuery($query, $bindings, $time = null) { global $TW_ENV_CAPSULE; - $TW_ENV_CAPSULE->logQuery($query, $bindings, $time); + $TW_ENV_CAPSULE::logQuery($query, $bindings, $time); } /** @@ -340,7 +340,7 @@ public static function logQuery($query, $bindings, $time = null) public static function reconnect() { global $TW_ENV_CAPSULE; - $TW_ENV_CAPSULE->reconnect(); + $TW_ENV_CAPSULE::reconnect(); } /** @@ -351,7 +351,7 @@ public static function reconnect() public static function disconnect() { global $TW_ENV_CAPSULE; - $TW_ENV_CAPSULE->disconnect(); + $TW_ENV_CAPSULE::disconnect(); } /** @@ -363,7 +363,7 @@ public static function disconnect() public static function raw($value) { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->raw($value); + return $TW_ENV_CAPSULE::raw($value); } /** @@ -375,7 +375,7 @@ public static function raw($value) public static function recordsHaveBeenModified($value = true) { global $TW_ENV_CAPSULE; - $TW_ENV_CAPSULE->recordsHaveBeenModified($value); + $TW_ENV_CAPSULE::recordsHaveBeenModified($value); } /** @@ -386,7 +386,7 @@ public static function recordsHaveBeenModified($value = true) public static function getPdo() { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->getPdo(); + return $TW_ENV_CAPSULE::getPdo(); } /** @@ -397,7 +397,7 @@ public static function getPdo() public static function getReadPdo() { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->getReadPdo(); + return $TW_ENV_CAPSULE::getReadPdo(); } /** @@ -409,7 +409,7 @@ public static function getReadPdo() public static function setPdo($pdo) { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->setPdo($pdo); + return $TW_ENV_CAPSULE::setPdo($pdo); } /** @@ -421,7 +421,7 @@ public static function setPdo($pdo) public static function setReadPdo($pdo) { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->setReadPdo($pdo); + return $TW_ENV_CAPSULE::setReadPdo($pdo); } /** @@ -433,7 +433,7 @@ public static function setReadPdo($pdo) public static function setReconnector(callable $reconnector) { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->setReconnector($reconnector); + return $TW_ENV_CAPSULE::setReconnector($reconnector); } /** @@ -444,7 +444,7 @@ public static function setReconnector(callable $reconnector) public static function getName() { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->getName(); + return $TW_ENV_CAPSULE::getName(); } /** @@ -456,7 +456,7 @@ public static function getName() public static function getConfig($option = null) { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->getConfig($option); + return $TW_ENV_CAPSULE::getConfig($option); } /** @@ -467,7 +467,7 @@ public static function getConfig($option = null) public static function getDriverName() { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->getDriverName(); + return $TW_ENV_CAPSULE::getDriverName(); } /** @@ -478,7 +478,7 @@ public static function getDriverName() public static function getQueryGrammar() { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->getQueryGrammar(); + return $TW_ENV_CAPSULE::getQueryGrammar(); } /** @@ -490,7 +490,7 @@ public static function getQueryGrammar() public static function setQueryGrammar(\Illuminate\Database\Query\Grammars\Grammar $grammar) { global $TW_ENV_CAPSULE; - $TW_ENV_CAPSULE->setQueryGrammar($grammar); + $TW_ENV_CAPSULE::setQueryGrammar($grammar); } /** @@ -501,7 +501,7 @@ public static function setQueryGrammar(\Illuminate\Database\Query\Grammars\Gramm public static function getSchemaGrammar() { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->getSchemaGrammar(); + return $TW_ENV_CAPSULE::getSchemaGrammar(); } /** @@ -513,7 +513,7 @@ public static function getSchemaGrammar() public static function setSchemaGrammar(\Illuminate\Database\Schema\Grammars\Grammar $grammar) { global $TW_ENV_CAPSULE; - $TW_ENV_CAPSULE->setSchemaGrammar(); + $TW_ENV_CAPSULE::setSchemaGrammar(); } /** @@ -524,7 +524,7 @@ public static function setSchemaGrammar(\Illuminate\Database\Schema\Grammars\Gra public static function getPostProcessor() { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->getPostProcessor(); + return $TW_ENV_CAPSULE::getPostProcessor(); } /** @@ -536,7 +536,7 @@ public static function getPostProcessor() public static function setPostProcessor(Processor $processor) { global $TW_ENV_CAPSULE; - $TW_ENV_CAPSULE->setPostProcessor($processor); + $TW_ENV_CAPSULE::setPostProcessor($processor); } /** @@ -547,7 +547,7 @@ public static function setPostProcessor(Processor $processor) public static function pretending() { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->pretending(); + return $TW_ENV_CAPSULE::pretending(); } /** @@ -558,7 +558,7 @@ public static function pretending() public static function getQueryLog() { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->getQueryLog(); + return $TW_ENV_CAPSULE::getQueryLog(); } /** @@ -569,7 +569,7 @@ public static function getQueryLog() public static function flushQueryLog() { global $TW_ENV_CAPSULE; - $TW_ENV_CAPSULE->flushQueryLog(); + $TW_ENV_CAPSULE::flushQueryLog(); } /** @@ -580,7 +580,7 @@ public static function flushQueryLog() public static function enableQueryLog() { global $TW_ENV_CAPSULE; - $TW_ENV_CAPSULE->enableQueryLog(); + $TW_ENV_CAPSULE::enableQueryLog(); } /** @@ -591,7 +591,7 @@ public static function enableQueryLog() public static function disableQueryLog() { global $TW_ENV_CAPSULE; - $TW_ENV_CAPSULE->disableQueryLog(); + $TW_ENV_CAPSULE::disableQueryLog(); } /** @@ -602,7 +602,7 @@ public static function disableQueryLog() public static function logging() { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->logging(); + return $TW_ENV_CAPSULE::logging(); } @@ -615,7 +615,7 @@ public static function logging() public static function getDatabaseName() { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->getDatabaseName(); + return $TW_ENV_CAPSULE::getDatabaseName(); } /** @@ -627,7 +627,7 @@ public static function getDatabaseName() public static function setDatabaseName($database) { global $TW_ENV_CAPSULE; - $TW_ENV_CAPSULE->setDatabaseName($database); + $TW_ENV_CAPSULE::setDatabaseName($database); } /** @@ -638,7 +638,7 @@ public static function setDatabaseName($database) public static function getTablePrefix() { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->getTablePrefix(); + return $TW_ENV_CAPSULE::getTablePrefix(); } /** @@ -650,7 +650,7 @@ public static function getTablePrefix() public static function setTablePrefix($prefix) { global $TW_ENV_CAPSULE; - $TW_ENV_CAPSULE->setTablePrefix($prefix); + $TW_ENV_CAPSULE::setTablePrefix($prefix); } /** @@ -662,7 +662,7 @@ public static function setTablePrefix($prefix) public static function withTablePrefix(Grammar $grammar) { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->withTablePrefix($grammar); + return $TW_ENV_CAPSULE::withTablePrefix($grammar); } /** @@ -675,7 +675,7 @@ public static function withTablePrefix(Grammar $grammar) public static function resolverFor($driver, Closure $callback) { global $TW_ENV_CAPSULE; - $TW_ENV_CAPSULE->resolverFor($driver, $callback); + $TW_ENV_CAPSULE::resolverFor($driver, $callback); } /** @@ -687,7 +687,7 @@ public static function resolverFor($driver, Closure $callback) public static function getResolver($driver) { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->getResolver($driver); + return $TW_ENV_CAPSULE::getResolver($driver); } @@ -702,7 +702,7 @@ public static function getResolver($driver) */ public static function transaction(Closure $callback, $attempts = 1){ global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->transaction($callback, $attempts); + return $TW_ENV_CAPSULE::transaction($callback, $attempts); } /** @@ -712,7 +712,7 @@ public static function transaction(Closure $callback, $attempts = 1){ */ public static function beginTransaction(){ global $TW_ENV_CAPSULE; - $TW_ENV_CAPSULE->beginTransaction(); + $TW_ENV_CAPSULE::beginTransaction(); } /** @@ -722,7 +722,7 @@ public static function beginTransaction(){ */ public static function commit(){ global $TW_ENV_CAPSULE; - $TW_ENV_CAPSULE->commit(); + $TW_ENV_CAPSULE::commit(); } /** @@ -732,7 +732,7 @@ public static function commit(){ */ public static function rollBack(){ global $TW_ENV_CAPSULE; - $TW_ENV_CAPSULE->rollBack(); + $TW_ENV_CAPSULE::rollBack(); } /** @@ -742,7 +742,7 @@ public static function rollBack(){ */ public static function transactionLevel(){ global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->transactionLevel(); + return $TW_ENV_CAPSULE::transactionLevel(); } /** @@ -753,7 +753,7 @@ public static function transactionLevel(){ public function getDatabaseManager() { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->getDatabaseManager(); + return $TW_ENV_CAPSULE::getDatabaseManager(); } /** @@ -766,6 +766,6 @@ public function getDatabaseManager() public static function __callStatic($method, $parameters) { global $TW_ENV_CAPSULE; - return $TW_ENV_CAPSULE->$method(...$parameters); + return $TW_ENV_CAPSULE->connection()->$method(...$parameters); } } \ No newline at end of file diff --git a/thinkworker/lib/think/Request.php b/thinkworker/lib/think/Request.php index 6ee5a15..5e8849a 100644 --- a/thinkworker/lib/think/Request.php +++ b/thinkworker/lib/think/Request.php @@ -125,7 +125,7 @@ public function __construct($data) foreach ($data['files'] as $fileinfo){ array_push($this->files, new File($fileinfo)); } - $this->hostname = $this->headers['HTTP_HOST']; + $this->hostname = think_core_clean_hostname($this->headers['HTTP_HOST']); $this->fullRequestUri = $this->headers['REQUEST_URI']; $this->requestUri = $this->headers['REQUEST_URI']; if(!!strpos($this->requestUri,"?")){ diff --git a/thinkworker/lib/think/StaticDispatcher.php b/thinkworker/lib/think/StaticDispatcher.php index 23454aa..d50c672 100644 --- a/thinkworker/lib/think/StaticDispatcher.php +++ b/thinkworker/lib/think/StaticDispatcher.php @@ -8,7 +8,7 @@ namespace think; - +//TODO: Caching use Workerman\Protocols\Http; class StaticDispatcher diff --git a/thinkworker/lib/think/View.php b/thinkworker/lib/think/View.php index 7866b45..0a72933 100644 --- a/thinkworker/lib/think/View.php +++ b/thinkworker/lib/think/View.php @@ -45,7 +45,7 @@ public function __construct($appName, $viewfile = null, $values = null) $this->enginePrepare(); if(is_null($viewfile) || is_array($viewfile)){ if(!strpos($appName, "@")){ - $viewfile = rtrim($appName, ".".$this->fileExt).".".$this->fileExt; + $viewfile = think_core_rtrim($appName, ".".$this->fileExt).".".$this->fileExt; $viewfile = fix_slashes_in_path($viewfile); if(is_file($viewfile)){ $this->filePath = $viewfile; @@ -116,7 +116,7 @@ private function filepathPrepare($appName, $viewfile){ * @return string */ private function parseTemplateFilepath($appName, $viewfile){ - $viewfile = rtrim($viewfile, ".".$this->fileExt); + $viewfile = think_core_rtrim($viewfile, ".".$this->fileExt); return fix_slashes_in_path(APP_PATH.$appName.DS."view".DS.$viewfile.".".$this->fileExt); } diff --git a/thinkworker/lib/think/exception/ClosureException.php b/thinkworker/lib/think/exception/ClosureException.php index d58665d..7724dfb 100644 --- a/thinkworker/lib/think/exception/ClosureException.php +++ b/thinkworker/lib/think/exception/ClosureException.php @@ -11,6 +11,12 @@ class ClosureException extends HttpException { + /** + * ClosureException constructor. + * + * @param \Exception $origin + * @param string $message + */ public function __construct($origin, $message = "") { if(!is_null($origin) && is_object($origin)){ @@ -24,6 +30,11 @@ public function __construct($origin, $message = "") } } + /** + * Get Http Return in Debug Mode + * + * @return string + */ private function getDebugHttpBody(){ return $this->loadTemplate("TracingPage", [ 'title' => think_core_lang("tracing page closure process error"), @@ -45,6 +56,11 @@ private function getDebugHttpBody(){ ]); } + /** + * Get Http Return in Production Mode + * + * @return string + */ private function getProHttpBody(){ return $this->loadTemplate("ErrorPage", [ 'title'=>think_core_lang('page error title'), diff --git a/thinkworker/lib/think/exception/ControllerException.php b/thinkworker/lib/think/exception/ControllerException.php index b6d3f0f..8c6ef9b 100644 --- a/thinkworker/lib/think/exception/ControllerException.php +++ b/thinkworker/lib/think/exception/ControllerException.php @@ -12,7 +12,19 @@ class ControllerException extends HttpException { + /** + * @var string + */ protected $controller, $method; + + /** + * ControllerException constructor. + * + * @param \Exception $origin + * @param string $controller + * @param bool $method + * @param string $message + */ public function __construct($origin, $controller, $method, $message = "") { if(!is_null($origin) && is_object($origin)){ @@ -28,6 +40,11 @@ public function __construct($origin, $controller, $method, $message = "") } } + /** + * Get Http Return in Debug Mode + * + * @return string + */ private function getDebugHttpBody(){ return $this->loadTemplate("TracingPage", [ 'title' => think_core_lang("tracing page controller process error"), @@ -49,6 +66,11 @@ private function getDebugHttpBody(){ ]); } + /** + * Get Http Return in Production Mode + * + * @return string + */ private function getProHttpBody(){ return $this->loadTemplate("ErrorPage", [ 'title'=>think_core_lang('page error title'), diff --git a/thinkworker/lib/think/exception/ControllerNotFoundException.php b/thinkworker/lib/think/exception/ControllerNotFoundException.php index 0ced3aa..67fe89e 100644 --- a/thinkworker/lib/think/exception/ControllerNotFoundException.php +++ b/thinkworker/lib/think/exception/ControllerNotFoundException.php @@ -11,7 +11,18 @@ class ControllerNotFoundException extends HttpException { + /** + * @var string + */ protected $controller; + + /** + * ControllerNotFoundException constructor. + * + * @param \Exception $origin + * @param string $controller + * @param string $message + */ public function __construct($origin, $controller, $message = "") { $message = "Controller Not Found: ".$controller; @@ -24,6 +35,11 @@ public function __construct($origin, $controller, $message = "") } } + /** + * Get Http Return in Debug Mode + * + * @return string + */ private function getDebugHttpBody(){ return $this->loadTemplate("TracingPage", [ 'title' => think_core_lang("tracing page controller not found"), @@ -45,6 +61,11 @@ private function getDebugHttpBody(){ ]); } + /** + * Get Http Return in Production Mode + * + * @return string + */ private function getProHttpBody(){ return $this->loadTemplate("ErrorPage", [ 'title'=>think_core_lang("page not found title"), diff --git a/thinkworker/lib/think/exception/DbException.php b/thinkworker/lib/think/exception/DbException.php index 6f065c6..fa1e7fa 100644 --- a/thinkworker/lib/think/exception/DbException.php +++ b/thinkworker/lib/think/exception/DbException.php @@ -11,7 +11,24 @@ class DbException extends HttpException { - protected $controller, $method; + /** + * @var string + */ + protected $controller; + + /** + * @var string + */ + protected $method; + + /** + * DbException constructor. + * + * @param \Exception $origin + * @param string $controller + * @param string $method + * @param string $message + */ public function __construct($origin, $controller="", $method="", $message = "") { if(!is_null($origin) && is_object($origin)){ @@ -27,6 +44,11 @@ public function __construct($origin, $controller="", $method="", $message = "") } } + /** + * Get Http Return in Debug Mode + * + * @return string + */ private function getDebugHttpBody(){ return $this->loadTemplate("TracingPage", [ 'title' => think_core_lang("tracing page db error"), @@ -48,6 +70,11 @@ private function getDebugHttpBody(){ ]); } + /** + * Get Http Return in Production Mode + * + * @return string + */ private function getProHttpBody(){ return $this->loadTemplate("ErrorPage", [ 'title'=>think_core_lang('page error title'), diff --git a/thinkworker/lib/think/exception/FatalException.php b/thinkworker/lib/think/exception/FatalException.php index fee48df..cc8b126 100644 --- a/thinkworker/lib/think/exception/FatalException.php +++ b/thinkworker/lib/think/exception/FatalException.php @@ -13,6 +13,13 @@ class FatalException extends \Exception { + /** + * FatalException constructor. + * + * @param string $message + * @param int $code + * @param Throwable|null $previous + */ public function __construct($message = "", $code = 0, Throwable $previous = null) { parent::__construct($message, $code, $previous); diff --git a/thinkworker/lib/think/exception/HttpException.php b/thinkworker/lib/think/exception/HttpException.php index e3addb6..1f2f96a 100644 --- a/thinkworker/lib/think/exception/HttpException.php +++ b/thinkworker/lib/think/exception/HttpException.php @@ -14,8 +14,34 @@ class HttpException extends \Exception { - private $debugOnly, $httpBody="", $statusCode = 400; + /** + * @var bool + */ + private $debugOnly; + + /** + * @var string + */ + private $httpBody=""; + + /** + * @var int + */ + private $statusCode = 400; + + /** + * @var null|\Exception + */ protected $origin = null; + + /** + * HttpException constructor. + * + * @param string $statusCode + * @param string $message + * @param bool $debugOnly + * @param \Exception|null $origin + */ public function __construct($statusCode, $message = "", $debugOnly = true, $origin = null) { $this->debugOnly = $debugOnly; @@ -25,26 +51,60 @@ public function __construct($statusCode, $message = "", $debugOnly = true, $orig parent::__construct($message, 0, null); } + /** + * Set original exception for tracing + * + * @param \Exception $e + * @return void + */ public function setOrigin($e){ $this->origin = $e; } + /** + * Set Http return + * + * @param string $content + * @return void + */ public function setHttpBody($content){ $this->httpBody = $content; } + /** + * Get Http return content + * + * @return string + */ public function getHttpBody(){ return $this->httpBody; } + /** + * Get status code + * + * @return int + */ public function getStatusCode(){ return $this->statusCode; } + /** + * Whether this exception is detailed in debug mode only + * + * @return bool + */ public function isDebugOnly(){ return $this->debugOnly; } + /** + * Load core template file content + * + * @param string $template + * @param array $vars + * @return string + */ public function loadTemplate($template, $vars = []){ $template = file_get_contents(THINK_PATH."tpl".DS.$template.".html"); if($template!=false && is_array($vars)){ @@ -57,11 +117,21 @@ public function loadTemplate($template, $vars = []){ } } + /** + * Generate error position description for tracing page + * + * @return string + */ public function formErrorPos(){ $traceSrc = is_null($this->origin)?$this:$this->origin; return fix_slashes_in_path($traceSrc->getFile())." (".$traceSrc->getLine().think_core_lang("tracing page line")."):"; } + /** + * Generate error message description for tracing page + * + * @return string + */ public function formErrorMsg(){ $traceSrc = is_null($this->origin)?$this:$this->origin; $head = ""; @@ -75,6 +145,11 @@ public function formErrorMsg(){ return $msg; } + /** + * Generate error tracing table for tracing page + * + * @return string + */ public function formTracingTable(){ $traceSrc = is_null($this->origin)?$this:$this->origin; $tableHtml = ""; @@ -96,6 +171,11 @@ public function formTracingTable(){ return $tableHtml; } + /** + * Generate request details table for tracing page + * + * @return string + */ public function formRequestTable(){ $tableHtml = "".think_core_lang("tracing page null").""; $request = envar("request"); @@ -115,6 +195,11 @@ public function formRequestTable(){ return $tableHtml; } + /** + * Generate server info table for tracing page + * + * @return string + */ public function formEnvTable(){ $tableHtml = ""; $tableHtml .= "".think_core_lang("tracing page env system")."".php_uname().""; diff --git a/thinkworker/lib/think/exception/MethodNotFoundException.php b/thinkworker/lib/think/exception/MethodNotFoundException.php index f8b63e4..2f97473 100644 --- a/thinkworker/lib/think/exception/MethodNotFoundException.php +++ b/thinkworker/lib/think/exception/MethodNotFoundException.php @@ -11,7 +11,24 @@ class MethodNotFoundException extends HttpException { - protected $controller, $method; + /** + * @var string + */ + protected $controller; + + /** + * @var bool + */ + protected $method; + + /** + * MethodNotFoundException constructor. + * + * @param \Exception $origin + * @param string $controller + * @param bool $method + * @param string $message + */ public function __construct($origin, $controller, $method, $message = "") { $message = "Method Not Found: ".$controller."->".$method."()" ; @@ -25,7 +42,11 @@ public function __construct($origin, $controller, $method, $message = "") } } - + /** + * Get Http Return in Debug Mode + * + * @return string + */ private function getDebugHttpBody(){ return $this->loadTemplate("TracingPage", [ 'title' => think_core_lang("tracing page method not found"), @@ -47,6 +68,11 @@ private function getDebugHttpBody(){ ]); } + /** + * Get Http Return in Production Mode + * + * @return string + */ private function getProHttpBody(){ return $this->loadTemplate("ErrorPage", [ 'title'=>think_core_lang("page not found title"), diff --git a/thinkworker/lib/think/exception/RouteNotFoundException.php b/thinkworker/lib/think/exception/RouteNotFoundException.php index 0960b4d..016c7a1 100644 --- a/thinkworker/lib/think/exception/RouteNotFoundException.php +++ b/thinkworker/lib/think/exception/RouteNotFoundException.php @@ -11,7 +11,18 @@ class RouteNotFoundException extends HttpException { + /** + * @var string + */ protected $uri; + + /** + * RouteNotFoundException constructor. + * + * @param \Exception $origin + * @param string $uri + * @param string $message + */ public function __construct($origin, $uri, $message = "") { $message = "Uri Not Matched: ".$uri; @@ -24,6 +35,11 @@ public function __construct($origin, $uri, $message = "") } } + /** + * Get Http Return in Debug Mode + * + * @return string + */ private function getDebugHttpBody(){ return $this->loadTemplate("TracingPage", [ 'title' => think_core_lang("tracing page route not found"), @@ -45,6 +61,11 @@ private function getDebugHttpBody(){ ]); } + /** + * Get Http Return in Production Mode + * + * @return string + */ private function getProHttpBody(){ return $this->loadTemplate("ErrorPage", [ 'title'=>think_core_lang("page not found title"), diff --git a/thinkworker/lib/think/exception/SyntaxParseException.php b/thinkworker/lib/think/exception/SyntaxParseException.php index 2143f4d..e2405de 100644 --- a/thinkworker/lib/think/exception/SyntaxParseException.php +++ b/thinkworker/lib/think/exception/SyntaxParseException.php @@ -11,7 +11,17 @@ class SyntaxParseException extends HttpException { + /** + * @var string + */ protected $filepath; + + /** + * SyntaxParseException constructor. + * + * @param string $filepath + * @param string $message + */ public function __construct($filepath, $message = "") { $message = "Syntax Parse Error: ".$filepath."\n".$message; @@ -24,7 +34,11 @@ public function __construct($filepath, $message = "") } } - + /** + * Get Http Return in Debug Mode + * + * @return string + */ private function getDebugHttpBody(){ return $this->loadTemplate("TracingPage", [ 'title' => think_core_lang("tracing page syntax parse error"), @@ -46,6 +60,11 @@ private function getDebugHttpBody(){ ]); } + /** + * Get Http Return in Production Mode + * + * @return string + */ private function getProHttpBody(){ return $this->loadTemplate("ErrorPage", [ 'title'=>think_core_lang('page error title'), diff --git a/thinkworker/lib/think/exception/UnknownException.php b/thinkworker/lib/think/exception/UnknownException.php index a204579..d6087b1 100644 --- a/thinkworker/lib/think/exception/UnknownException.php +++ b/thinkworker/lib/think/exception/UnknownException.php @@ -11,6 +11,12 @@ class UnknownException extends HttpException { + /** + * UnknownException constructor. + * + * @param string $origin + * @param string $message + */ public function __construct($origin, $message = "") { if(!is_null($origin) && is_object($origin)){ @@ -24,6 +30,11 @@ public function __construct($origin, $message = "") } } + /** + * Get Http Return in Debug Mode + * + * @return string + */ private function getDebugHttpBody(){ return $this->loadTemplate("TracingPage", [ 'title' => think_core_lang("tracing page unknown error"), @@ -45,6 +56,11 @@ private function getDebugHttpBody(){ ]); } + /** + * Get Http Return in Production Mode + * + * @return string + */ private function getProHttpBody(){ return $this->loadTemplate("ErrorPage", [ 'title'=>think_core_lang('page error title'), diff --git a/thinkworker/lib/think/exception/VHostNotFoundException.php b/thinkworker/lib/think/exception/VHostNotFoundException.php index 37f7877..8838da3 100644 --- a/thinkworker/lib/think/exception/VHostNotFoundException.php +++ b/thinkworker/lib/think/exception/VHostNotFoundException.php @@ -11,6 +11,10 @@ class VHostNotFoundException extends HttpException { + /** + * VHostNotFoundException constructor. + * @param string $message + */ public function __construct($message = "") { parent::__construct(400, $message, false); diff --git a/thinkworker/lib/think/log/Driver.php b/thinkworker/lib/think/log/Driver.php index 29397e1..00d66d1 100644 --- a/thinkworker/lib/think/log/Driver.php +++ b/thinkworker/lib/think/log/Driver.php @@ -11,6 +11,20 @@ interface Driver { - public function write($body); + + /** + * Logger Driver Init Interface method + * + * @param $config + * @return mixed + */ public function init($config); + + /** + * Logger Driver Write Interface method + * + * @param $body + * @return mixed + */ + public function write($body); } \ No newline at end of file diff --git a/thinkworker/lib/think/log/FileDriver.php b/thinkworker/lib/think/log/FileDriver.php index 86f8325..d7491d7 100644 --- a/thinkworker/lib/think/log/FileDriver.php +++ b/thinkworker/lib/think/log/FileDriver.php @@ -11,11 +11,23 @@ class FileDriver implements Driver { + /** + * FileDriver init method + * + * @param array $config + * @return void + */ public function init($config) { // TODO: Implement init() method. } + /** + * FileDriver write method + * + * @param string $body + * @return bool + */ public function write($body) { // TODO: Implement write() method. diff --git a/thinkworker/lib/think/route/SubRoute.php b/thinkworker/lib/think/route/SubRoute.php index 434743c..d4fd93a 100644 --- a/thinkworker/lib/think/route/SubRoute.php +++ b/thinkworker/lib/think/route/SubRoute.php @@ -11,9 +11,22 @@ class SubRoute { + /** + * @var array + */ protected $mapRules = []; + + /** + * @var null|string + */ protected $anyDefault = null; + + /** + * @var null|string + */ protected $suffix = null; + + protected $cache = null; public function __construct($anyDefault = null, $suffix = null, $cache = null) { diff --git a/thinkworker/lib/think/server/Loader.php b/thinkworker/lib/think/server/Loader.php index d969521..6da11dc 100644 --- a/thinkworker/lib/think/server/Loader.php +++ b/thinkworker/lib/think/server/Loader.php @@ -51,7 +51,7 @@ public static function resolveNamespace($serverFile){ $serverFileLen = strlen($serverFile); $lastDsPos = strrpos($serverFile, DS); $serverName = substr($serverFile, $lastDsPos + 1); - $serverName = rtrim($serverName, EXT); + $serverName = think_core_rtrim($serverName, EXT); $secLastDsPos = strrpos($serverFile, DS, -($serverFileLen - $lastDsPos)-1); $thrLastDsPos = strrpos($serverFile, DS, -($serverFileLen-$secLastDsPos)-1); $appName = substr($serverFile, $thrLastDsPos+1, $secLastDsPos-$thrLastDsPos-1); diff --git a/thinkworker/lib/think/task/server/FileDriver.php b/thinkworker/lib/think/task/server/FileDriver.php index 879812b..4274a0e 100644 --- a/thinkworker/lib/think/task/server/FileDriver.php +++ b/thinkworker/lib/think/task/server/FileDriver.php @@ -228,7 +228,7 @@ private function moveTo($file, $path){ if(!$ret){ return false; } - $filename = rtrim($filename, ".tsk"); + $filename = think_core_rtrim($filename, ".tsk"); return $filename; } } \ No newline at end of file diff --git a/vendor/.gitignore b/vendor/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/vendor/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file