streams/Code/Lib/Api_router.php

36 lines
713 B
PHP
Raw Normal View History

<?php
2022-02-16 04:08:28 +00:00
namespace Code\Lib;
2021-12-02 23:02:31 +00:00
class Api_router
{
2022-08-27 04:01:22 +00:00
private static array $routes = [];
2022-08-27 04:01:22 +00:00
public static function register($path, $fn, $auth_required): void
2021-12-02 23:02:31 +00:00
{
self::$routes[$path] = ['func' => $fn, 'auth' => $auth_required];
}
2021-12-02 23:02:31 +00:00
public static function find($path)
{
if (array_key_exists($path, self::$routes)) {
return self::$routes[$path];
}
2021-12-02 23:02:31 +00:00
$with_params = dirname($path) . '/[id]';
2021-12-02 23:02:31 +00:00
if (array_key_exists($with_params, self::$routes)) {
return self::$routes[$with_params];
}
2021-12-02 23:02:31 +00:00
return null;
}
2022-10-11 07:59:26 +00:00
/** @noinspection PhpUnused */
2022-08-27 04:01:22 +00:00
public static function dbg(): array
2021-12-02 23:02:31 +00:00
{
return self::$routes;
}
2021-12-03 03:01:39 +00:00
}