Skip to content

Commit

Permalink
change
Browse files Browse the repository at this point in the history
  • Loading branch information
guolifu committed Sep 16, 2017
1 parent 89b0495 commit 21e5ba6
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/Api/controller/indexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public function index(){
return "api";
}
public function api(){
return ['api'=>1];
return ['api'=>1,'TO_JSONP'=>true];
}
}
4 changes: 4 additions & 0 deletions app/Home/controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,9 @@ public function json(){
return ['data'=>'json','status'=>1];
// return ['data'=>'json','status'=>1,'to_array'=>1];
}
public function url1(){
$b = route()->action;
dump($b);die;
}

}
41 changes: 35 additions & 6 deletions core/common/function.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,31 @@ function json($array)
header('Content-Type:application/json; charset=utf-8');
return json_encode($array);
}
function jsonp($array)
{
header('Content-Type:application/javascript; charset=utf-8');
$data = json_encode($array);

$handler = !empty($_GET['callback']) ? $_GET['callback'] :'jsonpReturn' ;
$data = $handler . '(' . $data . ');';
return $data;
}

function show404()
{
header('HTTP/1.1 404 Not Found');
header("status: 404 Not Found");
exit();
}
function model($name=''){
$model_path = '\\app\\'.ucfirst($name);
return (class_exists($model_path))?
new $model_path :
new \thunder\Model($name);
}


function microtime_float(){
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}



function input($name,$default='',$filter=null,$datas=null) {
static $_PUT = null;
if(strpos($name,'/')){ // 指定修饰符
Expand Down Expand Up @@ -274,6 +282,8 @@ function input($name,$default='',$filter=null,$datas=null) {
is_array($data) && array_walk_recursive($data,'thunder_filter');
return $data;
}


function array_map_recursive($filter, $data) {
$result = array();
foreach ($data as $key => $val) {
Expand All @@ -283,12 +293,31 @@ function array_map_recursive($filter, $data) {
}
return $result;
}



function thunder_filter(&$value){
// 过滤查询特殊字符
if(preg_match('/^(EXP|NEQ|GT|EGT|LT|ELT|OR|XOR|LIKE|NOTLIKE|NOT BETWEEN|NOTBETWEEN|BETWEEN|NOTIN|NOT IN|IN)$/i',$value)){
$value .= ' ';
}
}


function model($name=''){
$model_path = '\\app\\'.ucfirst($name);
return (class_exists($model_path))?
new $model_path :
new \thunder\Model($name);
}


function session(){
return new \thunder\Session();
}



function route(){
return \thunder\Route::get_instance();
}
28 changes: 15 additions & 13 deletions core/thunder/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static function send($data){

$data = self::setContent($dataType,$data);
if(!is_array($data)){
echo($data);
echo $data;
}else{
dump($data);
}
Expand All @@ -23,20 +23,22 @@ protected static function getDataType($data){
protected static function setContent($dataType,$data){
switch($dataType){
case 'array' :{
$data =
(array_key_exists('to_array',$data) && $data['to_array']==1)?
self::getData():
$data = json($data);
break;
}
case 'integer' :{
$data = (int)$data;
break;
}
case 'string' :{
$data = (string)$data;
switch(true){
case (array_key_exists('TO_ARRAY',$data) && $data['TO_ARRAY']===true):{
$data = self::getData();
break;
}
case (array_key_exists('TO_JSONP',$data) && $data['TO_JSONP']===true):{
$data = jsonp($data);
break;
}
default:{
$data = json($data);
}
}
break;
}

default:{
$data = self::getData();
}
Expand Down
7 changes: 3 additions & 4 deletions core/thunder/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ public static function _get_route_path($path){

return $path;
}
/*
* 提供twig
* */
/*
* 提供twig
* */
public static function _get_pub_path(){
return self::$pub_path;
}
Expand All @@ -102,7 +102,6 @@ public static function init($rules,$route){
self::$rules = array_merge(self::$rules,$r);
}


/*
*
* 解析路由
Expand Down
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
if(version_compare(PHP_VERSION,'5.4.0','<')) die('require PHP > 5.4.0 !');
header("Content-type:text/html;charset=utf-8");
date_default_timezone_set('PRC');
header("Access-Control-Allow-Origin: *");
define('_PHP_FILE_',rtrim($_SERVER['SCRIPT_NAME'],'/'));
$_root = rtrim(dirname(_PHP_FILE_),'/');
define('__ROOT__', (($_root=='/' || $_root=='\\')?'':$_root));
Expand Down
91 changes: 91 additions & 0 deletions log/20170916/log.log
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,94 @@
2017-09-16 10:02:04"MODULE==>Api;CTRL==>Index;ACTION==>index"
2017-09-16 10:02:19"MODULE==>Api;CTRL==>Index;ACTION==>index"
2017-09-16 10:02:56"MODULE==>Api;CTRL==>Index;ACTION==>index"
2017-09-16 10:04:18"MODULE==>Api;CTRL==>Index;ACTION==>index"
2017-09-16 10:48:39"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 10:51:04"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 10:51:21"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 10:51:44"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 10:53:31"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 10:53:32"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 10:54:26"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 10:55:07"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 10:58:28"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 10:58:57"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 11:49:35"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 11:49:38"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 11:50:12"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 11:50:16"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 11:53:40"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 11:53:53"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 11:56:12"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 11:56:42"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 11:56:51"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 11:57:08"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 11:57:27"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 11:57:28"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 11:57:33"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:02:30"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:02:34"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:02:44"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:02:45"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:02:47"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:02:49"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:02:51"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:02:57"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:03:00"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:03:08"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:03:10"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:03:17"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:03:18"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:03:19"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:03:29"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:03:49"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:05:14"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:06:21"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:06:22"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:06:28"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:06:36"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:06:48"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:06:57"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:07:09"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:07:30"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:08:45"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:08:47"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:14:37"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:15:23"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:15:48"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:16:49"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:24:21"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:24:25"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:25:01"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:25:03"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:25:05"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:25:07"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 12:25:29"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:20:27"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:20:40"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:20:42"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:20:55"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:20:58"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:24:06"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:26:38"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:26:44"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:26:47"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:26:52"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:42:02"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:48:43"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:48:47"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:51:51"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:53:50"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:54:02"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:54:10"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:54:45"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:55:11"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:55:55"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:55:56"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:55:57"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 13:56:13"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 14:08:33"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 14:18:04"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 14:23:07"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 14:23:17"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 14:23:21"MODULE==>Api;CTRL==>Index;ACTION==>api"
2017-09-16 14:24:39"MODULE==>Api;CTRL==>Index;ACTION==>api"
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 注册路由
*
* */
Route::init('goapi','api/index/index');
Route::init('goapi','api/index/api');

Route::init('goapi2/add/{param}','api/index/index');

Expand Down

0 comments on commit 21e5ba6

Please sign in to comment.