Router bugfix, save and update route frontend
This commit is contained in:
@@ -10,7 +10,8 @@ use Core\Objects\DatabaseEntity\Attribute\MaxLength;
|
||||
use Core\Objects\DatabaseEntity\Attribute\Unique;
|
||||
use Core\Objects\DatabaseEntity\Controller\DatabaseEntity;
|
||||
use Core\Objects\Router\DocumentRoute;
|
||||
use Core\Objects\Router\RedirectRoute;
|
||||
use Core\Objects\Router\RedirectPermanentlyRoute;
|
||||
use Core\Objects\Router\RedirectTemporaryRoute;
|
||||
use Core\Objects\Router\Router;
|
||||
use Core\Objects\Router\StaticFileRoute;
|
||||
|
||||
@@ -23,8 +24,8 @@ abstract class Route extends DatabaseEntity {
|
||||
const TYPE_REDIRECT_PERMANENTLY = "redirect_permanently";
|
||||
const TYPE_REDIRECT_TEMPORARY = "redirect_temporary";
|
||||
const ROUTE_TYPES = [
|
||||
self::TYPE_REDIRECT_TEMPORARY => RedirectRoute::class,
|
||||
self::TYPE_REDIRECT_PERMANENTLY => RedirectRoute::class,
|
||||
self::TYPE_REDIRECT_TEMPORARY => RedirectTemporaryRoute::class,
|
||||
self::TYPE_REDIRECT_PERMANENTLY => RedirectPermanentlyRoute::class,
|
||||
self::TYPE_STATIC => StaticFileRoute::class,
|
||||
self::TYPE_DYNAMIC => DocumentRoute::class
|
||||
];
|
||||
@@ -60,6 +61,10 @@ abstract class Route extends DatabaseEntity {
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
public function isExact(): bool {
|
||||
return $this->exact;
|
||||
}
|
||||
|
||||
private static function parseParamType(?string $type): ?int {
|
||||
if ($type === null || trim($type) === "") {
|
||||
return null;
|
||||
|
||||
@@ -2,8 +2,18 @@
|
||||
|
||||
namespace Core\Objects\Router;
|
||||
|
||||
use Core\Driver\SQL\SQL;
|
||||
|
||||
class RedirectPermanentlyRoute extends RedirectRoute {
|
||||
|
||||
const HTTP_STATUS_CODE = 308;
|
||||
|
||||
public function __construct(string $pattern, bool $exact, string $destination) {
|
||||
parent::__construct("redirect_permanently", $pattern, $exact, $destination, 308);
|
||||
parent::__construct("redirect_permanently", $pattern, $exact, $destination, self::HTTP_STATUS_CODE);
|
||||
}
|
||||
|
||||
public function postFetch(SQL $sql, array $row) {
|
||||
parent::postFetch($sql, $row);
|
||||
$this->code = self::HTTP_STATUS_CODE;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ use JetBrains\PhpStorm\Pure;
|
||||
class RedirectRoute extends Route {
|
||||
|
||||
#[Transient]
|
||||
private int $code;
|
||||
protected int $code;
|
||||
|
||||
public function __construct(string $type, string $pattern, bool $exact, string $destination, int $code = 307) {
|
||||
parent::__construct($type, $pattern, $destination, $exact);
|
||||
|
||||
@@ -2,8 +2,18 @@
|
||||
|
||||
namespace Core\Objects\Router;
|
||||
|
||||
use Core\Driver\SQL\SQL;
|
||||
|
||||
class RedirectTemporaryRoute extends RedirectRoute {
|
||||
|
||||
const HTTP_STATUS_CODE = 307;
|
||||
|
||||
public function __construct(string $pattern, bool $exact, string $destination) {
|
||||
parent::__construct("redirect_temporary", $pattern, $exact, $destination, 307);
|
||||
parent::__construct("redirect_temporary", $pattern, $exact, $destination, self::HTTP_STATUS_CODE);
|
||||
}
|
||||
|
||||
public function postFetch(SQL $sql, array $row) {
|
||||
parent::postFetch($sql, $row);
|
||||
$this->code = self::HTTP_STATUS_CODE;
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ class StaticRoute extends Route {
|
||||
private int $code;
|
||||
|
||||
public function __construct(string $pattern, bool $exact, string $data, int $code = 200) {
|
||||
parent::__construct("static", $pattern, $exact);
|
||||
parent::__construct("static", $pattern, "", $exact);
|
||||
$this->data = $data;
|
||||
$this->code = $code;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user