Maurits van der Schee 6 years ago
parent
commit
def5e6461e
55 changed files with 233 additions and 315 deletions
  1. 2
    2
      src/Tqdev/PhpCrudApi/Cache/Cache.php
  2. 1
    1
      src/Tqdev/PhpCrudApi/Cache/CacheFactory.php
  3. 3
    3
      src/Tqdev/PhpCrudApi/Cache/MemcacheCache.php
  4. 1
    1
      src/Tqdev/PhpCrudApi/Cache/MemcachedCache.php
  5. 2
    2
      src/Tqdev/PhpCrudApi/Cache/NoCache.php
  6. 3
    3
      src/Tqdev/PhpCrudApi/Cache/RedisCache.php
  7. 6
    6
      src/Tqdev/PhpCrudApi/Cache/TempFileCache.php
  8. 5
    5
      src/Tqdev/PhpCrudApi/Column/DefinitionService.php
  9. 4
    4
      src/Tqdev/PhpCrudApi/Column/Reflection/ReflectedColumn.php
  10. 3
    3
      src/Tqdev/PhpCrudApi/Column/Reflection/ReflectedDatabase.php
  11. 7
    7
      src/Tqdev/PhpCrudApi/Column/Reflection/ReflectedTable.php
  12. 7
    7
      src/Tqdev/PhpCrudApi/Column/ReflectionService.php
  13. 12
    12
      src/Tqdev/PhpCrudApi/Config.php
  14. 1
    1
      src/Tqdev/PhpCrudApi/Controller/ColumnController.php
  15. 1
    1
      src/Tqdev/PhpCrudApi/Controller/RecordController.php
  16. 1
    1
      src/Tqdev/PhpCrudApi/Controller/Responder.php
  17. 3
    3
      src/Tqdev/PhpCrudApi/Database/ColumnConverter.php
  18. 10
    10
      src/Tqdev/PhpCrudApi/Database/ColumnsBuilder.php
  19. 13
    13
      src/Tqdev/PhpCrudApi/Database/ConditionsBuilder.php
  20. 3
    3
      src/Tqdev/PhpCrudApi/Database/DataConverter.php
  21. 8
    8
      src/Tqdev/PhpCrudApi/Database/GenericDB.php
  22. 33
    35
      src/Tqdev/PhpCrudApi/Database/GenericDefinition.php
  23. 11
    11
      src/Tqdev/PhpCrudApi/Database/GenericReflection.php
  24. 3
    3
      src/Tqdev/PhpCrudApi/Database/TypeConverter.php
  25. 2
    1
      src/Tqdev/PhpCrudApi/Middleware/AjaxOnlyMiddleware.php
  26. 4
    4
      src/Tqdev/PhpCrudApi/Middleware/AuthorizationMiddleware.php
  27. 2
    2
      src/Tqdev/PhpCrudApi/Middleware/Base/Middleware.php
  28. 8
    6
      src/Tqdev/PhpCrudApi/Middleware/BasicAuthMiddleware.php
  29. 2
    2
      src/Tqdev/PhpCrudApi/Middleware/Communication/VariableStore.php
  30. 1
    1
      src/Tqdev/PhpCrudApi/Middleware/CorsMiddleware.php
  31. 1
    1
      src/Tqdev/PhpCrudApi/Middleware/CustomizationMiddleware.php
  32. 2
    2
      src/Tqdev/PhpCrudApi/Middleware/FirewallMiddleware.php
  33. 2
    2
      src/Tqdev/PhpCrudApi/Middleware/IpAddressMiddleware.php
  34. 1
    1
      src/Tqdev/PhpCrudApi/Middleware/JoinLimitsMiddleware.php
  35. 7
    5
      src/Tqdev/PhpCrudApi/Middleware/JwtAuthMiddleware.php
  36. 4
    4
      src/Tqdev/PhpCrudApi/Middleware/MultiTenancyMiddleware.php
  37. 1
    1
      src/Tqdev/PhpCrudApi/Middleware/PageLimitsMiddleware.php
  38. 1
    1
      src/Tqdev/PhpCrudApi/Middleware/Router/Router.php
  39. 1
    1
      src/Tqdev/PhpCrudApi/Middleware/Router/SimpleRouter.php
  40. 2
    2
      src/Tqdev/PhpCrudApi/Middleware/SanitationMiddleware.php
  41. 2
    2
      src/Tqdev/PhpCrudApi/Middleware/ValidationMiddleware.php
  42. 1
    1
      src/Tqdev/PhpCrudApi/Middleware/XsrfMiddleware.php
  43. 8
    8
      src/Tqdev/PhpCrudApi/OpenApi/OpenApiBuilder.php
  44. 2
    2
      src/Tqdev/PhpCrudApi/OpenApi/OpenApiDefinition.php
  45. 2
    2
      src/Tqdev/PhpCrudApi/Record/ColumnIncluder.php
  46. 3
    3
      src/Tqdev/PhpCrudApi/Record/Condition/ColumnCondition.php
  47. 1
    1
      src/Tqdev/PhpCrudApi/Record/Condition/Condition.php
  48. 2
    2
      src/Tqdev/PhpCrudApi/Record/Document/ErrorDocument.php
  49. 1
    1
      src/Tqdev/PhpCrudApi/Record/ErrorCode.php
  50. 1
    1
      src/Tqdev/PhpCrudApi/Record/PathTree.php
  51. 9
    9
      src/Tqdev/PhpCrudApi/Record/RecordService.php
  52. 0
    85
      src/Tqdev/PhpCrudApi/Record/RequestUtils.php
  53. 12
    12
      src/Tqdev/PhpCrudApi/Request.old
  54. 1
    1
      src/Tqdev/PhpCrudApi/RequestFactory.php
  55. 4
    4
      src/Tqdev/PhpCrudApi/Response.php

+ 2
- 2
src/Tqdev/PhpCrudApi/Cache/Cache.php View File

@@ -3,7 +3,7 @@ namespace Tqdev\PhpCrudApi\Cache;
3 3
 
4 4
 interface Cache
5 5
 {
6
-    public function set(String $key, String $value, int $ttl = 0): bool;
7
-    public function get(String $key): String;
6
+    public function set(string $key, string $value, int $ttl = 0): bool;
7
+    public function get(string $key): string;
8 8
     public function clear(): bool;
9 9
 }

+ 1
- 1
src/Tqdev/PhpCrudApi/Cache/CacheFactory.php View File

@@ -7,7 +7,7 @@ class CacheFactory
7 7
 {
8 8
     const PREFIX = 'phpcrudapi-%s-%s-%s-';
9 9
 
10
-    private static function getPrefix(Config $config): String
10
+    private static function getPrefix(Config $config): string
11 11
     {
12 12
         $driver = $config->getDriver();
13 13
         $database = $config->getDatabase();

+ 3
- 3
src/Tqdev/PhpCrudApi/Cache/MemcacheCache.php View File

@@ -6,7 +6,7 @@ class MemcacheCache implements Cache
6 6
     protected $prefix;
7 7
     protected $memcache;
8 8
 
9
-    public function __construct(String $prefix, String $config)
9
+    public function __construct(string $prefix, string $config)
10 10
     {
11 11
         $this->prefix = $prefix;
12 12
         if ($config == '') {
@@ -27,12 +27,12 @@ class MemcacheCache implements Cache
27 27
         return new \Memcache();
28 28
     }
29 29
 
30
-    public function set(String $key, String $value, int $ttl = 0): bool
30
+    public function set(string $key, string $value, int $ttl = 0): bool
31 31
     {
32 32
         return $this->memcache->set($this->prefix . $key, $value, 0, $ttl);
33 33
     }
34 34
 
35
-    public function get(String $key): String
35
+    public function get(string $key): string
36 36
     {
37 37
         return $this->memcache->get($this->prefix . $key) ?: '';
38 38
     }

+ 1
- 1
src/Tqdev/PhpCrudApi/Cache/MemcachedCache.php View File

@@ -8,7 +8,7 @@ class MemcachedCache extends MemcacheCache
8 8
         return new \Memcached();
9 9
     }
10 10
 
11
-    public function set(String $key, String $value, int $ttl = 0): bool
11
+    public function set(string $key, string $value, int $ttl = 0): bool
12 12
     {
13 13
         return $this->memcache->set($this->prefix . $key, $value, $ttl);
14 14
     }

+ 2
- 2
src/Tqdev/PhpCrudApi/Cache/NoCache.php View File

@@ -7,12 +7,12 @@ class NoCache implements Cache
7 7
     {
8 8
     }
9 9
 
10
-    public function set(String $key, String $value, int $ttl = 0): bool
10
+    public function set(string $key, string $value, int $ttl = 0): bool
11 11
     {
12 12
         return true;
13 13
     }
14 14
 
15
-    public function get(String $key): String
15
+    public function get(string $key): string
16 16
     {
17 17
         return '';
18 18
     }

+ 3
- 3
src/Tqdev/PhpCrudApi/Cache/RedisCache.php View File

@@ -6,7 +6,7 @@ class RedisCache implements Cache
6 6
     protected $prefix;
7 7
     protected $redis;
8 8
 
9
-    public function __construct(String $prefix, String $config)
9
+    public function __construct(string $prefix, string $config)
10 10
     {
11 11
         $this->prefix = $prefix;
12 12
         if ($config == '') {
@@ -20,12 +20,12 @@ class RedisCache implements Cache
20 20
         call_user_func_array(array($this->redis, 'pconnect'), $params);
21 21
     }
22 22
 
23
-    public function set(String $key, String $value, int $ttl = 0): bool
23
+    public function set(string $key, string $value, int $ttl = 0): bool
24 24
     {
25 25
         return $this->redis->set($this->prefix . $key, $value, $ttl);
26 26
     }
27 27
 
28
-    public function get(String $key): String
28
+    public function get(string $key): string
29 29
     {
30 30
         return $this->redis->get($this->prefix . $key) ?: '';
31 31
     }

+ 6
- 6
src/Tqdev/PhpCrudApi/Cache/TempFileCache.php View File

@@ -8,7 +8,7 @@ class TempFileCache implements Cache
8 8
     private $path;
9 9
     private $segments;
10 10
 
11
-    public function __construct(String $prefix, String $config)
11
+    public function __construct(string $prefix, string $config)
12 12
     {
13 13
         $this->segments = [];
14 14
         $s = DIRECTORY_SEPARATOR;
@@ -27,7 +27,7 @@ class TempFileCache implements Cache
27 27
         }
28 28
     }
29 29
 
30
-    private function getFileName(String $key): String
30
+    private function getFileName(string $key): string
31 31
     {
32 32
         $s = DIRECTORY_SEPARATOR;
33 33
         $md5 = md5($key);
@@ -41,7 +41,7 @@ class TempFileCache implements Cache
41 41
         return $filename;
42 42
     }
43 43
 
44
-    public function set(String $key, String $value, int $ttl = 0): bool
44
+    public function set(string $key, string $value, int $ttl = 0): bool
45 45
     {
46 46
         $filename = $this->getFileName($key);
47 47
         $dirname = dirname($filename);
@@ -79,7 +79,7 @@ class TempFileCache implements Cache
79 79
         return $string;
80 80
     }
81 81
 
82
-    private function getString($filename): String
82
+    private function getString($filename): string
83 83
     {
84 84
         $data = $this->fileGetContents($filename);
85 85
         if ($data === false) {
@@ -92,7 +92,7 @@ class TempFileCache implements Cache
92 92
         return $string;
93 93
     }
94 94
 
95
-    public function get(String $key): String
95
+    public function get(string $key): string
96 96
     {
97 97
         $filename = $this->getFileName($key);
98 98
         if (!file_exists($filename)) {
@@ -105,7 +105,7 @@ class TempFileCache implements Cache
105 105
         return $string;
106 106
     }
107 107
 
108
-    private function clean(String $path, array $segments, int $len, bool $all) /*: void*/
108
+    private function clean(string $path, array $segments, int $len, bool $all) /*: void*/
109 109
     {
110 110
         $entries = scandir($path);
111 111
         foreach ($entries as $entry) {

+ 5
- 5
src/Tqdev/PhpCrudApi/Column/DefinitionService.php View File

@@ -16,7 +16,7 @@ class DefinitionService
16 16
         $this->reflection = $reflection;
17 17
     }
18 18
 
19
-    public function updateTable(String $tableName, /* object */ $changes): bool
19
+    public function updateTable(string $tableName, /* object */ $changes): bool
20 20
     {
21 21
         $table = $this->reflection->getTable($tableName);
22 22
         $newTable = ReflectedTable::fromJson((object) array_merge((array) $table->jsonSerialize(), (array) $changes));
@@ -28,7 +28,7 @@ class DefinitionService
28 28
         return true;
29 29
     }
30 30
 
31
-    public function updateColumn(String $tableName, String $columnName, /* object */ $changes): bool
31
+    public function updateColumn(string $tableName, string $columnName, /* object */ $changes): bool
32 32
     {
33 33
         $table = $this->reflection->getTable($tableName);
34 34
         $column = $table->getColumn($columnName);
@@ -106,7 +106,7 @@ class DefinitionService
106 106
         return true;
107 107
     }
108 108
 
109
-    public function addColumn(String $tableName, /* object */ $definition)
109
+    public function addColumn(string $tableName, /* object */ $definition)
110 110
     {
111 111
         $newColumn = ReflectedColumn::fromJson($definition);
112 112
         if (!$this->db->definition()->addColumn($tableName, $newColumn)) {
@@ -125,7 +125,7 @@ class DefinitionService
125 125
         return true;
126 126
     }
127 127
 
128
-    public function removeTable(String $tableName)
128
+    public function removeTable(string $tableName)
129 129
     {
130 130
         if (!$this->db->definition()->removeTable($tableName)) {
131 131
             return false;
@@ -133,7 +133,7 @@ class DefinitionService
133 133
         return true;
134 134
     }
135 135
 
136
-    public function removeColumn(String $tableName, String $columnName)
136
+    public function removeColumn(string $tableName, string $columnName)
137 137
     {
138 138
         $table = $this->reflection->getTable($tableName);
139 139
         $newColumn = $table->getColumn($columnName);

+ 4
- 4
src/Tqdev/PhpCrudApi/Column/Reflection/ReflectedColumn.php View File

@@ -18,7 +18,7 @@ class ReflectedColumn implements \JsonSerializable
18 18
     private $pk;
19 19
     private $fk;
20 20
 
21
-    public function __construct(String $name, String $type, int $length, int $precision, int $scale, bool $nullable, bool $pk, String $fk)
21
+    public function __construct(string $name, string $type, int $length, int $precision, int $scale, bool $nullable, bool $pk, string $fk)
22 22
     {
23 23
         $this->name = $name;
24 24
         $this->type = $type;
@@ -64,7 +64,7 @@ class ReflectedColumn implements \JsonSerializable
64 64
         $this->scale = $this->hasScale() ? $this->getScale() : 0;
65 65
     }
66 66
 
67
-    public function getName(): String
67
+    public function getName(): string
68 68
     {
69 69
         return $this->name;
70 70
     }
@@ -74,7 +74,7 @@ class ReflectedColumn implements \JsonSerializable
74 74
         return $this->nullable;
75 75
     }
76 76
 
77
-    public function getType(): String
77
+    public function getType(): string
78 78
     {
79 79
         return $this->type;
80 80
     }
@@ -144,7 +144,7 @@ class ReflectedColumn implements \JsonSerializable
144 144
         $this->fk = $value;
145 145
     }
146 146
 
147
-    public function getFk(): String
147
+    public function getFk(): string
148 148
     {
149 149
         return $this->fk;
150 150
     }

+ 3
- 3
src/Tqdev/PhpCrudApi/Column/Reflection/ReflectedDatabase.php View File

@@ -32,12 +32,12 @@ class ReflectedDatabase implements \JsonSerializable
32 32
         return new ReflectedDatabase($tableTypes);
33 33
     }
34 34
 
35
-    public function hasTable(String $tableName): bool
35
+    public function hasTable(string $tableName): bool
36 36
     {
37 37
         return isset($this->tableTypes[$tableName]);
38 38
     }
39 39
 
40
-    public function getType(String $tableName): String
40
+    public function getType(string $tableName): string
41 41
     {
42 42
         return isset($this->tableTypes[$tableName]) ? $this->tableTypes[$tableName] : '';
43 43
     }
@@ -47,7 +47,7 @@ class ReflectedDatabase implements \JsonSerializable
47 47
         return array_keys($this->tableTypes);
48 48
     }
49 49
 
50
-    public function removeTable(String $tableName): bool
50
+    public function removeTable(string $tableName): bool
51 51
     {
52 52
         if (!isset($this->tableTypes[$tableName])) {
53 53
             return false;

+ 7
- 7
src/Tqdev/PhpCrudApi/Column/Reflection/ReflectedTable.php View File

@@ -11,7 +11,7 @@ class ReflectedTable implements \JsonSerializable
11 11
     private $pk;
12 12
     private $fks;
13 13
 
14
-    public function __construct(String $name, String $type, array $columns)
14
+    public function __construct(string $name, string $type, array $columns)
15 15
     {
16 16
         $this->name = $name;
17 17
         $this->type = $type;
@@ -39,7 +39,7 @@ class ReflectedTable implements \JsonSerializable
39 39
         }
40 40
     }
41 41
 
42
-    public static function fromReflection(GenericReflection $reflection, String $name, String $type): ReflectedTable
42
+    public static function fromReflection(GenericReflection $reflection, string $name, string $type): ReflectedTable
43 43
     {
44 44
         // set columns
45 45
         $columns = [];
@@ -77,7 +77,7 @@ class ReflectedTable implements \JsonSerializable
77 77
         return new ReflectedTable($name, $type, $columns);
78 78
     }
79 79
 
80
-    public function hasColumn(String $columnName): bool
80
+    public function hasColumn(string $columnName): bool
81 81
     {
82 82
         return isset($this->columns[$columnName]);
83 83
     }
@@ -92,12 +92,12 @@ class ReflectedTable implements \JsonSerializable
92 92
         return $this->pk;
93 93
     }
94 94
 
95
-    public function getName(): String
95
+    public function getName(): string
96 96
     {
97 97
         return $this->name;
98 98
     }
99 99
 
100
-    public function getType(): String
100
+    public function getType(): string
101 101
     {
102 102
         return $this->type;
103 103
     }
@@ -112,7 +112,7 @@ class ReflectedTable implements \JsonSerializable
112 112
         return $this->columns[$columnName];
113 113
     }
114 114
 
115
-    public function getFksTo(String $tableName): array
115
+    public function getFksTo(string $tableName): array
116 116
     {
117 117
         $columns = array();
118 118
         foreach ($this->fks as $columnName => $referencedTableName) {
@@ -123,7 +123,7 @@ class ReflectedTable implements \JsonSerializable
123 123
         return $columns;
124 124
     }
125 125
 
126
-    public function removeColumn(String $columnName): bool
126
+    public function removeColumn(string $columnName): bool
127 127
     {
128 128
         if (!isset($this->columns[$columnName])) {
129 129
             return false;

+ 7
- 7
src/Tqdev/PhpCrudApi/Column/ReflectionService.php View File

@@ -36,7 +36,7 @@ class ReflectionService
36 36
         return $database;
37 37
     }
38 38
 
39
-    private function loadTable(String $tableName, bool $useCache): ReflectedTable
39
+    private function loadTable(string $tableName, bool $useCache): ReflectedTable
40 40
     {
41 41
         $data = $useCache ? $this->cache->get("ReflectedTable($tableName)") : '';
42 42
         if ($data != '') {
@@ -55,22 +55,22 @@ class ReflectionService
55 55
         $this->database = $this->loadDatabase(false);
56 56
     }
57 57
 
58
-    public function refreshTable(String $tableName)
58
+    public function refreshTable(string $tableName)
59 59
     {
60 60
         $this->tables[$tableName] = $this->loadTable($tableName, false);
61 61
     }
62 62
 
63
-    public function hasTable(String $tableName): bool
63
+    public function hasTable(string $tableName): bool
64 64
     {
65 65
         return $this->database->hasTable($tableName);
66 66
     }
67 67
 
68
-    public function getType(String $tableName): String
68
+    public function getType(string $tableName): string
69 69
     {
70 70
         return $this->database->getType($tableName);
71 71
     }
72 72
 
73
-    public function getTable(String $tableName): ReflectedTable
73
+    public function getTable(string $tableName): ReflectedTable
74 74
     {
75 75
         if (!isset($this->tables[$tableName])) {
76 76
             $this->tables[$tableName] = $this->loadTable($tableName, true);
@@ -83,12 +83,12 @@ class ReflectionService
83 83
         return $this->database->getTableNames();
84 84
     }
85 85
 
86
-    public function getDatabaseName(): String
86
+    public function getDatabaseName(): string
87 87
     {
88 88
         return $this->database->getName();
89 89
     }
90 90
 
91
-    public function removeTable(String $tableName): bool
91
+    public function removeTable(string $tableName): bool
92 92
     {
93 93
         unset($this->tables[$tableName]);
94 94
         return $this->database->removeTable($tableName);

+ 12
- 12
src/Tqdev/PhpCrudApi/Config.php View File

@@ -19,7 +19,7 @@ class Config
19 19
         'openApiBase' => '{"info":{"title":"PHP-CRUD-API","version":"1.0.0"}}',
20 20
     ];
21 21
 
22
-    private function getDefaultDriver(array $values): String
22
+    private function getDefaultDriver(array $values): string
23 23
     {
24 24
         if (isset($values['driver'])) {
25 25
             return $values['driver'];
@@ -27,7 +27,7 @@ class Config
27 27
         return 'mysql';
28 28
     }
29 29
 
30
-    private function getDefaultPort(String $driver): int
30
+    private function getDefaultPort(string $driver): int
31 31
     {
32 32
         switch ($driver) {
33 33
             case 'mysql':return 3306;
@@ -36,7 +36,7 @@ class Config
36 36
         }
37 37
     }
38 38
 
39
-    private function getDefaultAddress(String $driver): String
39
+    private function getDefaultAddress(string $driver): string
40 40
     {
41 41
         switch ($driver) {
42 42
             case 'mysql':return 'localhost';
@@ -45,7 +45,7 @@ class Config
45 45
         }
46 46
     }
47 47
 
48
-    private function getDriverDefaults(String $driver): array
48
+    private function getDriverDefaults(string $driver): array
49 49
     {
50 50
         return [
51 51
             'driver' => $driver,
@@ -92,12 +92,12 @@ class Config
92 92
         return $newValues;
93 93
     }
94 94
 
95
-    public function getDriver(): String
95
+    public function getDriver(): string
96 96
     {
97 97
         return $this->values['driver'];
98 98
     }
99 99
 
100
-    public function getAddress(): String
100
+    public function getAddress(): string
101 101
     {
102 102
         return $this->values['address'];
103 103
     }
@@ -107,17 +107,17 @@ class Config
107 107
         return $this->values['port'];
108 108
     }
109 109
 
110
-    public function getUsername(): String
110
+    public function getUsername(): string
111 111
     {
112 112
         return $this->values['username'];
113 113
     }
114 114
 
115
-    public function getPassword(): String
115
+    public function getPassword(): string
116 116
     {
117 117
         return $this->values['password'];
118 118
     }
119 119
 
120
-    public function getDatabase(): String
120
+    public function getDatabase(): string
121 121
     {
122 122
         return $this->values['database'];
123 123
     }
@@ -132,12 +132,12 @@ class Config
132 132
         return array_map('trim', explode(',', $this->values['controllers']));
133 133
     }
134 134
 
135
-    public function getCacheType(): String
135
+    public function getCacheType(): string
136 136
     {
137 137
         return $this->values['cacheType'];
138 138
     }
139 139
 
140
-    public function getCachePath(): String
140
+    public function getCachePath(): string
141 141
     {
142 142
         return $this->values['cachePath'];
143 143
     }
@@ -147,7 +147,7 @@ class Config
147 147
         return $this->values['cacheTime'];
148 148
     }
149 149
 
150
-    public function getDebug(): String
150
+    public function getDebug(): string
151 151
     {
152 152
         return $this->values['debug'];
153 153
     }

+ 1
- 1
src/Tqdev/PhpCrudApi/Controller/ColumnController.php View File

@@ -6,7 +6,7 @@ use Tqdev\PhpCrudApi\Column\DefinitionService;
6 6
 use Tqdev\PhpCrudApi\Column\ReflectionService;
7 7
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
8 8
 use Tqdev\PhpCrudApi\Record\ErrorCode;
9
-use Tqdev\PhpCrudApi\Record\RequestUtils;
9
+use Tqdev\PhpCrudApi\RequestUtils;
10 10
 use Tqdev\PhpCrudApi\Response;
11 11
 
12 12
 class ColumnController

+ 1
- 1
src/Tqdev/PhpCrudApi/Controller/RecordController.php View File

@@ -5,7 +5,7 @@ use Psr\Http\Message\ServerRequestInterface;
5 5
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
6 6
 use Tqdev\PhpCrudApi\Record\ErrorCode;
7 7
 use Tqdev\PhpCrudApi\Record\RecordService;
8
-use Tqdev\PhpCrudApi\Record\RequestUtils;
8
+use Tqdev\PhpCrudApi\RequestUtils;
9 9
 use Tqdev\PhpCrudApi\Response;
10 10
 
11 11
 class RecordController

+ 1
- 1
src/Tqdev/PhpCrudApi/Controller/Responder.php View File

@@ -7,7 +7,7 @@ use Tqdev\PhpCrudApi\Response;
7 7
 
8 8
 class Responder
9 9
 {
10
-    public function error(int $error, String $argument, $details = null): Response
10
+    public function error(int $error, string $argument, $details = null): Response
11 11
     {
12 12
         $errorCode = new ErrorCode($error);
13 13
         $status = $errorCode->getStatus();

+ 3
- 3
src/Tqdev/PhpCrudApi/Database/ColumnConverter.php View File

@@ -7,12 +7,12 @@ class ColumnConverter
7 7
 {
8 8
     private $driver;
9 9
 
10
-    public function __construct(String $driver)
10
+    public function __construct(string $driver)
11 11
     {
12 12
         $this->driver = $driver;
13 13
     }
14 14
 
15
-    public function convertColumnValue(ReflectedColumn $column): String
15
+    public function convertColumnValue(ReflectedColumn $column): string
16 16
     {
17 17
         if ($column->isBinary()) {
18 18
             switch ($this->driver) {
@@ -36,7 +36,7 @@ class ColumnConverter
36 36
         return '?';
37 37
     }
38 38
 
39
-    public function convertColumnName(ReflectedColumn $column, $value): String
39
+    public function convertColumnName(ReflectedColumn $column, $value): string
40 40
     {
41 41
         if ($column->isBinary()) {
42 42
             switch ($this->driver) {

+ 10
- 10
src/Tqdev/PhpCrudApi/Database/ColumnsBuilder.php View File

@@ -9,13 +9,13 @@ class ColumnsBuilder
9 9
     private $driver;
10 10
     private $converter;
11 11
 
12
-    public function __construct(String $driver)
12
+    public function __construct(string $driver)
13 13
     {
14 14
         $this->driver = $driver;
15 15
         $this->converter = new ColumnConverter($driver);
16 16
     }
17 17
 
18
-    public function getOffsetLimit(int $offset, int $limit): String
18
+    public function getOffsetLimit(int $offset, int $limit): string
19 19
     {
20 20
         if ($limit < 0 || $offset < 0) {
21 21
             return '';
@@ -27,14 +27,14 @@ class ColumnsBuilder
27 27
         }
28 28
     }
29 29
 
30
-    private function quoteColumnName(ReflectedColumn $column): String
30
+    private function quoteColumnName(ReflectedColumn $column): string
31 31
     {
32 32
         return '"' . $column->getName() . '"';
33 33
     }
34 34
 
35
-    public function getOrderBy(ReflectedTable $table, array $columnOrdering): String
35
+    public function getOrderBy(ReflectedTable $table, array $columnOrdering): string
36 36
     {
37
-        if (count($columnOrdering)==0) {
37
+        if (count($columnOrdering) == 0) {
38 38
             return '';
39 39
         }
40 40
         $results = array();
@@ -43,10 +43,10 @@ class ColumnsBuilder
43 43
             $quotedColumnName = $this->quoteColumnName($column);
44 44
             $results[] = $quotedColumnName . ' ' . $ordering;
45 45
         }
46
-        return ' ORDER BY '.implode(',', $results);
46
+        return ' ORDER BY ' . implode(',', $results);
47 47
     }
48 48
 
49
-    public function getSelect(ReflectedTable $table, array $columnNames): String
49
+    public function getSelect(ReflectedTable $table, array $columnNames): string
50 50
     {
51 51
         $results = array();
52 52
         foreach ($columnNames as $columnName) {
@@ -58,7 +58,7 @@ class ColumnsBuilder
58 58
         return implode(',', $results);
59 59
     }
60 60
 
61
-    public function getInsert(ReflectedTable $table, array $columnValues): String
61
+    public function getInsert(ReflectedTable $table, array $columnValues): string
62 62
     {
63 63
         $columns = array();
64 64
         $values = array();
@@ -79,7 +79,7 @@ class ColumnsBuilder
79 79
         }
80 80
     }
81 81
 
82
-    public function getUpdate(ReflectedTable $table, array $columnValues): String
82
+    public function getUpdate(ReflectedTable $table, array $columnValues): string
83 83
     {
84 84
         $results = array();
85 85
         foreach ($columnValues as $columnName => $columnValue) {
@@ -91,7 +91,7 @@ class ColumnsBuilder
91 91
         return implode(',', $results);
92 92
     }
93 93
 
94
-    public function getIncrement(ReflectedTable $table, array $columnValues): String
94
+    public function getIncrement(ReflectedTable $table, array $columnValues): string
95 95
     {
96 96
         $results = array();
97 97
         foreach ($columnValues as $columnName => $columnValue) {

+ 13
- 13
src/Tqdev/PhpCrudApi/Database/ConditionsBuilder.php View File

@@ -14,12 +14,12 @@ class ConditionsBuilder
14 14
 {
15 15
     private $driver;
16 16
 
17
-    public function __construct(String $driver)
17
+    public function __construct(string $driver)
18 18
     {
19 19
         $this->driver = $driver;
20 20
     }
21 21
 
22
-    private function getConditionSql(Condition $condition, array &$arguments): String
22
+    private function getConditionSql(Condition $condition, array &$arguments): string
23 23
     {
24 24
         if ($condition instanceof AndCondition) {
25 25
             return $this->getAndConditionSql($condition, $arguments);
@@ -39,7 +39,7 @@ class ConditionsBuilder
39 39
         throw new \Exception('Unknown Condition: ' . get_class($condition));
40 40
     }
41 41
 
42
-    private function getAndConditionSql(AndCondition $and, array &$arguments): String
42
+    private function getAndConditionSql(AndCondition $and, array &$arguments): string
43 43
     {
44 44
         $parts = [];
45 45
         foreach ($and->getConditions() as $condition) {
@@ -48,7 +48,7 @@ class ConditionsBuilder
48 48
         return '(' . implode(' AND ', $parts) . ')';
49 49
     }
50 50
 
51
-    private function getOrConditionSql(OrCondition $or, array &$arguments): String
51
+    private function getOrConditionSql(OrCondition $or, array &$arguments): string
52 52
     {
53 53
         $parts = [];
54 54
         foreach ($or->getConditions() as $condition) {
@@ -57,23 +57,23 @@ class ConditionsBuilder
57 57
         return '(' . implode(' OR ', $parts) . ')';
58 58
     }
59 59
 
60
-    private function getNotConditionSql(NotCondition $not, array &$arguments): String
60
+    private function getNotConditionSql(NotCondition $not, array &$arguments): string
61 61
     {
62 62
         $condition = $not->getCondition();
63 63
         return '(NOT ' . $this->getConditionSql($condition, $arguments) . ')';
64 64
     }
65 65
 
66
-    private function quoteColumnName(ReflectedColumn $column): String
66
+    private function quoteColumnName(ReflectedColumn $column): string
67 67
     {
68 68
         return '"' . $column->getName() . '"';
69 69
     }
70 70
 
71
-    private function escapeLikeValue(String $value): String
71
+    private function escapeLikeValue(string $value): string
72 72
     {
73 73
         return addcslashes($value, '%_');
74 74
     }
75 75
 
76
-    private function getColumnConditionSql(ColumnCondition $condition, array &$arguments): String
76
+    private function getColumnConditionSql(ColumnCondition $condition, array &$arguments): string
77 77
     {
78 78
         $column = $this->quoteColumnName($condition->getColumn());
79 79
         $operator = $condition->getOperator();
@@ -142,7 +142,7 @@ class ConditionsBuilder
142 142
         return $sql;
143 143
     }
144 144
 
145
-    private function getSpatialFunctionName(String $operator): String
145
+    private function getSpatialFunctionName(string $operator): string
146 146
     {
147 147
         switch ($operator) {
148 148
             case 'co':return 'ST_Contains';
@@ -159,12 +159,12 @@ class ConditionsBuilder
159 159
         }
160 160
     }
161 161
 
162
-    private function hasSpatialArgument(String $operator): bool
162
+    private function hasSpatialArgument(string $operator): bool
163 163
     {
164 164
         return in_array($operator, ['ic', 'is', 'iv']) ? false : true;
165 165
     }
166 166
 
167
-    private function getSpatialFunctionCall(String $functionName, String $column, bool $hasArgument): String
167
+    private function getSpatialFunctionCall(string $functionName, string $column, bool $hasArgument): string
168 168
     {
169 169
         switch ($this->driver) {
170 170
             case 'mysql':
@@ -178,7 +178,7 @@ class ConditionsBuilder
178 178
         }
179 179
     }
180 180
 
181
-    private function getSpatialConditionSql(ColumnCondition $condition, array &$arguments): String
181
+    private function getSpatialConditionSql(ColumnCondition $condition, array &$arguments): string
182 182
     {
183 183
         $column = $this->quoteColumnName($condition->getColumn());
184 184
         $operator = $condition->getOperator();
@@ -192,7 +192,7 @@ class ConditionsBuilder
192 192
         return $sql;
193 193
     }
194 194
 
195
-    public function getWhereClause(Condition $condition, array &$arguments): String
195
+    public function getWhereClause(Condition $condition, array &$arguments): string
196 196
     {
197 197
         if ($condition instanceof NoCondition) {
198 198
             return '';

+ 3
- 3
src/Tqdev/PhpCrudApi/Database/DataConverter.php View File

@@ -8,7 +8,7 @@ class DataConverter
8 8
 {
9 9
     private $driver;
10 10
 
11
-    public function __construct(String $driver)
11
+    public function __construct(string $driver)
12 12
     {
13 13
         $this->driver = $driver;
14 14
     }
@@ -24,7 +24,7 @@ class DataConverter
24 24
         return $value;
25 25
     }
26 26
 
27
-    private function getRecordValueConversion(ReflectedColumn $column): String
27
+    private function getRecordValueConversion(ReflectedColumn $column): string
28 28
     {
29 29
         if (in_array($this->driver, ['mysql', 'sqlsrv']) && $column->isBoolean()) {
30 30
             return 'boolean';
@@ -61,7 +61,7 @@ class DataConverter
61 61
         return $value;
62 62
     }
63 63
 
64
-    private function getInputValueConversion(ReflectedColumn $column): String
64
+    private function getInputValueConversion(ReflectedColumn $column): string
65 65
     {
66 66
         if ($column->isBinary()) {
67 67
             return 'base64url_to_base64';

+ 8
- 8
src/Tqdev/PhpCrudApi/Database/GenericDB.php View File

@@ -17,7 +17,7 @@ class GenericDB
17 17
     private $columns;
18 18
     private $converter;
19 19
 
20
-    private function getDsn(String $address, String $port = null, String $database = null): String
20
+    private function getDsn(string $address, string $port = null, string $database = null): string
21 21
     {
22 22
         switch ($this->driver) {
23 23
             case 'mysql':return "$this->driver:host=$address;port=$port;dbname=$database;charset=utf8mb4";
@@ -65,7 +65,7 @@ class GenericDB
65 65
         }
66 66
     }
67 67
 
68
-    public function __construct(String $driver, String $address, String $port = null, String $database = null, String $username = null, String $password = null)
68
+    public function __construct(string $driver, string $address, string $port = null, string $database = null, string $username = null, string $password = null)
69 69
     {
70 70
         $this->driver = $driver;
71 71
         $this->database = $database;
@@ -98,7 +98,7 @@ class GenericDB
98 98
         return $this->definition;
99 99
     }
100 100
 
101
-    private function addMiddlewareConditions(String $tableName, Condition $condition): Condition
101
+    private function addMiddlewareConditions(string $tableName, Condition $condition): Condition
102 102
     {
103 103
         $condition1 = VariableStore::get("authorization.conditions.$tableName");
104 104
         if ($condition1) {
@@ -137,7 +137,7 @@ class GenericDB
137 137
         return $pkValue;
138 138
     }
139 139
 
140
-    public function selectSingle(ReflectedTable $table, array $columnNames, String $id) /*: ?array*/
140
+    public function selectSingle(ReflectedTable $table, array $columnNames, string $id) /*: ?array*/
141 141
     {
142 142
         $selectColumns = $this->columns->getSelect($table, $columnNames);
143 143
         $tableName = $table->getName();
@@ -204,7 +204,7 @@ class GenericDB
204 204
         return $records;
205 205
     }
206 206
 
207
-    public function updateSingle(ReflectedTable $table, array $columnValues, String $id)
207
+    public function updateSingle(ReflectedTable $table, array $columnValues, string $id)
208 208
     {
209 209
         if (count($columnValues) == 0) {
210 210
             return 0;
@@ -221,7 +221,7 @@ class GenericDB
221 221
         return $stmt->rowCount();
222 222
     }
223 223
 
224
-    public function deleteSingle(ReflectedTable $table, String $id)
224
+    public function deleteSingle(ReflectedTable $table, string $id)
225 225
     {
226 226
         $tableName = $table->getName();
227 227
         $condition = new ColumnCondition($table->getPk(), 'eq', $id);
@@ -233,7 +233,7 @@ class GenericDB
233 233
         return $stmt->rowCount();
234 234
     }
235 235
 
236
-    public function incrementSingle(ReflectedTable $table, array $columnValues, String $id)
236
+    public function incrementSingle(ReflectedTable $table, array $columnValues, string $id)
237 237
     {
238 238
         if (count($columnValues) == 0) {
239 239
             return 0;
@@ -250,7 +250,7 @@ class GenericDB
250 250
         return $stmt->rowCount();
251 251
     }
252 252
 
253
-    private function query(String $sql, array $parameters): \PDOStatement
253
+    private function query(string $sql, array $parameters): \PDOStatement
254 254
     {
255 255
         $stmt = $this->pdo->prepare($sql);
256 256
         //echo "- $sql -- " . json_encode($parameters, JSON_UNESCAPED_UNICODE) . "\n";

+ 33
- 35
src/Tqdev/PhpCrudApi/Database/GenericDefinition.php View File

@@ -12,7 +12,7 @@ class GenericDefinition
12 12
     private $typeConverter;
13 13
     private $reflection;
14 14
 
15
-    public function __construct(\PDO $pdo, String $driver, String $database)
15
+    public function __construct(\PDO $pdo, string $driver, string $database)
16 16
     {
17 17
         $this->pdo = $pdo;
18 18
         $this->driver = $driver;
@@ -21,12 +21,12 @@ class GenericDefinition
21 21
         $this->reflection = new GenericReflection($pdo, $driver, $database);
22 22
     }
23 23
 
24
-    private function quote(String $identifier): String
24
+    private function quote(string $identifier): string
25 25
     {
26 26
         return '"' . str_replace('"', '', $identifier) . '"';
27 27
     }
28 28
 
29
-    public function getColumnType(ReflectedColumn $column, bool $update): String
29
+    public function getColumnType(ReflectedColumn $column, bool $update): string
30 30
     {
31 31
         if ($this->driver == 'pgsql' && !$update && $column->getPk() && $this->canAutoIncrement($column)) {
32 32
             return 'serial';
@@ -46,7 +46,7 @@ class GenericDefinition
46 46
         return $type . $size . $null . $auto;
47 47
     }
48 48
 
49
-    private function getPrimaryKey(String $tableName): String
49
+    private function getPrimaryKey(string $tableName): string
50 50
     {
51 51
         $pks = $this->reflection->getTablePrimaryKeys($tableName);
52 52
         if (count($pks) == 1) {
@@ -60,7 +60,7 @@ class GenericDefinition
60 60
         return in_array($column->getType(), ['integer', 'bigint']);
61 61
     }
62 62
 
63
-    private function getColumnAutoIncrement(ReflectedColumn $column, bool $update): String
63
+    private function getColumnAutoIncrement(ReflectedColumn $column, bool $update): string
64 64
     {
65 65
         if (!$this->canAutoIncrement($column)) {
66 66
             return '';
@@ -74,7 +74,7 @@ class GenericDefinition
74 74
         }
75 75
     }
76 76
 
77
-    private function getColumnNullType(ReflectedColumn $column, bool $update): String
77
+    private function getColumnNullType(ReflectedColumn $column, bool $update): string
78 78
     {
79 79
         if ($this->driver == 'pgsql' && $update) {
80 80
             return '';
@@ -82,7 +82,7 @@ class GenericDefinition
82 82
         return $column->getNullable() ? ' NULL' : ' NOT NULL';
83 83
     }
84 84
 
85
-    private function getTableRenameSQL(String $tableName, String $newTableName): String
85
+    private function getTableRenameSQL(string $tableName, string $newTableName): string
86 86
     {
87 87
         $p1 = $this->quote($tableName);
88 88
         $p2 = $this->quote($newTableName);
@@ -97,7 +97,7 @@ class GenericDefinition
97 97
         }
98 98
     }
99 99
 
100
-    private function getColumnRenameSQL(String $tableName, String $columnName, ReflectedColumn $newColumn): String
100
+    private function getColumnRenameSQL(string $tableName, string $columnName, ReflectedColumn $newColumn): string
101 101
     {
102 102
         $p1 = $this->quote($tableName);
103 103
         $p2 = $this->quote($columnName);
@@ -115,7 +115,7 @@ class GenericDefinition
115 115
         }
116 116
     }
117 117
 
118
-    private function getColumnRetypeSQL(String $tableName, String $columnName, ReflectedColumn $newColumn): String
118
+    private function getColumnRetypeSQL(string $tableName, string $columnName, ReflectedColumn $newColumn): string
119 119
     {
120 120
         $p1 = $this->quote($tableName);
121 121
         $p2 = $this->quote($columnName);
@@ -132,7 +132,7 @@ class GenericDefinition
132 132
         }
133 133
     }
134 134
 
135
-    private function getSetColumnNullableSQL(String $tableName, String $columnName, ReflectedColumn $newColumn): String
135
+    private function getSetColumnNullableSQL(string $tableName, string $columnName, ReflectedColumn $newColumn): string
136 136
     {
137 137
         $p1 = $this->quote($tableName);
138 138
         $p2 = $this->quote($columnName);
@@ -150,7 +150,7 @@ class GenericDefinition
150 150
         }
151 151
     }
152 152
 
153
-    private function getSetColumnPkConstraintSQL(String $tableName, String $columnName, ReflectedColumn $newColumn): String
153
+    private function getSetColumnPkConstraintSQL(string $tableName, string $columnName, ReflectedColumn $newColumn): string
154 154
     {
155 155
         $p1 = $this->quote($tableName);
156 156
         $p2 = $this->quote($columnName);
@@ -167,7 +167,7 @@ class GenericDefinition
167 167
         }
168 168
     }
169 169
 
170
-    private function getSetColumnPkSequenceSQL(String $tableName, String $columnName, ReflectedColumn $newColumn): String
170
+    private function getSetColumnPkSequenceSQL(string $tableName, string $columnName, ReflectedColumn $newColumn): string
171 171
     {
172 172
         $p1 = $this->quote($tableName);
173 173
         $p2 = $this->quote($columnName);
@@ -183,11 +183,11 @@ class GenericDefinition
183 183
         }
184 184
     }
185 185
 
186
-    private function getSetColumnPkSequenceStartSQL(String $tableName, String $columnName, ReflectedColumn $newColumn): String
186
+    private function getSetColumnPkSequenceStartSQL(string $tableName, string $columnName, ReflectedColumn $newColumn): string
187 187
     {
188 188
         $p1 = $this->quote($tableName);
189 189
         $p2 = $this->quote($columnName);
190
-        
190
+
191 191
         switch ($this->driver) {
192 192
             case 'mysql':
193 193
                 return "select 1";
@@ -201,7 +201,7 @@ class GenericDefinition
201 201
         }
202 202
     }
203 203
 
204
-    private function getSetColumnPkDefaultSQL(String $tableName, String $columnName, ReflectedColumn $newColumn): String
204
+    private function getSetColumnPkDefaultSQL(string $tableName, string $columnName, ReflectedColumn $newColumn): string
205 205
     {
206 206
         $p1 = $this->quote($tableName);
207 207
         $p2 = $this->quote($columnName);
@@ -230,7 +230,7 @@ class GenericDefinition
230 230
         }
231 231
     }
232 232
 
233
-    private function getAddColumnFkConstraintSQL(String $tableName, String $columnName, ReflectedColumn $newColumn): String
233
+    private function getAddColumnFkConstraintSQL(string $tableName, string $columnName, ReflectedColumn $newColumn): string
234 234
     {
235 235
         $p1 = $this->quote($tableName);
236 236
         $p2 = $this->quote($columnName);
@@ -241,7 +241,7 @@ class GenericDefinition
241 241
         return "ALTER TABLE $p1 ADD CONSTRAINT $p3 FOREIGN KEY ($p2) REFERENCES $p4 ($p5)";
242 242
     }
243 243
 
244
-    private function getRemoveColumnFkConstraintSQL(String $tableName, String $columnName, ReflectedColumn $newColumn): String
244
+    private function getRemoveColumnFkConstraintSQL(string $tableName, string $columnName, ReflectedColumn $newColumn): string
245 245
     {
246 246
         $p1 = $this->quote($tableName);
247 247
         $p2 = $this->quote($tableName . '_' . $columnName . '_fkey');
@@ -255,7 +255,7 @@ class GenericDefinition
255 255
         }
256 256
     }
257 257
 
258
-    private function getAddTableSQL(ReflectedTable $newTable): String
258
+    private function getAddTableSQL(ReflectedTable $newTable): string
259 259
     {
260 260
         $tableName = $newTable->getName();
261 261
         $p1 = $this->quote($tableName);
@@ -283,13 +283,12 @@ class GenericDefinition
283 283
         return "CREATE TABLE $p1 ($p2);";
284 284
     }
285 285
 
286
-    private function getAddColumnSQL(String $tableName, ReflectedColumn $newColumn): String
286
+    private function getAddColumnSQL(string $tableName, ReflectedColumn $newColumn): string
287 287
     {
288 288
         $p1 = $this->quote($tableName);
289 289
         $p2 = $this->quote($newColumn->getName());
290 290
         $p3 = $this->getColumnType($newColumn, false);
291 291
 
292
-        
293 292
         switch ($this->driver) {
294 293
             case 'mysql':
295 294
             case 'pgsql':
@@ -299,7 +298,7 @@ class GenericDefinition
299 298
         }
300 299
     }
301 300
 
302
-    private function getRemoveTableSQL(String $tableName): String
301
+    private function getRemoveTableSQL(string $tableName): string
303 302
     {
304 303
         $p1 = $this->quote($tableName);
305 304
 
@@ -312,12 +311,11 @@ class GenericDefinition
312 311
         }
313 312
     }
314 313
 
315
-    private function getRemoveColumnSQL(String $tableName, String $columnName): String
314
+    private function getRemoveColumnSQL(string $tableName, string $columnName): string
316 315
     {
317 316
         $p1 = $this->quote($tableName);
318 317
         $p2 = $this->quote($columnName);
319 318
 
320
-        
321 319
         switch ($this->driver) {
322 320
             case 'mysql':
323 321
             case 'pgsql':
@@ -327,31 +325,31 @@ class GenericDefinition
327 325
         }
328 326
     }
329 327
 
330
-    public function renameTable(String $tableName, String $newTableName)
328
+    public function renameTable(string $tableName, string $newTableName)
331 329
     {
332 330
         $sql = $this->getTableRenameSQL($tableName, $newTableName);
333 331
         return $this->query($sql);
334 332
     }
335 333
 
336
-    public function renameColumn(String $tableName, String $columnName, ReflectedColumn $newColumn)
334
+    public function renameColumn(string $tableName, string $columnName, ReflectedColumn $newColumn)
337 335
     {
338 336
         $sql = $this->getColumnRenameSQL($tableName, $columnName, $newColumn);
339 337
         return $this->query($sql);
340 338
     }
341 339
 
342
-    public function retypeColumn(String $tableName, String $columnName, ReflectedColumn $newColumn)
340
+    public function retypeColumn(string $tableName, string $columnName, ReflectedColumn $newColumn)
343 341
     {
344 342
         $sql = $this->getColumnRetypeSQL($tableName, $columnName, $newColumn);
345 343
         return $this->query($sql);
346 344
     }
347 345
 
348
-    public function setColumnNullable(String $tableName, String $columnName, ReflectedColumn $newColumn)
346
+    public function setColumnNullable(string $tableName, string $columnName, ReflectedColumn $newColumn)
349 347
     {
350 348
         $sql = $this->getSetColumnNullableSQL($tableName, $columnName, $newColumn);
351 349
         return $this->query($sql);
352 350
     }
353 351
 
354
-    public function addColumnPrimaryKey(String $tableName, String $columnName, ReflectedColumn $newColumn)
352
+    public function addColumnPrimaryKey(string $tableName, string $columnName, ReflectedColumn $newColumn)
355 353
     {
356 354
         $sql = $this->getSetColumnPkConstraintSQL($tableName, $columnName, $newColumn);
357 355
         $this->query($sql);
@@ -366,7 +364,7 @@ class GenericDefinition
366 364
         return true;
367 365
     }
368 366
 
369
-    public function removeColumnPrimaryKey(String $tableName, String $columnName, ReflectedColumn $newColumn)
367
+    public function removeColumnPrimaryKey(string $tableName, string $columnName, ReflectedColumn $newColumn)
370 368
     {
371 369
         if ($this->canAutoIncrement($newColumn)) {
372 370
             $sql = $this->getSetColumnPkDefaultSQL($tableName, $columnName, $newColumn);
@@ -379,13 +377,13 @@ class GenericDefinition
379 377
         return true;
380 378
     }
381 379
 
382
-    public function addColumnForeignKey(String $tableName, String $columnName, ReflectedColumn $newColumn)
380
+    public function addColumnForeignKey(string $tableName, string $columnName, ReflectedColumn $newColumn)
383 381
     {
384 382
         $sql = $this->getAddColumnFkConstraintSQL($tableName, $columnName, $newColumn);
385 383
         return $this->query($sql);
386 384
     }
387 385
 
388
-    public function removeColumnForeignKey(String $tableName, String $columnName, ReflectedColumn $newColumn)
386
+    public function removeColumnForeignKey(string $tableName, string $columnName, ReflectedColumn $newColumn)
389 387
     {
390 388
         $sql = $this->getRemoveColumnFkConstraintSQL($tableName, $columnName, $newColumn);
391 389
         return $this->query($sql);
@@ -397,25 +395,25 @@ class GenericDefinition
397 395
         return $this->query($sql);
398 396
     }
399 397
 
400
-    public function addColumn(String $tableName, ReflectedColumn $newColumn)
398
+    public function addColumn(string $tableName, ReflectedColumn $newColumn)
401 399
     {
402 400
         $sql = $this->getAddColumnSQL($tableName, $newColumn);
403 401
         return $this->query($sql);
404 402
     }
405 403
 
406
-    public function removeTable(String $tableName)
404
+    public function removeTable(string $tableName)
407 405
     {
408 406
         $sql = $this->getRemoveTableSQL($tableName);
409 407
         return $this->query($sql);
410 408
     }
411 409
 
412
-    public function removeColumn(String $tableName, String $columnName)
410
+    public function removeColumn(string $tableName, string $columnName)
413 411
     {
414 412
         $sql = $this->getRemoveColumnSQL($tableName, $columnName);
415 413
         return $this->query($sql);
416 414
     }
417 415
 
418
-    private function query(String $sql): bool
416
+    private function query(string $sql): bool
419 417
     {
420 418
         $stmt = $this->pdo->prepare($sql);
421 419
         //echo "- $sql -- []\n";

+ 11
- 11
src/Tqdev/PhpCrudApi/Database/GenericReflection.php View File

@@ -8,7 +8,7 @@ class GenericReflection
8 8
     private $database;
9 9
     private $typeConverter;
10 10
 
11
-    public function __construct(\PDO $pdo, String $driver, String $database)
11
+    public function __construct(\PDO $pdo, string $driver, string $database)
12 12
     {
13 13
         $this->pdo = $pdo;
14 14
         $this->driver = $driver;
@@ -25,7 +25,7 @@ class GenericReflection
25 25
         }
26 26
     }
27 27
 
28
-    private function getTablesSQL(): String
28
+    private function getTablesSQL(): string
29 29
     {
30 30
         switch ($this->driver) {
31 31
             case 'mysql':return 'SELECT "TABLE_NAME", "TABLE_TYPE" FROM "INFORMATION_SCHEMA"."TABLES" WHERE "TABLE_TYPE" IN (\'BASE TABLE\' , \'VIEW\') AND "TABLE_SCHEMA" = ? ORDER BY BINARY "TABLE_NAME"';
@@ -34,7 +34,7 @@ class GenericReflection
34 34
         }
35 35
     }
36 36
 
37
-    private function getTableColumnsSQL(): String
37
+    private function getTableColumnsSQL(): string
38 38
     {
39 39
         switch ($this->driver) {
40 40
             case 'mysql':return 'SELECT "COLUMN_NAME", "IS_NULLABLE", "DATA_TYPE", "CHARACTER_MAXIMUM_LENGTH", "NUMERIC_PRECISION", "NUMERIC_SCALE" FROM "INFORMATION_SCHEMA"."COLUMNS" WHERE "TABLE_NAME" = ? AND "TABLE_SCHEMA" = ?';
@@ -43,7 +43,7 @@ class GenericReflection
43 43
         }
44 44
     }
45 45
 
46
-    private function getTablePrimaryKeysSQL(): String
46
+    private function getTablePrimaryKeysSQL(): string
47 47
     {
48 48
         switch ($this->driver) {
49 49
             case 'mysql':return 'SELECT "COLUMN_NAME" FROM "INFORMATION_SCHEMA"."KEY_COLUMN_USAGE" WHERE "CONSTRAINT_NAME" = \'PRIMARY\' AND "TABLE_NAME" = ? AND "TABLE_SCHEMA" = ?';
@@ -52,7 +52,7 @@ class GenericReflection
52 52
         }
53 53
     }
54 54
 
55
-    private function getTableForeignKeysSQL(): String
55
+    private function getTableForeignKeysSQL(): string
56 56
     {
57 57
         switch ($this->driver) {
58 58
             case 'mysql':return 'SELECT "COLUMN_NAME", "REFERENCED_TABLE_NAME" FROM "INFORMATION_SCHEMA"."KEY_COLUMN_USAGE" WHERE "REFERENCED_TABLE_NAME" IS NOT NULL AND "TABLE_NAME" = ? AND "TABLE_SCHEMA" = ?';
@@ -61,7 +61,7 @@ class GenericReflection
61 61
         }
62 62
     }
63 63
 
64
-    public function getDatabaseName(): String
64
+    public function getDatabaseName(): string
65 65
     {
66 66
         return $this->database;
67 67
     }
@@ -89,7 +89,7 @@ class GenericReflection
89 89
         return $results;
90 90
     }
91 91
 
92
-    public function getTableColumns(String $tableName, String $type): array
92
+    public function getTableColumns(string $tableName, string $type): array
93 93
     {
94 94
         $sql = $this->getTableColumnsSQL();
95 95
         $results = $this->query($sql, [$tableName, $this->database]);
@@ -101,7 +101,7 @@ class GenericReflection
101 101
         return $results;
102 102
     }
103 103
 
104
-    public function getTablePrimaryKeys(String $tableName): array
104
+    public function getTablePrimaryKeys(string $tableName): array
105 105
     {
106 106
         $sql = $this->getTablePrimaryKeysSQL();
107 107
         $results = $this->query($sql, [$tableName, $this->database]);
@@ -112,7 +112,7 @@ class GenericReflection
112 112
         return $primaryKeys;
113 113
     }
114 114
 
115
-    public function getTableForeignKeys(String $tableName): array
115
+    public function getTableForeignKeys(string $tableName): array
116 116
     {
117 117
         $sql = $this->getTableForeignKeysSQL();
118 118
         $results = $this->query($sql, [$tableName, $this->database]);
@@ -123,12 +123,12 @@ class GenericReflection
123 123
         return $foreignKeys;
124 124
     }
125 125
 
126
-    public function toJdbcType(String $type, int $size): String
126
+    public function toJdbcType(string $type, int $size): string
127 127
     {
128 128
         return $this->typeConverter->toJdbc($type, $size);
129 129
     }
130 130
 
131
-    private function query(String $sql, array $parameters): array
131
+    private function query(string $sql, array $parameters): array
132 132
     {
133 133
         $stmt = $this->pdo->prepare($sql);
134 134
         //echo "- $sql -- " . json_encode($parameters, JSON_UNESCAPED_UNICODE) . "\n";

+ 3
- 3
src/Tqdev/PhpCrudApi/Database/TypeConverter.php View File

@@ -5,7 +5,7 @@ class TypeConverter
5 5
 {
6 6
     private $driver;
7 7
 
8
-    public function __construct(String $driver)
8
+    public function __construct(string $driver)
9 9
     {
10 10
         $this->driver = $driver;
11 11
     }
@@ -163,7 +163,7 @@ class TypeConverter
163 163
         'geometry' => true,
164 164
     ];
165 165
 
166
-    public function toJdbc(String $type, int $size): String
166
+    public function toJdbc(string $type, int $size): string
167 167
     {
168 168
         $jdbcType = strtolower($type);
169 169
         if (isset($this->toJdbc[$this->driver]["$jdbcType($size)"])) {
@@ -181,7 +181,7 @@ class TypeConverter
181 181
         return $jdbcType;
182 182
     }
183 183
 
184
-    public function fromJdbc(String $type): String
184
+    public function fromJdbc(string $type): string
185 185
     {
186 186
         $jdbcType = strtolower($type);
187 187
         if (isset($this->fromJdbc[$this->driver][$jdbcType])) {

+ 2
- 1
src/Tqdev/PhpCrudApi/Middleware/AjaxOnlyMiddleware.php View File

@@ -5,6 +5,7 @@ use Psr\Http\Message\ServerRequestInterface;
5 5
 use Tqdev\PhpCrudApi\Controller\Responder;
6 6
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
7 7
 use Tqdev\PhpCrudApi\Record\ErrorCode;
8
+use Tqdev\PhpCrudApi\RequestUtils;
8 9
 use Tqdev\PhpCrudApi\Response;
9 10
 
10 11
 class AjaxOnlyMiddleware extends Middleware
@@ -16,7 +17,7 @@ class AjaxOnlyMiddleware extends Middleware
16 17
         if (!in_array($method, $excludeMethods)) {
17 18
             $headerName = $this->getProperty('headerName', 'X-Requested-With');
18 19
             $headerValue = $this->getProperty('headerValue', 'XMLHttpRequest');
19
-            if ($headerValue != $request->getHeader($headerName)) {
20
+            if ($headerValue != RequestUtils::getHeader($request, $headerName)) {
20 21
                 return $this->responder->error(ErrorCode::ONLY_AJAX_REQUESTS_ALLOWED, $method);
21 22
             }
22 23
         }

+ 4
- 4
src/Tqdev/PhpCrudApi/Middleware/AuthorizationMiddleware.php View File

@@ -8,7 +8,7 @@ use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
8 8
 use Tqdev\PhpCrudApi\Middleware\Communication\VariableStore;
9 9
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
10 10
 use Tqdev\PhpCrudApi\Record\FilterInfo;
11
-use Tqdev\PhpCrudApi\Record\RequestUtils;
11
+use Tqdev\PhpCrudApi\RequestUtils;
12 12
 use Tqdev\PhpCrudApi\Response;
13 13
 
14 14
 class AuthorizationMiddleware extends Middleware
@@ -21,7 +21,7 @@ class AuthorizationMiddleware extends Middleware
21 21
         $this->reflection = $reflection;
22 22
     }
23 23
 
24
-    private function handleColumns(String $operation, String $tableName) /*: void*/
24
+    private function handleColumns(string $operation, string $tableName) /*: void*/
25 25
     {
26 26
         $columnHandler = $this->getProperty('columnHandler', '');
27 27
         if ($columnHandler) {
@@ -35,7 +35,7 @@ class AuthorizationMiddleware extends Middleware
35 35
         }
36 36
     }
37 37
 
38
-    private function handleTable(String $operation, String $tableName) /*: void*/
38
+    private function handleTable(string $operation, string $tableName) /*: void*/
39 39
     {
40 40
         if (!$this->reflection->hasTable($tableName)) {
41 41
             return;
@@ -51,7 +51,7 @@ class AuthorizationMiddleware extends Middleware
51 51
         }
52 52
     }
53 53
 
54
-    private function handleRecords(String $operation, String $tableName) /*: void*/
54
+    private function handleRecords(string $operation, string $tableName) /*: void*/
55 55
     {
56 56
         if (!$this->reflection->hasTable($tableName)) {
57 57
             return;

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/Base/Middleware.php View File

@@ -22,12 +22,12 @@ abstract class Middleware implements Handler
22 22
         $this->next = $handler;
23 23
     }
24 24
 
25
-    protected function getArrayProperty(String $key, String $default): array
25
+    protected function getArrayProperty(string $key, string $default): array
26 26
     {
27 27
         return array_filter(array_map('trim', explode(',', $this->getProperty($key, $default))));
28 28
     }
29 29
 
30
-    protected function getProperty(String $key, $default)
30
+    protected function getProperty(string $key, $default)
31 31
     {
32 32
         return isset($this->properties[$key]) ? $this->properties[$key] : $default;
33 33
     }

+ 8
- 6
src/Tqdev/PhpCrudApi/Middleware/BasicAuthMiddleware.php View File

@@ -5,11 +5,12 @@ use Psr\Http\Message\ServerRequestInterface;
5 5
 use Tqdev\PhpCrudApi\Controller\Responder;
6 6
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
7 7
 use Tqdev\PhpCrudApi\Record\ErrorCode;
8
+use Tqdev\PhpCrudApi\RequestUtils;
8 9
 use Tqdev\PhpCrudApi\Response;
9 10
 
10 11
 class BasicAuthMiddleware extends Middleware
11 12
 {
12
-    private function hasCorrectPassword(String $username, String $password, array &$passwords): bool
13
+    private function hasCorrectPassword(string $username, string $password, array &$passwords): bool
13 14
     {
14 15
         $hash = isset($passwords[$username]) ? $passwords[$username] : false;
15 16
         if ($hash && password_verify($password, $hash)) {
@@ -21,7 +22,7 @@ class BasicAuthMiddleware extends Middleware
21 22
         return false;
22 23
     }
23 24
 
24
-    private function getValidUsername(String $username, String $password, String $passwordFile): String
25
+    private function getValidUsername(string $username, string $password, string $passwordFile): string
25 26
     {
26 27
         $passwords = $this->readPasswords($passwordFile);
27 28
         $valid = $this->hasCorrectPassword($username, $password, $passwords);
@@ -29,7 +30,7 @@ class BasicAuthMiddleware extends Middleware
29 30
         return $valid ? $username : '';
30 31
     }
31 32
 
32
-    private function readPasswords(String $passwordFile): array
33
+    private function readPasswords(string $passwordFile): array
33 34
     {
34 35
         $passwords = [];
35 36
         $passwordLines = file($passwordFile);
@@ -45,7 +46,7 @@ class BasicAuthMiddleware extends Middleware
45 46
         return $passwords;
46 47
     }
47 48
 
48
-    private function writePasswords(String $passwordFile, array $passwords): bool
49
+    private function writePasswords(string $passwordFile, array $passwords): bool
49 50
     {
50 51
         $success = false;
51 52
         $passwordFileContents = '';
@@ -58,12 +59,13 @@ class BasicAuthMiddleware extends Middleware
58 59
         return $success;
59 60
     }
60 61
 
61
-    private function getAuthorizationCredentials(ServerRequestInterface $request): String
62
+    private function getAuthorizationCredentials(ServerRequestInterface $request): string
62 63
     {
63 64
         if (isset($_SERVER['PHP_AUTH_USER'])) {
64 65
             return $_SERVER['PHP_AUTH_USER'] . ':' . $_SERVER['PHP_AUTH_PW'];
65 66
         }
66
-        $parts = explode(' ', trim($request->getHeader('Authorization')), 2);
67
+        $header = RequestUtils::getHeader($request, 'Authorization');
68
+        $parts = explode(' ', trim($header), 2);
67 69
         if (count($parts) != 2) {
68 70
             return '';
69 71
         }

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/Communication/VariableStore.php View File

@@ -5,7 +5,7 @@ class VariableStore
5 5
 {
6 6
     static $values = array();
7 7
 
8
-    public static function get(String $key)
8
+    public static function get(string $key)
9 9
     {
10 10
         if (isset(self::$values[$key])) {
11 11
             return self::$values[$key];
@@ -13,7 +13,7 @@ class VariableStore
13 13
         return null;
14 14
     }
15 15
 
16
-    public static function set(String $key, /* object */ $value)
16
+    public static function set(string $key, /* object */ $value)
17 17
     {
18 18
         self::$values[$key] = $value;
19 19
     }

+ 1
- 1
src/Tqdev/PhpCrudApi/Middleware/CorsMiddleware.php View File

@@ -9,7 +9,7 @@ use Tqdev\PhpCrudApi\Response;
9 9
 
10 10
 class CorsMiddleware extends Middleware
11 11
 {
12
-    private function isOriginAllowed(String $origin, String $allowedOrigins): bool
12
+    private function isOriginAllowed(string $origin, string $allowedOrigins): bool
13 13
     {
14 14
         $found = false;
15 15
         foreach (explode(',', $allowedOrigins) as $allowedOrigin) {

+ 1
- 1
src/Tqdev/PhpCrudApi/Middleware/CustomizationMiddleware.php View File

@@ -6,7 +6,7 @@ use Tqdev\PhpCrudApi\Column\ReflectionService;
6 6
 use Tqdev\PhpCrudApi\Controller\Responder;
7 7
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
8 8
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
9
-use Tqdev\PhpCrudApi\Record\RequestUtils;
9
+use Tqdev\PhpCrudApi\RequestUtils;
10 10
 use Tqdev\PhpCrudApi\Response;
11 11
 
12 12
 class CustomizationMiddleware extends Middleware

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/FirewallMiddleware.php View File

@@ -9,7 +9,7 @@ use Tqdev\PhpCrudApi\Response;
9 9
 
10 10
 class FirewallMiddleware extends Middleware
11 11
 {
12
-    private function ipMatch(String $ip, String $cidr): bool
12
+    private function ipMatch(string $ip, string $cidr): bool
13 13
     {
14 14
         if (strpos($cidr, '/') !== false) {
15 15
             list($subnet, $mask) = explode('/', trim($cidr));
@@ -24,7 +24,7 @@ class FirewallMiddleware extends Middleware
24 24
         return false;
25 25
     }
26 26
 
27
-    private function isIpAllowed(String $ipAddress, String $allowedIpAddresses): bool
27
+    private function isIpAllowed(string $ipAddress, string $allowedIpAddresses): bool
28 28
     {
29 29
         foreach (explode(',', $allowedIpAddresses) as $allowedIp) {
30 30
             if ($this->ipMatch($ipAddress, $allowedIp)) {

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/IpAddressMiddleware.php View File

@@ -7,7 +7,7 @@ use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
7 7
 use Tqdev\PhpCrudApi\Controller\Responder;
8 8
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
9 9
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
10
-use Tqdev\PhpCrudApi\Record\RequestUtils;
10
+use Tqdev\PhpCrudApi\RequestUtils;
11 11
 use Tqdev\PhpCrudApi\Response;
12 12
 
13 13
 class IpAddressMiddleware extends Middleware
@@ -20,7 +20,7 @@ class IpAddressMiddleware extends Middleware
20 20
         $this->reflection = $reflection;
21 21
     }
22 22
 
23
-    private function callHandler($record, String $operation, ReflectedTable $table) /*: object */
23
+    private function callHandler($record, string $operation, ReflectedTable $table) /*: object */
24 24
     {
25 25
         $context = (array) $record;
26 26
         $columnNames = $this->getProperty('columns', '');

+ 1
- 1
src/Tqdev/PhpCrudApi/Middleware/JoinLimitsMiddleware.php View File

@@ -7,7 +7,7 @@ use Tqdev\PhpCrudApi\Controller\Responder;
7 7
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
8 8
 use Tqdev\PhpCrudApi\Middleware\Communication\VariableStore;
9 9
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
10
-use Tqdev\PhpCrudApi\Record\RequestUtils;
10
+use Tqdev\PhpCrudApi\RequestUtils;
11 11
 use Tqdev\PhpCrudApi\Response;
12 12
 
13 13
 class JoinLimitsMiddleware extends Middleware

+ 7
- 5
src/Tqdev/PhpCrudApi/Middleware/JwtAuthMiddleware.php View File

@@ -5,11 +5,12 @@ use Psr\Http\Message\ServerRequestInterface;
5 5
 use Tqdev\PhpCrudApi\Controller\Responder;
6 6
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
7 7
 use Tqdev\PhpCrudApi\Record\ErrorCode;
8
+use Tqdev\PhpCrudApi\RequestUtils;
8 9
 use Tqdev\PhpCrudApi\Response;
9 10
 
10 11
 class JwtAuthMiddleware extends Middleware
11 12
 {
12
-    private function getVerifiedClaims(String $token, int $time, int $leeway, int $ttl, String $secret, array $requirements): array
13
+    private function getVerifiedClaims(string $token, int $time, int $leeway, int $ttl, string $secret, array $requirements): array
13 14
     {
14 15
         $algorithms = array(
15 16
             'HS256' => 'sha256',
@@ -89,7 +90,7 @@ class JwtAuthMiddleware extends Middleware
89 90
         return $claims;
90 91
     }
91 92
 
92
-    private function getClaims(String $token): array
93
+    private function getClaims(string $token): array
93 94
     {
94 95
         $time = (int) $this->getProperty('time', time());
95 96
         $leeway = (int) $this->getProperty('leeway', '5');
@@ -106,10 +107,11 @@ class JwtAuthMiddleware extends Middleware
106 107
         return $this->getVerifiedClaims($token, $time, $leeway, $ttl, $secret, $requirements);
107 108
     }
108 109
 
109
-    private function getAuthorizationToken(ServerRequestInterface $request): String
110
+    private function getAuthorizationToken(ServerRequestInterface $request): string
110 111
     {
111
-        $header = $this->getProperty('header', 'X-Authorization');
112
-        $parts = explode(' ', trim($request->getHeader($header)), 2);
112
+        $headerName = $this->getProperty('header', 'X-Authorization');
113
+        $headerValue = RequestUtils::getHeader($request, $headerName);
114
+        $parts = explode(' ', trim($headerValue), 2);
113 115
         if (count($parts) != 2) {
114 116
             return '';
115 117
         }

+ 4
- 4
src/Tqdev/PhpCrudApi/Middleware/MultiTenancyMiddleware.php View File

@@ -10,7 +10,7 @@ use Tqdev\PhpCrudApi\Middleware\Router\Router;
10 10
 use Tqdev\PhpCrudApi\Record\Condition\ColumnCondition;
11 11
 use Tqdev\PhpCrudApi\Record\Condition\Condition;
12 12
 use Tqdev\PhpCrudApi\Record\Condition\NoCondition;
13
-use Tqdev\PhpCrudApi\Record\RequestUtils;
13
+use Tqdev\PhpCrudApi\RequestUtils;
14 14
 use Tqdev\PhpCrudApi\Response;
15 15
 
16 16
 class MultiTenancyMiddleware extends Middleware
@@ -23,7 +23,7 @@ class MultiTenancyMiddleware extends Middleware
23 23
         $this->reflection = $reflection;
24 24
     }
25 25
 
26
-    private function getCondition(String $tableName, array $pairs): Condition
26
+    private function getCondition(string $tableName, array $pairs): Condition
27 27
     {
28 28
         $condition = new NoCondition();
29 29
         $table = $this->reflection->getTable($tableName);
@@ -33,7 +33,7 @@ class MultiTenancyMiddleware extends Middleware
33 33
         return $condition;
34 34
     }
35 35
 
36
-    private function getPairs($handler, String $operation, String $tableName): array
36
+    private function getPairs($handler, string $operation, string $tableName): array
37 37
     {
38 38
         $result = array();
39 39
         $pairs = call_user_func($handler, $operation, $tableName);
@@ -46,7 +46,7 @@ class MultiTenancyMiddleware extends Middleware
46 46
         return $result;
47 47
     }
48 48
 
49
-    private function handleRecord(ServerRequestInterface $request, String $operation, array $pairs) /*: void*/
49
+    private function handleRecord(ServerRequestInterface $request, string $operation, array $pairs) /*: void*/
50 50
     {
51 51
         $record = $request->getBody();
52 52
         if ($record === null) {

+ 1
- 1
src/Tqdev/PhpCrudApi/Middleware/PageLimitsMiddleware.php View File

@@ -7,7 +7,7 @@ use Tqdev\PhpCrudApi\Controller\Responder;
7 7
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
8 8
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
9 9
 use Tqdev\PhpCrudApi\Record\ErrorCode;
10
-use Tqdev\PhpCrudApi\Record\RequestUtils;
10
+use Tqdev\PhpCrudApi\RequestUtils;
11 11
 use Tqdev\PhpCrudApi\Response;
12 12
 
13 13
 class PageLimitsMiddleware extends Middleware

+ 1
- 1
src/Tqdev/PhpCrudApi/Middleware/Router/Router.php View File

@@ -8,7 +8,7 @@ use Tqdev\PhpCrudApi\Response;
8 8
 
9 9
 interface Router extends Handler
10 10
 {
11
-    public function register(String $method, String $path, array $handler);
11
+    public function register(string $method, string $path, array $handler);
12 12
 
13 13
     public function load(Middleware $middleware);
14 14
 

+ 1
- 1
src/Tqdev/PhpCrudApi/Middleware/Router/SimpleRouter.php View File

@@ -44,7 +44,7 @@ class SimpleRouter implements Router
44 44
         return $tree;
45 45
     }
46 46
 
47
-    public function register(String $method, String $path, array $handler)
47
+    public function register(string $method, string $path, array $handler)
48 48
     {
49 49
         $routeNumber = count($this->routeHandlers);
50 50
         $this->routeHandlers[$routeNumber] = $handler;

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/SanitationMiddleware.php View File

@@ -7,7 +7,7 @@ use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
7 7
 use Tqdev\PhpCrudApi\Controller\Responder;
8 8
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
9 9
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
10
-use Tqdev\PhpCrudApi\Record\RequestUtils;
10
+use Tqdev\PhpCrudApi\RequestUtils;
11 11
 use Tqdev\PhpCrudApi\Response;
12 12
 
13 13
 class SanitationMiddleware extends Middleware
@@ -20,7 +20,7 @@ class SanitationMiddleware extends Middleware
20 20
         $this->reflection = $reflection;
21 21
     }
22 22
 
23
-    private function callHandler($handler, $record, String $operation, ReflectedTable $table) /*: object */
23
+    private function callHandler($handler, $record, string $operation, ReflectedTable $table) /*: object */
24 24
     {
25 25
         $context = (array) $record;
26 26
         $tableName = $table->getName();

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/ValidationMiddleware.php View File

@@ -8,7 +8,7 @@ use Tqdev\PhpCrudApi\Controller\Responder;
8 8
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
9 9
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
10 10
 use Tqdev\PhpCrudApi\Record\ErrorCode;
11
-use Tqdev\PhpCrudApi\Record\RequestUtils;
11
+use Tqdev\PhpCrudApi\RequestUtils;
12 12
 use Tqdev\PhpCrudApi\Response;
13 13
 
14 14
 class ValidationMiddleware extends Middleware
@@ -21,7 +21,7 @@ class ValidationMiddleware extends Middleware
21 21
         $this->reflection = $reflection;
22 22
     }
23 23
 
24
-    private function callHandler($handler, $record, String $operation, ReflectedTable $table) /*: Response?*/
24
+    private function callHandler($handler, $record, string $operation, ReflectedTable $table) /*: Response?*/
25 25
     {
26 26
         $context = (array) $record;
27 27
         $details = array();

+ 1
- 1
src/Tqdev/PhpCrudApi/Middleware/XsrfMiddleware.php View File

@@ -9,7 +9,7 @@ use Tqdev\PhpCrudApi\Response;
9 9
 
10 10
 class XsrfMiddleware extends Middleware
11 11
 {
12
-    private function getToken(): String
12
+    private function getToken(): string
13 13
     {
14 14
         $cookieName = $this->getProperty('cookieName', 'XSRF-TOKEN');
15 15
         if (isset($_COOKIE[$cookieName])) {

+ 8
- 8
src/Tqdev/PhpCrudApi/OpenApi/OpenApiBuilder.php View File

@@ -40,7 +40,7 @@ class OpenApiBuilder
40 40
         $this->openapi = new OpenApiDefinition($base);
41 41
     }
42 42
 
43
-    private function getServerUrl(): String
43
+    private function getServerUrl(): string
44 44
     {
45 45
         $protocol = @$_SERVER['HTTP_X_FORWARDED_PROTO'] ?: @$_SERVER['REQUEST_SCHEME'] ?: ((isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") ? "https" : "http");
46 46
         $port = @intval($_SERVER['HTTP_X_FORWARDED_PORT']) ?: @intval($_SERVER["SERVER_PORT"]) ?: (($protocol === 'https') ? 443 : 80);
@@ -102,7 +102,7 @@ class OpenApiBuilder
102 102
         return $this->openapi;
103 103
     }
104 104
 
105
-    private function isOperationOnTableAllowed(String $operation, String $tableName): bool
105
+    private function isOperationOnTableAllowed(string $operation, string $tableName): bool
106 106
     {
107 107
         $tableHandler = VariableStore::get('authorization.tableHandler');
108 108
         if (!$tableHandler) {
@@ -111,7 +111,7 @@ class OpenApiBuilder
111 111
         return (bool) call_user_func($tableHandler, $operation, $tableName);
112 112
     }
113 113
 
114
-    private function isOperationOnColumnAllowed(String $operation, String $tableName, String $columnName): bool
114
+    private function isOperationOnColumnAllowed(string $operation, string $tableName, string $columnName): bool
115 115
     {
116 116
         $columnHandler = VariableStore::get('authorization.columnHandler');
117 117
         if (!$columnHandler) {
@@ -120,7 +120,7 @@ class OpenApiBuilder
120 120
         return (bool) call_user_func($columnHandler, $operation, $tableName, $columnName);
121 121
     }
122 122
 
123
-    private function setPath(String $tableName) /*: void*/
123
+    private function setPath(string $tableName) /*: void*/
124 124
     {
125 125
         $table = $this->reflection->getTable($tableName);
126 126
         $type = $table->getType();
@@ -181,7 +181,7 @@ class OpenApiBuilder
181 181
         }
182 182
     }
183 183
 
184
-    private function setComponentSchema(String $tableName, array $references) /*: void*/
184
+    private function setComponentSchema(string $tableName, array $references) /*: void*/
185 185
     {
186 186
         $table = $this->reflection->getTable($tableName);
187 187
         $type = $table->getType();
@@ -231,7 +231,7 @@ class OpenApiBuilder
231 231
         }
232 232
     }
233 233
 
234
-    private function setComponentResponse(String $tableName) /*: void*/
234
+    private function setComponentResponse(string $tableName) /*: void*/
235 235
     {
236 236
         $table = $this->reflection->getTable($tableName);
237 237
         $type = $table->getType();
@@ -256,7 +256,7 @@ class OpenApiBuilder
256 256
         }
257 257
     }
258 258
 
259
-    private function setComponentRequestBody(String $tableName) /*: void*/
259
+    private function setComponentRequestBody(string $tableName) /*: void*/
260 260
     {
261 261
         $table = $this->reflection->getTable($tableName);
262 262
         $type = $table->getType();
@@ -327,7 +327,7 @@ class OpenApiBuilder
327 327
         $this->openapi->set("components|parameters|join|required", false);
328 328
     }
329 329
 
330
-    private function setTag(int $index, String $tableName) /*: void*/
330
+    private function setTag(int $index, string $tableName) /*: void*/
331 331
     {
332 332
         $this->openapi->set("tags|$index|name", "$tableName");
333 333
         $this->openapi->set("tags|$index|description", "$tableName operations");

+ 2
- 2
src/Tqdev/PhpCrudApi/OpenApi/OpenApiDefinition.php View File

@@ -10,7 +10,7 @@ class OpenApiDefinition implements \JsonSerializable
10 10
         $this->root = $base;
11 11
     }
12 12
 
13
-    public function set(String $path, $value) /*: void*/
13
+    public function set(string $path, $value) /*: void*/
14 14
     {
15 15
         $parts = explode('|', trim($path, '|'));
16 16
         $current = &$this->root;
@@ -24,7 +24,7 @@ class OpenApiDefinition implements \JsonSerializable
24 24
         $current = $value;
25 25
     }
26 26
 
27
-    public function has(String $path): bool
27
+    public function has(string $path): bool
28 28
     {
29 29
         $parts = explode('|', trim($path, '|'));
30 30
         $current = &$this->root;

+ 2
- 2
src/Tqdev/PhpCrudApi/Record/ColumnIncluder.php View File

@@ -6,12 +6,12 @@ use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
6 6
 class ColumnIncluder
7 7
 {
8 8
 
9
-    private function isMandatory(String $tableName, String $columnName, array $params): bool
9
+    private function isMandatory(string $tableName, string $columnName, array $params): bool
10 10
     {
11 11
         return isset($params['mandatory']) && in_array($tableName . "." . $columnName, $params['mandatory']);
12 12
     }
13 13
 
14
-    private function select(String $tableName, bool $primaryTable, array $params, String $paramName,
14
+    private function select(string $tableName, bool $primaryTable, array $params, string $paramName,
15 15
         array $columnNames, bool $include): array{
16 16
         if (!isset($params[$paramName])) {
17 17
             return $columnNames;

+ 3
- 3
src/Tqdev/PhpCrudApi/Record/Condition/ColumnCondition.php View File

@@ -9,7 +9,7 @@ class ColumnCondition extends Condition
9 9
     private $operator;
10 10
     private $value;
11 11
 
12
-    public function __construct(ReflectedColumn $column, String $operator, String $value)
12
+    public function __construct(ReflectedColumn $column, string $operator, string $value)
13 13
     {
14 14
         $this->column = $column;
15 15
         $this->operator = $operator;
@@ -21,12 +21,12 @@ class ColumnCondition extends Condition
21 21
         return $this->column;
22 22
     }
23 23
 
24
-    public function getOperator(): String
24
+    public function getOperator(): string
25 25
     {
26 26
         return $this->operator;
27 27
     }
28 28
 
29
-    public function getValue(): String
29
+    public function getValue(): string
30 30
     {
31 31
         return $this->value;
32 32
     }

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

@@ -26,7 +26,7 @@ abstract class Condition
26 26
         return new NotCondition($this);
27 27
     }
28 28
 
29
-    public static function fromString(ReflectedTable $table, String $value): Condition
29
+    public static function fromString(ReflectedTable $table, string $value): Condition
30 30
     {
31 31
         $condition = new NoCondition();
32 32
         $parts = explode(',', $value, 3);

+ 2
- 2
src/Tqdev/PhpCrudApi/Record/Document/ErrorDocument.php View File

@@ -9,7 +9,7 @@ class ErrorDocument implements \JsonSerializable
9 9
     public $message;
10 10
     public $details;
11 11
 
12
-    public function __construct(ErrorCode $errorCode, String $argument, $details)
12
+    public function __construct(ErrorCode $errorCode, string $argument, $details)
13 13
     {
14 14
         $this->code = $errorCode->getCode();
15 15
         $this->message = $errorCode->getMessage($argument);
@@ -21,7 +21,7 @@ class ErrorDocument implements \JsonSerializable
21 21
         return $this->code;
22 22
     }
23 23
 
24
-    public function getMessage(): String
24
+    public function getMessage(): string
25 25
     {
26 26
         return $this->message;
27 27
     }

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

@@ -71,7 +71,7 @@ class ErrorCode
71 71
         return $this->code;
72 72
     }
73 73
 
74
-    public function getMessage(String $argument): String
74
+    public function getMessage(string $argument): string
75 75
     {
76 76
         return sprintf($this->message, $argument);
77 77
     }

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

@@ -31,7 +31,7 @@ class PathTree implements \JsonSerializable
31 31
         return $this->tree->values;
32 32
     }
33 33
 
34
-    public function get(String $key): PathTree
34
+    public function get(string $key): PathTree
35 35
     {
36 36
         if (!isset($this->tree->branches->$key)) {
37 37
             return null;

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

@@ -26,7 +26,7 @@ class RecordService
26 26
         $this->pagination = new PaginationInfo();
27 27
     }
28 28
 
29
-    private function sanitizeRecord(String $tableName, /* object */ $record, String $id)
29
+    private function sanitizeRecord(string $tableName, /* object */ $record, string $id)
30 30
     {
31 31
         $keyset = array_keys((array) $record);
32 32
         foreach ($keyset as $key) {
@@ -45,17 +45,17 @@ class RecordService
45 45
         }
46 46
     }
47 47
 
48
-    public function hasTable(String $table): bool
48
+    public function hasTable(string $table): bool
49 49
     {
50 50
         return $this->reflection->hasTable($table);
51 51
     }
52 52
 
53
-    public function getType(String $table): String
53
+    public function getType(string $table): string
54 54
     {
55 55
         return $this->reflection->getType($table);
56 56
     }
57 57
 
58
-    public function create(String $tableName, /* object */ $record, array $params)
58
+    public function create(string $tableName, /* object */ $record, array $params)
59 59
     {
60 60
         $this->sanitizeRecord($tableName, $record, '');
61 61
         $table = $this->reflection->getTable($tableName);
@@ -63,7 +63,7 @@ class RecordService
63 63
         return $this->db->createSingle($table, $columnValues);
64 64
     }
65 65
 
66
-    public function read(String $tableName, String $id, array $params) /*: ?object*/
66
+    public function read(string $tableName, string $id, array $params) /*: ?object*/
67 67
     {
68 68
         $table = $this->reflection->getTable($tableName);
69 69
         $this->joiner->addMandatoryColumns($table, $params);
@@ -77,7 +77,7 @@ class RecordService
77 77
         return $records[0];
78 78
     }
79 79
 
80
-    public function update(String $tableName, String $id, /* object */ $record, array $params)
80
+    public function update(string $tableName, string $id, /* object */ $record, array $params)
81 81
     {
82 82
         $this->sanitizeRecord($tableName, $record, $id);
83 83
         $table = $this->reflection->getTable($tableName);
@@ -85,13 +85,13 @@ class RecordService
85 85
         return $this->db->updateSingle($table, $columnValues, $id);
86 86
     }
87 87
 
88
-    public function delete(String $tableName, String $id, array $params)
88
+    public function delete(string $tableName, string $id, array $params)
89 89
     {
90 90
         $table = $this->reflection->getTable($tableName);
91 91
         return $this->db->deleteSingle($table, $id);
92 92
     }
93 93
 
94
-    public function increment(String $tableName, String $id, /* object */ $record, array $params)
94
+    public function increment(string $tableName, string $id, /* object */ $record, array $params)
95 95
     {
96 96
         $this->sanitizeRecord($tableName, $record, $id);
97 97
         $table = $this->reflection->getTable($tableName);
@@ -99,7 +99,7 @@ class RecordService
99 99
         return $this->db->incrementSingle($table, $columnValues, $id);
100 100
     }
101 101
 
102
-    public function _list(String $tableName, array $params): ListDocument
102
+    public function _list(string $tableName, array $params): ListDocument
103 103
     {
104 104
         $table = $this->reflection->getTable($tableName);
105 105
         $this->joiner->addMandatoryColumns($table, $params);

+ 0
- 85
src/Tqdev/PhpCrudApi/Record/RequestUtils.php View File

@@ -1,85 +0,0 @@
1
-<?php
2
-namespace Tqdev\PhpCrudApi\Record;
3
-
4
-use Psr\Http\Message\ServerRequestInterface;
5
-use Tqdev\PhpCrudApi\Column\ReflectionService;
6
-
7
-class RequestUtils
8
-{
9
-    public static function getParams(ServerRequestInterface $request): array
10
-    {
11
-        $params = array();
12
-        $query = $request->getUri()->getQuery();
13
-        $query = str_replace('][]=', ']=', str_replace('=', '[]=', $query));
14
-        parse_str($query, $params);
15
-        return $params;
16
-    }
17
-
18
-    public static function getPathSegment(ServerRequestInterface $request, int $part): String
19
-    {
20
-        $pathSegments = explode('/', rtrim($request->getUri()->getPath(), '/'));
21
-        if ($part < 0 || $part >= count($pathSegments)) {
22
-            return '';
23
-        }
24
-        return $pathSegments[$part];
25
-    }
26
-
27
-    public static function getOperation(ServerRequestInterface $request): String
28
-    {
29
-        $method = $request->getMethod();
30
-        $path = RequestUtils::getPathSegment($request, 1);
31
-        $hasPk = RequestUtils::getPathSegment($request, 3) != '';
32
-        switch ($path) {
33
-            case 'openapi':
34
-                return 'document';
35
-            case 'columns':
36
-                return $method == 'get' ? 'reflect' : 'remodel';
37
-            case 'records':
38
-                switch ($method) {
39
-                    case 'POST':
40
-                        return 'create';
41
-                    case 'GET':
42
-                        return $hasPk ? 'read' : 'list';
43
-                    case 'PUT':
44
-                        return 'update';
45
-                    case 'DELETE':
46
-                        return 'delete';
47
-                    case 'PATCH':
48
-                        return 'increment';
49
-                }
50
-        }
51
-        return 'unknown';
52
-    }
53
-
54
-    private static function getJoinTables(String $tableName, array $parameters): array
55
-    {
56
-        $uniqueTableNames = array();
57
-        $uniqueTableNames[$tableName] = true;
58
-        if (isset($parameters['join'])) {
59
-            foreach ($parameters['join'] as $parameter) {
60
-                $tableNames = explode(',', trim($parameter));
61
-                foreach ($tableNames as $tableName) {
62
-                    $uniqueTableNames[$tableName] = true;
63
-                }
64
-            }
65
-        }
66
-        return array_keys($uniqueTableNames);
67
-    }
68
-
69
-    public static function getTableNames(ServerRequestInterface $request, ReflectionService $reflection): array
70
-    {
71
-        $path = RequestUtils::getPathSegment($request, 1);
72
-        $tableName = RequestUtils::getPathSegment($request, 2);
73
-        $allTableNames = $reflection->getTableNames();
74
-        switch ($path) {
75
-            case 'openapi':
76
-                return $allTableNames;
77
-            case 'columns':
78
-                return $tableName ? [$tableName] : $allTableNames;
79
-            case 'records':
80
-                return self::getJoinTables($tableName, RequestUtils::getParams($request));
81
-        }
82
-        return $allTableNames;
83
-    }
84
-
85
-}

+ 12
- 12
src/Tqdev/PhpCrudApi/Request.old View File

@@ -11,7 +11,7 @@ class Request
11 11
     private $headers;
12 12
     private $highPerformance;
13 13
 
14
-    public function __construct(String $method = null, String $path = null, String $query = null, array $headers = null, String $body = null, bool $highPerformance = true)
14
+    public function __construct(string $method = null, string $path = null, string $query = null, array $headers = null, string $body = null, bool $highPerformance = true)
15 15
     {
16 16
         $this->parseMethod($method);
17 17
         $this->parsePath($path);
@@ -21,7 +21,7 @@ class Request
21 21
         $this->highPerformance = $highPerformance;
22 22
     }
23 23
 
24
-    private function parseMethod(String $method = null)
24
+    private function parseMethod(string $method = null)
25 25
     {
26 26
         if (!$method) {
27 27
             if (isset($_SERVER['REQUEST_METHOD'])) {
@@ -33,7 +33,7 @@ class Request
33 33
         $this->method = $method;
34 34
     }
35 35
 
36
-    private function parsePath(String $path = null)
36
+    private function parsePath(string $path = null)
37 37
     {
38 38
         if (!$path) {
39 39
             if (isset($_SERVER['PATH_INFO'])) {
@@ -46,7 +46,7 @@ class Request
46 46
         $this->pathSegments = explode('/', $path);
47 47
     }
48 48
 
49
-    private function parseParams(String $query = null)
49
+    private function parseParams(string $query = null)
50 50
     {
51 51
         if (!$query) {
52 52
             if (isset($_SERVER['QUERY_STRING'])) {
@@ -75,7 +75,7 @@ class Request
75 75
         $this->headers = $headers;
76 76
     }
77 77
 
78
-    private function decodeBody(String $body) /*: ?object*/
78
+    private function decodeBody(string $body) /*: ?object*/
79 79
     {
80 80
         $first = substr($body, 0, 1);
81 81
         if ($first == '[' || $first == '{') {
@@ -97,7 +97,7 @@ class Request
97 97
         return $object;
98 98
     }
99 99
 
100
-    private function parseBody(String $body = null) /*: void*/
100
+    private function parseBody(string $body = null) /*: void*/
101 101
     {
102 102
         if (!$body) {
103 103
             $body = file_get_contents('php://input');
@@ -105,17 +105,17 @@ class Request
105 105
         $this->body = $this->decodeBody($body);
106 106
     }
107 107
 
108
-    public function getMethod(): String
108
+    public function getMethod(): string
109 109
     {
110 110
         return $this->method;
111 111
     }
112 112
 
113
-    public function getPath(): String
113
+    public function getPath(): string
114 114
     {
115 115
         return $this->path;
116 116
     }
117 117
 
118
-    public function getPathSegment(int $part): String
118
+    public function getPathSegment(int $part): string
119 119
     {
120 120
         if ($part < 0 || $part >= count($this->pathSegments)) {
121 121
             return '';
@@ -143,12 +143,12 @@ class Request
143 143
         $this->body = $body;
144 144
     }
145 145
 
146
-    public function addHeader(String $key, String $value)
146
+    public function addHeader(string $key, string $value)
147 147
     {
148 148
         $this->headers[$key] = $value;
149 149
     }
150 150
 
151
-    public function getHeader(String $key): String
151
+    public function getHeader(string $key): string
152 152
     {
153 153
         if (isset($this->headers[$key])) {
154 154
             return $this->headers[$key];
@@ -167,7 +167,7 @@ class Request
167 167
         return $this->headers;
168 168
     }
169 169
 
170
-    public static function fromString(String $request): Request
170
+    public static function fromString(string $request): Request
171 171
     {
172 172
         $parts = explode("\n\n", trim($request), 2);
173 173
         $head = $parts[0];

+ 1
- 1
src/Tqdev/PhpCrudApi/RequestFactory.php View File

@@ -14,7 +14,7 @@ class RequestFactory
14 14
         return $creator->fromGlobals();
15 15
     }
16 16
 
17
-    public static function fromString(String $request): ServerRequestInterface
17
+    public static function fromString(string $request): ServerRequestInterface
18 18
     {
19 19
         $parts = explode("\n\n", trim($request), 2);
20 20
         $lines = explode("\n", $parts[0]);

+ 4
- 4
src/Tqdev/PhpCrudApi/Response.php View File

@@ -39,17 +39,17 @@ class Response
39 39
         return $this->status;
40 40
     }
41 41
 
42
-    public function getBody(): String
42
+    public function getBody(): string
43 43
     {
44 44
         return $this->body;
45 45
     }
46 46
 
47
-    public function addHeader(String $key, String $value)
47
+    public function addHeader(string $key, string $value)
48 48
     {
49 49
         $this->headers[$key] = $value;
50 50
     }
51 51
 
52
-    public function getHeader(String $key): String
52
+    public function getHeader(string $key): string
53 53
     {
54 54
         if (isset($this->headers[$key])) {
55 55
             return $this->headers[$key];
@@ -78,7 +78,7 @@ class Response
78 78
         $this->addHeader('X-Exception-File', $e->getFile() . ':' . $e->getLine());
79 79
     }
80 80
 
81
-    public function __toString(): String
81
+    public function __toString(): string
82 82
     {
83 83
         $str = "$this->status\n";
84 84
         foreach ($this->headers as $key => $value) {

Loading…
Cancel
Save