Browse Source

[CORE][Router] Rename \App\Core\Router\Router to \App\Core\Router and merge \App\Core\Router\RouteLoader with \App\Core\Router

experimental
parent
commit
483983790a
Signed by: diogo <mail@diogo.site> GPG Key ID: 18D2D35001FBFAB0
79 changed files with 362 additions and 260 deletions
  1. +2
    -2
      components/Attachment/Attachment.php
  2. +1
    -1
      components/Attachment/Entity/Attachment.php
  3. +1
    -1
      components/Attachment/Entity/AttachmentThumbnail.php
  4. +1
    -1
      components/Attachment/tests/Entity/AttachmentTest.php
  5. +2
    -3
      components/Avatar/Avatar.php
  6. +1
    -1
      components/Avatar/Entity/Avatar.php
  7. +2
    -2
      components/Blog/Blog.php
  8. +2
    -3
      components/Circle/Circle.php
  9. +1
    -1
      components/Circle/Controller/Circles.php
  10. +1
    -1
      components/Circle/Entity/ActorCircle.php
  11. +1
    -1
      components/Circle/Entity/ActorTag.php
  12. +1
    -1
      components/Conversation/Controller/Conversation.php
  13. +2
    -3
      components/Conversation/Conversation.php
  14. +1
    -1
      components/Conversation/Entity/Conversation.php
  15. +2
    -2
      components/Feed/Feed.php
  16. +1
    -1
      components/Feed/tests/Controller/FeedsTest.php
  17. +2
    -3
      components/FreeNetwork/FreeNetwork.php
  18. +1
    -1
      components/FreeNetwork/Util/WebfingerResource/WebfingerResourceActor.php
  19. +1
    -1
      components/Group/Controller/GroupFeed.php
  20. +2
    -3
      components/Group/Group.php
  21. +2
    -2
      components/Language/Language.php
  22. +1
    -1
      components/LeftPanel/Controller/EditFeeds.php
  23. +2
    -3
      components/LeftPanel/LeftPanel.php
  24. +2
    -3
      components/Notification/Notification.php
  25. +1
    -1
      components/Person/Controller/PersonFeed.php
  26. +2
    -2
      components/Person/Person.php
  27. +1
    -1
      components/Person/tests/Controller/PersonSettingsTest.php
  28. +1
    -1
      components/Posting/Form/Posting.php
  29. +2
    -3
      components/Posting/Posting.php
  30. +1
    -1
      components/Subscription/Controller/Subscribers.php
  31. +2
    -3
      components/Subscription/Subscription.php
  32. +1
    -1
      components/Tag/Entity/NoteTag.php
  33. +1
    -1
      components/Tag/Tag.php
  34. +1
    -1
      config/services.yaml
  35. +3
    -4
      plugins/ActivityPub/ActivityPub.php
  36. +1
    -1
      plugins/ActivityPub/Controller/Inbox.php
  37. +1
    -1
      plugins/ActivityPub/Controller/Outbox.php
  38. +1
    -1
      plugins/ActivityPub/Util/Model/Activity.php
  39. +1
    -1
      plugins/ActivityPub/Util/Model/Actor.php
  40. +1
    -1
      plugins/ActivityPub/Util/Model/Note.php
  41. +1
    -1
      plugins/ActivityPub/Util/OrderedCollectionController.php
  42. +2
    -3
      plugins/AttachmentCollections/AttachmentCollections.php
  43. +1
    -1
      plugins/AttachmentCollections/Controller/AttachmentCollections.php
  44. +1
    -1
      plugins/Bundles/Controller/BundleCollections.php
  45. +2
    -2
      plugins/Cover/Cover.php
  46. +1
    -1
      plugins/DeleteNote/Controller/DeleteNote.php
  47. +3
    -4
      plugins/DeleteNote/DeleteNote.php
  48. +2
    -3
      plugins/Directory/Directory.php
  49. +4
    -5
      plugins/Embed/Embed.php
  50. +2
    -2
      plugins/Favourite/Controller/Favourite.php
  51. +2
    -3
      plugins/Favourite/Favourite.php
  52. +3
    -4
      plugins/OAuth2/OAuth2.php
  53. +2
    -3
      plugins/Oomox/Oomox.php
  54. +1
    -1
      plugins/PinnedNotes/Controller/PinnedNotes.php
  55. +2
    -3
      plugins/PinnedNotes/PinnedNotes.php
  56. +2
    -2
      plugins/Poll/Poll.php
  57. +2
    -2
      plugins/ProfileColor/ProfileColor.php
  58. +2
    -2
      plugins/RepeatNote/Controller/Repeat.php
  59. +2
    -3
      plugins/RepeatNote/RepeatNote.php
  60. +2
    -3
      plugins/TagBasedFiltering/TagBasedFiltering.php
  61. +1
    -1
      plugins/WebHooks/Controller/WebHooks.php
  62. +2
    -2
      plugins/WebHooks/WebHooks.php
  63. +1
    -1
      src/Controller/ActorProfile.php
  64. +1
    -1
      src/Controller/Security.php
  65. +1
    -1
      src/Core/Form.php
  66. +1
    -1
      src/Core/GNUsocial.php
  67. +244
    -0
      src/Core/Router.php
  68. +0
    -121
      src/Core/Router/Router.php
  69. +1
    -1
      src/Entity/Actor.php
  70. +1
    -1
      src/Entity/Feed.php
  71. +1
    -1
      src/Entity/Note.php
  72. +2
    -2
      src/Routes/Activity.php
  73. +2
    -2
      src/Routes/Actor.php
  74. +2
    -2
      src/Routes/Main.php
  75. +2
    -2
      src/Routes/Note.php
  76. +1
    -1
      src/Twig/Runtime.php
  77. +1
    -1
      src/Util/Common.php
  78. +1
    -1
      src/Util/Exception/RedirectException.php
  79. +2
    -3
      tests/Core/RouterTest.php

+ 2
- 2
components/Attachment/Attachment.php View File

@@ -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']);


+ 1
- 1
components/Attachment/Entity/Attachment.php View File

@@ -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;


+ 1
- 1
components/Attachment/Entity/AttachmentThumbnail.php View File

@@ -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;


+ 1
- 1
components/Attachment/tests/Entity/AttachmentTest.php View File

@@ -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;


+ 2
- 3
components/Avatar/Avatar.php View File

@@ -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<full|big|medium|small>?medium}', [Controller\Avatar::class, 'avatar_view']);
$r->connect('avatar_default', '/avatar/default/{size<full|big|medium|small>?medium}', [Controller\Avatar::class, 'default_avatar_view']);


+ 1
- 1
components/Avatar/Entity/Avatar.php View File

@@ -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;


+ 2
- 2
components/Blog/Blog.php View File

@@ -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;


+ 2
- 3
components/Circle/Circle.php View File

@@ -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


+ 1
- 1
components/Circle/Controller/Circles.php View File

@@ -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;


+ 1
- 1
components/Circle/Entity/ActorCircle.php View File

@@ -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;

/**


+ 1
- 1
components/Circle/Entity/ActorTag.php View File

@@ -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;


+ 1
- 1
components/Conversation/Controller/Conversation.php View File

@@ -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;


+ 2
- 3
components/Conversation/Conversation.php View File

@@ -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']);


+ 1
- 1
components/Conversation/Entity/Conversation.php View File

@@ -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


+ 2
- 2
components/Feed/Feed.php View File

@@ -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']);


+ 1
- 1
components/Feed/tests/Controller/FeedsTest.php View File

@@ -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;


+ 2
- 3
components/FreeNetwork/FreeNetwork.php View File

@@ -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']);


+ 1
- 1
components/FreeNetwork/Util/WebfingerResource/WebfingerResourceActor.php View File

@@ -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;


+ 1
- 1
components/Group/Controller/GroupFeed.php View File

@@ -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;


+ 2
- 3
components/Group/Group.php View File

@@ -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']);


+ 2
- 2
components/Language/Language.php View File

@@ -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;


+ 1
- 1
components/LeftPanel/Controller/EditFeeds.php View File

@@ -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;


+ 2
- 3
components/LeftPanel/LeftPanel.php View File

@@ -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;


+ 2
- 3
components/Notification/Notification.php View File

@@ -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;


+ 1
- 1
components/Person/Controller/PersonFeed.php View File

@@ -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;


+ 2
- 2
components/Person/Person.php View File

@@ -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]);


+ 1
- 1
components/Person/tests/Controller/PersonSettingsTest.php View File

@@ -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;


+ 1
- 1
components/Posting/Form/Posting.php View File

@@ -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;


+ 2
- 3
components/Posting/Posting.php View File

@@ -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;


+ 1
- 1
components/Subscription/Controller/Subscribers.php View File

@@ -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;


+ 2
- 3
components/Subscription/Subscription.php View File

@@ -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']);


+ 1
- 1
components/Tag/Entity/NoteTag.php View File

@@ -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;


+ 1
- 1
components/Tag/Tag.php View File

@@ -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;


+ 1
- 1
config/services.yaml View File

@@ -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


+ 3
- 4
plugins/ActivityPub/ActivityPub.php View File

@@ -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',


+ 1
- 1
plugins/ActivityPub/Controller/Inbox.php View File

@@ -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;


+ 1
- 1
plugins/ActivityPub/Controller/Outbox.php View File

@@ -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;


+ 1
- 1
plugins/ActivityPub/Util/Model/Activity.php View File

@@ -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;


+ 1
- 1
plugins/ActivityPub/Util/Model/Actor.php View File

@@ -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;


+ 1
- 1
plugins/ActivityPub/Util/Model/Note.php View File

@@ -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;


+ 1
- 1
plugins/ActivityPub/Util/OrderedCollectionController.php View File

@@ -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;


+ 2
- 3
plugins/AttachmentCollections/AttachmentCollections.php View File

@@ -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(


+ 1
- 1
plugins/AttachmentCollections/Controller/AttachmentCollections.php View File

@@ -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;



+ 1
- 1
plugins/Bundles/Controller/BundleCollections.php View File

@@ -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;



+ 2
- 2
plugins/Cover/Cover.php View File

@@ -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']);


+ 1
- 1
plugins/DeleteNote/Controller/DeleteNote.php View File

@@ -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;


+ 3
- 4
plugins/DeleteNote/DeleteNote.php View File

@@ -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 <mail@eliseuama.ro>
* @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);



+ 2
- 3
plugins/Directory/Directory.php View File

@@ -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']);


+ 4
- 5
plugins/Embed/Embed.php View File

@@ -31,7 +31,7 @@ declare(strict_types = 1);
* @author Miguel Dantas
* @author Hugo Sales <hugo@hsal.es>
* @author Diogo Peralta Cordeiro <mail@diogo.site>
* @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;


+ 2
- 2
plugins/Favourite/Controller/Favourite.php View File

@@ -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;



+ 2
- 3
plugins/Favourite/Favourite.php View File

@@ -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']);


+ 3
- 4
plugins/OAuth2/OAuth2.php View File

@@ -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']]);


+ 2
- 3
plugins/Oomox/Oomox.php View File

@@ -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']);


+ 1
- 1
plugins/PinnedNotes/Controller/PinnedNotes.php View File

@@ -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;


+ 2
- 3
plugins/PinnedNotes/PinnedNotes.php View File

@@ -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']);


+ 2
- 2
plugins/Poll/Poll.php View File

@@ -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']);



+ 2
- 2
plugins/ProfileColor/ProfileColor.php View File

@@ -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;


+ 2
- 2
plugins/RepeatNote/Controller/Repeat.php View File

@@ -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;



+ 2
- 3
plugins/RepeatNote/RepeatNote.php View File

@@ -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']);


+ 2
- 3
plugins/TagBasedFiltering/TagBasedFiltering.php View File

@@ -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']);


+ 1
- 1
plugins/WebHooks/Controller/WebHooks.php View File

@@ -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;


+ 2
- 2
plugins/WebHooks/WebHooks.php View File

@@ -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);
}


+ 1
- 1
src/Controller/ActorProfile.php View File

@@ -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;


+ 1
- 1
src/Controller/Security.php View File

@@ -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;


+ 1
- 1
src/Core/Form.php View File

@@ -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;


+ 1
- 1
src/Core/GNUsocial.php View File

@@ -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;


+ 244
- 0
src/Core/Router.php View File

@@ -0,0 +1,244 @@
<?php

declare(strict_types = 1);

// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}

/**
* Static wrapper for Symfony's router
*
* @package GNUsocial
* @category URL
*
* @author Hugo Sales <hugo@hsal.es>
* @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);
}
}

+ 0
- 121
src/Core/Router/Router.php View File

@@ -1,121 +0,0 @@
<?php

declare(strict_types = 1);

// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}

/**
* Static wrapper for Symfony's router
*
* @package GNUsocial
* @category URL
*
* @author Hugo Sales <hugo@hsal.es>
* @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);
}
}

+ 1
- 1
src/Entity/Actor.php View File

@@ -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;


+ 1
- 1
src/Entity/Feed.php View File

@@ -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;

/**


+ 1
- 1
src/Entity/Note.php View File

@@ -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;


+ 2
- 2
src/Routes/Activity.php View File

@@ -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']);
}


+ 2
- 2
src/Routes/Actor.php View File

@@ -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']);
}


+ 2
- 2
src/Routes/Main.php View File

@@ -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']);


+ 2
- 2
src/Routes/Note.php View File

@@ -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']);
}


+ 1
- 1
src/Twig/Runtime.php View File

@@ -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;


+ 1
- 1
src/Util/Common.php View File

@@ -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;


+ 1
- 1
src/Util/Exception/RedirectException.php View File

@@ -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;



+ 2
- 3
tests/Core/RouterTest.php View File

@@ -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: []);


Loading…
Cancel
Save