streams/Zotlabs/Lib/Api_router.php

36 lines
663 B
PHP
Raw Normal View History

<?php
namespace Zotlabs\Lib;
2021-12-02 23:02:31 +00:00
class Api_router
{
2021-12-02 23:02:31 +00:00
private static $routes = [];
2021-12-02 23:02:31 +00:00
public static function register($path, $fn, $auth_required)
{
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;
}
2021-12-02 23:02:31 +00:00
public static function dbg()
{
return self::$routes;
}
}