2016-08-12 00:02:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Zotlabs\Lib;
|
|
|
|
|
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
class Api_router
|
|
|
|
{
|
2016-08-12 00:02:52 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
private static $routes = [];
|
2016-08-12 00:02:52 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
public static function register($path, $fn, $auth_required)
|
|
|
|
{
|
|
|
|
self::$routes[$path] = ['func' => $fn, 'auth' => $auth_required];
|
|
|
|
}
|
2016-08-12 00:02:52 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
public static function find($path)
|
|
|
|
{
|
|
|
|
if (array_key_exists($path, self::$routes)) {
|
|
|
|
return self::$routes[$path];
|
|
|
|
}
|
2019-03-04 23:39:03 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$with_params = dirname($path) . '/[id]';
|
2019-03-04 23:39:03 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
if (array_key_exists($with_params, self::$routes)) {
|
|
|
|
return self::$routes[$with_params];
|
|
|
|
}
|
2019-03-04 23:39:03 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
return null;
|
|
|
|
}
|
2016-08-12 00:02:52 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
public static function dbg()
|
|
|
|
{
|
|
|
|
return self::$routes;
|
|
|
|
}
|
2016-08-12 00:02:52 +00:00
|
|
|
|
|
|
|
}
|