Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
dizys committed Dec 8, 2017
1 parent bd6bed6 commit 884e1d0
Show file tree
Hide file tree
Showing 21 changed files with 151 additions and 376 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ Model is powered by `Eloquent ORM` (from the famous Laravel)
Simply Run The Command: `php start.php start`
Then open your browser, visit localhost!

## To Do
- Maybe Validator? I guess?
## Now Progress
version: 1.0.0 alpha

[中文文档](http://docs.thinkworker.cn/#/zh-cn/guide/essentials/)
3 changes: 2 additions & 1 deletion app/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
* Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
* Author: Dizy <derzart@gmail.com>
*/
/** Application Default Entrance */
/** Application Default Entrance */
require __DIR__."common.php";
7 changes: 7 additions & 0 deletions app/common.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
/**
* ThinkWorker - THINK AND WORK FAST
* Copyright (c) 2017 http://thinkworker.cn All Rights Reserved.
* Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
* Author: Dizy <derzart@gmail.com>
*/
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"email": "derzart@gmail.com"
}],
"require": {
"php": ">=5.6.0",
"php": ">=5.4.0",
"illuminate/database": "*"
},
"autoload": {
Expand Down
12 changes: 12 additions & 0 deletions config/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
'caching' => true,
'cache_lifetime' => 0,
'debugging' => true,
'left_delimiter' => '{',
'right_delimiter' => '}',
'function_cacheable' => true,
'allow_php_tag' => true,
'debugging_ctrl' => 'URL',
'view_replace_str' => [
'__PUBLIC__' => '/',
Expand All @@ -84,5 +88,13 @@
'domain' => '',
'secure' => false,
'httponly' => ''
],

/**
* Log Settings
*/
'log' => [
'driver' => 'file',
'log_path' => LOG_PATH
]
];
2 changes: 1 addition & 1 deletion thinkworker/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use think\StaticDispatcher;

/** Server Core */
define('THINK_VERSION', '1.0.1');
define('THINK_VERSION', '1.0.0 alpha');
define('THINK_START_TIME', microtime(true));
define('THINK_START_MEM', memory_get_usage());
define('EXT', '.php');
Expand Down
23 changes: 21 additions & 2 deletions thinkworker/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,28 @@ function merge_slashes($string)
if(!function_exists("think_controller_analyze")) {
function think_controller_analyze($controller)
{
$controllerSep = explode("/", $controller);
$controller = rtrim($controller, "/");
$appNameSpace = config('think.default_app');
$appNameSpace = is_null($appNameSpace)?"index":$appNameSpace;
$controllerNameSpace = config('think.default_controller');
$controllerNameSpace = is_null($controllerNameSpace)?"Index":$controllerNameSpace;
$methodName = config('think.default_method');
$methodName = is_null($methodName)?"index":$methodName;

$controllerSep = explode("/", $controller);
$sepSize = sizeof($controllerSep);
$subController = false;
if($sepSize>3){
$controllerSepPre = [];
$controllerSepPre[0] = $controllerSep[0];
$controllerSepPre[1] = "";
for ($i=1; $i<$sepSize-1; $i++){
$controllerSepPre[1] .= $controllerSep[$i].($i == $sepSize-2?"":"\\");
}
$controllerSepPre[2] = $controllerSep[$sepSize-1];
$controllerSep = $controllerSepPre;
$subController = true;
}
if(isset($controllerSep[2])){
$appNameSpace = $controllerSep[0];
$controllerNameSpace = $controllerSep[1];
Expand All @@ -52,7 +66,12 @@ function think_controller_analyze($controller)
}else if(isset($controllerSep[0]) && !empty($controllerSep[0])){
$methodName = $controllerSep[0];
}
$controllerNameSpace[0] = strtoupper($controllerNameSpace[0]);
if($subController){
$slashPos = strrpos($controllerNameSpace, "\\");
$controllerNameSpace[$slashPos+1] = strtoupper($controllerNameSpace[$slashPos+1]);
}else{
$controllerNameSpace[0] = strtoupper($controllerNameSpace[0]);
}
$appRootNameSpace = config("app_namespace");
$appRootNameSpace = is_null($appRootNameSpace)?"app":$appRootNameSpace;
$classFullName = $appRootNameSpace."\\".$appNameSpace."\\controller\\".$controllerNameSpace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
$function = $tag_info[ 0 ];
// compile code
if (!is_array($function)) {
$output = "{$function}({$_params},\$_smarty_tpl)";
if($function instanceof Closure){
$output = "\"".$function($_attr)."\"";
}else{
$output = "{$function}({$_params},\$_smarty_tpl)";
}
} elseif (is_object($function[ 0 ])) {
$output =
"\$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl)";
Expand Down
18 changes: 18 additions & 0 deletions thinkworker/lib/think/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ public function clearAllAssign(){
}
}

public function replace($name, $value = null){
if($this->view) {
$this->view->replace($name, $value);
}
}

public function outReplace($name, $value = null){
if($this->view) {
$this->view->outReplace($name, $value);
}
}

public function registerFunction($functionName, $asName = null){
if($this->view) {
$this->view->registerFunction($functionName, $asName);
}
}

public function fetch($template = null){
if($this->view){
return $this->view->fetch($template);
Expand Down
2 changes: 1 addition & 1 deletion thinkworker/lib/think/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static function checkPHPSyntax($filename, &$error_msg){
$file_content = file_get_contents($filename);

$check_code = "return true; ?>";
$file_content = $check_code . $file_content . "<?php ";
$file_content = "<?php ".$check_code . $file_content ;

try{
if(!eval($file_content)) {
Expand Down
6 changes: 5 additions & 1 deletion thinkworker/lib/think/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ class Log
{
protected static $driver;
public static function _init($configs){
self::$driver = new FileDriver();
$driverName = isset($configs['driver'])?$configs['driver']:"file";
$driverName[0] = strtoupper($driverName[0]);
$engineFullName = "think\\log\\".$driverName."Driver";
self::$driver = new $engineFullName();
self::$driver->init($configs);
var_dump($engineFullName);
}

public static function log($type, $marker, $msg){
Expand Down
2 changes: 1 addition & 1 deletion thinkworker/lib/think/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private static function onMessage($connection, $data){
$eDesc = describeException($e);
Log::e($eDesc, "FatalException");
}catch (\Exception $e){
//Unknown Exception
//Unknown but not Fatal Exception
$ne = new UnknownException($e);
$resp->setHeader("HTTP", true, $ne->getStatusCode());
$resp->send($ne->getHttpBody());
Expand Down
8 changes: 8 additions & 0 deletions thinkworker/lib/think/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public function replace($name, $value = null){
$this->template->replace($name, $value);
}

public function outReplace($name, $value = null){
$this->template->outReplace($name, $value);
}

public function assign($name, $value = null){
$this->template->assign($name, $value);
}
Expand All @@ -92,6 +96,10 @@ public function clearAllAssign(){
$this->template->clearAllAssign();
}

public function registerFunction($functionName, $asName = null){
$this->template->registerFunction($functionName, $asName);
}

public function fetch($template = null){
if(is_null($template)){
return $this->template->fetch($this->filePath);
Expand Down
2 changes: 1 addition & 1 deletion thinkworker/lib/think/exception/HttpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function loadTemplate($template, $vars = []){

public function formErrorPos(){
$traceSrc = is_null($this->origin)?$this:$this->origin;
return $traceSrc->getFile()." (".$traceSrc->getLine().think_core_lang("tracing page line")."):";
return fix_slashes_in_path($traceSrc->getFile())." (".$traceSrc->getLine().think_core_lang("tracing page line")."):";
}

public function formErrorMsg(){
Expand Down
2 changes: 1 addition & 1 deletion thinkworker/lib/think/exception/SyntaxParseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private function getDebugHttpBody(){
'title' => think_core_lang("tracing page syntax parse error"),
'main_msg' => think_core_lang("tracing page syntax parse error"),
'main_msg_detail' => think_core_shorten_filepath($this->filepath),
'main_error_pos' => $this->filepath.":",
'main_error_pos' => fix_slashes_in_path($this->filepath).":",
'main_error_detail' => think_core_lang("tracing page syntax parse error detail").": <br>".$this->getMessage(),
'lang_tracing' => think_core_lang("tracing page tracing"),
'lang_src' => think_core_lang("tracing page src file"),
Expand Down
8 changes: 4 additions & 4 deletions thinkworker/lib/think/route/SubRoute.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
/**
* Created by PhpStorm.
* User: Dizy
* Date: 2017/12/6
* Time: 20:20
* ThinkWorker - THINK AND WORK FAST
* Copyright (c) 2017 http://thinkworker.cn All Rights Reserved.
* Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
* Author: Dizy <derzart@gmail.com>
*/

namespace think\route;
Expand Down
2 changes: 2 additions & 0 deletions thinkworker/lib/think/view/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public function assign($name, $value = null);
public function clearAssign($name);
public function clearAllAssign();
public function replace($name, $value = null);
public function outReplace($name, $value = null);
public function config($name, $value);
public function registerFunction($functionName, $asName = null);
public function getInstance();
}
57 changes: 55 additions & 2 deletions thinkworker/lib/think/view/SmartyDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ class SmartyDriver implements Driver

protected $replaceMap = [];

protected $outReplaceMap = [];

protected $function_cacheable = true;

public function init($config)
{
if(!class_exists("Smarty")){
require_once LIB_PATH."smarty".DS."Smarty.class.php";
require_once LIB_PATH."smarty".DS."SmartyBC.class.php";
}
$this->smarty = new \Smarty();
$this->smarty = new \SmartyBC();
$this->smarty->compile_dir = CACHE_PATH."smarty".DS."compile".DS;
$this->smarty->cache_dir = CACHE_PATH."smarty".DS."cache".DS;
$this->smarty->registerFilter('pre', array($this, "prefilter_replace"));
$this->smarty->registerFilter('post', array($this, "postfilter_replace"));
$this->addAllAppViewDir();
foreach ($config as $key=>$value){
$this->config($key, $value);
Expand Down Expand Up @@ -79,6 +84,22 @@ public function config($name, $value)
case "view_replace_str":
$this->replace($value);
break;
case "allow_php_tag":
if($value){
$this->smarty->php_handling = \Smarty::PHP_ALLOW;
}else{
$this->smarty->php_handling = \Smarty::PHP_PASSTHRU;
}
break;
case "left_delimiter":
$this->smarty->left_delimiter = $value;
break;
case "right_delimiter":
$this->smarty->right_delimiter = $value;
break;
case "function_cacheable":
$this->function_cacheable = $value;
break;
}
}

Expand All @@ -98,13 +119,44 @@ public function replace($name, $value = null)
return false;
}

public function outReplace($name, $value = null)
{
if(is_array($name) && is_null($value)){
$this->outReplaceMap = array_merge($this->outReplaceMap, $name);
return true;
} else if(is_string($name) && is_string($value)){
$this->outReplaceMap[$name] = $value;
return true;
}
return false;
}




public function prefilter_replace($tpl_source, $template){
foreach ($this->replaceMap as $name=>$value){
$tpl_source = str_replace($name, $value, $tpl_source);
}
return $tpl_source;
}

public function postfilter_replace($tpl_source, $template){
foreach ($this->replaceMap as $name=>$value){
$tpl_source = str_replace($name, $value, $tpl_source);
}
return $tpl_source;
}

public function registerFunction($functionName, $asName = null){
if(is_null($asName)){
$asName = $functionName;
}
if(is_string($asName)){
$this->smarty->registerPlugin("function",$asName, $functionName, $this->function_cacheable);
}
}

private function addAllAppViewDir(){
$request = envar("request");
$nowApp = null;
Expand All @@ -127,4 +179,5 @@ private function addAllAppViewDir(){
}
$this->smarty->addTemplateDir($dirs);
}

}
Loading

0 comments on commit 884e1d0

Please sign in to comment.