Publiczna aplikacja fdmtech.pl: renderer CMS, formularz audytu, szablony i logotypy
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FDMTech;
|
||||
|
||||
final class Router
|
||||
{
|
||||
/** No decoding ambiguity: public paths are ASCII single slugs. */
|
||||
public static function route(string $uri): array
|
||||
{
|
||||
$path = explode('?', $uri, 2)[0];
|
||||
if ($path === '/') {
|
||||
return ['slug' => 'home', 'path' => '/'];
|
||||
}
|
||||
if (!preg_match('~^/([a-z0-9]+(?:-[a-z0-9]+)*)(/?)$~D', $path, $match) || strlen($match[1]) > 160) {
|
||||
return ['error' => 404];
|
||||
}
|
||||
if ($match[1] === 'home') {
|
||||
return ['redirect' => '/'];
|
||||
}
|
||||
if (($match[2] ?? '') === '/') {
|
||||
return ['redirect' => '/' . $match[1]];
|
||||
}
|
||||
return ['slug' => $match[1], 'path' => $path];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user