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
 
3
 
4
 interface Cache
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
     public function clear(): bool;
8
     public function clear(): bool;
9
 }
9
 }

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

7
 {
7
 {
8
     const PREFIX = 'phpcrudapi-%s-%s-%s-';
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
         $driver = $config->getDriver();
12
         $driver = $config->getDriver();
13
         $database = $config->getDatabase();
13
         $database = $config->getDatabase();

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

6
     protected $prefix;
6
     protected $prefix;
7
     protected $memcache;
7
     protected $memcache;
8
 
8
 
9
-    public function __construct(String $prefix, String $config)
9
+    public function __construct(string $prefix, string $config)
10
     {
10
     {
11
         $this->prefix = $prefix;
11
         $this->prefix = $prefix;
12
         if ($config == '') {
12
         if ($config == '') {
27
         return new \Memcache();
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
         return $this->memcache->set($this->prefix . $key, $value, 0, $ttl);
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
         return $this->memcache->get($this->prefix . $key) ?: '';
37
         return $this->memcache->get($this->prefix . $key) ?: '';
38
     }
38
     }

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

8
         return new \Memcached();
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
         return $this->memcache->set($this->prefix . $key, $value, $ttl);
13
         return $this->memcache->set($this->prefix . $key, $value, $ttl);
14
     }
14
     }

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

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
         return true;
12
         return true;
13
     }
13
     }
14
 
14
 
15
-    public function get(String $key): String
15
+    public function get(string $key): string
16
     {
16
     {
17
         return '';
17
         return '';
18
     }
18
     }

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

6
     protected $prefix;
6
     protected $prefix;
7
     protected $redis;
7
     protected $redis;
8
 
8
 
9
-    public function __construct(String $prefix, String $config)
9
+    public function __construct(string $prefix, string $config)
10
     {
10
     {
11
         $this->prefix = $prefix;
11
         $this->prefix = $prefix;
12
         if ($config == '') {
12
         if ($config == '') {
20
         call_user_func_array(array($this->redis, 'pconnect'), $params);
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
         return $this->redis->set($this->prefix . $key, $value, $ttl);
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
         return $this->redis->get($this->prefix . $key) ?: '';
30
         return $this->redis->get($this->prefix . $key) ?: '';
31
     }
31
     }

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

8
     private $path;
8
     private $path;
9
     private $segments;
9
     private $segments;
10
 
10
 
11
-    public function __construct(String $prefix, String $config)
11
+    public function __construct(string $prefix, string $config)
12
     {
12
     {
13
         $this->segments = [];
13
         $this->segments = [];
14
         $s = DIRECTORY_SEPARATOR;
14
         $s = DIRECTORY_SEPARATOR;
27
         }
27
         }
28
     }
28
     }
29
 
29
 
30
-    private function getFileName(String $key): String
30
+    private function getFileName(string $key): string
31
     {
31
     {
32
         $s = DIRECTORY_SEPARATOR;
32
         $s = DIRECTORY_SEPARATOR;
33
         $md5 = md5($key);
33
         $md5 = md5($key);
41
         return $filename;
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
         $filename = $this->getFileName($key);
46
         $filename = $this->getFileName($key);
47
         $dirname = dirname($filename);
47
         $dirname = dirname($filename);
79
         return $string;
79
         return $string;
80
     }
80
     }
81
 
81
 
82
-    private function getString($filename): String
82
+    private function getString($filename): string
83
     {
83
     {
84
         $data = $this->fileGetContents($filename);
84
         $data = $this->fileGetContents($filename);
85
         if ($data === false) {
85
         if ($data === false) {
92
         return $string;
92
         return $string;
93
     }
93
     }
94
 
94
 
95
-    public function get(String $key): String
95
+    public function get(string $key): string
96
     {
96
     {
97
         $filename = $this->getFileName($key);
97
         $filename = $this->getFileName($key);
98
         if (!file_exists($filename)) {
98
         if (!file_exists($filename)) {
105
         return $string;
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
         $entries = scandir($path);
110
         $entries = scandir($path);
111
         foreach ($entries as $entry) {
111
         foreach ($entries as $entry) {

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

16
         $this->reflection = $reflection;
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
         $table = $this->reflection->getTable($tableName);
21
         $table = $this->reflection->getTable($tableName);
22
         $newTable = ReflectedTable::fromJson((object) array_merge((array) $table->jsonSerialize(), (array) $changes));
22
         $newTable = ReflectedTable::fromJson((object) array_merge((array) $table->jsonSerialize(), (array) $changes));
28
         return true;
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
         $table = $this->reflection->getTable($tableName);
33
         $table = $this->reflection->getTable($tableName);
34
         $column = $table->getColumn($columnName);
34
         $column = $table->getColumn($columnName);
106
         return true;
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
         $newColumn = ReflectedColumn::fromJson($definition);
111
         $newColumn = ReflectedColumn::fromJson($definition);
112
         if (!$this->db->definition()->addColumn($tableName, $newColumn)) {
112
         if (!$this->db->definition()->addColumn($tableName, $newColumn)) {
125
         return true;
125
         return true;
126
     }
126
     }
127
 
127
 
128
-    public function removeTable(String $tableName)
128
+    public function removeTable(string $tableName)
129
     {
129
     {
130
         if (!$this->db->definition()->removeTable($tableName)) {
130
         if (!$this->db->definition()->removeTable($tableName)) {
131
             return false;
131
             return false;
133
         return true;
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
         $table = $this->reflection->getTable($tableName);
138
         $table = $this->reflection->getTable($tableName);
139
         $newColumn = $table->getColumn($columnName);
139
         $newColumn = $table->getColumn($columnName);

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

18
     private $pk;
18
     private $pk;
19
     private $fk;
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
         $this->name = $name;
23
         $this->name = $name;
24
         $this->type = $type;
24
         $this->type = $type;
64
         $this->scale = $this->hasScale() ? $this->getScale() : 0;
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
         return $this->name;
69
         return $this->name;
70
     }
70
     }
74
         return $this->nullable;
74
         return $this->nullable;
75
     }
75
     }
76
 
76
 
77
-    public function getType(): String
77
+    public function getType(): string
78
     {
78
     {
79
         return $this->type;
79
         return $this->type;
80
     }
80
     }
144
         $this->fk = $value;
144
         $this->fk = $value;
145
     }
145
     }
146
 
146
 
147
-    public function getFk(): String
147
+    public function getFk(): string
148
     {
148
     {
149
         return $this->fk;
149
         return $this->fk;
150
     }
150
     }

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

32
         return new ReflectedDatabase($tableTypes);
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
         return isset($this->tableTypes[$tableName]);
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
         return isset($this->tableTypes[$tableName]) ? $this->tableTypes[$tableName] : '';
42
         return isset($this->tableTypes[$tableName]) ? $this->tableTypes[$tableName] : '';
43
     }
43
     }
47
         return array_keys($this->tableTypes);
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
         if (!isset($this->tableTypes[$tableName])) {
52
         if (!isset($this->tableTypes[$tableName])) {
53
             return false;
53
             return false;

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

11
     private $pk;
11
     private $pk;
12
     private $fks;
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
         $this->name = $name;
16
         $this->name = $name;
17
         $this->type = $type;
17
         $this->type = $type;
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
         // set columns
44
         // set columns
45
         $columns = [];
45
         $columns = [];
77
         return new ReflectedTable($name, $type, $columns);
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
         return isset($this->columns[$columnName]);
82
         return isset($this->columns[$columnName]);
83
     }
83
     }
92
         return $this->pk;
92
         return $this->pk;
93
     }
93
     }
94
 
94
 
95
-    public function getName(): String
95
+    public function getName(): string
96
     {
96
     {
97
         return $this->name;
97
         return $this->name;
98
     }
98
     }
99
 
99
 
100
-    public function getType(): String
100
+    public function getType(): string
101
     {
101
     {
102
         return $this->type;
102
         return $this->type;
103
     }
103
     }
112
         return $this->columns[$columnName];
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
         $columns = array();
117
         $columns = array();
118
         foreach ($this->fks as $columnName => $referencedTableName) {
118
         foreach ($this->fks as $columnName => $referencedTableName) {
123
         return $columns;
123
         return $columns;
124
     }
124
     }
125
 
125
 
126
-    public function removeColumn(String $columnName): bool
126
+    public function removeColumn(string $columnName): bool
127
     {
127
     {
128
         if (!isset($this->columns[$columnName])) {
128
         if (!isset($this->columns[$columnName])) {
129
             return false;
129
             return false;

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

36
         return $database;
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
         $data = $useCache ? $this->cache->get("ReflectedTable($tableName)") : '';
41
         $data = $useCache ? $this->cache->get("ReflectedTable($tableName)") : '';
42
         if ($data != '') {
42
         if ($data != '') {
55
         $this->database = $this->loadDatabase(false);
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
         $this->tables[$tableName] = $this->loadTable($tableName, false);
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
         return $this->database->hasTable($tableName);
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
         return $this->database->getType($tableName);
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
         if (!isset($this->tables[$tableName])) {
75
         if (!isset($this->tables[$tableName])) {
76
             $this->tables[$tableName] = $this->loadTable($tableName, true);
76
             $this->tables[$tableName] = $this->loadTable($tableName, true);
83
         return $this->database->getTableNames();
83
         return $this->database->getTableNames();
84
     }
84
     }
85
 
85
 
86
-    public function getDatabaseName(): String
86
+    public function getDatabaseName(): string
87
     {
87
     {
88
         return $this->database->getName();
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
         unset($this->tables[$tableName]);
93
         unset($this->tables[$tableName]);
94
         return $this->database->removeTable($tableName);
94
         return $this->database->removeTable($tableName);

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

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

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

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

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

5
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
5
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
6
 use Tqdev\PhpCrudApi\Record\ErrorCode;
6
 use Tqdev\PhpCrudApi\Record\ErrorCode;
7
 use Tqdev\PhpCrudApi\Record\RecordService;
7
 use Tqdev\PhpCrudApi\Record\RecordService;
8
-use Tqdev\PhpCrudApi\Record\RequestUtils;
8
+use Tqdev\PhpCrudApi\RequestUtils;
9
 use Tqdev\PhpCrudApi\Response;
9
 use Tqdev\PhpCrudApi\Response;
10
 
10
 
11
 class RecordController
11
 class RecordController

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

7
 
7
 
8
 class Responder
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
         $errorCode = new ErrorCode($error);
12
         $errorCode = new ErrorCode($error);
13
         $status = $errorCode->getStatus();
13
         $status = $errorCode->getStatus();

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

7
 {
7
 {
8
     private $driver;
8
     private $driver;
9
 
9
 
10
-    public function __construct(String $driver)
10
+    public function __construct(string $driver)
11
     {
11
     {
12
         $this->driver = $driver;
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
         if ($column->isBinary()) {
17
         if ($column->isBinary()) {
18
             switch ($this->driver) {
18
             switch ($this->driver) {
36
         return '?';
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
         if ($column->isBinary()) {
41
         if ($column->isBinary()) {
42
             switch ($this->driver) {
42
             switch ($this->driver) {

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

9
     private $driver;
9
     private $driver;
10
     private $converter;
10
     private $converter;
11
 
11
 
12
-    public function __construct(String $driver)
12
+    public function __construct(string $driver)
13
     {
13
     {
14
         $this->driver = $driver;
14
         $this->driver = $driver;
15
         $this->converter = new ColumnConverter($driver);
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
         if ($limit < 0 || $offset < 0) {
20
         if ($limit < 0 || $offset < 0) {
21
             return '';
21
             return '';
27
         }
27
         }
28
     }
28
     }
29
 
29
 
30
-    private function quoteColumnName(ReflectedColumn $column): String
30
+    private function quoteColumnName(ReflectedColumn $column): string
31
     {
31
     {
32
         return '"' . $column->getName() . '"';
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
             return '';
38
             return '';
39
         }
39
         }
40
         $results = array();
40
         $results = array();
43
             $quotedColumnName = $this->quoteColumnName($column);
43
             $quotedColumnName = $this->quoteColumnName($column);
44
             $results[] = $quotedColumnName . ' ' . $ordering;
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
         $results = array();
51
         $results = array();
52
         foreach ($columnNames as $columnName) {
52
         foreach ($columnNames as $columnName) {
58
         return implode(',', $results);
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
         $columns = array();
63
         $columns = array();
64
         $values = array();
64
         $values = array();
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
         $results = array();
84
         $results = array();
85
         foreach ($columnValues as $columnName => $columnValue) {
85
         foreach ($columnValues as $columnName => $columnValue) {
91
         return implode(',', $results);
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
         $results = array();
96
         $results = array();
97
         foreach ($columnValues as $columnName => $columnValue) {
97
         foreach ($columnValues as $columnName => $columnValue) {

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

14
 {
14
 {
15
     private $driver;
15
     private $driver;
16
 
16
 
17
-    public function __construct(String $driver)
17
+    public function __construct(string $driver)
18
     {
18
     {
19
         $this->driver = $driver;
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
         if ($condition instanceof AndCondition) {
24
         if ($condition instanceof AndCondition) {
25
             return $this->getAndConditionSql($condition, $arguments);
25
             return $this->getAndConditionSql($condition, $arguments);
39
         throw new \Exception('Unknown Condition: ' . get_class($condition));
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
         $parts = [];
44
         $parts = [];
45
         foreach ($and->getConditions() as $condition) {
45
         foreach ($and->getConditions() as $condition) {
48
         return '(' . implode(' AND ', $parts) . ')';
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
         $parts = [];
53
         $parts = [];
54
         foreach ($or->getConditions() as $condition) {
54
         foreach ($or->getConditions() as $condition) {
57
         return '(' . implode(' OR ', $parts) . ')';
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
         $condition = $not->getCondition();
62
         $condition = $not->getCondition();
63
         return '(NOT ' . $this->getConditionSql($condition, $arguments) . ')';
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
         return '"' . $column->getName() . '"';
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
         return addcslashes($value, '%_');
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
         $column = $this->quoteColumnName($condition->getColumn());
78
         $column = $this->quoteColumnName($condition->getColumn());
79
         $operator = $condition->getOperator();
79
         $operator = $condition->getOperator();
142
         return $sql;
142
         return $sql;
143
     }
143
     }
144
 
144
 
145
-    private function getSpatialFunctionName(String $operator): String
145
+    private function getSpatialFunctionName(string $operator): string
146
     {
146
     {
147
         switch ($operator) {
147
         switch ($operator) {
148
             case 'co':return 'ST_Contains';
148
             case 'co':return 'ST_Contains';
159
         }
159
         }
160
     }
160
     }
161
 
161
 
162
-    private function hasSpatialArgument(String $operator): bool
162
+    private function hasSpatialArgument(string $operator): bool
163
     {
163
     {
164
         return in_array($operator, ['ic', 'is', 'iv']) ? false : true;
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
         switch ($this->driver) {
169
         switch ($this->driver) {
170
             case 'mysql':
170
             case 'mysql':
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
         $column = $this->quoteColumnName($condition->getColumn());
183
         $column = $this->quoteColumnName($condition->getColumn());
184
         $operator = $condition->getOperator();
184
         $operator = $condition->getOperator();
192
         return $sql;
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
         if ($condition instanceof NoCondition) {
197
         if ($condition instanceof NoCondition) {
198
             return '';
198
             return '';

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

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

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

17
     private $columns;
17
     private $columns;
18
     private $converter;
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
         switch ($this->driver) {
22
         switch ($this->driver) {
23
             case 'mysql':return "$this->driver:host=$address;port=$port;dbname=$database;charset=utf8mb4";
23
             case 'mysql':return "$this->driver:host=$address;port=$port;dbname=$database;charset=utf8mb4";
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
         $this->driver = $driver;
70
         $this->driver = $driver;
71
         $this->database = $database;
71
         $this->database = $database;
98
         return $this->definition;
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
         $condition1 = VariableStore::get("authorization.conditions.$tableName");
103
         $condition1 = VariableStore::get("authorization.conditions.$tableName");
104
         if ($condition1) {
104
         if ($condition1) {
137
         return $pkValue;
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
         $selectColumns = $this->columns->getSelect($table, $columnNames);
142
         $selectColumns = $this->columns->getSelect($table, $columnNames);
143
         $tableName = $table->getName();
143
         $tableName = $table->getName();
204
         return $records;
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
         if (count($columnValues) == 0) {
209
         if (count($columnValues) == 0) {
210
             return 0;
210
             return 0;
221
         return $stmt->rowCount();
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
         $tableName = $table->getName();
226
         $tableName = $table->getName();
227
         $condition = new ColumnCondition($table->getPk(), 'eq', $id);
227
         $condition = new ColumnCondition($table->getPk(), 'eq', $id);
233
         return $stmt->rowCount();
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
         if (count($columnValues) == 0) {
238
         if (count($columnValues) == 0) {
239
             return 0;
239
             return 0;
250
         return $stmt->rowCount();
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
         $stmt = $this->pdo->prepare($sql);
255
         $stmt = $this->pdo->prepare($sql);
256
         //echo "- $sql -- " . json_encode($parameters, JSON_UNESCAPED_UNICODE) . "\n";
256
         //echo "- $sql -- " . json_encode($parameters, JSON_UNESCAPED_UNICODE) . "\n";

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

12
     private $typeConverter;
12
     private $typeConverter;
13
     private $reflection;
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
         $this->pdo = $pdo;
17
         $this->pdo = $pdo;
18
         $this->driver = $driver;
18
         $this->driver = $driver;
21
         $this->reflection = new GenericReflection($pdo, $driver, $database);
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
         return '"' . str_replace('"', '', $identifier) . '"';
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
         if ($this->driver == 'pgsql' && !$update && $column->getPk() && $this->canAutoIncrement($column)) {
31
         if ($this->driver == 'pgsql' && !$update && $column->getPk() && $this->canAutoIncrement($column)) {
32
             return 'serial';
32
             return 'serial';
46
         return $type . $size . $null . $auto;
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
         $pks = $this->reflection->getTablePrimaryKeys($tableName);
51
         $pks = $this->reflection->getTablePrimaryKeys($tableName);
52
         if (count($pks) == 1) {
52
         if (count($pks) == 1) {
60
         return in_array($column->getType(), ['integer', 'bigint']);
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
         if (!$this->canAutoIncrement($column)) {
65
         if (!$this->canAutoIncrement($column)) {
66
             return '';
66
             return '';
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
         if ($this->driver == 'pgsql' && $update) {
79
         if ($this->driver == 'pgsql' && $update) {
80
             return '';
80
             return '';
82
         return $column->getNullable() ? ' NULL' : ' NOT NULL';
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
         $p1 = $this->quote($tableName);
87
         $p1 = $this->quote($tableName);
88
         $p2 = $this->quote($newTableName);
88
         $p2 = $this->quote($newTableName);
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
         $p1 = $this->quote($tableName);
102
         $p1 = $this->quote($tableName);
103
         $p2 = $this->quote($columnName);
103
         $p2 = $this->quote($columnName);
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
         $p1 = $this->quote($tableName);
120
         $p1 = $this->quote($tableName);
121
         $p2 = $this->quote($columnName);
121
         $p2 = $this->quote($columnName);
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
         $p1 = $this->quote($tableName);
137
         $p1 = $this->quote($tableName);
138
         $p2 = $this->quote($columnName);
138
         $p2 = $this->quote($columnName);
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
         $p1 = $this->quote($tableName);
155
         $p1 = $this->quote($tableName);
156
         $p2 = $this->quote($columnName);
156
         $p2 = $this->quote($columnName);
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
         $p1 = $this->quote($tableName);
172
         $p1 = $this->quote($tableName);
173
         $p2 = $this->quote($columnName);
173
         $p2 = $this->quote($columnName);
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
         $p1 = $this->quote($tableName);
188
         $p1 = $this->quote($tableName);
189
         $p2 = $this->quote($columnName);
189
         $p2 = $this->quote($columnName);
190
-        
190
+
191
         switch ($this->driver) {
191
         switch ($this->driver) {
192
             case 'mysql':
192
             case 'mysql':
193
                 return "select 1";
193
                 return "select 1";
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
         $p1 = $this->quote($tableName);
206
         $p1 = $this->quote($tableName);
207
         $p2 = $this->quote($columnName);
207
         $p2 = $this->quote($columnName);
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
         $p1 = $this->quote($tableName);
235
         $p1 = $this->quote($tableName);
236
         $p2 = $this->quote($columnName);
236
         $p2 = $this->quote($columnName);
241
         return "ALTER TABLE $p1 ADD CONSTRAINT $p3 FOREIGN KEY ($p2) REFERENCES $p4 ($p5)";
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
         $p1 = $this->quote($tableName);
246
         $p1 = $this->quote($tableName);
247
         $p2 = $this->quote($tableName . '_' . $columnName . '_fkey');
247
         $p2 = $this->quote($tableName . '_' . $columnName . '_fkey');
255
         }
255
         }
256
     }
256
     }
257
 
257
 
258
-    private function getAddTableSQL(ReflectedTable $newTable): String
258
+    private function getAddTableSQL(ReflectedTable $newTable): string
259
     {
259
     {
260
         $tableName = $newTable->getName();
260
         $tableName = $newTable->getName();
261
         $p1 = $this->quote($tableName);
261
         $p1 = $this->quote($tableName);
283
         return "CREATE TABLE $p1 ($p2);";
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
         $p1 = $this->quote($tableName);
288
         $p1 = $this->quote($tableName);
289
         $p2 = $this->quote($newColumn->getName());
289
         $p2 = $this->quote($newColumn->getName());
290
         $p3 = $this->getColumnType($newColumn, false);
290
         $p3 = $this->getColumnType($newColumn, false);
291
 
291
 
292
-        
293
         switch ($this->driver) {
292
         switch ($this->driver) {
294
             case 'mysql':
293
             case 'mysql':
295
             case 'pgsql':
294
             case 'pgsql':
299
         }
298
         }
300
     }
299
     }
301
 
300
 
302
-    private function getRemoveTableSQL(String $tableName): String
301
+    private function getRemoveTableSQL(string $tableName): string
303
     {
302
     {
304
         $p1 = $this->quote($tableName);
303
         $p1 = $this->quote($tableName);
305
 
304
 
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
         $p1 = $this->quote($tableName);
316
         $p1 = $this->quote($tableName);
318
         $p2 = $this->quote($columnName);
317
         $p2 = $this->quote($columnName);
319
 
318
 
320
-        
321
         switch ($this->driver) {
319
         switch ($this->driver) {
322
             case 'mysql':
320
             case 'mysql':
323
             case 'pgsql':
321
             case 'pgsql':
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
         $sql = $this->getTableRenameSQL($tableName, $newTableName);
330
         $sql = $this->getTableRenameSQL($tableName, $newTableName);
333
         return $this->query($sql);
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
         $sql = $this->getColumnRenameSQL($tableName, $columnName, $newColumn);
336
         $sql = $this->getColumnRenameSQL($tableName, $columnName, $newColumn);
339
         return $this->query($sql);
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
         $sql = $this->getColumnRetypeSQL($tableName, $columnName, $newColumn);
342
         $sql = $this->getColumnRetypeSQL($tableName, $columnName, $newColumn);
345
         return $this->query($sql);
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
         $sql = $this->getSetColumnNullableSQL($tableName, $columnName, $newColumn);
348
         $sql = $this->getSetColumnNullableSQL($tableName, $columnName, $newColumn);
351
         return $this->query($sql);
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
         $sql = $this->getSetColumnPkConstraintSQL($tableName, $columnName, $newColumn);
354
         $sql = $this->getSetColumnPkConstraintSQL($tableName, $columnName, $newColumn);
357
         $this->query($sql);
355
         $this->query($sql);
366
         return true;
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
         if ($this->canAutoIncrement($newColumn)) {
369
         if ($this->canAutoIncrement($newColumn)) {
372
             $sql = $this->getSetColumnPkDefaultSQL($tableName, $columnName, $newColumn);
370
             $sql = $this->getSetColumnPkDefaultSQL($tableName, $columnName, $newColumn);
379
         return true;
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
         $sql = $this->getAddColumnFkConstraintSQL($tableName, $columnName, $newColumn);
382
         $sql = $this->getAddColumnFkConstraintSQL($tableName, $columnName, $newColumn);
385
         return $this->query($sql);
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
         $sql = $this->getRemoveColumnFkConstraintSQL($tableName, $columnName, $newColumn);
388
         $sql = $this->getRemoveColumnFkConstraintSQL($tableName, $columnName, $newColumn);
391
         return $this->query($sql);
389
         return $this->query($sql);
397
         return $this->query($sql);
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
         $sql = $this->getAddColumnSQL($tableName, $newColumn);
400
         $sql = $this->getAddColumnSQL($tableName, $newColumn);
403
         return $this->query($sql);
401
         return $this->query($sql);
404
     }
402
     }
405
 
403
 
406
-    public function removeTable(String $tableName)
404
+    public function removeTable(string $tableName)
407
     {
405
     {
408
         $sql = $this->getRemoveTableSQL($tableName);
406
         $sql = $this->getRemoveTableSQL($tableName);
409
         return $this->query($sql);
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
         $sql = $this->getRemoveColumnSQL($tableName, $columnName);
412
         $sql = $this->getRemoveColumnSQL($tableName, $columnName);
415
         return $this->query($sql);
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
         $stmt = $this->pdo->prepare($sql);
418
         $stmt = $this->pdo->prepare($sql);
421
         //echo "- $sql -- []\n";
419
         //echo "- $sql -- []\n";

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

8
     private $database;
8
     private $database;
9
     private $typeConverter;
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
         $this->pdo = $pdo;
13
         $this->pdo = $pdo;
14
         $this->driver = $driver;
14
         $this->driver = $driver;
25
         }
25
         }
26
     }
26
     }
27
 
27
 
28
-    private function getTablesSQL(): String
28
+    private function getTablesSQL(): string
29
     {
29
     {
30
         switch ($this->driver) {
30
         switch ($this->driver) {
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"';
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
         }
34
         }
35
     }
35
     }
36
 
36
 
37
-    private function getTableColumnsSQL(): String
37
+    private function getTableColumnsSQL(): string
38
     {
38
     {
39
         switch ($this->driver) {
39
         switch ($this->driver) {
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" = ?';
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
         }
43
         }
44
     }
44
     }
45
 
45
 
46
-    private function getTablePrimaryKeysSQL(): String
46
+    private function getTablePrimaryKeysSQL(): string
47
     {
47
     {
48
         switch ($this->driver) {
48
         switch ($this->driver) {
49
             case 'mysql':return 'SELECT "COLUMN_NAME" FROM "INFORMATION_SCHEMA"."KEY_COLUMN_USAGE" WHERE "CONSTRAINT_NAME" = \'PRIMARY\' AND "TABLE_NAME" = ? AND "TABLE_SCHEMA" = ?';
49
             case 'mysql':return 'SELECT "COLUMN_NAME" FROM "INFORMATION_SCHEMA"."KEY_COLUMN_USAGE" WHERE "CONSTRAINT_NAME" = \'PRIMARY\' AND "TABLE_NAME" = ? AND "TABLE_SCHEMA" = ?';
52
         }
52
         }
53
     }
53
     }
54
 
54
 
55
-    private function getTableForeignKeysSQL(): String
55
+    private function getTableForeignKeysSQL(): string
56
     {
56
     {
57
         switch ($this->driver) {
57
         switch ($this->driver) {
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" = ?';
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
         }
61
         }
62
     }
62
     }
63
 
63
 
64
-    public function getDatabaseName(): String
64
+    public function getDatabaseName(): string
65
     {
65
     {
66
         return $this->database;
66
         return $this->database;
67
     }
67
     }
89
         return $results;
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
         $sql = $this->getTableColumnsSQL();
94
         $sql = $this->getTableColumnsSQL();
95
         $results = $this->query($sql, [$tableName, $this->database]);
95
         $results = $this->query($sql, [$tableName, $this->database]);
101
         return $results;
101
         return $results;
102
     }
102
     }
103
 
103
 
104
-    public function getTablePrimaryKeys(String $tableName): array
104
+    public function getTablePrimaryKeys(string $tableName): array
105
     {
105
     {
106
         $sql = $this->getTablePrimaryKeysSQL();
106
         $sql = $this->getTablePrimaryKeysSQL();
107
         $results = $this->query($sql, [$tableName, $this->database]);
107
         $results = $this->query($sql, [$tableName, $this->database]);
112
         return $primaryKeys;
112
         return $primaryKeys;
113
     }
113
     }
114
 
114
 
115
-    public function getTableForeignKeys(String $tableName): array
115
+    public function getTableForeignKeys(string $tableName): array
116
     {
116
     {
117
         $sql = $this->getTableForeignKeysSQL();
117
         $sql = $this->getTableForeignKeysSQL();
118
         $results = $this->query($sql, [$tableName, $this->database]);
118
         $results = $this->query($sql, [$tableName, $this->database]);
123
         return $foreignKeys;
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
         return $this->typeConverter->toJdbc($type, $size);
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
         $stmt = $this->pdo->prepare($sql);
133
         $stmt = $this->pdo->prepare($sql);
134
         //echo "- $sql -- " . json_encode($parameters, JSON_UNESCAPED_UNICODE) . "\n";
134
         //echo "- $sql -- " . json_encode($parameters, JSON_UNESCAPED_UNICODE) . "\n";

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

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

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

5
 use Tqdev\PhpCrudApi\Controller\Responder;
5
 use Tqdev\PhpCrudApi\Controller\Responder;
6
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
6
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
7
 use Tqdev\PhpCrudApi\Record\ErrorCode;
7
 use Tqdev\PhpCrudApi\Record\ErrorCode;
8
+use Tqdev\PhpCrudApi\RequestUtils;
8
 use Tqdev\PhpCrudApi\Response;
9
 use Tqdev\PhpCrudApi\Response;
9
 
10
 
10
 class AjaxOnlyMiddleware extends Middleware
11
 class AjaxOnlyMiddleware extends Middleware
16
         if (!in_array($method, $excludeMethods)) {
17
         if (!in_array($method, $excludeMethods)) {
17
             $headerName = $this->getProperty('headerName', 'X-Requested-With');
18
             $headerName = $this->getProperty('headerName', 'X-Requested-With');
18
             $headerValue = $this->getProperty('headerValue', 'XMLHttpRequest');
19
             $headerValue = $this->getProperty('headerValue', 'XMLHttpRequest');
19
-            if ($headerValue != $request->getHeader($headerName)) {
20
+            if ($headerValue != RequestUtils::getHeader($request, $headerName)) {
20
                 return $this->responder->error(ErrorCode::ONLY_AJAX_REQUESTS_ALLOWED, $method);
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
 use Tqdev\PhpCrudApi\Middleware\Communication\VariableStore;
8
 use Tqdev\PhpCrudApi\Middleware\Communication\VariableStore;
9
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
9
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
10
 use Tqdev\PhpCrudApi\Record\FilterInfo;
10
 use Tqdev\PhpCrudApi\Record\FilterInfo;
11
-use Tqdev\PhpCrudApi\Record\RequestUtils;
11
+use Tqdev\PhpCrudApi\RequestUtils;
12
 use Tqdev\PhpCrudApi\Response;
12
 use Tqdev\PhpCrudApi\Response;
13
 
13
 
14
 class AuthorizationMiddleware extends Middleware
14
 class AuthorizationMiddleware extends Middleware
21
         $this->reflection = $reflection;
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
         $columnHandler = $this->getProperty('columnHandler', '');
26
         $columnHandler = $this->getProperty('columnHandler', '');
27
         if ($columnHandler) {
27
         if ($columnHandler) {
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
         if (!$this->reflection->hasTable($tableName)) {
40
         if (!$this->reflection->hasTable($tableName)) {
41
             return;
41
             return;
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
         if (!$this->reflection->hasTable($tableName)) {
56
         if (!$this->reflection->hasTable($tableName)) {
57
             return;
57
             return;

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

22
         $this->next = $handler;
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
         return array_filter(array_map('trim', explode(',', $this->getProperty($key, $default))));
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
         return isset($this->properties[$key]) ? $this->properties[$key] : $default;
32
         return isset($this->properties[$key]) ? $this->properties[$key] : $default;
33
     }
33
     }

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

5
 use Tqdev\PhpCrudApi\Controller\Responder;
5
 use Tqdev\PhpCrudApi\Controller\Responder;
6
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
6
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
7
 use Tqdev\PhpCrudApi\Record\ErrorCode;
7
 use Tqdev\PhpCrudApi\Record\ErrorCode;
8
+use Tqdev\PhpCrudApi\RequestUtils;
8
 use Tqdev\PhpCrudApi\Response;
9
 use Tqdev\PhpCrudApi\Response;
9
 
10
 
10
 class BasicAuthMiddleware extends Middleware
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
         $hash = isset($passwords[$username]) ? $passwords[$username] : false;
15
         $hash = isset($passwords[$username]) ? $passwords[$username] : false;
15
         if ($hash && password_verify($password, $hash)) {
16
         if ($hash && password_verify($password, $hash)) {
21
         return false;
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
         $passwords = $this->readPasswords($passwordFile);
27
         $passwords = $this->readPasswords($passwordFile);
27
         $valid = $this->hasCorrectPassword($username, $password, $passwords);
28
         $valid = $this->hasCorrectPassword($username, $password, $passwords);
29
         return $valid ? $username : '';
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
         $passwords = [];
35
         $passwords = [];
35
         $passwordLines = file($passwordFile);
36
         $passwordLines = file($passwordFile);
45
         return $passwords;
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
         $success = false;
51
         $success = false;
51
         $passwordFileContents = '';
52
         $passwordFileContents = '';
58
         return $success;
59
         return $success;
59
     }
60
     }
60
 
61
 
61
-    private function getAuthorizationCredentials(ServerRequestInterface $request): String
62
+    private function getAuthorizationCredentials(ServerRequestInterface $request): string
62
     {
63
     {
63
         if (isset($_SERVER['PHP_AUTH_USER'])) {
64
         if (isset($_SERVER['PHP_AUTH_USER'])) {
64
             return $_SERVER['PHP_AUTH_USER'] . ':' . $_SERVER['PHP_AUTH_PW'];
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
         if (count($parts) != 2) {
69
         if (count($parts) != 2) {
68
             return '';
70
             return '';
69
         }
71
         }

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

5
 {
5
 {
6
     static $values = array();
6
     static $values = array();
7
 
7
 
8
-    public static function get(String $key)
8
+    public static function get(string $key)
9
     {
9
     {
10
         if (isset(self::$values[$key])) {
10
         if (isset(self::$values[$key])) {
11
             return self::$values[$key];
11
             return self::$values[$key];
13
         return null;
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
         self::$values[$key] = $value;
18
         self::$values[$key] = $value;
19
     }
19
     }

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

9
 
9
 
10
 class CorsMiddleware extends Middleware
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
         $found = false;
14
         $found = false;
15
         foreach (explode(',', $allowedOrigins) as $allowedOrigin) {
15
         foreach (explode(',', $allowedOrigins) as $allowedOrigin) {

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

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

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

9
 
9
 
10
 class FirewallMiddleware extends Middleware
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
         if (strpos($cidr, '/') !== false) {
14
         if (strpos($cidr, '/') !== false) {
15
             list($subnet, $mask) = explode('/', trim($cidr));
15
             list($subnet, $mask) = explode('/', trim($cidr));
24
         return false;
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
         foreach (explode(',', $allowedIpAddresses) as $allowedIp) {
29
         foreach (explode(',', $allowedIpAddresses) as $allowedIp) {
30
             if ($this->ipMatch($ipAddress, $allowedIp)) {
30
             if ($this->ipMatch($ipAddress, $allowedIp)) {

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

7
 use Tqdev\PhpCrudApi\Controller\Responder;
7
 use Tqdev\PhpCrudApi\Controller\Responder;
8
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
8
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
9
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
9
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
10
-use Tqdev\PhpCrudApi\Record\RequestUtils;
10
+use Tqdev\PhpCrudApi\RequestUtils;
11
 use Tqdev\PhpCrudApi\Response;
11
 use Tqdev\PhpCrudApi\Response;
12
 
12
 
13
 class IpAddressMiddleware extends Middleware
13
 class IpAddressMiddleware extends Middleware
20
         $this->reflection = $reflection;
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
         $context = (array) $record;
25
         $context = (array) $record;
26
         $columnNames = $this->getProperty('columns', '');
26
         $columnNames = $this->getProperty('columns', '');

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

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

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

5
 use Tqdev\PhpCrudApi\Controller\Responder;
5
 use Tqdev\PhpCrudApi\Controller\Responder;
6
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
6
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
7
 use Tqdev\PhpCrudApi\Record\ErrorCode;
7
 use Tqdev\PhpCrudApi\Record\ErrorCode;
8
+use Tqdev\PhpCrudApi\RequestUtils;
8
 use Tqdev\PhpCrudApi\Response;
9
 use Tqdev\PhpCrudApi\Response;
9
 
10
 
10
 class JwtAuthMiddleware extends Middleware
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
         $algorithms = array(
15
         $algorithms = array(
15
             'HS256' => 'sha256',
16
             'HS256' => 'sha256',
89
         return $claims;
90
         return $claims;
90
     }
91
     }
91
 
92
 
92
-    private function getClaims(String $token): array
93
+    private function getClaims(string $token): array
93
     {
94
     {
94
         $time = (int) $this->getProperty('time', time());
95
         $time = (int) $this->getProperty('time', time());
95
         $leeway = (int) $this->getProperty('leeway', '5');
96
         $leeway = (int) $this->getProperty('leeway', '5');
106
         return $this->getVerifiedClaims($token, $time, $leeway, $ttl, $secret, $requirements);
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
         if (count($parts) != 2) {
115
         if (count($parts) != 2) {
114
             return '';
116
             return '';
115
         }
117
         }

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

10
 use Tqdev\PhpCrudApi\Record\Condition\ColumnCondition;
10
 use Tqdev\PhpCrudApi\Record\Condition\ColumnCondition;
11
 use Tqdev\PhpCrudApi\Record\Condition\Condition;
11
 use Tqdev\PhpCrudApi\Record\Condition\Condition;
12
 use Tqdev\PhpCrudApi\Record\Condition\NoCondition;
12
 use Tqdev\PhpCrudApi\Record\Condition\NoCondition;
13
-use Tqdev\PhpCrudApi\Record\RequestUtils;
13
+use Tqdev\PhpCrudApi\RequestUtils;
14
 use Tqdev\PhpCrudApi\Response;
14
 use Tqdev\PhpCrudApi\Response;
15
 
15
 
16
 class MultiTenancyMiddleware extends Middleware
16
 class MultiTenancyMiddleware extends Middleware
23
         $this->reflection = $reflection;
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
         $condition = new NoCondition();
28
         $condition = new NoCondition();
29
         $table = $this->reflection->getTable($tableName);
29
         $table = $this->reflection->getTable($tableName);
33
         return $condition;
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
         $result = array();
38
         $result = array();
39
         $pairs = call_user_func($handler, $operation, $tableName);
39
         $pairs = call_user_func($handler, $operation, $tableName);
46
         return $result;
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
         $record = $request->getBody();
51
         $record = $request->getBody();
52
         if ($record === null) {
52
         if ($record === null) {

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

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

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

8
 
8
 
9
 interface Router extends Handler
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
     public function load(Middleware $middleware);
13
     public function load(Middleware $middleware);
14
 
14
 

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

44
         return $tree;
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
         $routeNumber = count($this->routeHandlers);
49
         $routeNumber = count($this->routeHandlers);
50
         $this->routeHandlers[$routeNumber] = $handler;
50
         $this->routeHandlers[$routeNumber] = $handler;

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

7
 use Tqdev\PhpCrudApi\Controller\Responder;
7
 use Tqdev\PhpCrudApi\Controller\Responder;
8
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
8
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
9
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
9
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
10
-use Tqdev\PhpCrudApi\Record\RequestUtils;
10
+use Tqdev\PhpCrudApi\RequestUtils;
11
 use Tqdev\PhpCrudApi\Response;
11
 use Tqdev\PhpCrudApi\Response;
12
 
12
 
13
 class SanitationMiddleware extends Middleware
13
 class SanitationMiddleware extends Middleware
20
         $this->reflection = $reflection;
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
         $context = (array) $record;
25
         $context = (array) $record;
26
         $tableName = $table->getName();
26
         $tableName = $table->getName();

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

8
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
8
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
9
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
9
 use Tqdev\PhpCrudApi\Middleware\Router\Router;
10
 use Tqdev\PhpCrudApi\Record\ErrorCode;
10
 use Tqdev\PhpCrudApi\Record\ErrorCode;
11
-use Tqdev\PhpCrudApi\Record\RequestUtils;
11
+use Tqdev\PhpCrudApi\RequestUtils;
12
 use Tqdev\PhpCrudApi\Response;
12
 use Tqdev\PhpCrudApi\Response;
13
 
13
 
14
 class ValidationMiddleware extends Middleware
14
 class ValidationMiddleware extends Middleware
21
         $this->reflection = $reflection;
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
         $context = (array) $record;
26
         $context = (array) $record;
27
         $details = array();
27
         $details = array();

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

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

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

40
         $this->openapi = new OpenApiDefinition($base);
40
         $this->openapi = new OpenApiDefinition($base);
41
     }
41
     }
42
 
42
 
43
-    private function getServerUrl(): String
43
+    private function getServerUrl(): string
44
     {
44
     {
45
         $protocol = @$_SERVER['HTTP_X_FORWARDED_PROTO'] ?: @$_SERVER['REQUEST_SCHEME'] ?: ((isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") ? "https" : "http");
45
         $protocol = @$_SERVER['HTTP_X_FORWARDED_PROTO'] ?: @$_SERVER['REQUEST_SCHEME'] ?: ((isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") ? "https" : "http");
46
         $port = @intval($_SERVER['HTTP_X_FORWARDED_PORT']) ?: @intval($_SERVER["SERVER_PORT"]) ?: (($protocol === 'https') ? 443 : 80);
46
         $port = @intval($_SERVER['HTTP_X_FORWARDED_PORT']) ?: @intval($_SERVER["SERVER_PORT"]) ?: (($protocol === 'https') ? 443 : 80);
102
         return $this->openapi;
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
         $tableHandler = VariableStore::get('authorization.tableHandler');
107
         $tableHandler = VariableStore::get('authorization.tableHandler');
108
         if (!$tableHandler) {
108
         if (!$tableHandler) {
111
         return (bool) call_user_func($tableHandler, $operation, $tableName);
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
         $columnHandler = VariableStore::get('authorization.columnHandler');
116
         $columnHandler = VariableStore::get('authorization.columnHandler');
117
         if (!$columnHandler) {
117
         if (!$columnHandler) {
120
         return (bool) call_user_func($columnHandler, $operation, $tableName, $columnName);
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
         $table = $this->reflection->getTable($tableName);
125
         $table = $this->reflection->getTable($tableName);
126
         $type = $table->getType();
126
         $type = $table->getType();
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
         $table = $this->reflection->getTable($tableName);
186
         $table = $this->reflection->getTable($tableName);
187
         $type = $table->getType();
187
         $type = $table->getType();
231
         }
231
         }
232
     }
232
     }
233
 
233
 
234
-    private function setComponentResponse(String $tableName) /*: void*/
234
+    private function setComponentResponse(string $tableName) /*: void*/
235
     {
235
     {
236
         $table = $this->reflection->getTable($tableName);
236
         $table = $this->reflection->getTable($tableName);
237
         $type = $table->getType();
237
         $type = $table->getType();
256
         }
256
         }
257
     }
257
     }
258
 
258
 
259
-    private function setComponentRequestBody(String $tableName) /*: void*/
259
+    private function setComponentRequestBody(string $tableName) /*: void*/
260
     {
260
     {
261
         $table = $this->reflection->getTable($tableName);
261
         $table = $this->reflection->getTable($tableName);
262
         $type = $table->getType();
262
         $type = $table->getType();
327
         $this->openapi->set("components|parameters|join|required", false);
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
         $this->openapi->set("tags|$index|name", "$tableName");
332
         $this->openapi->set("tags|$index|name", "$tableName");
333
         $this->openapi->set("tags|$index|description", "$tableName operations");
333
         $this->openapi->set("tags|$index|description", "$tableName operations");

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

10
         $this->root = $base;
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
         $parts = explode('|', trim($path, '|'));
15
         $parts = explode('|', trim($path, '|'));
16
         $current = &$this->root;
16
         $current = &$this->root;
24
         $current = $value;
24
         $current = $value;
25
     }
25
     }
26
 
26
 
27
-    public function has(String $path): bool
27
+    public function has(string $path): bool
28
     {
28
     {
29
         $parts = explode('|', trim($path, '|'));
29
         $parts = explode('|', trim($path, '|'));
30
         $current = &$this->root;
30
         $current = &$this->root;

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

6
 class ColumnIncluder
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
         return isset($params['mandatory']) && in_array($tableName . "." . $columnName, $params['mandatory']);
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
         array $columnNames, bool $include): array{
15
         array $columnNames, bool $include): array{
16
         if (!isset($params[$paramName])) {
16
         if (!isset($params[$paramName])) {
17
             return $columnNames;
17
             return $columnNames;

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

9
     private $operator;
9
     private $operator;
10
     private $value;
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
         $this->column = $column;
14
         $this->column = $column;
15
         $this->operator = $operator;
15
         $this->operator = $operator;
21
         return $this->column;
21
         return $this->column;
22
     }
22
     }
23
 
23
 
24
-    public function getOperator(): String
24
+    public function getOperator(): string
25
     {
25
     {
26
         return $this->operator;
26
         return $this->operator;
27
     }
27
     }
28
 
28
 
29
-    public function getValue(): String
29
+    public function getValue(): string
30
     {
30
     {
31
         return $this->value;
31
         return $this->value;
32
     }
32
     }

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

26
         return new NotCondition($this);
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
         $condition = new NoCondition();
31
         $condition = new NoCondition();
32
         $parts = explode(',', $value, 3);
32
         $parts = explode(',', $value, 3);

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

9
     public $message;
9
     public $message;
10
     public $details;
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
         $this->code = $errorCode->getCode();
14
         $this->code = $errorCode->getCode();
15
         $this->message = $errorCode->getMessage($argument);
15
         $this->message = $errorCode->getMessage($argument);
21
         return $this->code;
21
         return $this->code;
22
     }
22
     }
23
 
23
 
24
-    public function getMessage(): String
24
+    public function getMessage(): string
25
     {
25
     {
26
         return $this->message;
26
         return $this->message;
27
     }
27
     }

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

71
         return $this->code;
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
         return sprintf($this->message, $argument);
76
         return sprintf($this->message, $argument);
77
     }
77
     }

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

31
         return $this->tree->values;
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
         if (!isset($this->tree->branches->$key)) {
36
         if (!isset($this->tree->branches->$key)) {
37
             return null;
37
             return null;

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

26
         $this->pagination = new PaginationInfo();
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
         $keyset = array_keys((array) $record);
31
         $keyset = array_keys((array) $record);
32
         foreach ($keyset as $key) {
32
         foreach ($keyset as $key) {
45
         }
45
         }
46
     }
46
     }
47
 
47
 
48
-    public function hasTable(String $table): bool
48
+    public function hasTable(string $table): bool
49
     {
49
     {
50
         return $this->reflection->hasTable($table);
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
         return $this->reflection->getType($table);
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
         $this->sanitizeRecord($tableName, $record, '');
60
         $this->sanitizeRecord($tableName, $record, '');
61
         $table = $this->reflection->getTable($tableName);
61
         $table = $this->reflection->getTable($tableName);
63
         return $this->db->createSingle($table, $columnValues);
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
         $table = $this->reflection->getTable($tableName);
68
         $table = $this->reflection->getTable($tableName);
69
         $this->joiner->addMandatoryColumns($table, $params);
69
         $this->joiner->addMandatoryColumns($table, $params);
77
         return $records[0];
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
         $this->sanitizeRecord($tableName, $record, $id);
82
         $this->sanitizeRecord($tableName, $record, $id);
83
         $table = $this->reflection->getTable($tableName);
83
         $table = $this->reflection->getTable($tableName);
85
         return $this->db->updateSingle($table, $columnValues, $id);
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
         $table = $this->reflection->getTable($tableName);
90
         $table = $this->reflection->getTable($tableName);
91
         return $this->db->deleteSingle($table, $id);
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
         $this->sanitizeRecord($tableName, $record, $id);
96
         $this->sanitizeRecord($tableName, $record, $id);
97
         $table = $this->reflection->getTable($tableName);
97
         $table = $this->reflection->getTable($tableName);
99
         return $this->db->incrementSingle($table, $columnValues, $id);
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
         $table = $this->reflection->getTable($tableName);
104
         $table = $this->reflection->getTable($tableName);
105
         $this->joiner->addMandatoryColumns($table, $params);
105
         $this->joiner->addMandatoryColumns($table, $params);

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

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
     private $headers;
11
     private $headers;
12
     private $highPerformance;
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
         $this->parseMethod($method);
16
         $this->parseMethod($method);
17
         $this->parsePath($path);
17
         $this->parsePath($path);
21
         $this->highPerformance = $highPerformance;
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
         if (!$method) {
26
         if (!$method) {
27
             if (isset($_SERVER['REQUEST_METHOD'])) {
27
             if (isset($_SERVER['REQUEST_METHOD'])) {
33
         $this->method = $method;
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
         if (!$path) {
38
         if (!$path) {
39
             if (isset($_SERVER['PATH_INFO'])) {
39
             if (isset($_SERVER['PATH_INFO'])) {
46
         $this->pathSegments = explode('/', $path);
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
         if (!$query) {
51
         if (!$query) {
52
             if (isset($_SERVER['QUERY_STRING'])) {
52
             if (isset($_SERVER['QUERY_STRING'])) {
75
         $this->headers = $headers;
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
         $first = substr($body, 0, 1);
80
         $first = substr($body, 0, 1);
81
         if ($first == '[' || $first == '{') {
81
         if ($first == '[' || $first == '{') {
97
         return $object;
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
         if (!$body) {
102
         if (!$body) {
103
             $body = file_get_contents('php://input');
103
             $body = file_get_contents('php://input');
105
         $this->body = $this->decodeBody($body);
105
         $this->body = $this->decodeBody($body);
106
     }
106
     }
107
 
107
 
108
-    public function getMethod(): String
108
+    public function getMethod(): string
109
     {
109
     {
110
         return $this->method;
110
         return $this->method;
111
     }
111
     }
112
 
112
 
113
-    public function getPath(): String
113
+    public function getPath(): string
114
     {
114
     {
115
         return $this->path;
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
         if ($part < 0 || $part >= count($this->pathSegments)) {
120
         if ($part < 0 || $part >= count($this->pathSegments)) {
121
             return '';
121
             return '';
143
         $this->body = $body;
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
         $this->headers[$key] = $value;
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
         if (isset($this->headers[$key])) {
153
         if (isset($this->headers[$key])) {
154
             return $this->headers[$key];
154
             return $this->headers[$key];
167
         return $this->headers;
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
         $parts = explode("\n\n", trim($request), 2);
172
         $parts = explode("\n\n", trim($request), 2);
173
         $head = $parts[0];
173
         $head = $parts[0];

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

14
         return $creator->fromGlobals();
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
         $parts = explode("\n\n", trim($request), 2);
19
         $parts = explode("\n\n", trim($request), 2);
20
         $lines = explode("\n", $parts[0]);
20
         $lines = explode("\n", $parts[0]);

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

39
         return $this->status;
39
         return $this->status;
40
     }
40
     }
41
 
41
 
42
-    public function getBody(): String
42
+    public function getBody(): string
43
     {
43
     {
44
         return $this->body;
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
         $this->headers[$key] = $value;
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
         if (isset($this->headers[$key])) {
54
         if (isset($this->headers[$key])) {
55
             return $this->headers[$key];
55
             return $this->headers[$key];
78
         $this->addHeader('X-Exception-File', $e->getFile() . ':' . $e->getLine());
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
         $str = "$this->status\n";
83
         $str = "$this->status\n";
84
         foreach ($this->headers as $key => $value) {
84
         foreach ($this->headers as $key => $value) {

Loading…
Cancel
Save