From 483983790a534632ed5bf63094c769777d7a1614 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sun, 27 Mar 2022 16:43:59 +0100 Subject: [PATCH] [CORE][Router] Rename \App\Core\Router\Router to \App\Core\Router and merge \App\Core\Router\RouteLoader with \App\Core\Router --- components/Attachment/Attachment.php | 4 +- components/Attachment/Entity/Attachment.php | 2 +- .../Attachment/Entity/AttachmentThumbnail.php | 2 +- .../tests/Entity/AttachmentTest.php | 2 +- components/Avatar/Avatar.php | 5 +- components/Avatar/Entity/Avatar.php | 2 +- components/Blog/Blog.php | 4 +- components/Circle/Circle.php | 5 +- components/Circle/Controller/Circles.php | 2 +- components/Circle/Entity/ActorCircle.php | 2 +- components/Circle/Entity/ActorTag.php | 2 +- .../Conversation/Controller/Conversation.php | 2 +- components/Conversation/Conversation.php | 5 +- .../Conversation/Entity/Conversation.php | 2 +- components/Feed/Feed.php | 4 +- .../Feed/tests/Controller/FeedsTest.php | 2 +- components/FreeNetwork/FreeNetwork.php | 5 +- .../WebfingerResourceActor.php | 2 +- components/Group/Controller/GroupFeed.php | 2 +- components/Group/Group.php | 5 +- components/Language/Language.php | 4 +- components/LeftPanel/Controller/EditFeeds.php | 2 +- components/LeftPanel/LeftPanel.php | 5 +- components/Notification/Notification.php | 5 +- components/Person/Controller/PersonFeed.php | 2 +- components/Person/Person.php | 4 +- .../tests/Controller/PersonSettingsTest.php | 2 +- components/Posting/Form/Posting.php | 2 +- components/Posting/Posting.php | 5 +- .../Subscription/Controller/Subscribers.php | 2 +- components/Subscription/Subscription.php | 5 +- components/Tag/Entity/NoteTag.php | 2 +- components/Tag/Tag.php | 2 +- config/services.yaml | 2 +- plugins/ActivityPub/ActivityPub.php | 7 +- plugins/ActivityPub/Controller/Inbox.php | 2 +- plugins/ActivityPub/Controller/Outbox.php | 2 +- plugins/ActivityPub/Util/Model/Activity.php | 2 +- plugins/ActivityPub/Util/Model/Actor.php | 2 +- plugins/ActivityPub/Util/Model/Note.php | 2 +- .../Util/OrderedCollectionController.php | 2 +- .../AttachmentCollections.php | 5 +- .../Controller/AttachmentCollections.php | 2 +- .../Bundles/Controller/BundleCollections.php | 2 +- plugins/Cover/Cover.php | 4 +- plugins/DeleteNote/Controller/DeleteNote.php | 2 +- plugins/DeleteNote/DeleteNote.php | 7 +- plugins/Directory/Directory.php | 5 +- plugins/Embed/Embed.php | 9 +- plugins/Favourite/Controller/Favourite.php | 4 +- plugins/Favourite/Favourite.php | 5 +- plugins/OAuth2/OAuth2.php | 7 +- plugins/Oomox/Oomox.php | 5 +- .../PinnedNotes/Controller/PinnedNotes.php | 2 +- plugins/PinnedNotes/PinnedNotes.php | 5 +- plugins/Poll/Poll.php | 4 +- plugins/ProfileColor/ProfileColor.php | 4 +- plugins/RepeatNote/Controller/Repeat.php | 4 +- plugins/RepeatNote/RepeatNote.php | 5 +- .../TagBasedFiltering/TagBasedFiltering.php | 5 +- plugins/WebHooks/Controller/WebHooks.php | 2 +- plugins/WebHooks/WebHooks.php | 4 +- src/Controller/ActorProfile.php | 2 +- src/Controller/Security.php | 2 +- src/Core/Form.php | 2 +- src/Core/GNUsocial.php | 2 +- src/Core/Router.php | 244 ++++++++++++++++++ src/Core/Router/Router.php | 121 --------- src/Entity/Actor.php | 2 +- src/Entity/Feed.php | 2 +- src/Entity/Note.php | 2 +- src/Routes/Activity.php | 4 +- src/Routes/Actor.php | 4 +- src/Routes/Main.php | 4 +- src/Routes/Note.php | 4 +- src/Twig/Runtime.php | 2 +- src/Util/Common.php | 2 +- src/Util/Exception/RedirectException.php | 2 +- tests/Core/RouterTest.php | 5 +- 79 files changed, 362 insertions(+), 260 deletions(-) create mode 100644 src/Core/Router.php delete mode 100644 src/Core/Router/Router.php diff --git a/components/Attachment/Attachment.php b/components/Attachment/Attachment.php index e7d9b8c07c..5437ff1996 100644 --- a/components/Attachment/Attachment.php +++ b/components/Attachment/Attachment.php @@ -25,7 +25,7 @@ use App\Core\Cache; use App\Core\DB; use App\Core\Event; use App\Core\Modules\Component; -use App\Core\Router\RouteLoader; +use App\Core\Router; use App\Entity\Actor; use App\Entity\Note; use App\Util\Formatting; @@ -37,7 +37,7 @@ use Doctrine\ORM\QueryBuilder; class Attachment extends Component { - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { $r->connect('note_attachment_show', '/object/note/{note_id<\d+>}/attachment/{attachment_id<\d+>}', [C\Attachment::class, 'attachmentShowWithNote']); $r->connect('note_attachment_view', '/object/note/{note_id<\d+>}/attachment/{attachment_id<\d+>}/view', [C\Attachment::class, 'attachmentViewWithNote']); diff --git a/components/Attachment/Entity/Attachment.php b/components/Attachment/Entity/Attachment.php index c0b7a6620f..ca9b53e448 100644 --- a/components/Attachment/Entity/Attachment.php +++ b/components/Attachment/Entity/Attachment.php @@ -30,7 +30,7 @@ use App\Core\Event; use App\Core\GSFile; use function App\Core\I18n\_m; use App\Core\Log; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Note; use App\Util\Common; use App\Util\Exception\ClientException; diff --git a/components/Attachment/Entity/AttachmentThumbnail.php b/components/Attachment/Entity/AttachmentThumbnail.php index 13d1638ce9..a3eafca48f 100644 --- a/components/Attachment/Entity/AttachmentThumbnail.php +++ b/components/Attachment/Entity/AttachmentThumbnail.php @@ -29,7 +29,7 @@ use App\Core\Entity; use App\Core\Event; use App\Core\GSFile; use App\Core\Log; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Note; use App\Util\Common; use App\Util\Exception\ClientException; diff --git a/components/Attachment/tests/Entity/AttachmentTest.php b/components/Attachment/tests/Entity/AttachmentTest.php index ad8bd2cdc9..4149c89dc3 100644 --- a/components/Attachment/tests/Entity/AttachmentTest.php +++ b/components/Attachment/tests/Entity/AttachmentTest.php @@ -24,7 +24,7 @@ namespace Component\Attachment\tests\Entity; use App\Core\DB; use App\Core\Event; use App\Core\GSFile; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Note; use App\Util\GNUsocialTestCase; use App\Util\TemporaryFile; diff --git a/components/Avatar/Avatar.php b/components/Avatar/Avatar.php index 1f8bc73c87..ba27e5e1bb 100644 --- a/components/Avatar/Avatar.php +++ b/components/Avatar/Avatar.php @@ -26,8 +26,7 @@ use App\Core\DB; use App\Core\Event; use App\Core\GSFile; use App\Core\Modules\Component; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Util\Common; use Component\Attachment\Entity\Attachment; use Component\Attachment\Entity\AttachmentThumbnail; @@ -41,7 +40,7 @@ class Avatar extends Component { } - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { $r->connect('avatar_actor', '/actor/{actor_id<\d+>}/avatar/{size?medium}', [Controller\Avatar::class, 'avatar_view']); $r->connect('avatar_default', '/avatar/default/{size?medium}', [Controller\Avatar::class, 'default_avatar_view']); diff --git a/components/Avatar/Entity/Avatar.php b/components/Avatar/Entity/Avatar.php index bcecfcbb69..2bff89661c 100644 --- a/components/Avatar/Entity/Avatar.php +++ b/components/Avatar/Entity/Avatar.php @@ -27,7 +27,7 @@ use App\Core\Cache; use App\Core\DB; use App\Core\Entity; use App\Core\Event; -use App\Core\Router\Router; +use App\Core\Router; use App\Util\Common; use Component\Attachment\Entity\Attachment; use Component\Attachment\Entity\AttachmentThumbnail; diff --git a/components/Blog/Blog.php b/components/Blog/Blog.php index 6d475ed47f..520cdd8f6f 100644 --- a/components/Blog/Blog.php +++ b/components/Blog/Blog.php @@ -24,12 +24,12 @@ namespace Component\Blog; use App\Core\Event; use App\Core\Modules\Plugin; -use App\Core\Router\RouteLoader; +use App\Core\Router; use Component\Blog\Controller as C; class Blog extends Plugin { - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { $r->connect(id: 'blog_post', uri_path: '/blog/post', target: [C\Post::class, 'makePost']); return Event::next; diff --git a/components/Circle/Circle.php b/components/Circle/Circle.php index df5eb89045..888f9a82e5 100644 --- a/components/Circle/Circle.php +++ b/components/Circle/Circle.php @@ -28,8 +28,7 @@ use App\Core\DB; use App\Core\Event; use function App\Core\I18n\_m; use App\Core\Modules\Component; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Actor; use App\Entity\Feed; use App\Entity\LocalUser; @@ -59,7 +58,7 @@ class Circle extends Component protected const SLUG = 'circle'; protected const PLURAL_SLUG = 'circles'; - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { $r->connect('actor_circle_view_by_circle_id', '/circle/{circle_id<\d+>}', [CircleController\Circle::class, 'circleById']); // View circle members by (tagger id or nickname) and tag diff --git a/components/Circle/Controller/Circles.php b/components/Circle/Controller/Circles.php index 903159e8ec..a78df78fbf 100644 --- a/components/Circle/Controller/Circles.php +++ b/components/Circle/Controller/Circles.php @@ -25,7 +25,7 @@ namespace Component\Circle\Controller; use App\Core\Cache; use App\Core\DB; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Actor; use App\Entity\LocalUser; use Component\Circle\Entity\ActorCircle; diff --git a/components/Circle/Entity/ActorCircle.php b/components/Circle/Entity/ActorCircle.php index a2735fefb1..31ed2cea44 100644 --- a/components/Circle/Entity/ActorCircle.php +++ b/components/Circle/Entity/ActorCircle.php @@ -24,7 +24,7 @@ namespace Component\Circle\Entity; use App\Core\Cache; use App\Core\DB; use App\Core\Entity; -use App\Core\Router\Router; +use App\Core\Router; use DateTimeInterface; /** diff --git a/components/Circle/Entity/ActorTag.php b/components/Circle/Entity/ActorTag.php index 7085774633..f61cb6aaf2 100644 --- a/components/Circle/Entity/ActorTag.php +++ b/components/Circle/Entity/ActorTag.php @@ -23,7 +23,7 @@ namespace Component\Circle\Entity; use App\Core\DB; use App\Core\Entity; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Actor; use Component\Tag\Tag; use DateTimeInterface; diff --git a/components/Conversation/Controller/Conversation.php b/components/Conversation/Controller/Conversation.php index ae3384ff00..e387b11a5a 100644 --- a/components/Conversation/Controller/Conversation.php +++ b/components/Conversation/Controller/Conversation.php @@ -32,7 +32,7 @@ use App\Core\DB; use App\Core\Form; use function App\Core\I18n\_m; use App\Core\Log; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Note; use App\Util\Common; use App\Util\Exception\ClientException; diff --git a/components/Conversation/Conversation.php b/components/Conversation/Conversation.php index cb8b2506ed..3396c99b2d 100644 --- a/components/Conversation/Conversation.php +++ b/components/Conversation/Conversation.php @@ -32,8 +32,7 @@ use App\Core\DB; use App\Core\Event; use function App\Core\I18n\_m; use App\Core\Modules\Component; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Activity; use App\Entity\Actor; use App\Entity\Note; @@ -46,7 +45,7 @@ use Symfony\Component\HttpFoundation\Request; class Conversation extends Component { - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { $r->connect('conversation', '/conversation/{conversation_id<\d+>}', [Controller\Conversation::class, 'showConversation']); $r->connect('conversation_mute', '/conversation/{conversation_id<\d+>}/mute', [Controller\Conversation::class, 'muteConversation']); diff --git a/components/Conversation/Entity/Conversation.php b/components/Conversation/Entity/Conversation.php index 896b10831f..e977d1fc8e 100644 --- a/components/Conversation/Entity/Conversation.php +++ b/components/Conversation/Entity/Conversation.php @@ -25,7 +25,7 @@ namespace Component\Conversation\Entity; use App\Core\DB; use App\Core\Entity; -use App\Core\Router\Router; +use App\Core\Router; /** * Entity class for Conversations diff --git a/components/Feed/Feed.php b/components/Feed/Feed.php index 0470fba105..6e8a134d2b 100644 --- a/components/Feed/Feed.php +++ b/components/Feed/Feed.php @@ -25,12 +25,12 @@ namespace Component\Feed; use App\Core\Event; use App\Core\Modules\Component; -use App\Core\Router\RouteLoader; +use App\Core\Router; use Component\Feed\Controller as C; class Feed extends Component { - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { $r->connect('feed_public', '/feed/public', [C\Feeds::class, 'public']); $r->connect('feed_home', '/feed/home', [C\Feeds::class, 'home']); diff --git a/components/Feed/tests/Controller/FeedsTest.php b/components/Feed/tests/Controller/FeedsTest.php index 14bcf3319c..3b8459b96f 100644 --- a/components/Feed/tests/Controller/FeedsTest.php +++ b/components/Feed/tests/Controller/FeedsTest.php @@ -23,7 +23,7 @@ declare(strict_types = 1); namespace Component\Feed\tests\Controller; -use App\Core\Router\Router; +use App\Core\Router; use App\Util\GNUsocialTestCase; use Component\Feed\Controller\Feeds; use Jchook\AssertThrows\AssertThrows; diff --git a/components/FreeNetwork/FreeNetwork.php b/components/FreeNetwork/FreeNetwork.php index f2c1d5bc75..77bc78d92f 100644 --- a/components/FreeNetwork/FreeNetwork.php +++ b/components/FreeNetwork/FreeNetwork.php @@ -28,8 +28,7 @@ use App\Core\HTTPClient; use function App\Core\I18n\_m; use App\Core\Log; use App\Core\Modules\Component; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Activity; use App\Entity\Actor; use App\Entity\LocalUser; @@ -86,7 +85,7 @@ class FreeNetwork extends Component return Event::next; } - public function onAddRoute(RouteLoader $m): bool + public function onAddRoute(Router $m): bool { // Feeds $m->connect('feed_network', '/feed/network', [Feeds::class, 'network']); diff --git a/components/FreeNetwork/Util/WebfingerResource/WebfingerResourceActor.php b/components/FreeNetwork/Util/WebfingerResource/WebfingerResourceActor.php index bece04a291..ca634361cf 100644 --- a/components/FreeNetwork/Util/WebfingerResource/WebfingerResourceActor.php +++ b/components/FreeNetwork/Util/WebfingerResource/WebfingerResourceActor.php @@ -6,7 +6,7 @@ namespace Component\FreeNetwork\Util\WebfingerResource; use App\Core\Event; use App\Core\Log; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Actor; use App\Util\Common; use Component\FreeNetwork\Exception\WebfingerReconstructionException; diff --git a/components/Group/Controller/GroupFeed.php b/components/Group/Controller/GroupFeed.php index 422dfde4bb..f562b0848c 100644 --- a/components/Group/Controller/GroupFeed.php +++ b/components/Group/Controller/GroupFeed.php @@ -27,7 +27,7 @@ use App\Core\Cache; use App\Core\DB; use App\Core\Form; use function App\Core\I18n\_m; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Actor; use App\Entity as E; use App\Util\Common; diff --git a/components/Group/Group.php b/components/Group/Group.php index 318b68ff3b..0b254790da 100644 --- a/components/Group/Group.php +++ b/components/Group/Group.php @@ -24,8 +24,7 @@ namespace Component\Group; use App\Core\Event; use function App\Core\I18n\_m; use App\Core\Modules\Component; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Activity; use App\Entity\Actor; use App\Util\Common; @@ -38,7 +37,7 @@ use Symfony\Component\HttpFoundation\Request; class Group extends Component { - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { $r->connect(id: 'group_actor_view_id', uri_path: '/group/{id<\d+>}', target: [C\GroupFeed::class, 'groupViewId']); $r->connect(id: 'group_actor_view_nickname', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\GroupFeed::class, 'groupViewNickname']); diff --git a/components/Language/Language.php b/components/Language/Language.php index 74bac1880c..8bb00cfcca 100644 --- a/components/Language/Language.php +++ b/components/Language/Language.php @@ -23,7 +23,7 @@ namespace Component\Language; use App\Core\Event; use App\Core\Modules\Component; -use App\Core\Router\RouteLoader; +use App\Core\Router; use App\Entity\Actor; use App\Entity\Note; use App\Util\Formatting; @@ -38,7 +38,7 @@ use Symfony\Component\HttpFoundation\Request; class Language extends Component { - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { $r->connect('settings_sort_languages', '/settings/sort_languages', [C\Language::class, 'sortLanguages']); return Event::next; diff --git a/components/LeftPanel/Controller/EditFeeds.php b/components/LeftPanel/Controller/EditFeeds.php index 8ef877b0d8..f6e9d7bdb7 100644 --- a/components/LeftPanel/Controller/EditFeeds.php +++ b/components/LeftPanel/Controller/EditFeeds.php @@ -28,7 +28,7 @@ use App\Core\Controller; use App\Core\DB; use App\Core\Form; use function App\Core\I18n\_m; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Feed; use App\Util\Common; use App\Util\Exception\ClientException; diff --git a/components/LeftPanel/LeftPanel.php b/components/LeftPanel/LeftPanel.php index a535af830a..6cb885c3ad 100644 --- a/components/LeftPanel/LeftPanel.php +++ b/components/LeftPanel/LeftPanel.php @@ -26,8 +26,7 @@ use App\Core\DB; use App\Core\Event; use function App\Core\I18n\_m; use App\Core\Modules\Component; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Actor; use App\Entity\Feed; use App\Util\Exception\ClientException; @@ -36,7 +35,7 @@ use Component\LeftPanel\Controller as C; class LeftPanel extends Component { - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { $r->connect('edit_feeds', '/edit-feeds', C\EditFeeds::class); return Event::next; diff --git a/components/Notification/Notification.php b/components/Notification/Notification.php index bef60bc2cd..6d2350ce0c 100644 --- a/components/Notification/Notification.php +++ b/components/Notification/Notification.php @@ -27,8 +27,7 @@ use function App\Core\I18n\_m; use App\Core\Log; use App\Core\Modules\Component; use App\Core\Queue; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Activity; use App\Entity\Actor; use App\Entity\LocalUser; @@ -40,7 +39,7 @@ use Throwable; class Notification extends Component { - public function onAddRoute(RouteLoader $m): bool + public function onAddRoute(Router $m): bool { $m->connect('feed_notifications', '/feed/notifications', [Feed::class, 'notifications']); return Event::next; diff --git a/components/Person/Controller/PersonFeed.php b/components/Person/Controller/PersonFeed.php index 1d997791fc..e24d5bb80c 100644 --- a/components/Person/Controller/PersonFeed.php +++ b/components/Person/Controller/PersonFeed.php @@ -24,7 +24,7 @@ declare(strict_types = 1); namespace Component\Person\Controller; use function App\Core\I18n\_m; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Actor; use App\Entity as E; use App\Entity\LocalUser; diff --git a/components/Person/Person.php b/components/Person/Person.php index b6e64f0a28..3d5847aa14 100644 --- a/components/Person/Person.php +++ b/components/Person/Person.php @@ -23,13 +23,13 @@ namespace Component\Person; use App\Core\Event; use App\Core\Modules\Component; -use App\Core\Router\RouteLoader; +use App\Core\Router; use App\Util\Nickname; use Component\Person\Controller as C; class Person extends Component { - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { $r->connect(id: 'person_actor_view_id', uri_path: '/person/{id<\d+>}', target: [C\PersonFeed::class, 'personViewId']); $r->connect(id: 'person_actor_view_nickname', uri_path: '/@{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\PersonFeed::class, 'personViewNickname'], options: ['is_system_path' => false]); diff --git a/components/Person/tests/Controller/PersonSettingsTest.php b/components/Person/tests/Controller/PersonSettingsTest.php index e2e9b2d801..3ebbce4473 100644 --- a/components/Person/tests/Controller/PersonSettingsTest.php +++ b/components/Person/tests/Controller/PersonSettingsTest.php @@ -24,7 +24,7 @@ declare(strict_types = 1); namespace Component\Person\tests\Controller; use App\Core\DB; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\LocalUser; use App\Util\GNUsocialTestCase; use Jchook\AssertThrows\AssertThrows; diff --git a/components/Posting/Form/Posting.php b/components/Posting/Form/Posting.php index 9940496f08..90c55611fa 100644 --- a/components/Posting/Form/Posting.php +++ b/components/Posting/Form/Posting.php @@ -8,7 +8,7 @@ use App\Core\ActorLocalRoles; use App\Core\Event; use App\Core\Form; use function App\Core\I18n\_m; -use App\Core\Router\Router; +use App\Core\Router; use App\Core\VisibilityScope; use App\Entity\Actor; use App\Util\Common; diff --git a/components/Posting/Posting.php b/components/Posting/Posting.php index 8dc8b0bff9..513f72f1b2 100644 --- a/components/Posting/Posting.php +++ b/components/Posting/Posting.php @@ -29,8 +29,7 @@ use App\Core\Event; use App\Core\GSFile; use function App\Core\I18n\_m; use App\Core\Modules\Component; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Core\VisibilityScope; use App\Entity\Activity; use App\Entity\Actor; @@ -55,7 +54,7 @@ class Posting extends Component { public const route = 'posting_form_action'; - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { $r->connect(self::route, '/form/posting', Controller\Posting::class); return Event::next; diff --git a/components/Subscription/Controller/Subscribers.php b/components/Subscription/Controller/Subscribers.php index 8c044c2a72..afb6ac516a 100644 --- a/components/Subscription/Controller/Subscribers.php +++ b/components/Subscription/Controller/Subscribers.php @@ -27,7 +27,7 @@ use App\Core\DB; use App\Core\Form; use function App\Core\I18n\_m; use App\Core\Log; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Actor; use App\Util\Common; use App\Util\Exception\ClientException; diff --git a/components/Subscription/Subscription.php b/components/Subscription/Subscription.php index fc1b60c589..7ac978c3ff 100644 --- a/components/Subscription/Subscription.php +++ b/components/Subscription/Subscription.php @@ -28,8 +28,7 @@ use App\Core\DB; use App\Core\Event; use function App\Core\I18n\_m; use App\Core\Modules\Component; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Activity; use App\Entity\Actor; use App\Entity\LocalUser; @@ -44,7 +43,7 @@ use Symfony\Component\HttpFoundation\Request; class Subscription extends Component { - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { $r->connect(id: 'actor_subscribe_add', uri_path: '/actor/subscribe/{object_id<\d+>}', target: [SubscribersController::class, 'subscribersAdd']); $r->connect(id: 'actor_subscribe_remove', uri_path: '/actor/unsubscribe/{object_id<\d+>}', target: [SubscribersController::class, 'subscribersRemove']); diff --git a/components/Tag/Entity/NoteTag.php b/components/Tag/Entity/NoteTag.php index 6b856aed5b..d51ac5325a 100644 --- a/components/Tag/Entity/NoteTag.php +++ b/components/Tag/Entity/NoteTag.php @@ -24,7 +24,7 @@ namespace Component\Tag\Entity; use App\Core\Cache; use App\Core\DB; use App\Core\Entity; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Actor; use App\Entity\Note; use Component\Language\Entity\Language; diff --git a/components/Tag/Tag.php b/components/Tag/Tag.php index 6338316337..059fbd70b4 100644 --- a/components/Tag/Tag.php +++ b/components/Tag/Tag.php @@ -28,7 +28,7 @@ use App\Core\DB; use App\Core\Event; use function App\Core\I18n\_m; use App\Core\Modules\Component; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Actor; use App\Entity\Note; use App\Util\Common; diff --git a/config/services.yaml b/config/services.yaml index 8e06e3b9c7..182b7e2a9e 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -24,7 +24,7 @@ services: resource: '../src/Controller' tags: ['controller.service_arguments'] - App\Core\Router\RouteLoader: + App\Core\Router: tags: ['routing.loader'] # Wrapper around Doctrine's StaticPHP metadata driver diff --git a/plugins/ActivityPub/ActivityPub.php b/plugins/ActivityPub/ActivityPub.php index 5b53d2686a..b1e0ee6a86 100644 --- a/plugins/ActivityPub/ActivityPub.php +++ b/plugins/ActivityPub/ActivityPub.php @@ -41,8 +41,7 @@ use function App\Core\I18n\_m; use App\Core\Log; use App\Core\Modules\Plugin; use App\Core\Queue; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Activity; use App\Entity\Actor; use App\Entity\Note; @@ -156,9 +155,9 @@ class ActivityPub extends Plugin * This code executes when GNU social creates the page routing, and we hook * on this event to add our Inbox and Outbox handler for ActivityPub. * - * @param RouteLoader $r the router that was initialized + * @param Router $r the router that was initialized */ - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { $r->connect( 'activitypub_inbox', diff --git a/plugins/ActivityPub/Controller/Inbox.php b/plugins/ActivityPub/Controller/Inbox.php index 3716441348..023e9f13c9 100644 --- a/plugins/ActivityPub/Controller/Inbox.php +++ b/plugins/ActivityPub/Controller/Inbox.php @@ -37,7 +37,7 @@ use App\Core\DB; use function App\Core\I18n\_m; use App\Core\Log; use App\Core\Queue; -use App\Core\Router\Router; +use App\Core\Router; use App\Util\Common; use App\Util\Exception\ClientException; use Exception; diff --git a/plugins/ActivityPub/Controller/Outbox.php b/plugins/ActivityPub/Controller/Outbox.php index 618e1a4021..cfa81028b0 100644 --- a/plugins/ActivityPub/Controller/Outbox.php +++ b/plugins/ActivityPub/Controller/Outbox.php @@ -34,7 +34,7 @@ namespace Plugin\ActivityPub\Controller; use function App\Core\I18n\_m; use App\Core\Log; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Activity; use App\Entity\Actor; use App\Util\Exception\ClientException; diff --git a/plugins/ActivityPub/Util/Model/Activity.php b/plugins/ActivityPub/Util/Model/Activity.php index f985a945a9..05b6d47f15 100644 --- a/plugins/ActivityPub/Util/Model/Activity.php +++ b/plugins/ActivityPub/Util/Model/Activity.php @@ -37,7 +37,7 @@ use ActivityPhp\Type\AbstractObject; use App\Core\DB; use App\Core\Event; use App\Core\Log; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Activity as GSActivity; use App\Util\Common; use App\Util\Exception\ClientException; diff --git a/plugins/ActivityPub/Util/Model/Actor.php b/plugins/ActivityPub/Util/Model/Actor.php index 4fe4acd09e..62e2d5c377 100644 --- a/plugins/ActivityPub/Util/Model/Actor.php +++ b/plugins/ActivityPub/Util/Model/Actor.php @@ -39,7 +39,7 @@ use App\Core\Event; use App\Core\GSFile; use App\Core\HTTPClient; use App\Core\Log; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Actor as GSActor; use App\Util\Exception\ServerException; use App\Util\TemporaryFile; diff --git a/plugins/ActivityPub/Util/Model/Note.php b/plugins/ActivityPub/Util/Model/Note.php index 5f0a392d8c..5a770fe578 100644 --- a/plugins/ActivityPub/Util/Model/Note.php +++ b/plugins/ActivityPub/Util/Model/Note.php @@ -41,7 +41,7 @@ use App\Core\GSFile; use App\Core\HTTPClient; use function App\Core\I18n\_m; use App\Core\Log; -use App\Core\Router\Router; +use App\Core\Router; use App\Core\VisibilityScope; use App\Entity\Note as GSNote; use App\Util\Common; diff --git a/plugins/ActivityPub/Util/OrderedCollectionController.php b/plugins/ActivityPub/Util/OrderedCollectionController.php index a662c66362..f992ff62c9 100644 --- a/plugins/ActivityPub/Util/OrderedCollectionController.php +++ b/plugins/ActivityPub/Util/OrderedCollectionController.php @@ -34,7 +34,7 @@ namespace Plugin\ActivityPub\Util; use ActivityPhp\Type\Core\OrderedCollection; use ActivityPhp\Type\Core\OrderedCollectionPage; -use App\Core\Router\Router; +use App\Core\Router; use Component\Collection\Util\Controller\CircleController; use Component\Collection\Util\Controller\FeedController; use Component\Collection\Util\Controller\OrderedCollection as GSOrderedCollection; diff --git a/plugins/AttachmentCollections/AttachmentCollections.php b/plugins/AttachmentCollections/AttachmentCollections.php index 09bc3bf8e6..40fa0e3824 100644 --- a/plugins/AttachmentCollections/AttachmentCollections.php +++ b/plugins/AttachmentCollections/AttachmentCollections.php @@ -35,8 +35,7 @@ use App\Core\DB; use App\Core\Event; use function App\Core\I18n\_m; use App\Core\Modules\Plugin; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Actor; use App\Entity\Feed; use App\Entity\LocalUser; @@ -123,7 +122,7 @@ class AttachmentCollections extends Plugin return array_map(fn ($x) => $x['attachment_collection_id'], $res); } - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { // View all collections by actor id and nickname $r->connect( diff --git a/plugins/AttachmentCollections/Controller/AttachmentCollections.php b/plugins/AttachmentCollections/Controller/AttachmentCollections.php index dc672db9c9..aa91e332e0 100644 --- a/plugins/AttachmentCollections/Controller/AttachmentCollections.php +++ b/plugins/AttachmentCollections/Controller/AttachmentCollections.php @@ -24,7 +24,7 @@ declare(strict_types = 1); namespace Plugin\AttachmentCollections\Controller; use App\Core\DB; -use App\Core\Router\Router; +use App\Core\Router; use Component\Collection\Util\Controller\MetaCollectionController; use Plugin\AttachmentCollections\Entity\AttachmentCollection; diff --git a/plugins/Bundles/Controller/BundleCollections.php b/plugins/Bundles/Controller/BundleCollections.php index 7c75020acd..6417676eeb 100644 --- a/plugins/Bundles/Controller/BundleCollections.php +++ b/plugins/Bundles/Controller/BundleCollections.php @@ -24,7 +24,7 @@ declare(strict_types = 1); namespace Plugin\Bundles\Controller; use App\Core\DB; -use App\Core\Router\Router; +use App\Core\Router; use Component\Collection\Util\Controller\MetaCollectionController; use Plugin\Bundles\Entity\BundleCollection; diff --git a/plugins/Cover/Cover.php b/plugins/Cover/Cover.php index 2fc02d20d2..7a76c00a62 100644 --- a/plugins/Cover/Cover.php +++ b/plugins/Cover/Cover.php @@ -25,7 +25,7 @@ namespace Plugin\Cover; use App\Core\DB; use App\Core\Event; use App\Core\Modules\Plugin; -use App\Core\Router\RouteLoader; +use App\Core\Router; use App\Util\Common; use Plugin\Cover\Controller as C; use Symfony\Component\HttpFoundation\Request; @@ -47,7 +47,7 @@ class Cover extends Plugin * * @return bool hook value; true means continue processing, false means stop */ - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { $r->connect('settings_profile_cover', 'settings/cover', [Controller\Cover::class, 'coversettings']); $r->connect('cover', '/cover', [Controller\Cover::class, 'cover']); diff --git a/plugins/DeleteNote/Controller/DeleteNote.php b/plugins/DeleteNote/Controller/DeleteNote.php index 8d74c9e3de..f6b647c673 100644 --- a/plugins/DeleteNote/Controller/DeleteNote.php +++ b/plugins/DeleteNote/Controller/DeleteNote.php @@ -28,7 +28,7 @@ use App\Core\DB; use App\Core\Form; use function App\Core\I18n\_m; use App\Core\Log; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Note; use App\Util\Common; use App\Util\Exception\ClientException; diff --git a/plugins/DeleteNote/DeleteNote.php b/plugins/DeleteNote/DeleteNote.php index 84d46443ab..d3c395667a 100644 --- a/plugins/DeleteNote/DeleteNote.php +++ b/plugins/DeleteNote/DeleteNote.php @@ -27,8 +27,7 @@ use App\Core\DB; use App\Core\Event; use function App\Core\I18n\_m; use App\Core\Modules\NoteHandlerPlugin; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Activity; use App\Entity\Actor; use App\Entity\Note; @@ -47,7 +46,7 @@ use Symfony\Component\HttpFoundation\Request; * @category DeleteNote * * @author Eliseu Amaro - * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org + * @copyright 2021-2022 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ class DeleteNote extends NoteHandlerPlugin @@ -136,7 +135,7 @@ class DeleteNote extends NoteHandlerPlugin * * @return bool Event hook */ - public function onAddRoute(RouteLoader $r) + public function onAddRoute(Router $r) { $r->connect(id: 'delete_note_action', uri_path: '/object/note/{note_id<\d+>}/delete', target: Controller\DeleteNote::class); diff --git a/plugins/Directory/Directory.php b/plugins/Directory/Directory.php index bb9c908169..337bb5883d 100644 --- a/plugins/Directory/Directory.php +++ b/plugins/Directory/Directory.php @@ -25,8 +25,7 @@ namespace Plugin\Directory; use App\Core\Event; use App\Core\Modules\Plugin; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Util\Common; use App\Util\Exception\RedirectException; use App\Util\Exception\ServerException; @@ -41,7 +40,7 @@ class Directory extends Plugin * * @return bool */ - public function onAddRoute(RouteLoader $r) + public function onAddRoute(Router $r) { $r->connect('directory_people', '/directory/people', [Controller\Directory::class, 'people']); $r->connect('directory_groups', '/directory/groups', [Controller\Directory::class, 'groups']); diff --git a/plugins/Embed/Embed.php b/plugins/Embed/Embed.php index a85919b32d..022f523304 100644 --- a/plugins/Embed/Embed.php +++ b/plugins/Embed/Embed.php @@ -31,7 +31,7 @@ declare(strict_types = 1); * @author Miguel Dantas * @author Hugo Sales * @author Diogo Peralta Cordeiro - * @copyright 2014-2021 Free Software Foundation, Inc http://www.fsf.org + * @copyright 2014-2022 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ @@ -45,8 +45,7 @@ use App\Core\HTTPClient; use function App\Core\I18n\_m; use App\Core\Log; use App\Core\Modules\Plugin; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Note; use App\Util\Common; use App\Util\Exception\ClientException; @@ -108,11 +107,11 @@ class Embed extends Plugin * This code executes when GNU social creates the page routing, and we hook * on this event to add our action handler for Embed. * - * @param RouteLoader $m the router that was initialized + * @param Router $m the router that was initialized * * @throws Exception */ - public function onAddRoute(RouteLoader $m): bool + public function onAddRoute(Router $m): bool { $m->connect('oembed', 'main/oembed', Controller\OEmbed::class); return Event::next; diff --git a/plugins/Favourite/Controller/Favourite.php b/plugins/Favourite/Controller/Favourite.php index eb45523e4f..99999ee4d0 100644 --- a/plugins/Favourite/Controller/Favourite.php +++ b/plugins/Favourite/Controller/Favourite.php @@ -26,9 +26,8 @@ namespace Plugin\Favourite\Controller; use App\Core\DB; use App\Core\Event; use App\Core\Form; -use function App\Core\I18n\_m; use App\Core\Log; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Activity; use App\Entity\Actor; use App\Entity\LocalUser; @@ -42,6 +41,7 @@ use App\Util\Exception\RedirectException; use App\Util\Exception\ServerException; use Component\Collection\Util\Controller\FeedController; use Component\Notification\Entity\Attention; +use function App\Core\I18n\_m; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\HttpFoundation\Request; diff --git a/plugins/Favourite/Favourite.php b/plugins/Favourite/Favourite.php index 8fa6a37610..ed24f59ea1 100644 --- a/plugins/Favourite/Favourite.php +++ b/plugins/Favourite/Favourite.php @@ -35,8 +35,7 @@ use App\Core\DB; use App\Core\Event; use function App\Core\I18n\_m; use App\Core\Modules\NoteHandlerPlugin; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Activity; use App\Entity\Actor; use App\Entity\Feed; @@ -211,7 +210,7 @@ class Favourite extends NoteHandlerPlugin /** * Maps Routes to their respective Controllers */ - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { // Add/remove note to/from favourites $r->connect(id: 'favourite_add', uri_path: '/object/note/{id<\d+>}/favour', target: [Controller\Favourite::class, 'favouriteAddNote']); diff --git a/plugins/OAuth2/OAuth2.php b/plugins/OAuth2/OAuth2.php index f58521b3d5..7402494fea 100644 --- a/plugins/OAuth2/OAuth2.php +++ b/plugins/OAuth2/OAuth2.php @@ -35,8 +35,7 @@ namespace Plugin\OAuth2; use App\Core\Event; use App\Core\Modules\Plugin; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Util\Common; use DateInterval; use Exception; @@ -93,9 +92,9 @@ class OAuth2 extends Plugin * This code executes when GNU social creates the page routing, and we hook * on this event to add our Inbox and Outbox handler for ActivityPub. * - * @param RouteLoader $r the router that was initialized + * @param Router $r the router that was initialized */ - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { $r->connect('oauth2_mastodon_api_apps', '/api/v1/apps', C\Client::class, ['http-methods' => ['POST']]); $r->connect('oauth2_client', '/oauth/client', C\Client::class, ['http-methods' => ['POST']]); diff --git a/plugins/Oomox/Oomox.php b/plugins/Oomox/Oomox.php index d78047b6bf..d32a83e733 100644 --- a/plugins/Oomox/Oomox.php +++ b/plugins/Oomox/Oomox.php @@ -26,8 +26,7 @@ use App\Core\Cache; use App\Core\DB; use App\Core\Event; use App\Core\Modules\Plugin; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\LocalUser; use App\Util\Common; use App\Util\Exception\NotFoundException; @@ -51,7 +50,7 @@ class Oomox extends Plugin /** * Maps Routes to their respective Controllers */ - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { $r->connect('oomox_settings', 'settings/oomox', [Controller\Oomox::class, 'oomoxSettings']); $r->connect('oomox_css', 'plugins/oomox/colours', [Controller\Oomox::class, 'oomoxCSS']); diff --git a/plugins/PinnedNotes/Controller/PinnedNotes.php b/plugins/PinnedNotes/Controller/PinnedNotes.php index 57f71d9638..0ee6b20f06 100644 --- a/plugins/PinnedNotes/Controller/PinnedNotes.php +++ b/plugins/PinnedNotes/Controller/PinnedNotes.php @@ -26,7 +26,7 @@ namespace Plugin\PinnedNotes\Controller; use App\Core\DB; use App\Core\Form; use function App\Core\I18n\_m; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Actor; use App\Entity\LocalUser; use App\Util\Common; diff --git a/plugins/PinnedNotes/PinnedNotes.php b/plugins/PinnedNotes/PinnedNotes.php index f408b3357c..815c8bd21e 100644 --- a/plugins/PinnedNotes/PinnedNotes.php +++ b/plugins/PinnedNotes/PinnedNotes.php @@ -34,8 +34,7 @@ namespace Plugin\PinnedNotes; use App\Core\DB; use App\Core\Event; use App\Core\Modules\Plugin; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Actor; use App\Entity\LocalUser; use App\Entity\Note; @@ -54,7 +53,7 @@ use Symfony\Component\HttpFoundation\Request; class PinnedNotes extends Plugin { - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { // Pin and unpin notes $r->connect(id: 'toggle_note_pin', uri_path: '/object/note/{id<\d+>}/pin', target: [C\PinnedNotes::class, 'togglePin']); diff --git a/plugins/Poll/Poll.php b/plugins/Poll/Poll.php index 296ce4b2db..dc0fe21f9b 100644 --- a/plugins/Poll/Poll.php +++ b/plugins/Poll/Poll.php @@ -27,7 +27,7 @@ use App\Core\Event; use App\Core\Form; use function App\Core\I18n\_m; use App\Core\Modules\NoteHandlerPlugin; -use App\Core\Router\RouteLoader; +use App\Core\Router; use App\Entity\Note; use App\Util\Common; use App\Util\Exception\InvalidFormException; @@ -57,7 +57,7 @@ class Poll extends NoteHandlerPlugin * * @return bool hook value; true means continue processing, false means stop */ - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { $r->connect('newpoll', 'main/poll/new/{num<\\d+>?3}', [Controller\NewPoll::class, 'newpoll']); diff --git a/plugins/ProfileColor/ProfileColor.php b/plugins/ProfileColor/ProfileColor.php index 6d346df7a4..0d324d38b1 100644 --- a/plugins/ProfileColor/ProfileColor.php +++ b/plugins/ProfileColor/ProfileColor.php @@ -26,7 +26,7 @@ use App\Core\Cache; use App\Core\DB; use App\Core\Event; use App\Core\Modules\Plugin; -use App\Core\Router\RouteLoader; +use App\Core\Router; use App\Util\Exception\RedirectException; use App\Util\Exception\ServerException; use App\Util\Formatting; @@ -51,7 +51,7 @@ class ProfileColor extends Plugin * * @return bool hook value; true means continue processing, false means stop */ - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { $r->connect('settings_profile_color', 'settings/color', [Controller\ProfileColor::class, 'profileColorSettings']); return Event::next; diff --git a/plugins/RepeatNote/Controller/Repeat.php b/plugins/RepeatNote/Controller/Repeat.php index 5156d1914f..4113b31c9d 100644 --- a/plugins/RepeatNote/Controller/Repeat.php +++ b/plugins/RepeatNote/Controller/Repeat.php @@ -27,9 +27,8 @@ use App\Core\Controller; use App\Core\DB; use App\Core\Event; use App\Core\Form; -use function App\Core\I18n\_m; use App\Core\Log; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Activity; use App\Entity\Actor; use App\Entity\Note; @@ -39,6 +38,7 @@ use App\Util\Exception\NoLoggedInUser; use App\Util\Exception\RedirectException; use App\Util\Exception\ServerException; use Component\Notification\Entity\Attention; +use function App\Core\I18n\_m; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\HttpFoundation\Request; diff --git a/plugins/RepeatNote/RepeatNote.php b/plugins/RepeatNote/RepeatNote.php index ab12ab1f77..4e6b6c52b6 100644 --- a/plugins/RepeatNote/RepeatNote.php +++ b/plugins/RepeatNote/RepeatNote.php @@ -33,8 +33,7 @@ use App\Core\DB; use App\Core\Event; use function App\Core\I18n\_m; use App\Core\Modules\NoteHandlerPlugin; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Activity; use App\Entity\Actor; use App\Entity\Note; @@ -341,7 +340,7 @@ class RepeatNote extends NoteHandlerPlugin * * @return bool Event hook, Event::next (true) is returned to allow Event to be handled by other handlers */ - public function onAddRoute(RouteLoader $r): bool + public function onAddRoute(Router $r): bool { // Add/remove note to/from repeats $r->connect(id: 'repeat_add', uri_path: '/object/note/{note_id<\d+>}/repeat', target: [Controller\Repeat::class, 'repeatAddNote']); diff --git a/plugins/TagBasedFiltering/TagBasedFiltering.php b/plugins/TagBasedFiltering/TagBasedFiltering.php index a2a36f6841..7bdc303d50 100644 --- a/plugins/TagBasedFiltering/TagBasedFiltering.php +++ b/plugins/TagBasedFiltering/TagBasedFiltering.php @@ -28,8 +28,7 @@ use App\Core\DB; use App\Core\Event; use function App\Core\I18n\_m; use App\Core\Modules\Plugin; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Actor; use App\Entity\LocalUser; use App\Entity\Note; @@ -52,7 +51,7 @@ class TagBasedFiltering extends Plugin return ['note' => "blocked-note-tags-{$actor_id}", 'actor' => "blocked-actor-tags-{$actor_id}"]; } - public function onAddRoute(RouteLoader $r) + public function onAddRoute(Router $r) { $r->connect(id: self::NOTE_TAG_FILTER_ROUTE, uri_path: '/filter/edit-blocked-note-tags/{note_id<\d+>}', target: [Controller\AddBlocked::class, 'addBlockedNoteTags']); $r->connect(id: self::ACTOR_TAG_FILTER_ROUTE, uri_path: '/filter/edit-blocked-actor-tags/{actor_id<\d+>}', target: [Controller\AddBlocked::class, 'addBlockedActorTags']); diff --git a/plugins/WebHooks/Controller/WebHooks.php b/plugins/WebHooks/Controller/WebHooks.php index 50465e5e2d..f7c123f3b6 100644 --- a/plugins/WebHooks/Controller/WebHooks.php +++ b/plugins/WebHooks/Controller/WebHooks.php @@ -27,7 +27,7 @@ use App\Core\Controller; use App\Core\DB; use App\Core\Form; use function App\Core\I18n\_m; -use App\Core\Router\Router; +use App\Core\Router; use App\Util\Common; use App\Util\Exception\ClientException; use Functional as F; diff --git a/plugins/WebHooks/WebHooks.php b/plugins/WebHooks/WebHooks.php index 33b266faca..170ea5c735 100644 --- a/plugins/WebHooks/WebHooks.php +++ b/plugins/WebHooks/WebHooks.php @@ -27,7 +27,7 @@ use App\Core\HTTPClient; use App\Core\Log; use App\Core\Modules\Plugin; use App\Core\Queue; -use App\Core\Router\RouteLoader; +use App\Core\Router; use App\Entity\Activity; use App\Entity\Actor; use App\Entity\LocalUser; @@ -43,7 +43,7 @@ class WebHooks extends Plugin { public const controller_route = 'webhook'; - public function onAddRoute(RouteLoader $r) + public function onAddRoute(Router $r) { $r->connect(self::controller_route, '/webhook-settings', C\WebHooks::class); } diff --git a/src/Controller/ActorProfile.php b/src/Controller/ActorProfile.php index fc70ce13e8..d4e34a9a1c 100644 --- a/src/Controller/ActorProfile.php +++ b/src/Controller/ActorProfile.php @@ -24,7 +24,7 @@ declare(strict_types = 1); namespace App\Controller; use App\Core\Controller; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Actor; use InvalidArgumentException; use Symfony\Component\HttpFoundation\Request; diff --git a/src/Controller/Security.php b/src/Controller/Security.php index f6495cc7af..0cb45aa7a4 100644 --- a/src/Controller/Security.php +++ b/src/Controller/Security.php @@ -11,7 +11,7 @@ use App\Core\Event; use App\Core\Form; use function App\Core\I18n\_m; use App\Core\Log; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Actor; use App\Entity\Feed; use App\Entity\LocalUser; diff --git a/src/Core/Form.php b/src/Core/Form.php index 8d8ebd6cd3..3517dd1be6 100644 --- a/src/Core/Form.php +++ b/src/Core/Form.php @@ -34,7 +34,7 @@ namespace App\Core; use App\Core\DB; use function App\Core\I18n\_m; -use App\Core\Router\Router; +use App\Core\Router; use App\Util\Common; use App\Util\Exception\ClientException; use App\Util\Exception\ServerException; diff --git a/src/Core/GNUsocial.php b/src/Core/GNUsocial.php index bab7c7e6f2..89baa35e47 100644 --- a/src/Core/GNUsocial.php +++ b/src/Core/GNUsocial.php @@ -47,7 +47,7 @@ namespace App\Core; use App\Core\DB; use App\Core\I18n\I18n; use App\Core\Queue; -use App\Core\Router\Router; +use App\Core\Router; use App\Kernel; use App\Util\Common; use App\Util\Exception\ConfigurationException; diff --git a/src/Core/Router.php b/src/Core/Router.php new file mode 100644 index 0000000000..add720e4f8 --- /dev/null +++ b/src/Core/Router.php @@ -0,0 +1,244 @@ +. +// }}} + +/** + * Static wrapper for Symfony's router + * + * @package GNUsocial + * @category URL + * + * @author Hugo Sales + * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later + */ + +namespace App\Core; + +use App\Core\Event; +use App\Core\Log; +use App\Util\Common; +use Symfony\Component\Config\Loader\Loader; +use Symfony\Component\Routing\Exception\ResourceNotFoundException; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Symfony\Component\Routing\Route; +use Symfony\Component\Routing\RouteCollection; +use Symfony\Component\Routing\Router as SymfonyRouter; + +/** + * @mixin SymfonyRouter + */ +class Router extends Loader +{ + /** + * Generates an absolute URL, e.g. "http://example.com/dir/file". + */ + public const ABSOLUTE_URL = UrlGeneratorInterface::ABSOLUTE_URL; + + /** + * Generates an absolute path, e.g. "/dir/file". + */ + public const ABSOLUTE_PATH = UrlGeneratorInterface::ABSOLUTE_PATH; + + /** + * Generates a relative path based on the current request path, e.g. "../parent-file". + * + * @see UrlGenerator::getRelativePath() + */ + public const RELATIVE_PATH = UrlGeneratorInterface::RELATIVE_PATH; + + /** + * Generates a network path, e.g. "//example.com/dir/file". + * Such reference reuses the current scheme but specifies the host. + */ + public const NETWORK_PATH = UrlGeneratorInterface::NETWORK_PATH; + + public static ?SymfonyRouter $router = null; + + public static function setRouter($rtr): void + { + self::$router = $rtr; + } + + public static function isAbsolute(string $url) + { + return isset(parse_url($url)['host']); + } + + /** + * Generate a URL for route $id with $args replacing the + * placeholder route values. Extra params are added as query + * string to the URL + */ + public static function url(string $id, array $args = [], int $type = self::ABSOLUTE_PATH): string + { + if ($type === self::RELATIVE_PATH) { + Log::debug('Requested relative path which is not an absolute path... just saying...'); + } + return self::$router->generate($id, $args, $type); + } + + public static function sanitizeLocalURL(string $url, array $unset_query_args = []): ?string + { + try { + $parts = parse_url($url); + if ($parts === false || (isset($parts['host']) && $parts['host'] !== Common::config('site', 'server'))) { + return null; + } + self::match($parts['path']); + if ($unset_query_args !== [] && isset($parts['query'])) { + $args = []; + parse_str($parts['query'], $args); + $args = array_diff_key($args, $unset_query_args); + $parts['query'] = http_build_query($args); + } + return $parts['path'] . (empty($parts['query']) ? '' : ('?' . $parts['query'])) . (empty($parts['fragment']) ? '' : ('#' . $parts['fragment'])); + } catch (ResourceNotFoundException) { + return null; + } + } + + private RouteCollection $rc; + + /** + * Route loading entry point, called from `config/routes.php` + * + * Must conform to symfony's interface, but the $resource is unused + * and $type must not be null + */ + public function load($resource, ?string $type = null): RouteCollection + { + $this->rc = new RouteCollection(); + + $route_files = glob(INSTALLDIR . '/src/Routes/*.php'); + $to_load = []; + foreach ($route_files as $file) { + require_once $file; + $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); + } + + Event::handle('AddRoute', [&$this]); + + // Sort routes so that whichever route has the smallest accept option matches first, as it's more specific + // This requires a copy, sadly, as it doesn't seem to be possible to modify the collection in-place + // However, this is fine since this gets cached + $it = $this->rc->getIterator(); + $it->uasort(fn (Route $left, Route $right) => \count($left->getDefaults()['accept']) <=> \count($right->getDefaults()['accept'])); + $this->rc = new RouteCollection(); + foreach ($it as $id => $route) { + $this->rc->add($id, $route); + } + + return $this->rc; + } + + /** + * Connect a route to a controller + * + * @param string $id Route unique id, used to generate urls, for instance + * @param string $uri_path Path, possibly with {param}s + * @param mixed $target Some kind of callable, typically class with `__invoke` or [object, method] + * @param null|array $param_reqs Array of {param} => regex + * @param null|array $options Possible keys are ['condition', 'defaults', 'format', + * 'fragment', 'http-methods', 'locale', 'methods', 'schemes', 'accept', 'is_system_path'] + * 'http-methods' and 'methods' are aliases + */ + public function connect(string $id, string $uri_path, $target, ?array $options = [], ?array $param_reqs = []) + { + // XXX: This hack can definitely be optimised by actually intersecting the arrays, + // maybe this helps: https://backbeat.tech/blog/symfony-routing-tricks-part-1 + // see: https://symfony.com/index.php/doc/3.1/components/http_foundation.html#accessing-accept-headers-data + $accept_header_condition = ''; + if (isset($options['accept'])) { + foreach ($options['accept'] as $accept) { + $accept_header_condition .= "('{$accept}' in request.getAcceptableContentTypes()) ||"; + } + $accept_header_condition = mb_substr($accept_header_condition, 0, -3); + } + + $this->rc->add( + $id, + new Route( + // path -- URI path + path: $uri_path, + // defaults = [] -- param default values, + // and special configuration options + defaults: array_merge( + [ + '_controller' => \is_array($target) ? $target : [$target, '__invoke'], + '_format' => $options['format'] ?? 'html', + '_fragment' => $options['fragment'] ?? '', + '_locale' => $options['locale'] ?? 'en', + 'template' => $options['template'] ?? '', + 'accept' => $options['accept'] ?? [], + 'is_system_path' => $options['is_system_path'] ?? true, + ], + $options['defaults'] ?? [], + ), + // requirements = [] -- param => regex + requirements: $param_reqs, + // options = [] -- possible keys: compiler_class:, utf8 + // No need for a special compiler class for now, + // Enforce UTF8 + options: ['utf8' => true], + // host = '' -- hostname (subdomain, for instance) to match, + // we don't want this + host: '', + // schemes = [] -- URI schemes (https, ftp and such) + schemes: $options['schemes'] ?? [], + // methods = [] -- HTTP methods + methods: $options['http-methods'] ?? $options['methods'] ?? [], + // condition = '' -- Symfony condition expression, + // see https://symfony.com/doc/current/routing.html#matching-expressions + condition: isset($options['accept']) ? $accept_header_condition : ($options['condition'] ?? ''), + ), + ); + } + + /** + * Whether this loader supports loading this route type + * Passed the arguments from the `RoutingConfigurator::import` call from + * `config/routes.php` + * + * @codeCoverageIgnore + */ + public function supports($resource, ?string $type = null): bool + { + return 'GNUsocial' === $type; + } + + /** + * function match($url) throws Symfony\Component\Routing\Exception\ResourceNotFoundException + */ + public static function __callStatic(string $name, array $args) + { + return self::$router->{$name}(...$args); + } +} diff --git a/src/Core/Router/Router.php b/src/Core/Router/Router.php deleted file mode 100644 index c17dfa4867..0000000000 --- a/src/Core/Router/Router.php +++ /dev/null @@ -1,121 +0,0 @@ -. -// }}} - -/** - * Static wrapper for Symfony's router - * - * @package GNUsocial - * @category URL - * - * @author Hugo Sales - * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org - * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later - */ - -namespace App\Core\Router; - -use App\Core\Log; -use App\Util\Common; -use Symfony\Component\Routing\Exception\ResourceNotFoundException; -use Symfony\Component\Routing\Generator\UrlGeneratorInterface; -use Symfony\Component\Routing\Router as SymfonyRouter; - -/** - * @mixin SymfonyRouter - */ -abstract class Router -{ - /** - * Generates an absolute URL, e.g. "http://example.com/dir/file". - */ - public const ABSOLUTE_URL = UrlGeneratorInterface::ABSOLUTE_URL; - - /** - * Generates an absolute path, e.g. "/dir/file". - */ - public const ABSOLUTE_PATH = UrlGeneratorInterface::ABSOLUTE_PATH; - - /** - * Generates a relative path based on the current request path, e.g. "../parent-file". - * - * @see UrlGenerator::getRelativePath() - */ - public const RELATIVE_PATH = UrlGeneratorInterface::RELATIVE_PATH; - - /** - * Generates a network path, e.g. "//example.com/dir/file". - * Such reference reuses the current scheme but specifies the host. - */ - public const NETWORK_PATH = UrlGeneratorInterface::NETWORK_PATH; - - public static ?SymfonyRouter $router = null; - - public static function setRouter($rtr): void - { - self::$router = $rtr; - } - - public static function isAbsolute(string $url) - { - return isset(parse_url($url)['host']); - } - - /** - * Generate a URL for route $id with $args replacing the - * placeholder route values. Extra params are added as query - * string to the URL - */ - public static function url(string $id, array $args = [], int $type = self::ABSOLUTE_PATH): string - { - if ($type === self::RELATIVE_PATH) { - Log::debug('Requested relative path which is not an absolute path... just saying...'); - } - return self::$router->generate($id, $args, $type); - } - - public static function sanitizeLocalURL(string $url, array $unset_query_args = []): ?string - { - try { - $parts = parse_url($url); - if ($parts === false || (isset($parts['host']) && $parts['host'] !== Common::config('site', 'server'))) { - return null; - } - self::match($parts['path']); - if ($unset_query_args !== [] && isset($parts['query'])) { - $args = []; - parse_str($parts['query'], $args); - $args = array_diff_key($args, $unset_query_args); - $parts['query'] = http_build_query($args); - } - return $parts['path'] . (empty($parts['query']) ? '' : ('?' . $parts['query'])) . (empty($parts['fragment']) ? '' : ('#' . $parts['fragment'])); - } catch (ResourceNotFoundException) { - return null; - } - } - - /** - * function match($url) throws Symfony\Component\Routing\Exception\ResourceNotFoundException - */ - public static function __callStatic(string $name, array $args) - { - return self::$router->{$name}(...$args); - } -} diff --git a/src/Entity/Actor.php b/src/Entity/Actor.php index 9d566e7584..d9580232f9 100644 --- a/src/Entity/Actor.php +++ b/src/Entity/Actor.php @@ -28,7 +28,7 @@ use App\Core\Cache; use App\Core\DB; use App\Core\Entity; use App\Core\Event; -use App\Core\Router\Router; +use App\Core\Router; use App\Util\Exception\BugFoundException; use App\Util\Exception\NicknameException; use App\Util\Exception\NotFoundException; diff --git a/src/Entity/Feed.php b/src/Entity/Feed.php index 73b9e308d5..ddf8ee6999 100644 --- a/src/Entity/Feed.php +++ b/src/Entity/Feed.php @@ -26,7 +26,7 @@ use App\Core\DB; use App\Core\Entity; use App\Core\Event; use function App\Core\I18n\_m; -use App\Core\Router\Router; +use App\Core\Router; use DateTimeInterface; /** diff --git a/src/Entity/Note.php b/src/Entity/Note.php index 362f8d24f8..66578361e3 100644 --- a/src/Entity/Note.php +++ b/src/Entity/Note.php @@ -29,7 +29,7 @@ use App\Core\DB; use App\Core\Entity; use App\Core\Event; use App\Core\Log; -use App\Core\Router\Router; +use App\Core\Router; use App\Core\VisibilityScope; use App\Util\Common; use App\Util\Exception\BugFoundException; diff --git a/src/Routes/Activity.php b/src/Routes/Activity.php index 86dc5d230b..4e319024ee 100644 --- a/src/Routes/Activity.php +++ b/src/Routes/Activity.php @@ -35,12 +35,12 @@ declare(strict_types = 1); namespace App\Routes; use App\Controller as C; -use App\Core\Router\RouteLoader; +use App\Core\Router; abstract class Activity { public const LOAD_ORDER = 11; - public static function load(RouteLoader $r): void + public static function load(Router $r): void { $r->connect('activity_view', '/activity/{id<\d+>}', [C\Activity::class, 'ActivityShow']); } diff --git a/src/Routes/Actor.php b/src/Routes/Actor.php index 334ef58957..51bdcbb205 100644 --- a/src/Routes/Actor.php +++ b/src/Routes/Actor.php @@ -36,13 +36,13 @@ declare(strict_types = 1); namespace App\Routes; use App\Controller as C; -use App\Core\Router\RouteLoader; +use App\Core\Router; abstract class Actor { public const LOAD_ORDER = 30; - public static function load(RouteLoader $r): void + public static function load(Router $r): void { $r->connect(id: 'actor_view_id', uri_path: '/actor/{id<\d+>}', target: [C\ActorProfile::class, 'actorViewId']); } diff --git a/src/Routes/Main.php b/src/Routes/Main.php index 50aa9b979e..6b2118e974 100644 --- a/src/Routes/Main.php +++ b/src/Routes/Main.php @@ -37,14 +37,14 @@ declare(strict_types = 1); namespace App\Routes; use App\Controller as C; -use App\Core\Router\RouteLoader; +use App\Core\Router; use Symfony\Bundle\FrameworkBundle\Controller\RedirectController; abstract class Main { public const LOAD_ORDER = 10; - public static function load(RouteLoader $r): void + public static function load(Router $r): void { $r->connect('security_login', '/main/login', [C\Security::class, 'login']); $r->connect('security_logout', '/main/logout', [C\Security::class, 'logout']); diff --git a/src/Routes/Note.php b/src/Routes/Note.php index 126265992c..a17732668e 100644 --- a/src/Routes/Note.php +++ b/src/Routes/Note.php @@ -36,12 +36,12 @@ declare(strict_types = 1); namespace App\Routes; use App\Controller as C; -use App\Core\Router\RouteLoader; +use App\Core\Router; abstract class Note { public const LOAD_ORDER = 40; - public static function load(RouteLoader $r): void + public static function load(Router $r): void { $r->connect('note_view', '/object/note/{id<\d+>}', [C\Note::class, 'NoteShow']); } diff --git a/src/Twig/Runtime.php b/src/Twig/Runtime.php index cff8b79365..6b1e00d9d1 100644 --- a/src/Twig/Runtime.php +++ b/src/Twig/Runtime.php @@ -33,7 +33,7 @@ declare(strict_types = 1); namespace App\Twig; use App\Core\Event; -use App\Core\Router\Router; +use App\Core\Router; use App\Entity\Actor; use App\Entity\Feed; use App\Entity\Note; diff --git a/src/Util/Common.php b/src/Util/Common.php index df23f07b85..aae421f670 100644 --- a/src/Util/Common.php +++ b/src/Util/Common.php @@ -35,7 +35,7 @@ declare(strict_types = 1); namespace App\Util; use App\Core\I18n\I18n; -use App\Core\Router\Router; +use App\Core\Router; use App\Core\Security; use App\Entity\Actor; use App\Entity\LocalUser; diff --git a/src/Util/Exception/RedirectException.php b/src/Util/Exception/RedirectException.php index dce2abba58..ecec1231c5 100644 --- a/src/Util/Exception/RedirectException.php +++ b/src/Util/Exception/RedirectException.php @@ -23,7 +23,7 @@ namespace App\Util\Exception; use function App\Core\I18n\_m; use App\Core\Log; -use App\Core\Router\Router; +use App\Core\Router; use Exception; use Symfony\Component\HttpFoundation\RedirectResponse; diff --git a/tests/Core/RouterTest.php b/tests/Core/RouterTest.php index ea3029ff74..487f5ba01e 100644 --- a/tests/Core/RouterTest.php +++ b/tests/Core/RouterTest.php @@ -23,8 +23,7 @@ declare(strict_types = 1); namespace App\Test\Core; -use App\Core\Router\RouteLoader; -use App\Core\Router\Router; +use App\Core\Router; use App\Util\GNUsocialTestCase; use ReflectionClass; use Symfony\Component\Routing\Route as SRoute; @@ -34,7 +33,7 @@ class RouterTest extends GNUsocialTestCase public function testRouter() { parent::bootKernel(); - $rl = new RouteLoader(); + $rl = new Router(); $rl->load('', null); // parameters ignored $rl->connect(id: 'test_route', uri_path: '/test/{id<\d+>}', target: []);