PSR-12 compatibility
This commit is contained in:
parent
7de40e0391
commit
de08ff5a2a
77 changed files with 135 additions and 83 deletions
|
@ -114,7 +114,7 @@ The following features are supported:
|
|||
- Support for reading database structure in JSON
|
||||
- Support for modifying database structure using REST endpoint
|
||||
- Security enhancing middleware is included
|
||||
- Standard compliant: PSR-2, PSR-4, PSR-7, PSR-15 and PSR-17
|
||||
- Standard compliant: PSR-4, PSR-7, PSR-12, PSR-15 and PSR-17
|
||||
|
||||
## Compilation
|
||||
|
||||
|
|
|
@ -50,5 +50,5 @@
|
|||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Tqdev\\PhpCrudApi\\": "src/Tqdev/PhpCrudApi" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,9 +25,9 @@ use Tqdev\PhpCrudApi\Middleware\FirewallMiddleware;
|
|||
use Tqdev\PhpCrudApi\Middleware\IpAddressMiddleware;
|
||||
use Tqdev\PhpCrudApi\Middleware\JoinLimitsMiddleware;
|
||||
use Tqdev\PhpCrudApi\Middleware\JwtAuthMiddleware;
|
||||
use Tqdev\PhpCrudApi\Middleware\ReconnectMiddleware;
|
||||
use Tqdev\PhpCrudApi\Middleware\MultiTenancyMiddleware;
|
||||
use Tqdev\PhpCrudApi\Middleware\PageLimitsMiddleware;
|
||||
use Tqdev\PhpCrudApi\Middleware\ReconnectMiddleware;
|
||||
use Tqdev\PhpCrudApi\Middleware\Router\SimpleRouter;
|
||||
use Tqdev\PhpCrudApi\Middleware\SanitationMiddleware;
|
||||
use Tqdev\PhpCrudApi\Middleware\ValidationMiddleware;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Cache;
|
||||
|
||||
interface Cache
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Cache;
|
||||
|
||||
class CacheFactory
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Cache;
|
||||
|
||||
class MemcacheCache implements Cache
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Cache;
|
||||
|
||||
class MemcachedCache extends MemcacheCache
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Cache;
|
||||
|
||||
class NoCache implements Cache
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Cache;
|
||||
|
||||
class RedisCache implements Cache
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Cache;
|
||||
|
||||
class TempFileCache implements Cache
|
||||
{
|
||||
const SUFFIX = 'cache';
|
||||
public const SUFFIX = 'cache';
|
||||
|
||||
private $path;
|
||||
private $segments;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Column;
|
||||
|
||||
use Tqdev\PhpCrudApi\Column\Reflection\ReflectedColumn;
|
||||
|
@ -97,7 +98,7 @@ class DefinitionService
|
|||
return true;
|
||||
}
|
||||
|
||||
public function addTable( /* object */$definition)
|
||||
public function addTable(/* object */$definition)
|
||||
{
|
||||
$newTable = ReflectedTable::fromJson($definition);
|
||||
if (!$this->db->definition()->addTable($newTable)) {
|
||||
|
@ -154,5 +155,4 @@ class DefinitionService
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Column\Reflection;
|
||||
|
||||
use Tqdev\PhpCrudApi\Database\GenericReflection;
|
||||
|
||||
class ReflectedColumn implements \JsonSerializable
|
||||
{
|
||||
const DEFAULT_LENGTH = 255;
|
||||
const DEFAULT_PRECISION = 19;
|
||||
const DEFAULT_SCALE = 4;
|
||||
public const DEFAULT_LENGTH = 255;
|
||||
public const DEFAULT_PRECISION = 19;
|
||||
public const DEFAULT_SCALE = 4;
|
||||
|
||||
private $name;
|
||||
private $type;
|
||||
|
@ -44,7 +45,7 @@ class ReflectedColumn implements \JsonSerializable
|
|||
return new ReflectedColumn($name, $type, $length, $precision, $scale, $nullable, $pk, $fk);
|
||||
}
|
||||
|
||||
public static function fromJson( /* object */$json): ReflectedColumn
|
||||
public static function fromJson(/* object */$json): ReflectedColumn
|
||||
{
|
||||
$name = $json->name;
|
||||
$type = $json->type;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Column\Reflection;
|
||||
|
||||
use Tqdev\PhpCrudApi\Database\GenericReflection;
|
||||
|
@ -26,7 +27,7 @@ class ReflectedDatabase implements \JsonSerializable
|
|||
return new ReflectedDatabase($tableTypes);
|
||||
}
|
||||
|
||||
public static function fromJson( /* object */$json): ReflectedDatabase
|
||||
public static function fromJson(/* object */$json): ReflectedDatabase
|
||||
{
|
||||
$tableTypes = (array) $json->tables;
|
||||
return new ReflectedDatabase($tableTypes);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Column\Reflection;
|
||||
|
||||
use Tqdev\PhpCrudApi\Database\GenericReflection;
|
||||
|
@ -64,7 +65,7 @@ class ReflectedTable implements \JsonSerializable
|
|||
return new ReflectedTable($name, $type, array_values($columns));
|
||||
}
|
||||
|
||||
public static function fromJson( /* object */$json): ReflectedTable
|
||||
public static function fromJson(/* object */$json): ReflectedTable
|
||||
{
|
||||
$name = $json->name;
|
||||
$type = $json->type;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi;
|
||||
|
||||
class Config
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
@ -22,5 +23,4 @@ class CacheController
|
|||
{
|
||||
return $this->responder->success($this->cache->clear());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
@ -58,5 +59,4 @@ class GeoJsonController
|
|||
return $this->responder->success($response);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
@ -20,5 +21,4 @@ class JsonResponder implements Responder
|
|||
{
|
||||
return ResponseFactory::fromObject(ResponseFactory::OK, $result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
@ -22,5 +23,4 @@ class OpenApiController
|
|||
{
|
||||
return $this->responder->success($this->openApi->get());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
@ -175,5 +176,4 @@ class RecordController
|
|||
return $this->responder->success($this->service->increment($table, $id, $record, $params));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
@ -8,5 +9,4 @@ interface Responder
|
|||
public function error(int $error, string $argument, $details = null): ResponseInterface;
|
||||
|
||||
public function success($result): ResponseInterface;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Database;
|
||||
|
||||
use Tqdev\PhpCrudApi\Column\Reflection\ReflectedColumn;
|
||||
|
@ -60,5 +61,4 @@ class ColumnConverter
|
|||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Database;
|
||||
|
||||
use Tqdev\PhpCrudApi\Column\Reflection\ReflectedColumn;
|
||||
|
@ -105,5 +106,4 @@ class ColumnsBuilder
|
|||
}
|
||||
return implode(',', $results);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Database;
|
||||
|
||||
use Tqdev\PhpCrudApi\Column\Reflection\ReflectedColumn;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Database;
|
||||
|
||||
use Tqdev\PhpCrudApi\Column\Reflection\ReflectedColumn;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Database;
|
||||
|
||||
use Tqdev\PhpCrudApi\Column\Reflection\ReflectedColumn;
|
||||
|
@ -35,9 +36,9 @@ class GenericDefinition
|
|||
$type = $this->typeConverter->fromJdbc($column->getType());
|
||||
if ($column->hasPrecision() && $column->hasScale()) {
|
||||
$size = '(' . $column->getPrecision() . ',' . $column->getScale() . ')';
|
||||
} else if ($column->hasPrecision()) {
|
||||
} elseif ($column->hasPrecision()) {
|
||||
$size = '(' . $column->getPrecision() . ')';
|
||||
} else if ($column->hasLength()) {
|
||||
} elseif ($column->hasLength()) {
|
||||
$size = '(' . $column->getLength() . ')';
|
||||
} else {
|
||||
$size = '';
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Database;
|
||||
|
||||
use Tqdev\PhpCrudApi\Database\LazyPdo;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Database;
|
||||
|
||||
class TypeConverter
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\GeoJson;
|
||||
|
||||
class Feature implements \JsonSerializable
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\GeoJson;
|
||||
|
||||
class FeatureCollection implements \JsonSerializable
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\GeoJson;
|
||||
|
||||
use Tqdev\PhpCrudApi\Column\ReflectionService;
|
||||
|
@ -78,7 +79,7 @@ class GeoJsonService
|
|||
return [$lon, $lat];
|
||||
}
|
||||
|
||||
private function convertRecordToFeature( /*object*/$record, string $primaryKeyColumnName, string $geometryColumnName)
|
||||
private function convertRecordToFeature(/*object*/$record, string $primaryKeyColumnName, string $geometryColumnName)
|
||||
{
|
||||
$id = null;
|
||||
if ($primaryKeyColumnName) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\GeoJson;
|
||||
|
||||
class Geometry implements \JsonSerializable
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Middleware\Base;
|
||||
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Middleware\Communication;
|
||||
|
||||
class VariableStore
|
||||
{
|
||||
static $values = array();
|
||||
public static $values = array();
|
||||
|
||||
public static function get(string $key)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Tqdev\PhpCrudApi\Column\ReflectionService;
|
||||
use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
|
||||
use Tqdev\PhpCrudApi\Column\ReflectionService;
|
||||
use Tqdev\PhpCrudApi\Controller\Responder;
|
||||
use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
|
||||
use Tqdev\PhpCrudApi\Middleware\Router\Router;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Middleware\Router;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Middleware\Router;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
@ -156,5 +157,4 @@ class SimpleRouter implements Router
|
|||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Tqdev\PhpCrudApi\Column\ReflectionService;
|
||||
use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
|
||||
use Tqdev\PhpCrudApi\Column\ReflectionService;
|
||||
use Tqdev\PhpCrudApi\Controller\Responder;
|
||||
use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
|
||||
use Tqdev\PhpCrudApi\Middleware\Router\Router;
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Tqdev\PhpCrudApi\Column\ReflectionService;
|
||||
use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
|
||||
use Tqdev\PhpCrudApi\Column\ReflectionService;
|
||||
use Tqdev\PhpCrudApi\Controller\Responder;
|
||||
use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
|
||||
use Tqdev\PhpCrudApi\Middleware\Router\Router;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\OpenApi;
|
||||
|
||||
use Tqdev\PhpCrudApi\Column\ReflectionService;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\OpenApi;
|
||||
|
||||
class OpenApiDefinition implements \JsonSerializable
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\OpenApi;
|
||||
|
||||
use Tqdev\PhpCrudApi\Column\ReflectionService;
|
||||
|
@ -17,5 +18,4 @@ class OpenApiService
|
|||
{
|
||||
return $this->builder->build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Record;
|
||||
|
||||
use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
|
||||
|
||||
class ColumnIncluder
|
||||
{
|
||||
|
||||
private function isMandatory(string $tableName, string $columnName, array $params): bool
|
||||
{
|
||||
return isset($params['mandatory']) && in_array($tableName . "." . $columnName, $params['mandatory']);
|
||||
}
|
||||
|
||||
private function select(string $tableName, bool $primaryTable, array $params, string $paramName,
|
||||
array $columnNames, bool $include): array{
|
||||
private function select(
|
||||
string $tableName,
|
||||
bool $primaryTable,
|
||||
array $params,
|
||||
string $paramName,
|
||||
array $columnNames,
|
||||
bool $include
|
||||
): array {
|
||||
if (!isset($params[$paramName])) {
|
||||
return $columnNames;
|
||||
}
|
||||
|
@ -62,5 +68,4 @@ class ColumnIncluder
|
|||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Record\Condition;
|
||||
|
||||
class AndCondition extends Condition
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Record\Condition;
|
||||
|
||||
use Tqdev\PhpCrudApi\Column\Reflection\ReflectedColumn;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Record\Condition;
|
||||
|
||||
use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
|
||||
|
@ -64,5 +65,4 @@ abstract class Condition
|
|||
}
|
||||
return $condition;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Record\Condition;
|
||||
|
||||
class NoCondition extends Condition
|
||||
|
@ -17,5 +18,4 @@ class NoCondition extends Condition
|
|||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Record\Condition;
|
||||
|
||||
class NotCondition extends Condition
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Record\Condition;
|
||||
|
||||
class OrCondition extends Condition
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Record\Condition;
|
||||
|
||||
class SpatialCondition extends ColumnCondition
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Record\Document;
|
||||
|
||||
use Tqdev\PhpCrudApi\Record\ErrorCode;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Record\Document;
|
||||
|
||||
class ListDocument implements \JsonSerializable
|
||||
{
|
||||
|
||||
private $records;
|
||||
|
||||
private $results;
|
||||
|
|
|
@ -1,36 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Record;
|
||||
|
||||
use Tqdev\PhpCrudApi\ResponseFactory;
|
||||
|
||||
class ErrorCode
|
||||
{
|
||||
|
||||
private $code;
|
||||
private $message;
|
||||
private $status;
|
||||
|
||||
const ERROR_NOT_FOUND = 9999;
|
||||
const ROUTE_NOT_FOUND = 1000;
|
||||
const TABLE_NOT_FOUND = 1001;
|
||||
const ARGUMENT_COUNT_MISMATCH = 1002;
|
||||
const RECORD_NOT_FOUND = 1003;
|
||||
const ORIGIN_FORBIDDEN = 1004;
|
||||
const COLUMN_NOT_FOUND = 1005;
|
||||
const TABLE_ALREADY_EXISTS = 1006;
|
||||
const COLUMN_ALREADY_EXISTS = 1007;
|
||||
const HTTP_MESSAGE_NOT_READABLE = 1008;
|
||||
const DUPLICATE_KEY_EXCEPTION = 1009;
|
||||
const DATA_INTEGRITY_VIOLATION = 1010;
|
||||
const AUTHENTICATION_REQUIRED = 1011;
|
||||
const AUTHENTICATION_FAILED = 1012;
|
||||
const INPUT_VALIDATION_FAILED = 1013;
|
||||
const OPERATION_FORBIDDEN = 1014;
|
||||
const OPERATION_NOT_SUPPORTED = 1015;
|
||||
const TEMPORARY_OR_PERMANENTLY_BLOCKED = 1016;
|
||||
const BAD_OR_MISSING_XSRF_TOKEN = 1017;
|
||||
const ONLY_AJAX_REQUESTS_ALLOWED = 1018;
|
||||
const PAGINATION_FORBIDDEN = 1019;
|
||||
public const ERROR_NOT_FOUND = 9999;
|
||||
public const ROUTE_NOT_FOUND = 1000;
|
||||
public const TABLE_NOT_FOUND = 1001;
|
||||
public const ARGUMENT_COUNT_MISMATCH = 1002;
|
||||
public const RECORD_NOT_FOUND = 1003;
|
||||
public const ORIGIN_FORBIDDEN = 1004;
|
||||
public const COLUMN_NOT_FOUND = 1005;
|
||||
public const TABLE_ALREADY_EXISTS = 1006;
|
||||
public const COLUMN_ALREADY_EXISTS = 1007;
|
||||
public const HTTP_MESSAGE_NOT_READABLE = 1008;
|
||||
public const DUPLICATE_KEY_EXCEPTION = 1009;
|
||||
public const DATA_INTEGRITY_VIOLATION = 1010;
|
||||
public const AUTHENTICATION_REQUIRED = 1011;
|
||||
public const AUTHENTICATION_FAILED = 1012;
|
||||
public const INPUT_VALIDATION_FAILED = 1013;
|
||||
public const OPERATION_FORBIDDEN = 1014;
|
||||
public const OPERATION_NOT_SUPPORTED = 1015;
|
||||
public const TEMPORARY_OR_PERMANENTLY_BLOCKED = 1016;
|
||||
public const BAD_OR_MISSING_XSRF_TOKEN = 1017;
|
||||
public const ONLY_AJAX_REQUESTS_ALLOWED = 1018;
|
||||
public const PAGINATION_FORBIDDEN = 1019;
|
||||
|
||||
private $values = [
|
||||
9999 => ["%s", ResponseFactory::INTERNAL_SERVER_ERROR],
|
||||
|
@ -80,5 +80,4 @@ class ErrorCode
|
|||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Record;
|
||||
|
||||
use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
|
||||
|
@ -9,7 +10,6 @@ use Tqdev\PhpCrudApi\Record\Condition\OrCondition;
|
|||
|
||||
class FilterInfo
|
||||
{
|
||||
|
||||
private function addConditionFromFilterPath(PathTree $conditions, array $path, ReflectedTable $table, array $params)
|
||||
{
|
||||
$key = 'filter' . implode('', $path);
|
||||
|
@ -52,5 +52,4 @@ class FilterInfo
|
|||
{
|
||||
return $this->combinePathTreeOfConditions($this->getConditionsAsPathTree($table, $params));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Record;
|
||||
|
||||
class HabtmValues
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Record;
|
||||
|
||||
use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
|
||||
|
||||
class OrderingInfo
|
||||
{
|
||||
|
||||
public function getColumnOrdering(ReflectedTable $table, array $params): array
|
||||
{
|
||||
$fields = array();
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Record;
|
||||
|
||||
class PaginationInfo
|
||||
{
|
||||
|
||||
public $DEFAULT_PAGE_SIZE = 20;
|
||||
|
||||
public function hasPage(array $params): bool
|
||||
|
@ -66,5 +66,4 @@ class PaginationInfo
|
|||
}
|
||||
return $pageLimit;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Record;
|
||||
|
||||
class PathTree implements \JsonSerializable
|
||||
{
|
||||
const WILDCARD = '*';
|
||||
public const WILDCARD = '*';
|
||||
|
||||
private $tree;
|
||||
|
||||
public function __construct( /* object */&$tree = null)
|
||||
public function __construct(/* object */&$tree = null)
|
||||
{
|
||||
if (!$tree) {
|
||||
$tree = $this->newTree();
|
||||
|
@ -58,7 +59,7 @@ class PathTree implements \JsonSerializable
|
|||
foreach ($path as $key) {
|
||||
if (isset($tree->branches->$key)) {
|
||||
$tree = &$tree->branches->$key;
|
||||
} else if (isset($tree->branches->$star)) {
|
||||
} elseif (isset($tree->branches->$star)) {
|
||||
$tree = &$tree->branches->$star;
|
||||
} else {
|
||||
return [];
|
||||
|
@ -67,7 +68,7 @@ class PathTree implements \JsonSerializable
|
|||
return $tree->values;
|
||||
}
|
||||
|
||||
public static function fromJson( /* object */$tree): PathTree
|
||||
public static function fromJson(/* object */$tree): PathTree
|
||||
{
|
||||
return new PathTree($tree);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Record;
|
||||
|
||||
use Tqdev\PhpCrudApi\Column\ReflectionService;
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi\Record;
|
||||
|
||||
use Tqdev\PhpCrudApi\Column\ReflectionService;
|
||||
use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
|
||||
use Tqdev\PhpCrudApi\Column\ReflectionService;
|
||||
use Tqdev\PhpCrudApi\Database\GenericDB;
|
||||
use Tqdev\PhpCrudApi\Middleware\Communication\VariableStore;
|
||||
use Tqdev\PhpCrudApi\Record\Condition\ColumnCondition;
|
||||
|
@ -10,7 +11,6 @@ use Tqdev\PhpCrudApi\Record\Condition\OrCondition;
|
|||
|
||||
class RelationJoiner
|
||||
{
|
||||
|
||||
private $reflection;
|
||||
private $ordering;
|
||||
private $columns;
|
||||
|
@ -92,9 +92,7 @@ class RelationJoiner
|
|||
|
||||
private function addJoinsForTables(ReflectedTable $t1, PathTree $joins, array &$records, array $params, GenericDB $db)
|
||||
{
|
||||
|
||||
foreach ($joins->getKeys() as $t2Name) {
|
||||
|
||||
$t2 = $this->reflection->getTable($t2Name);
|
||||
|
||||
$belongsTo = count($t1->getFksTo($t2->getName())) > 0;
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi;
|
||||
|
||||
use Nyholm\Psr7Server\ServerRequestCreator;
|
||||
use Nyholm\Psr7\Factory\Psr17Factory;
|
||||
use Nyholm\Psr7Server\ServerRequestCreator;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class RequestFactory
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
@ -94,5 +95,4 @@ class RequestUtils
|
|||
}
|
||||
return $allTableNames;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi;
|
||||
|
||||
use Nyholm\Psr7\Factory\Psr17Factory;
|
||||
|
@ -6,14 +7,14 @@ use Psr\Http\Message\ResponseInterface;
|
|||
|
||||
class ResponseFactory
|
||||
{
|
||||
const OK = 200;
|
||||
const UNAUTHORIZED = 401;
|
||||
const FORBIDDEN = 403;
|
||||
const NOT_FOUND = 404;
|
||||
const METHOD_NOT_ALLOWED = 405;
|
||||
const CONFLICT = 409;
|
||||
const UNPROCESSABLE_ENTITY = 422;
|
||||
const INTERNAL_SERVER_ERROR = 500;
|
||||
public const OK = 200;
|
||||
public const UNAUTHORIZED = 401;
|
||||
public const FORBIDDEN = 403;
|
||||
public const NOT_FOUND = 404;
|
||||
public const METHOD_NOT_ALLOWED = 405;
|
||||
public const CONFLICT = 409;
|
||||
public const UNPROCESSABLE_ENTITY = 422;
|
||||
public const INTERNAL_SERVER_ERROR = 500;
|
||||
|
||||
public static function fromHtml(int $status, string $html): ResponseInterface
|
||||
{
|
||||
|
@ -43,5 +44,4 @@ class ResponseFactory
|
|||
$psr17Factory = new Psr17Factory();
|
||||
return $psr17Factory->createResponse($status);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Tqdev\PhpCrudApi;
|
||||
|
||||
use Tqdev\PhpCrudApi\Api;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue