Browse Source

rename columns to include

Maurits van der Schee 6 years ago
parent
commit
c352c18c47

+ 15
- 15
api.php View File

@@ -3428,9 +3428,9 @@ class ListDocument implements \JsonSerializable
3428 3428
     }
3429 3429
 }
3430 3430
 
3431
-// file: src/Tqdev/PhpCrudApi/Record/ColumnSelector.php
3431
+// file: src/Tqdev/PhpCrudApi/Record/ColumnIncluder.php
3432 3432
 
3433
-class ColumnSelector
3433
+class ColumnIncluder
3434 3434
 {
3435 3435
 
3436 3436
     private function isMandatory(String $tableName, String $columnName, array $params): bool
@@ -3473,7 +3473,7 @@ class ColumnSelector
3473 3473
     {
3474 3474
         $tableName = $table->getName();
3475 3475
         $results = $table->columnNames();
3476
-        $results = $this->select($tableName, $primaryTable, $params, 'columns', $results, true);
3476
+        $results = $this->select($tableName, $primaryTable, $params, 'include', $results, true);
3477 3477
         $results = $this->select($tableName, $primaryTable, $params, 'exclude', $results, false);
3478 3478
         return $results;
3479 3479
     }
@@ -3772,7 +3772,7 @@ class RecordService
3772 3772
     {
3773 3773
         $this->db = $db;
3774 3774
         $this->tables = $reflection->getDatabase();
3775
-        $this->columns = new ColumnSelector();
3775
+        $this->columns = new ColumnIncluder();
3776 3776
         $this->joiner = new RelationJoiner($this->columns);
3777 3777
         $this->filters = new FilterInfo();
3778 3778
         $this->ordering = new OrderingInfo();
@@ -3876,14 +3876,14 @@ class RelationJoiner
3876 3876
 
3877 3877
     private $columns;
3878 3878
 
3879
-    public function __construct(ColumnSelector $columns)
3879
+    public function __construct(ColumnIncluder $columns)
3880 3880
     {
3881 3881
         $this->columns = $columns;
3882 3882
     }
3883 3883
 
3884
-    public function addMandatoryColumns(ReflectedTable $table, ReflectedDatabase $tables, array &$params)/*: void*/
3884
+    public function addMandatoryColumns(ReflectedTable $table, ReflectedDatabase $tables, array &$params) /*: void*/
3885 3885
     {
3886
-        if (!isset($params['join']) || !isset($params['columns'])) {
3886
+        if (!isset($params['join']) || !isset($params['include'])) {
3887 3887
             return;
3888 3888
         }
3889 3889
         $params['mandatory'] = array();
@@ -3933,7 +3933,7 @@ class RelationJoiner
3933 3933
     }
3934 3934
 
3935 3935
     public function addJoins(ReflectedTable $table, array &$records, ReflectedDatabase $tables, array $params,
3936
-        GenericDB $db)/*: void*/{
3936
+        GenericDB $db) /*: void*/ {
3937 3937
 
3938 3938
         $joins = $this->getJoinsAsPathTree($tables, $params);
3939 3939
         $this->addJoinsForTables($table, $joins, $records, $tables, $params, $db);
@@ -4013,7 +4013,7 @@ class RelationJoiner
4013 4013
         return $fkValues;
4014 4014
     }
4015 4015
 
4016
-    private function addFkRecords(ReflectedTable $t2, array $fkValues, array $params, GenericDB $db, array &$records)/*: void*/
4016
+    private function addFkRecords(ReflectedTable $t2, array $fkValues, array $params, GenericDB $db, array &$records) /*: void*/
4017 4017
     {
4018 4018
         $pk = $t2->getPk();
4019 4019
         $columnNames = $this->columns->getNames($t2, false, $params);
@@ -4024,7 +4024,7 @@ class RelationJoiner
4024 4024
         }
4025 4025
     }
4026 4026
 
4027
-    private function fillFkValues(ReflectedTable $t2, array $fkRecords, array &$fkValues)/*: void*/
4027
+    private function fillFkValues(ReflectedTable $t2, array $fkRecords, array &$fkValues) /*: void*/
4028 4028
     {
4029 4029
         $pkName = $t2->getPk()->getName();
4030 4030
         foreach ($fkRecords as $fkRecord) {
@@ -4033,7 +4033,7 @@ class RelationJoiner
4033 4033
         }
4034 4034
     }
4035 4035
 
4036
-    private function setFkValues(ReflectedTable $t1, ReflectedTable $t2, array &$records, array $fkValues)/*: void*/
4036
+    private function setFkValues(ReflectedTable $t1, ReflectedTable $t2, array &$records, array $fkValues) /*: void*/
4037 4037
     {
4038 4038
         $fks = $t1->getFksTo($t2->getName());
4039 4039
         foreach ($fks as $fk) {
@@ -4058,7 +4058,7 @@ class RelationJoiner
4058 4058
         return $pkValues;
4059 4059
     }
4060 4060
 
4061
-    private function addPkRecords(ReflectedTable $t1, ReflectedTable $t2, array $pkValues, array $params, GenericDB $db, array &$records)/*: void*/
4061
+    private function addPkRecords(ReflectedTable $t1, ReflectedTable $t2, array $pkValues, array $params, GenericDB $db, array &$records) /*: void*/
4062 4062
     {
4063 4063
         $fks = $t2->getFksTo($t1->getName());
4064 4064
         $columnNames = $this->columns->getNames($t2, false, $params);
@@ -4073,7 +4073,7 @@ class RelationJoiner
4073 4073
         }
4074 4074
     }
4075 4075
 
4076
-    private function fillPkValues(ReflectedTable $t1, ReflectedTable $t2, array $pkRecords, array &$pkValues)/*: void*/
4076
+    private function fillPkValues(ReflectedTable $t1, ReflectedTable $t2, array $pkRecords, array &$pkValues) /*: void*/
4077 4077
     {
4078 4078
         $fks = $t2->getFksTo($t1->getName());
4079 4079
         foreach ($fks as $fk) {
@@ -4087,7 +4087,7 @@ class RelationJoiner
4087 4087
         }
4088 4088
     }
4089 4089
 
4090
-    private function setPkValues(ReflectedTable $t1, ReflectedTable $t2, array &$records, array $pkValues)/*: void*/
4090
+    private function setPkValues(ReflectedTable $t1, ReflectedTable $t2, array &$records, array $pkValues) /*: void*/
4091 4091
     {
4092 4092
         $pkName = $t1->getPk()->getName();
4093 4093
         $t2Name = $t2->getName();
@@ -4125,7 +4125,7 @@ class RelationJoiner
4125 4125
         return new HabtmValues($pkValues, $fkValues);
4126 4126
     }
4127 4127
 
4128
-    private function setHabtmValues(ReflectedTable $t1, ReflectedTable $t3, array &$records, HabtmValues $habtmValues)/*: void*/
4128
+    private function setHabtmValues(ReflectedTable $t1, ReflectedTable $t3, array &$records, HabtmValues $habtmValues) /*: void*/
4129 4129
     {
4130 4130
         $pkName = $t1->getPk()->getName();
4131 4131
         $t3Name = $t3->getName();

+ 0
- 66
src/Tqdev/PhpCrudApi/Record/ColumnSelector.php View File

@@ -1,66 +0,0 @@
1
-<?php
2
-namespace Tqdev\PhpCrudApi\Record;
3
-
4
-use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
5
-
6
-class ColumnSelector
7
-{
8
-
9
-    private function isMandatory(String $tableName, String $columnName, array $params): bool
10
-    {
11
-        return isset($params['mandatory']) && in_array($tableName . "." . $columnName, $params['mandatory']);
12
-    }
13
-
14
-    private function select(String $tableName, bool $primaryTable, array $params, String $paramName,
15
-        array $columnNames, bool $include): array{
16
-        if (!isset($params[$paramName])) {
17
-            return $columnNames;
18
-        }
19
-        $columns = array();
20
-        foreach (explode(',', $params[$paramName][0]) as $columnName) {
21
-            $columns[$columnName] = true;
22
-        }
23
-        $result = array();
24
-        foreach ($columnNames as $columnName) {
25
-            $match = isset($columns['*.*']);
26
-            if (!$match) {
27
-                $match = isset($columns[$tableName . '.*']) || isset($columns[$tableName . '.' . $columnName]);
28
-            }
29
-            if ($primaryTable && !$match) {
30
-                $match = isset($columns['*']) || isset($columns[$columnName]);
31
-            }
32
-            if ($match) {
33
-                if ($include || $this->isMandatory($tableName, $columnName, $params)) {
34
-                    $result[] = $columnName;
35
-                }
36
-            } else {
37
-                if (!$include || $this->isMandatory($tableName, $columnName, $params)) {
38
-                    $result[] = $columnName;
39
-                }
40
-            }
41
-        }
42
-        return $result;
43
-    }
44
-
45
-    public function getNames(ReflectedTable $table, bool $primaryTable, array $params): array
46
-    {
47
-        $tableName = $table->getName();
48
-        $results = $table->columnNames();
49
-        $results = $this->select($tableName, $primaryTable, $params, 'columns', $results, true);
50
-        $results = $this->select($tableName, $primaryTable, $params, 'exclude', $results, false);
51
-        return $results;
52
-    }
53
-
54
-    public function getValues(ReflectedTable $table, bool $primaryTable, /* object */ $record, array $params): array
55
-    {
56
-        $results = array();
57
-        $columnNames = $this->getNames($table, $primaryTable, $params);
58
-        foreach ($columnNames as $columnName) {
59
-            if (property_exists($record, $columnName)) {
60
-                $results[$columnName] = $record->$columnName;
61
-            }
62
-        }
63
-        return $results;
64
-    }
65
-
66
-}

+ 1
- 1
src/Tqdev/PhpCrudApi/Record/RecordService.php View File

@@ -19,7 +19,7 @@ class RecordService
19 19
     {
20 20
         $this->db = $db;
21 21
         $this->tables = $reflection->getDatabase();
22
-        $this->columns = new ColumnSelector();
22
+        $this->columns = new ColumnIncluder();
23 23
         $this->joiner = new RelationJoiner($this->columns);
24 24
         $this->filters = new FilterInfo();
25 25
         $this->ordering = new OrderingInfo();

+ 13
- 13
src/Tqdev/PhpCrudApi/Record/RelationJoiner.php View File

@@ -1,25 +1,25 @@
1 1
 <?php
2 2
 namespace Tqdev\PhpCrudApi\Record;
3 3
 
4
+use Tqdev\PhpCrudApi\Column\Reflection\ReflectedDatabase;
5
+use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
4 6
 use Tqdev\PhpCrudApi\Database\GenericDB;
5 7
 use Tqdev\PhpCrudApi\Record\Condition\ColumnCondition;
6 8
 use Tqdev\PhpCrudApi\Record\Condition\OrCondition;
7
-use Tqdev\PhpCrudApi\Column\Reflection\ReflectedDatabase;
8
-use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
9 9
 
10 10
 class RelationJoiner
11 11
 {
12 12
 
13 13
     private $columns;
14 14
 
15
-    public function __construct(ColumnSelector $columns)
15
+    public function __construct(ColumnIncluder $columns)
16 16
     {
17 17
         $this->columns = $columns;
18 18
     }
19 19
 
20
-    public function addMandatoryColumns(ReflectedTable $table, ReflectedDatabase $tables, array &$params)/*: void*/
20
+    public function addMandatoryColumns(ReflectedTable $table, ReflectedDatabase $tables, array &$params) /*: void*/
21 21
     {
22
-        if (!isset($params['join']) || !isset($params['columns'])) {
22
+        if (!isset($params['join']) || !isset($params['include'])) {
23 23
             return;
24 24
         }
25 25
         $params['mandatory'] = array();
@@ -69,7 +69,7 @@ class RelationJoiner
69 69
     }
70 70
 
71 71
     public function addJoins(ReflectedTable $table, array &$records, ReflectedDatabase $tables, array $params,
72
-        GenericDB $db)/*: void*/{
72
+        GenericDB $db) /*: void*/ {
73 73
 
74 74
         $joins = $this->getJoinsAsPathTree($tables, $params);
75 75
         $this->addJoinsForTables($table, $joins, $records, $tables, $params, $db);
@@ -149,7 +149,7 @@ class RelationJoiner
149 149
         return $fkValues;
150 150
     }
151 151
 
152
-    private function addFkRecords(ReflectedTable $t2, array $fkValues, array $params, GenericDB $db, array &$records)/*: void*/
152
+    private function addFkRecords(ReflectedTable $t2, array $fkValues, array $params, GenericDB $db, array &$records) /*: void*/
153 153
     {
154 154
         $pk = $t2->getPk();
155 155
         $columnNames = $this->columns->getNames($t2, false, $params);
@@ -160,7 +160,7 @@ class RelationJoiner
160 160
         }
161 161
     }
162 162
 
163
-    private function fillFkValues(ReflectedTable $t2, array $fkRecords, array &$fkValues)/*: void*/
163
+    private function fillFkValues(ReflectedTable $t2, array $fkRecords, array &$fkValues) /*: void*/
164 164
     {
165 165
         $pkName = $t2->getPk()->getName();
166 166
         foreach ($fkRecords as $fkRecord) {
@@ -169,7 +169,7 @@ class RelationJoiner
169 169
         }
170 170
     }
171 171
 
172
-    private function setFkValues(ReflectedTable $t1, ReflectedTable $t2, array &$records, array $fkValues)/*: void*/
172
+    private function setFkValues(ReflectedTable $t1, ReflectedTable $t2, array &$records, array $fkValues) /*: void*/
173 173
     {
174 174
         $fks = $t1->getFksTo($t2->getName());
175 175
         foreach ($fks as $fk) {
@@ -194,7 +194,7 @@ class RelationJoiner
194 194
         return $pkValues;
195 195
     }
196 196
 
197
-    private function addPkRecords(ReflectedTable $t1, ReflectedTable $t2, array $pkValues, array $params, GenericDB $db, array &$records)/*: void*/
197
+    private function addPkRecords(ReflectedTable $t1, ReflectedTable $t2, array $pkValues, array $params, GenericDB $db, array &$records) /*: void*/
198 198
     {
199 199
         $fks = $t2->getFksTo($t1->getName());
200 200
         $columnNames = $this->columns->getNames($t2, false, $params);
@@ -209,7 +209,7 @@ class RelationJoiner
209 209
         }
210 210
     }
211 211
 
212
-    private function fillPkValues(ReflectedTable $t1, ReflectedTable $t2, array $pkRecords, array &$pkValues)/*: void*/
212
+    private function fillPkValues(ReflectedTable $t1, ReflectedTable $t2, array $pkRecords, array &$pkValues) /*: void*/
213 213
     {
214 214
         $fks = $t2->getFksTo($t1->getName());
215 215
         foreach ($fks as $fk) {
@@ -223,7 +223,7 @@ class RelationJoiner
223 223
         }
224 224
     }
225 225
 
226
-    private function setPkValues(ReflectedTable $t1, ReflectedTable $t2, array &$records, array $pkValues)/*: void*/
226
+    private function setPkValues(ReflectedTable $t1, ReflectedTable $t2, array &$records, array $pkValues) /*: void*/
227 227
     {
228 228
         $pkName = $t1->getPk()->getName();
229 229
         $t2Name = $t2->getName();
@@ -261,7 +261,7 @@ class RelationJoiner
261 261
         return new HabtmValues($pkValues, $fkValues);
262 262
     }
263 263
 
264
-    private function setHabtmValues(ReflectedTable $t1, ReflectedTable $t3, array &$records, HabtmValues $habtmValues)/*: void*/
264
+    private function setHabtmValues(ReflectedTable $t1, ReflectedTable $t3, array &$records, HabtmValues $habtmValues) /*: void*/
265 265
     {
266 266
         $pkName = $t1->getPk()->getName();
267 267
         $t3Name = $t3->getName();

+ 1
- 1
tests/functional/001_records/002_list_post_columns.log View File

@@ -1,4 +1,4 @@
1
-GET /records/posts?columns=id,content
1
+GET /records/posts?include=id,content
2 2
 ===
3 3
 200
4 4
 Content-Type: application/json

+ 1
- 1
tests/functional/001_records/005_read_post_columns.log View File

@@ -1,4 +1,4 @@
1
-GET /records/posts/2?columns=id,content
1
+GET /records/posts/2?include=id,content
2 2
 ===
3 3
 200
4 4
 Content-Type: application/json

+ 1
- 1
tests/functional/001_records/008_edit_post_columns_missing_field.log View File

@@ -1,4 +1,4 @@
1
-PUT /records/posts/3?columns=id,content
1
+PUT /records/posts/3?include=id,content
2 2
 
3 3
 {"content":"test (edited 2)"}
4 4
 ===

+ 1
- 1
tests/functional/001_records/009_edit_post_columns_extra_field.log View File

@@ -1,4 +1,4 @@
1
-PUT /records/posts/3?columns=id,content
1
+PUT /records/posts/3?include=id,content
2 2
 
3 3
 {"user_id":2,"content":"test (edited 3)"}
4 4
 ===

+ 1
- 1
tests/functional/001_records/015_delete_post_ignore_columns.log View File

@@ -1,4 +1,4 @@
1
-DELETE /records/posts/4?columns=id,content
1
+DELETE /records/posts/4?include=id,content
2 2
 ===
3 3
 200
4 4
 Content-Type: application/json

+ 1
- 1
tests/functional/001_records/033_list_example_from_readme_tag_name_only.log View File

@@ -1,4 +1,4 @@
1
-GET /records/posts?columns=tags.name&join=categories&join=post_tags,tags&join=comments&filter=id,eq,1
1
+GET /records/posts?include=tags.name&join=categories&join=post_tags,tags&join=comments&filter=id,eq,1
2 2
 ===
3 3
 200
4 4
 Content-Type: application/json

+ 1
- 1
tests/functional/001_records/041_cors_pre_flight.log View File

@@ -1,4 +1,4 @@
1
-OPTIONS /records/posts/1?columns=id
1
+OPTIONS /records/posts/1?include=id
2 2
 Origin: http://example.com
3 3
 Access-Control-Request-Method: POST
4 4
 Access-Control-Request-Headers: X-XSRF-TOKEN, X-Requested-With

+ 1
- 1
tests/functional/001_records/042_cors_headers.log View File

@@ -1,4 +1,4 @@
1
-GET /records/posts/1?columns=id
1
+GET /records/posts/1?include=id
2 2
 Origin: http://example.com
3 3
 ===
4 4
 200

+ 1
- 1
tests/functional/001_records/052_edit_user_location.log View File

@@ -8,7 +8,7 @@ Content-Length: 1
8 8
 
9 9
 1
10 10
 ===
11
-GET /records/users/1?columns=id,location
11
+GET /records/users/1?include=id,location
12 12
 ===
13 13
 200
14 14
 Content-Type: application/json

+ 1
- 1
tests/functional/001_records/053_list_user_locations.log View File

@@ -1,4 +1,4 @@
1
-GET /records/users?columns=id,location
1
+GET /records/users?include=id,location
2 2
 ===
3 3
 200
4 4
 Content-Type: application/json

+ 1
- 1
tests/functional/001_records/054_edit_user_with_id.log View File

@@ -8,7 +8,7 @@ Content-Length: 1
8 8
 
9 9
 1
10 10
 ===
11
-GET /records/users/1?columns=id,username,password
11
+GET /records/users/1?include=id,username,password
12 12
 ===
13 13
 200
14 14
 Content-Type: application/json

+ 1
- 1
tests/functional/001_records/057_filter_on_and.log View File

@@ -1,4 +1,4 @@
1
-GET /records/posts?columns=id&filter=id,ge,1&filter=id,le,2
1
+GET /records/posts?include=id&filter=id,ge,1&filter=id,le,2
2 2
 ===
3 3
 200
4 4
 Content-Type: application/json

+ 1
- 1
tests/functional/001_records/058_filter_on_or.log View File

@@ -1,4 +1,4 @@
1
-GET /records/posts?columns=id&filter1=id,eq,1&filter2=id,eq,2
1
+GET /records/posts?include=id&filter1=id,eq,1&filter2=id,eq,2
2 2
 ===
3 3
 200
4 4
 Content-Type: application/json

+ 1
- 1
tests/functional/001_records/059_filter_on_and_plus_or.log View File

@@ -1,4 +1,4 @@
1
-GET /records/posts?columns=id&filter1=id,eq,1&filter2=id,gt,1&filter2=id,lt,3
1
+GET /records/posts?include=id&filter1=id,eq,1&filter2=id,gt,1&filter2=id,lt,3
2 2
 ===
3 3
 200
4 4
 Content-Type: application/json

+ 1
- 1
tests/functional/001_records/060_filter_on_or_plus_and.log View File

@@ -1,4 +1,4 @@
1
-GET /records/posts?columns=id&filter1=id,eq,1&filter2=id,eq,2&filter=user_id,eq,1
1
+GET /records/posts?include=id&filter1=id,eq,1&filter2=id,eq,2&filter=user_id,eq,1
2 2
 ===
3 3
 200
4 4
 Content-Type: application/json

+ 1
- 1
tests/functional/001_records/061_get_post_content_with_included_tag_names.log View File

@@ -1,4 +1,4 @@
1
-GET /records/posts/1?columns=content,tags.name&join=tags
1
+GET /records/posts/1?include=content,tags.name&join=tags
2 2
 ===
3 3
 200
4 4
 Content-Type: application/json

+ 3
- 3
tests/functional/001_records/069_increment_event_visitors.log View File

@@ -1,4 +1,4 @@
1
-GET /records/events/1?columns=visitors
1
+GET /records/events/1?include=visitors
2 2
 ===
3 3
 200
4 4
 Content-Type: application/json
@@ -36,7 +36,7 @@ Content-Length: 5
36 36
 
37 37
 [1,1]
38 38
 ===
39
-GET /records/events/1?columns=visitors
39
+GET /records/events/1?include=visitors
40 40
 ===
41 41
 200
42 42
 Content-Type: application/json
@@ -54,7 +54,7 @@ Content-Length: 1
54 54
 
55 55
 1
56 56
 ===
57
-GET /records/events/1?columns=visitors
57
+GET /records/events/1?include=visitors
58 58
 ===
59 59
 200
60 60
 Content-Type: application/json

Loading…
Cancel
Save