Skip to content

Commit

Permalink
Some more improvements as per mevdschee#436
Browse files Browse the repository at this point in the history
  • Loading branch information
mevdschee committed Sep 28, 2018
1 parent e738617 commit a0f2a96
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 21 deletions.
19 changes: 9 additions & 10 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct(String $prefix, String $config)
$this->memcache->addServer($address, $port);
}

protected function create(): object
protected function create(): stdClass
{
return new \Memcache();
}
Expand All @@ -97,7 +97,7 @@ public function clear(): bool

class MemcachedCache extends MemcacheCache
{
protected function create(): object
protected function create(): stdClass
{
return new \Memcached();
}
Expand Down Expand Up @@ -2014,7 +2014,7 @@ public function getColumnType(ReflectedColumn $column, bool $update): String
if ($this->driver == 'pgsql' && !$update && $column->getPk() && $this->canAutoIncrement($column)) {
return 'serial';
}
$type = $this->typeConverter->fromJdbc($column->getType(), $column->getPk());
$type = $this->typeConverter->fromJdbc($column->getType());
if ($column->hasPrecision() && $column->hasScale()) {
$size = '(' . $column->getPrecision() . ',' . $column->getScale() . ')';
} else if ($column->hasPrecision()) {
Expand Down Expand Up @@ -2739,7 +2739,8 @@ class SimpleRouter implements Router
private $ttl;
private $registration;
private $routes;
private $midlewares;
private $routeHandlers;
private $middlewares;

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

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

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

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

Expand Down
10 changes: 9 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@
}
],
"require": {
"php": ">=7.0.0"
"php": ">=7.0.0",
"ext-zlib": "*",
"ext-json": "*",
"ext-pdo": "*"
},
"suggest": {
"ext-memcache": "*",
"ext-memcached": "*",
"ext-redis": "*"
},
"autoload": {
"psr-4": { "Tqdev\\PhpCrudApi\\": "src/Tqdev/PhpCrudApi" }
Expand Down
2 changes: 1 addition & 1 deletion src/Tqdev/PhpCrudApi/Cache/MemcacheCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(String $prefix, String $config)
$this->memcache->addServer($address, $port);
}

protected function create(): object
protected function create(): stdClass
{
return new \Memcache();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tqdev/PhpCrudApi/Cache/MemcachedCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class MemcachedCache extends MemcacheCache
{
protected function create(): object
protected function create(): stdClass
{
return new \Memcached();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tqdev/PhpCrudApi/Database/GenericDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getColumnType(ReflectedColumn $column, bool $update): String
if ($this->driver == 'pgsql' && !$update && $column->getPk() && $this->canAutoIncrement($column)) {
return 'serial';
}
$type = $this->typeConverter->fromJdbc($column->getType(), $column->getPk());
$type = $this->typeConverter->fromJdbc($column->getType());
if ($column->hasPrecision() && $column->hasScale()) {
$size = '(' . $column->getPrecision() . ',' . $column->getScale() . ')';
} else if ($column->hasPrecision()) {
Expand Down
3 changes: 2 additions & 1 deletion src/Tqdev/PhpCrudApi/Middleware/Router/SimpleRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class SimpleRouter implements Router
private $ttl;
private $registration;
private $routes;
private $midlewares;
private $routeHandlers;
private $middlewares;

public function __construct(Responder $responder, Cache $cache, int $ttl)
{
Expand Down
9 changes: 4 additions & 5 deletions src/Tqdev/PhpCrudApi/OpenApi/OpenApiDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ private function set(String $path, String $value) /*: void*/
$current = $value;
}

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

private function fillParametersWithPrimaryKey(String $method, TableDefinition $table) /*: void*/
private function fillParametersWithPrimaryKey(String $method, ReflectedTable $table) /*: void*/
{
if ($table->getPk() != null) {
$pathWithId = sprintf('/records/%s/{%s}', $table->getName(), $table->getPk()->getName());
Expand Down
1 change: 0 additions & 1 deletion src/Tqdev/PhpCrudApi/Record/RelationJoiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ private function getFkEmptyValues(ReflectedTable $t1, ReflectedTable $t2, array

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

Expand Down

0 comments on commit a0f2a96

Please sign in to comment.