作者 邓超

1

1 <?php 1 <?php
2 2
3 -use Model\listsSql; 3 +echo strlen("你好啊阿萨德你白求恩是奥斯卡女把万科城那就睡吧八十年代你");
4 4
5 -include_once __DIR__."/../vendor/autoload.php"; 5 +
  6 +//use Model\listsSql;
  7 +
  8 +//include_once __DIR__."/../vendor/autoload.php";
6 9
7 10
8 //$ids = db()->all('select `id` from `'.\Model\emailSql::$table.'` limit 1000 offset 0'); 11 //$ids = db()->all('select `id` from `'.\Model\emailSql::$table.'` limit 1000 offset 0');
@@ -3,6 +3,9 @@ @@ -3,6 +3,9 @@
3 namespace Controller; 3 namespace Controller;
4 4
5 5
  6 +use Lib\Mail\MailFun;
  7 +use Model\folderSql;
  8 +
6 /** 9 /**
7 * 文件夹管理 10 * 文件夹管理
8 * @author:dc 11 * @author:dc
@@ -42,6 +45,33 @@ class Folder extends Base { @@ -42,6 +45,33 @@ class Folder extends Base {
42 * @time 2023/2/18 17:56 45 * @time 2023/2/18 17:56
43 */ 46 */
44 public function create(){ 47 public function create(){
  48 + $formData = app()->request(['pid','folder']);
  49 + // 验证目录 可以输入中文英文数字
  50 + if(empty($formData['folder']) || !preg_match("/^[\u4E00-\u9FA5A-Za-z0-9_]+$/",$formData['folder'])){
  51 + app()->e('folder_create_name_error');
  52 + }
  53 + // 不为空上级
  54 + if(!empty($formData['pid'])){
  55 + $parent = db()->first(folderSql::first(['id'=>$formData['pid']]));
  56 + if(!$parent || $parent['email_id'] != $this->login_email['id']){
  57 + app()->e('folder_parent_not_fount');
  58 + }
  59 + if($parent['pid']){
  60 + app()->e('folder_tree_max_two');
  61 + }
  62 +
  63 + }
  64 +
  65 + // 判断文件夹是否存在
  66 + $has = db()->count(folderSql::has(
  67 + [
  68 + 'email_id' => $this->login_email['id'],
  69 + 'origin_folder' => $formData['folder']
  70 + ]
  71 + ));
  72 +
  73 +
  74 +
45 75
46 } 76 }
47 77
  1 +<?php
  2 +
  3 +namespace Controller;
  4 +
  5 +use Lib\Mail\MailFun;
  6 +use Model\emailSql;
  7 +use Model\listsSql;
  8 +
  9 +/**
  10 + * @author:dc
  11 + * @time 2023/2/13 11:28
  12 + * Class Home
  13 + * @package Controller
  14 + */
  15 +class Test {
  16 +
  17 +
  18 + public function home(){
  19 + ob_start();
  20 + header("Content-Type:text/event-stream;Charset=UTF-8;\n\n");
  21 + header("cache-control:no-cache;\n\n");
  22 +
  23 +
  24 + foreach (range(1,10) as $i)
  25 +
  26 + {
  27 +
  28 + echo $i.'hello world'.PHP_EOL.PHP_EOL ;
  29 +
  30 + ob_flush();
  31 +
  32 + flush();
  33 +
  34 +
  35 + sleep(1);
  36 +
  37 + }
  38 +
  39 + ob_clean();
  40 + }
  41 +
  42 + public function a(){
  43 + header("Content-Type:text/html;Charset=UTF-8;");
  44 + echo '1';
  45 + }
  46 +
  47 +
  48 +
  49 +
  50 +
  51 +}
  52 +
  53 +
  54 +
  55 +
  56 +
  57 +
  58 +
  59 +
  60 +
  61 +
  62 +
  63 +
  64 +
  65 +
@@ -18,4 +18,10 @@ return [ @@ -18,4 +18,10 @@ return [
18 'login_error' => '登录失败', 18 'login_error' => '登录失败',
19 'token_verify_error' => '令牌验证失败', 19 'token_verify_error' => '令牌验证失败',
20 'token_verify_notfound' => '令牌验证失败.', 20 'token_verify_notfound' => '令牌验证失败.',
  21 +
  22 + 'param_request_error' => '参数异常',
  23 + 'folder_create_name_error' => '文件夹名称只能输入中文英文数字',
  24 + 'folder_parent_not_fount' => '上级文件夹不存在',
  25 + 'folder_tree_max_two' => '文件夹最多2级',
  26 +
21 ]; 27 ];
@@ -53,7 +53,6 @@ class App { @@ -53,7 +53,6 @@ class App {
53 53
54 public function __construct() 54 public function __construct()
55 { 55 {
56 - header("Content-Type:application/json;Charset=utf8;");  
57 56
58 $this->date = date('Y-m-d'); 57 $this->date = date('Y-m-d');
59 $this->dateTime = date('Y-m-d H:i:s'); 58 $this->dateTime = date('Y-m-d H:i:s');
@@ -63,7 +62,7 @@ class App { @@ -63,7 +62,7 @@ class App {
63 $this->route = new Route(); 62 $this->route = new Route();
64 63
65 // 请求参数 TODO::不允许其他类型的请求参数 64 // 请求参数 TODO::不允许其他类型的请求参数
66 - $this->request = my_filter($_POST); 65 + $this->request = my_filter($_POST,['trim']);
67 66
68 67
69 } 68 }
@@ -90,9 +89,9 @@ class App { @@ -90,9 +89,9 @@ class App {
90 public static function run() { 89 public static function run() {
91 $app = self::instance(); 90 $app = self::instance();
92 try { 91 try {
93 - if ($_SERVER['REQUEST_METHOD'] != 'POST'){  
94 - $app->e('need_post_request');  
95 - } 92 +// if ($_SERVER['REQUEST_METHOD'] != 'POST'){
  93 +// $app->e('need_post_request');
  94 +// }
96 95
97 // 取到路由 控制器 96 // 取到路由 控制器
98 $route = $app->route->get(explode('?',$_SERVER['REQUEST_URI'])[0]); 97 $route = $app->route->get(explode('?',$_SERVER['REQUEST_URI'])[0]);
@@ -222,9 +221,16 @@ class App { @@ -222,9 +221,16 @@ class App {
222 221
223 // end code 222 // end code
224 223
  224 + header("Content-Type:application/json;Charset=UTF-8;");
  225 +// header("Content-Type:text/html;Charset=UTF-8;");
  226 +// header("Content-Type:text/event-stream;Charset=UTF-8;");
225 227
  228 + if(self::instance()->data){
  229 + echo json_encode(self::instance()->data,JSON_UNESCAPED_UNICODE);
  230 + }
226 231
227 - echo json_encode(self::instance()->data,JSON_UNESCAPED_UNICODE); 232 +// ob_flush();
  233 +// ob_clean();
228 } 234 }
229 235
230 236
@@ -33,6 +33,9 @@ class Route { @@ -33,6 +33,9 @@ class Route {
33 */ 33 */
34 public function get($route):array{ 34 public function get($route):array{
35 $route = trim($route,'/'); 35 $route = trim($route,'/');
  36 + if(empty($route)){
  37 + return $this->url['/']??[];
  38 + }
36 return $this->url[$route]??[]; 39 return $this->url[$route]??[];
37 } 40 }
38 41
@@ -32,10 +32,20 @@ class folderSql { @@ -32,10 +32,20 @@ class folderSql {
32 * @author:dc 32 * @author:dc
33 * @time 2023/2/18 11:48 33 * @time 2023/2/18 11:48
34 */ 34 */
35 - public static function has($where){ 35 + public static function has($where):string {
36 return "select `id` from `".self::$table."` where ".dbWhere($where); 36 return "select `id` from `".self::$table."` where ".dbWhere($where);
37 } 37 }
38 38
  39 + /**
  40 + * 查询一条完整的数据
  41 + * @param $where
  42 + * @return string
  43 + * @author:dc
  44 + * @time 2023/2/20 16:39
  45 + */
  46 + public static function first($where):string {
  47 + return "select * from `".self::$table."` where ".dbWhere($where);
  48 + }
39 49
40 50
41 51
@@ -7,6 +7,13 @@ @@ -7,6 +7,13 @@
7 return [ 7 return [
8 8
9 /** 9 /**
  10 + * home
  11 + * @see \Controller\Test::a()
  12 + */
  13 + '/' => [\Controller\Test::class, 'a'],
  14 + 't' => [\Controller\Test::class, 'home'],
  15 +
  16 + /**
10 * 登录操作 17 * 登录操作
11 * @see \Controller\Login::login() 18 * @see \Controller\Login::login()
12 * @param string email 邮箱 19 * @param string email 邮箱