Skip to content

Commit a0f2a96

Browse files
committed
Some more improvements as per #436
1 parent e738617 commit a0f2a96

File tree

8 files changed

+27
-21
lines changed

8 files changed

+27
-21
lines changed

api.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function __construct(String $prefix, String $config)
7272
$this->memcache->addServer($address, $port);
7373
}
7474

75-
protected function create(): object
75+
protected function create(): stdClass
7676
{
7777
return new \Memcache();
7878
}
@@ -97,7 +97,7 @@ public function clear(): bool
9797

9898
class MemcachedCache extends MemcacheCache
9999
{
100-
protected function create(): object
100+
protected function create(): stdClass
101101
{
102102
return new \Memcached();
103103
}
@@ -2014,7 +2014,7 @@ public function getColumnType(ReflectedColumn $column, bool $update): String
20142014
if ($this->driver == 'pgsql' && !$update && $column->getPk() && $this->canAutoIncrement($column)) {
20152015
return 'serial';
20162016
}
2017-
$type = $this->typeConverter->fromJdbc($column->getType(), $column->getPk());
2017+
$type = $this->typeConverter->fromJdbc($column->getType());
20182018
if ($column->hasPrecision() && $column->hasScale()) {
20192019
$size = '(' . $column->getPrecision() . ',' . $column->getScale() . ')';
20202020
} else if ($column->hasPrecision()) {
@@ -2739,7 +2739,8 @@ class SimpleRouter implements Router
27392739
private $ttl;
27402740
private $registration;
27412741
private $routes;
2742-
private $midlewares;
2742+
private $routeHandlers;
2743+
private $middlewares;
27432744

27442745
public function __construct(Responder $responder, Cache $cache, int $ttl)
27452746
{
@@ -3276,18 +3277,17 @@ private function set(String $path, String $value) /*: void*/
32763277
$current = $value;
32773278
}
32783279

3279-
public function setPaths(DatabaseDefinition $database) /*: void*/
3280+
public function setPaths(ReflectedDatabase $database) /*: void*/
32803281
{
3281-
$result = [];
3282-
foreach ($database->getTables() as $table) {
3283-
$path = sprintf('/records/%s', $table->getName());
3282+
foreach ($database->getTableNames() as $tableName) {
3283+
$path = sprintf('/records/%s', $tableName);
32843284
foreach (['get', 'post', 'put', 'patch', 'delete'] as $method) {
32853285
$this->set("/paths/$path/$method/description", "$method operation");
32863286
}
32873287
}
32883288
}
32893289

3290-
private function fillParametersWithPrimaryKey(String $method, TableDefinition $table) /*: void*/
3290+
private function fillParametersWithPrimaryKey(String $method, ReflectedTable $table) /*: void*/
32913291
{
32923292
if ($table->getPk() != null) {
32933293
$pathWithId = sprintf('/records/%s/{%s}', $table->getName(), $table->getPk()->getName());
@@ -4231,7 +4231,6 @@ private function getFkEmptyValues(ReflectedTable $t1, ReflectedTable $t2, array
42314231

42324232
private function addFkRecords(ReflectedTable $t2, array $fkValues, array $params, GenericDB $db, array &$records) /*: void*/
42334233
{
4234-
$pk = $t2->getPk();
42354234
$columnNames = $this->columns->getNames($t2, false, $params);
42364235
$fkIds = array_keys($fkValues);
42374236

composer.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@
3232
}
3333
],
3434
"require": {
35-
"php": ">=7.0.0"
35+
"php": ">=7.0.0",
36+
"ext-zlib": "*",
37+
"ext-json": "*",
38+
"ext-pdo": "*"
39+
},
40+
"suggest": {
41+
"ext-memcache": "*",
42+
"ext-memcached": "*",
43+
"ext-redis": "*"
3644
},
3745
"autoload": {
3846
"psr-4": { "Tqdev\\PhpCrudApi\\": "src/Tqdev/PhpCrudApi" }

src/Tqdev/PhpCrudApi/Cache/MemcacheCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(String $prefix, String $config)
2222
$this->memcache->addServer($address, $port);
2323
}
2424

25-
protected function create(): object
25+
protected function create(): stdClass
2626
{
2727
return new \Memcache();
2828
}

src/Tqdev/PhpCrudApi/Cache/MemcachedCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class MemcachedCache extends MemcacheCache
55
{
6-
protected function create(): object
6+
protected function create(): stdClass
77
{
88
return new \Memcached();
99
}

src/Tqdev/PhpCrudApi/Database/GenericDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function getColumnType(ReflectedColumn $column, bool $update): String
3131
if ($this->driver == 'pgsql' && !$update && $column->getPk() && $this->canAutoIncrement($column)) {
3232
return 'serial';
3333
}
34-
$type = $this->typeConverter->fromJdbc($column->getType(), $column->getPk());
34+
$type = $this->typeConverter->fromJdbc($column->getType());
3535
if ($column->hasPrecision() && $column->hasScale()) {
3636
$size = '(' . $column->getPrecision() . ',' . $column->getScale() . ')';
3737
} else if ($column->hasPrecision()) {

src/Tqdev/PhpCrudApi/Middleware/Router/SimpleRouter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class SimpleRouter implements Router
1616
private $ttl;
1717
private $registration;
1818
private $routes;
19-
private $midlewares;
19+
private $routeHandlers;
20+
private $middlewares;
2021

2122
public function __construct(Responder $responder, Cache $cache, int $ttl)
2223
{

src/Tqdev/PhpCrudApi/OpenApi/OpenApiDefinition.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@ private function set(String $path, String $value) /*: void*/
1717
$current = $value;
1818
}
1919

20-
public function setPaths(DatabaseDefinition $database) /*: void*/
20+
public function setPaths(ReflectedDatabase $database) /*: void*/
2121
{
22-
$result = [];
23-
foreach ($database->getTables() as $table) {
24-
$path = sprintf('/records/%s', $table->getName());
22+
foreach ($database->getTableNames() as $tableName) {
23+
$path = sprintf('/records/%s', $tableName);
2524
foreach (['get', 'post', 'put', 'patch', 'delete'] as $method) {
2625
$this->set("/paths/$path/$method/description", "$method operation");
2726
}
2827
}
2928
}
3029

31-
private function fillParametersWithPrimaryKey(String $method, TableDefinition $table) /*: void*/
30+
private function fillParametersWithPrimaryKey(String $method, ReflectedTable $table) /*: void*/
3231
{
3332
if ($table->getPk() != null) {
3433
$pathWithId = sprintf('/records/%s/{%s}', $table->getName(), $table->getPk()->getName());

src/Tqdev/PhpCrudApi/Record/RelationJoiner.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ private function getFkEmptyValues(ReflectedTable $t1, ReflectedTable $t2, array
152152

153153
private function addFkRecords(ReflectedTable $t2, array $fkValues, array $params, GenericDB $db, array &$records) /*: void*/
154154
{
155-
$pk = $t2->getPk();
156155
$columnNames = $this->columns->getNames($t2, false, $params);
157156
$fkIds = array_keys($fkValues);
158157

0 commit comments

Comments
 (0)