[ROUTER] Add mechanism for sorting the order in which core routes are loaded
This commit is contained in:
parent
b26f3bca14
commit
e563c393f8
@ -56,9 +56,20 @@ class RouteLoader extends Loader
|
|||||||
$this->rc = new RouteCollection();
|
$this->rc = new RouteCollection();
|
||||||
|
|
||||||
$route_files = glob(INSTALLDIR . '/src/Routes/*.php');
|
$route_files = glob(INSTALLDIR . '/src/Routes/*.php');
|
||||||
|
$to_load = [];
|
||||||
foreach ($route_files as $file) {
|
foreach ($route_files as $file) {
|
||||||
require_once $file;
|
require_once $file;
|
||||||
$ns = '\\App\\Routes\\' . basename($file, '.php');
|
$ns = '\\App\\Routes\\' . basename($file, '.php');
|
||||||
|
if (defined("{$ns}::LOAD_ORDER")) {
|
||||||
|
$to_load[$ns::LOAD_ORDER] = $ns;
|
||||||
|
} else {
|
||||||
|
$to_load[] = $ns;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ksort($to_load);
|
||||||
|
|
||||||
|
foreach ($to_load as $ns) {
|
||||||
$ns::load($this);
|
$ns::load($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,8 @@ use App\Core\Router\RouteLoader;
|
|||||||
|
|
||||||
abstract class Attachments
|
abstract class Attachments
|
||||||
{
|
{
|
||||||
|
const LOAD_ORDER = 20;
|
||||||
|
|
||||||
public static function load(RouteLoader $r): void
|
public static function load(RouteLoader $r): void
|
||||||
{
|
{
|
||||||
$r->connect('attachment_show', '/attachment/{id<\d+>}', [C\Attachment::class, 'attachment_show']);
|
$r->connect('attachment_show', '/attachment/{id<\d+>}', [C\Attachment::class, 'attachment_show']);
|
||||||
|
@ -39,6 +39,7 @@ use App\Util\Nickname;
|
|||||||
|
|
||||||
abstract class GSActor
|
abstract class GSActor
|
||||||
{
|
{
|
||||||
|
const LOAD_ORDER = 30;
|
||||||
public static function load(RouteLoader $r): void
|
public static function load(RouteLoader $r): void
|
||||||
{
|
{
|
||||||
$r->connect(id: 'gsactor_view_id', uri_path: '/actor/{id<\d+>}', target: [C\GSActor::class, 'GSActorShowId']);
|
$r->connect(id: 'gsactor_view_id', uri_path: '/actor/{id<\d+>}', target: [C\GSActor::class, 'GSActorShowId']);
|
||||||
|
@ -40,6 +40,8 @@ use Symfony\Bundle\FrameworkBundle\Controller\RedirectController;
|
|||||||
|
|
||||||
abstract class Main
|
abstract class Main
|
||||||
{
|
{
|
||||||
|
const LOAD_ORDER = 10;
|
||||||
|
|
||||||
public static function load(RouteLoader $r): void
|
public static function load(RouteLoader $r): void
|
||||||
{
|
{
|
||||||
$r->connect('login', '/login', [C\Security::class, 'login']);
|
$r->connect('login', '/login', [C\Security::class, 'login']);
|
||||||
|
@ -38,6 +38,7 @@ use App\Core\Router\RouteLoader;
|
|||||||
|
|
||||||
abstract class Note
|
abstract class Note
|
||||||
{
|
{
|
||||||
|
const LOAD_ORDER = 40;
|
||||||
public static function load(RouteLoader $r): void
|
public static function load(RouteLoader $r): void
|
||||||
{
|
{
|
||||||
$r->connect('note_view', '/note/{id<\d+>}', [C\Note::class, 'NoteShow']);
|
$r->connect('note_view', '/note/{id<\d+>}', [C\Note::class, 'NoteShow']);
|
||||||
|
Loading…
Reference in New Issue
Block a user