File tree Expand file tree Collapse file tree 8 files changed +178
-80
lines changed
Expand file tree Collapse file tree 8 files changed +178
-80
lines changed Original file line number Diff line number Diff line change 11<?php
22namespace Controller ;
33use System \Collection ;
4- use Model \ Demo ;
4+ use System \ Controller ;
55use System \Database ;
6+ use Model \Demo ;
67
7- class apiController {
8-
9- public function test (){
8+ class apiController extends Controller {
109
10+ public function test ($ id ){
11+
1112 }
1213
1314 // ORM 查询类方法演示
Original file line number Diff line number Diff line change 1+ <?php
2+ namespace System ;
3+ /**
4+ * PHP-QuickORM 框架的 Controller 基本类
5+ * @author Rytia <rytia@outlook.com>
6+ * @copyright 2018 PHP-QuickORM
7+ */
8+ class Controller
9+ {
10+ protected $ request ;
11+
12+ public function response ($ data = null , $ statusCode = 200 ){
13+ return $ data ;
14+ }
15+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 22namespace System \Http ;
33Class Request
44{
5+ protected $ method ;
56 protected $ postArray ;
67 protected $ getArray ;
78
8- public function all (){
99
10+ /**
11+ * Request constructor.
12+ */
13+ public function __construct (){
14+ // 获取请求的方式
15+ $ this ->method = strtolower ($ _SERVER ['REQUEST_METHOD ' ]);
16+ $ this ->postArray = $ _POST ;
17+ $ this ->getArray = $ _GET ;
1018 }
1119
12- public function input (){
1320
21+ /**
22+ * 返回全部请求数据
23+ * @return array
24+ */
25+ public function all (){
26+ return array_merge ($ this ->postArray , $ this ->getArray );
1427 }
1528
16- public function path (){
29+ /**
30+ * 通过字段(或字段数组)获取相应请求数据
31+ * @param string|array $field
32+ * @return array|null
33+ */
34+ public function get ($ field ){
35+ if (is_array ($ field )){
36+ // 如果传入的是数组,则递归取值
37+ // 写框架快一个月了,时至今日 Model、Collection、Database 已经完工,第一次想起将递归取值用上,可喜可贺
38+ // 此方法的缺陷是:如果传入一个二维数组(比如某个字段本身也是个数组),则该会返回 null,只能单独使用 get() 获取
39+ foreach ($ field as $ value ) {
40+ $ resultArray [] = $ this ->get ($ value );
41+ return $ resultArray ;
42+ }
43+ } else if (array_key_exists ($ field ,$ this ->postArray )) {
44+ // POST 取值
45+ return $ this ->postArray [$ field ];
46+ } elseif (array_key_exists ($ field ,$ this ->getArray )) {
47+ // GET 取值
48+ return $ this ->getArray [$ field ];
49+ } else {
50+ // 键值不存在
51+ return null ;
52+ }
53+ }
1754
55+ /**
56+ * 获取请求的路径
57+ * @return string
58+ */
59+ public function path (){
60+ return dirname ($ _SERVER ["REQUEST_URI " ]);
1861 }
1962
63+ /**
64+ * 获取请求的具体链接
65+ * @return string
66+ */
2067 public function url (){
21-
68+ return $ _SERVER [ " REQUEST_URI " ];
2269 }
2370
71+ /**
72+ * 获取请求的方法
73+ * @return string
74+ */
2475 public function method (){
25-
76+ return $ this -> method ;
2677 }
2778
2879}
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Created by PhpStorm.
4+ * User: rytia
5+ * Date: 2018/8/23
6+ * Time: 1:39
7+ */
Original file line number Diff line number Diff line change 77
88return array (
99 'System \\Collection ' => $ baseDir . '/App/System/Collection.php ' ,
10+ 'System \\Controller ' => $ baseDir . '/App/System/Controller.php ' ,
1011 'System \\Database ' => $ baseDir . '/App/System/Database.php ' ,
1112 'System \\DatabaseDriver \\pdo_mysql ' => $ baseDir . '/App/System/DatabaseDriver/pdo_mysql.php ' ,
1213 'System \\DatabaseDriver \\pdo_sqlite ' => $ baseDir . '/App/System/DatabaseDriver/pdo_sqlite.php ' ,
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ class ComposerStaticInit3dcce667708e66b2aabbed3c392db095
3030
3131 public static $ classMap = array (
3232 'System \\Collection ' => __DIR__ . '/../.. ' . '/App/System/Collection.php ' ,
33+ 'System \\Controller ' => __DIR__ . '/../.. ' . '/App/System/Controller.php ' ,
3334 'System \\Database ' => __DIR__ . '/../.. ' . '/App/System/Database.php ' ,
3435 'System \\DatabaseDriver \\pdo_mysql ' => __DIR__ . '/../.. ' . '/App/System/DatabaseDriver/pdo_mysql.php ' ,
3536 'System \\DatabaseDriver \\pdo_sqlite ' => __DIR__ . '/../.. ' . '/App/System/DatabaseDriver/pdo_sqlite.php ' ,
You can’t perform that action at this time.
0 commit comments