Router refactor.
This commit is contained in:
parent
6dbe226d15
commit
870afbfecd
|
@ -48,8 +48,8 @@ final class LoginTokenCommand extends CommandAbstract
|
|||
$loginToken = $this->loginTokenRepo->createToken($user);
|
||||
|
||||
$url = $this->router->named(
|
||||
route_name: 'account:recover',
|
||||
route_params: ['token' => $loginToken],
|
||||
routeName: 'account:recover',
|
||||
routeParams: ['token' => $loginToken],
|
||||
absolute: true
|
||||
);
|
||||
|
||||
|
|
|
@ -70,8 +70,8 @@ abstract class AbstractApiCrudController
|
|||
if ($record instanceof IdentifiableEntityInterface) {
|
||||
$return['links'] = [
|
||||
'self' => (string)$router->fromHere(
|
||||
route_name: $this->resourceRouteName,
|
||||
route_params: ['id' => $record->getIdRequired()],
|
||||
routeName: $this->resourceRouteName,
|
||||
routeParams: ['id' => $record->getIdRequired()],
|
||||
absolute: !$isInternal
|
||||
),
|
||||
];
|
||||
|
|
|
@ -193,18 +193,18 @@ class StationsController extends AbstractAdminApiCrudController
|
|||
|
||||
$return['links'] = [
|
||||
'self' => (string)$router->fromHere(
|
||||
route_name: $this->resourceRouteName,
|
||||
route_params: ['id' => $record->getIdRequired()],
|
||||
routeName: $this->resourceRouteName,
|
||||
routeParams: ['id' => $record->getIdRequired()],
|
||||
absolute: !$isInternal
|
||||
),
|
||||
'manage' => (string)$router->named(
|
||||
route_name: 'stations:index:index',
|
||||
route_params: ['station_id' => $record->getIdRequired()],
|
||||
routeName: 'stations:index:index',
|
||||
routeParams: ['station_id' => $record->getIdRequired()],
|
||||
absolute: !$isInternal
|
||||
),
|
||||
'clone' => (string)$router->fromHere(
|
||||
route_name: 'api:admin:station:clone',
|
||||
route_params: ['id' => $record->getIdRequired()],
|
||||
routeName: 'api:admin:station:clone',
|
||||
routeParams: ['id' => $record->getIdRequired()],
|
||||
absolute: !$isInternal
|
||||
),
|
||||
];
|
||||
|
|
|
@ -178,13 +178,13 @@ class UsersController extends AbstractAdminApiCrudController
|
|||
|
||||
$return['links'] = [
|
||||
'self' => (string)$router->fromHere(
|
||||
route_name: $this->resourceRouteName,
|
||||
route_params: ['id' => $record->getIdRequired()],
|
||||
routeName: $this->resourceRouteName,
|
||||
routeParams: ['id' => $record->getIdRequired()],
|
||||
absolute: !$isInternal
|
||||
),
|
||||
'masquerade' => (string)$router->fromHere(
|
||||
route_name: 'account:masquerade',
|
||||
route_params: [
|
||||
routeName: 'account:masquerade',
|
||||
routeParams: [
|
||||
'id' => $record->getIdRequired(),
|
||||
'csrf' => $csrf->generate(MasqueradeAction::CSRF_NAMESPACE),
|
||||
],
|
||||
|
|
|
@ -201,8 +201,8 @@ final class MountsController extends AbstractStationApiCrudController
|
|||
$frontend = $this->adapters->getFrontendAdapter($station);
|
||||
|
||||
$return['links']['intro'] = (string)$router->fromHere(
|
||||
route_name: 'api:stations:mounts:intro',
|
||||
route_params: ['id' => $record->getId()],
|
||||
routeName: 'api:stations:mounts:intro',
|
||||
routeParams: ['id' => $record->getId()],
|
||||
absolute: true
|
||||
);
|
||||
|
||||
|
|
|
@ -270,23 +270,23 @@ final class PlaylistsController extends AbstractScheduledEntityController
|
|||
!$isInternal
|
||||
),
|
||||
'reshuffle' => (string)$router->fromHere(
|
||||
route_name: 'api:stations:playlist:reshuffle',
|
||||
route_params: ['id' => $record->getId()],
|
||||
routeName: 'api:stations:playlist:reshuffle',
|
||||
routeParams: ['id' => $record->getId()],
|
||||
absolute: !$isInternal
|
||||
),
|
||||
'queue' => (string)$router->fromHere(
|
||||
route_name: 'api:stations:playlist:queue',
|
||||
route_params: ['id' => $record->getId()],
|
||||
routeName: 'api:stations:playlist:queue',
|
||||
routeParams: ['id' => $record->getId()],
|
||||
absolute: !$isInternal
|
||||
),
|
||||
'import' => (string)$router->fromHere(
|
||||
route_name: 'api:stations:playlist:import',
|
||||
route_params: ['id' => $record->getId()],
|
||||
routeName: 'api:stations:playlist:import',
|
||||
routeParams: ['id' => $record->getId()],
|
||||
absolute: !$isInternal
|
||||
),
|
||||
'clone' => (string)$router->fromHere(
|
||||
route_name: 'api:stations:playlist:clone',
|
||||
route_params: ['id' => $record->getId()],
|
||||
routeName: 'api:stations:playlist:clone',
|
||||
routeParams: ['id' => $record->getId()],
|
||||
absolute: !$isInternal
|
||||
),
|
||||
'self' => (string)$router->fromHere(
|
||||
|
@ -299,8 +299,8 @@ final class PlaylistsController extends AbstractScheduledEntityController
|
|||
|
||||
foreach (['pls', 'm3u'] as $format) {
|
||||
$return['links']['export'][$format] = (string)$router->fromHere(
|
||||
route_name: 'api:stations:playlist:export',
|
||||
route_params: ['id' => $record->getId(), 'format' => $format],
|
||||
routeName: 'api:stations:playlist:export',
|
||||
routeParams: ['id' => $record->getId(), 'format' => $format],
|
||||
absolute: !$isInternal
|
||||
);
|
||||
}
|
||||
|
|
|
@ -377,25 +377,25 @@ final class PodcastEpisodesController extends AbstractApiCrudController
|
|||
$return->has_custom_art = (0 !== $return->art_updated_at);
|
||||
|
||||
$return->art = (string)$router->fromHere(
|
||||
route_name: 'api:stations:podcast:episode:art',
|
||||
route_params: ['episode_id' => $record->getId() . '|' . $record->getArtUpdatedAt()],
|
||||
routeName: 'api:stations:podcast:episode:art',
|
||||
routeParams: ['episode_id' => $record->getId() . '|' . $record->getArtUpdatedAt()],
|
||||
absolute: true
|
||||
);
|
||||
|
||||
$return->links = [
|
||||
'self' => (string)$router->fromHere(
|
||||
route_name: $this->resourceRouteName,
|
||||
route_params: ['episode_id' => $record->getId()],
|
||||
routeName: $this->resourceRouteName,
|
||||
routeParams: ['episode_id' => $record->getId()],
|
||||
absolute: !$isInternal
|
||||
),
|
||||
'public' => (string)$router->fromHere(
|
||||
route_name: 'public:podcast:episode',
|
||||
route_params: ['episode_id' => $record->getId()],
|
||||
routeName: 'public:podcast:episode',
|
||||
routeParams: ['episode_id' => $record->getId()],
|
||||
absolute: !$isInternal
|
||||
),
|
||||
'download' => (string)$router->fromHere(
|
||||
route_name: 'api:stations:podcast:episode:download',
|
||||
route_params: ['episode_id' => $record->getId()],
|
||||
routeName: 'api:stations:podcast:episode:download',
|
||||
routeParams: ['episode_id' => $record->getId()],
|
||||
absolute: !$isInternal
|
||||
),
|
||||
];
|
||||
|
@ -405,13 +405,13 @@ final class PodcastEpisodesController extends AbstractApiCrudController
|
|||
|
||||
if ($acl->isAllowed(StationPermissions::Podcasts, $station)) {
|
||||
$return->links['art'] = (string)$router->fromHere(
|
||||
route_name: 'api:stations:podcast:episode:art-internal',
|
||||
route_params: ['episode_id' => $record->getId()],
|
||||
routeName: 'api:stations:podcast:episode:art-internal',
|
||||
routeParams: ['episode_id' => $record->getId()],
|
||||
absolute: !$isInternal
|
||||
);
|
||||
$return->links['media'] = (string)$router->fromHere(
|
||||
route_name: 'api:stations:podcast:episode:media-internal',
|
||||
route_params: ['episode_id' => $record->getId()],
|
||||
routeName: 'api:stations:podcast:episode:media-internal',
|
||||
routeParams: ['episode_id' => $record->getId()],
|
||||
absolute: !$isInternal
|
||||
);
|
||||
}
|
||||
|
|
|
@ -313,30 +313,30 @@ final class PodcastsController extends AbstractApiCrudController
|
|||
|
||||
$return->has_custom_art = (0 !== $record->getArtUpdatedAt());
|
||||
$return->art = (string)$router->fromHere(
|
||||
route_name: 'api:stations:podcast:art',
|
||||
route_params: ['podcast_id' => $record->getId() . '|' . $record->getArtUpdatedAt()],
|
||||
routeName: 'api:stations:podcast:art',
|
||||
routeParams: ['podcast_id' => $record->getId() . '|' . $record->getArtUpdatedAt()],
|
||||
absolute: true
|
||||
);
|
||||
|
||||
$return->links = [
|
||||
'self' => (string)$router->fromHere(
|
||||
route_name: $this->resourceRouteName,
|
||||
route_params: ['podcast_id' => $record->getId()],
|
||||
routeName: $this->resourceRouteName,
|
||||
routeParams: ['podcast_id' => $record->getId()],
|
||||
absolute: !$isInternal
|
||||
),
|
||||
'episodes' => (string)$router->fromHere(
|
||||
route_name: 'api:stations:podcast:episodes',
|
||||
route_params: ['podcast_id' => $record->getId()],
|
||||
routeName: 'api:stations:podcast:episodes',
|
||||
routeParams: ['podcast_id' => $record->getId()],
|
||||
absolute: !$isInternal
|
||||
),
|
||||
'public_episodes' => (string)$router->fromHere(
|
||||
route_name: 'public:podcast:episodes',
|
||||
route_params: ['podcast_id' => $record->getId()],
|
||||
routeName: 'public:podcast:episodes',
|
||||
routeParams: ['podcast_id' => $record->getId()],
|
||||
absolute: !$isInternal
|
||||
),
|
||||
'public_feed' => (string)$router->fromHere(
|
||||
route_name: 'public:podcast:feed',
|
||||
route_params: ['podcast_id' => $record->getId()],
|
||||
routeName: 'public:podcast:feed',
|
||||
routeParams: ['podcast_id' => $record->getId()],
|
||||
absolute: !$isInternal
|
||||
),
|
||||
];
|
||||
|
@ -345,19 +345,19 @@ final class PodcastsController extends AbstractApiCrudController
|
|||
|
||||
if ($acl->isAllowed(StationPermissions::Podcasts, $station)) {
|
||||
$return->links['art'] = (string)$router->fromHere(
|
||||
route_name: 'api:stations:podcast:art-internal',
|
||||
route_params: ['podcast_id' => $record->getId()],
|
||||
routeName: 'api:stations:podcast:art-internal',
|
||||
routeParams: ['podcast_id' => $record->getId()],
|
||||
absolute: !$isInternal
|
||||
);
|
||||
|
||||
$return->links['episode_new_art'] = (string)$router->fromHere(
|
||||
route_name: 'api:stations:podcast:episodes:new-art',
|
||||
route_params: ['podcast_id' => $record->getId()],
|
||||
routeName: 'api:stations:podcast:episodes:new-art',
|
||||
routeParams: ['podcast_id' => $record->getId()],
|
||||
absolute: !$isInternal
|
||||
);
|
||||
$return->links['episode_new_media'] = (string)$router->fromHere(
|
||||
route_name: 'api:stations:podcast:episodes:new-media',
|
||||
route_params: ['podcast_id' => $record->getId()],
|
||||
routeName: 'api:stations:podcast:episodes:new-media',
|
||||
routeParams: ['podcast_id' => $record->getId()],
|
||||
absolute: !$isInternal
|
||||
);
|
||||
}
|
||||
|
|
|
@ -198,8 +198,8 @@ final class RemotesController extends AbstractStationApiCrudController
|
|||
|
||||
$return->links = [
|
||||
'self' => (string)$router->fromHere(
|
||||
route_name: $this->resourceRouteName,
|
||||
route_params: ['id' => $record->getIdRequired()],
|
||||
routeName: $this->resourceRouteName,
|
||||
routeParams: ['id' => $record->getIdRequired()],
|
||||
absolute: !$isInternal
|
||||
),
|
||||
];
|
||||
|
|
|
@ -284,19 +284,19 @@ final class StreamersController extends AbstractScheduledEntityController
|
|||
|
||||
$return['has_custom_art'] = (0 !== $record->getArtUpdatedAt());
|
||||
$return['art'] = (string)$router->fromHere(
|
||||
route_name: 'api:stations:streamer:art',
|
||||
route_params: ['id' => $record->getIdRequired() . '|' . $record->getArtUpdatedAt()],
|
||||
routeName: 'api:stations:streamer:art',
|
||||
routeParams: ['id' => $record->getIdRequired() . '|' . $record->getArtUpdatedAt()],
|
||||
absolute: !$isInternal
|
||||
);
|
||||
|
||||
$return['links']['broadcasts'] = (string)$router->fromHere(
|
||||
route_name: 'api:stations:streamer:broadcasts',
|
||||
route_params: ['id' => $record->getId()],
|
||||
routeName: 'api:stations:streamer:broadcasts',
|
||||
routeParams: ['id' => $record->getId()],
|
||||
absolute: !$isInternal
|
||||
);
|
||||
$return['links']['art'] = (string)$router->fromHere(
|
||||
route_name: 'api:stations:streamer:art-internal',
|
||||
route_params: ['id' => $record->getId()],
|
||||
routeName: 'api:stations:streamer:art-internal',
|
||||
routeParams: ['id' => $record->getId()],
|
||||
absolute: !$isInternal
|
||||
);
|
||||
|
||||
|
|
|
@ -193,18 +193,18 @@ final class WebhooksController extends AbstractStationApiCrudController
|
|||
|
||||
$return['links'] = [
|
||||
'self' => (string)$router->fromHere(
|
||||
route_name: $this->resourceRouteName,
|
||||
route_params: ['id' => $record->getIdRequired()],
|
||||
routeName: $this->resourceRouteName,
|
||||
routeParams: ['id' => $record->getIdRequired()],
|
||||
absolute: !$isInternal
|
||||
),
|
||||
'toggle' => (string)$router->fromHere(
|
||||
route_name: 'api:stations:webhook:toggle',
|
||||
route_params: ['id' => $record->getIdRequired()],
|
||||
routeName: 'api:stations:webhook:toggle',
|
||||
routeParams: ['id' => $record->getIdRequired()],
|
||||
absolute: !$isInternal
|
||||
),
|
||||
'test' => (string)$router->fromHere(
|
||||
route_name: 'api:stations:webhook:test',
|
||||
route_params: ['id' => $record->getIdRequired()],
|
||||
routeName: 'api:stations:webhook:test',
|
||||
routeParams: ['id' => $record->getIdRequired()],
|
||||
absolute: !$isInternal
|
||||
),
|
||||
];
|
||||
|
|
|
@ -137,7 +137,7 @@ final class PodcastFeedAction
|
|||
$channelLink = $podcast->getLink();
|
||||
if (empty($channelLink)) {
|
||||
$channelLink = (string)$serverRequest->getRouter()->fromHere(
|
||||
route_name: 'public:podcast:episodes',
|
||||
routeName: 'public:podcast:episodes',
|
||||
absolute: true
|
||||
);
|
||||
}
|
||||
|
@ -238,8 +238,8 @@ final class PodcastFeedAction
|
|||
|
||||
if ($podcastsFilesystem->fileExists(Podcast::getArtPath($podcast->getIdRequired()))) {
|
||||
$podcastArtworkSrc = (string)$this->router->fromHere(
|
||||
route_name: 'api:stations:podcast:art',
|
||||
route_params: ['podcast_id' => $podcast->getIdRequired() . '|' . $podcast->getArtUpdatedAt()],
|
||||
routeName: 'api:stations:podcast:art',
|
||||
routeParams: ['podcast_id' => $podcast->getIdRequired() . '|' . $podcast->getArtUpdatedAt()],
|
||||
absolute: true
|
||||
);
|
||||
}
|
||||
|
@ -276,8 +276,8 @@ final class PodcastFeedAction
|
|||
$episodeLink = $episode->getLink();
|
||||
if (empty($episodeLink)) {
|
||||
$episodeLink = (string)$this->router->fromHere(
|
||||
route_name: 'public:podcast:episode',
|
||||
route_params: ['episode_id' => $episode->getId()],
|
||||
routeName: 'public:podcast:episode',
|
||||
routeParams: ['episode_id' => $episode->getId()],
|
||||
absolute: true
|
||||
);
|
||||
}
|
||||
|
@ -319,8 +319,8 @@ final class PodcastFeedAction
|
|||
$rssEnclosure = new RssEnclosure();
|
||||
|
||||
$podcastMediaPlayUrl = (string)$this->router->fromHere(
|
||||
route_name: 'api:stations:podcast:episode:download',
|
||||
route_params: ['episode_id' => $episode->getId()],
|
||||
routeName: 'api:stations:podcast:episode:download',
|
||||
routeParams: ['episode_id' => $episode->getId()],
|
||||
absolute: true
|
||||
);
|
||||
|
||||
|
@ -346,8 +346,8 @@ final class PodcastFeedAction
|
|||
|
||||
if ($podcastsFilesystem->fileExists(PodcastEpisode::getArtPath($episode->getIdRequired()))) {
|
||||
$episodeArtworkSrc = (string)$this->router->fromHere(
|
||||
route_name: 'api:stations:podcast:episode:art',
|
||||
route_params: ['episode_id' => $episode->getId() . '|' . $episode->getArtUpdatedAt()],
|
||||
routeName: 'api:stations:podcast:episode:art',
|
||||
routeParams: ['episode_id' => $episode->getId() . '|' . $episode->getArtUpdatedAt()],
|
||||
absolute: true
|
||||
);
|
||||
}
|
||||
|
|
|
@ -121,59 +121,59 @@ final class ProfileController
|
|||
|
||||
// Public Pages
|
||||
'publicPageUri' => (string)$router->named(
|
||||
route_name: 'public:index',
|
||||
route_params: ['station_id' => $station->getShortName()],
|
||||
routeName: 'public:index',
|
||||
routeParams: ['station_id' => $station->getShortName()],
|
||||
absolute: true
|
||||
),
|
||||
'publicPageEmbedUri' => (string)$router->named(
|
||||
route_name: 'public:index',
|
||||
route_params: ['station_id' => $station->getShortName(), 'embed' => 'embed'],
|
||||
routeName: 'public:index',
|
||||
routeParams: ['station_id' => $station->getShortName(), 'embed' => 'embed'],
|
||||
absolute: true
|
||||
),
|
||||
'publicWebDjUri' => (string)$router->named(
|
||||
route_name: 'public:dj',
|
||||
route_params: ['station_id' => $station->getShortName()],
|
||||
routeName: 'public:dj',
|
||||
routeParams: ['station_id' => $station->getShortName()],
|
||||
absolute: true
|
||||
),
|
||||
'publicOnDemandUri' => (string)$router->named(
|
||||
route_name: 'public:ondemand',
|
||||
route_params: ['station_id' => $station->getShortName()],
|
||||
routeName: 'public:ondemand',
|
||||
routeParams: ['station_id' => $station->getShortName()],
|
||||
absolute: true
|
||||
),
|
||||
'publicPodcastsUri' => (string)$router->named(
|
||||
route_name: 'public:podcasts',
|
||||
route_params: ['station_id' => $station->getShortName()],
|
||||
routeName: 'public:podcasts',
|
||||
routeParams: ['station_id' => $station->getShortName()],
|
||||
absolute: true
|
||||
),
|
||||
'publicScheduleUri' => (string)$router->named(
|
||||
route_name: 'public:schedule',
|
||||
route_params: ['station_id' => $station->getShortName()],
|
||||
routeName: 'public:schedule',
|
||||
routeParams: ['station_id' => $station->getShortName()],
|
||||
absolute: true
|
||||
),
|
||||
'publicOnDemandEmbedUri' => (string)$router->named(
|
||||
route_name: 'public:ondemand',
|
||||
route_params: ['station_id' => $station->getShortName(), 'embed' => 'embed'],
|
||||
routeName: 'public:ondemand',
|
||||
routeParams: ['station_id' => $station->getShortName(), 'embed' => 'embed'],
|
||||
absolute: true
|
||||
),
|
||||
'publicRequestEmbedUri' => (string)$router->named(
|
||||
route_name: 'public:embedrequests',
|
||||
route_params: ['station_id' => $station->getShortName()],
|
||||
routeName: 'public:embedrequests',
|
||||
routeParams: ['station_id' => $station->getShortName()],
|
||||
absolute: true
|
||||
),
|
||||
'publicHistoryEmbedUri' => (string)$router->named(
|
||||
route_name: 'public:history',
|
||||
route_params: ['station_id' => $station->getShortName()],
|
||||
routeName: 'public:history',
|
||||
routeParams: ['station_id' => $station->getShortName()],
|
||||
absolute: true
|
||||
),
|
||||
'publicScheduleEmbedUri' => (string)$router->named(
|
||||
route_name: 'public:schedule',
|
||||
route_params: ['station_id' => $station->getShortName(), 'embed' => 'embed'],
|
||||
routeName: 'public:schedule',
|
||||
routeParams: ['station_id' => $station->getShortName(), 'embed' => 'embed'],
|
||||
absolute: true
|
||||
),
|
||||
|
||||
'togglePublicPageUri' => (string)$router->fromHere(
|
||||
route_name: 'stations:profile:toggle',
|
||||
route_params: ['feature' => 'public', 'csrf' => $csrf]
|
||||
routeName: 'stations:profile:toggle',
|
||||
routeParams: ['feature' => 'public', 'csrf' => $csrf]
|
||||
),
|
||||
|
||||
// Frontend
|
||||
|
|
|
@ -119,8 +119,8 @@ final class NowPlayingApiGenerator
|
|||
|
||||
if (0 !== $currentStreamer->getArtUpdatedAt()) {
|
||||
$live->art = $this->router->named(
|
||||
route_name: 'api:stations:streamer:art',
|
||||
route_params: [
|
||||
routeName: 'api:stations:streamer:art',
|
||||
routeParams: [
|
||||
'station_id' => $station->getIdRequired(),
|
||||
'id' => $currentStreamer->getIdRequired() . '|' . $currentStreamer->getArtUpdatedAt(),
|
||||
],
|
||||
|
|
|
@ -69,8 +69,8 @@ final class SongApiGenerator
|
|||
}
|
||||
|
||||
return $this->router->named(
|
||||
route_name: 'api:stations:media:art',
|
||||
route_params: [
|
||||
routeName: 'api:stations:media:art',
|
||||
routeParams: [
|
||||
'station_id' => $station->getId(),
|
||||
'media_id' => $mediaId,
|
||||
]
|
||||
|
@ -88,8 +88,8 @@ final class SongApiGenerator
|
|||
$currentStreamer = $station->getCurrentStreamer();
|
||||
if (null !== $currentStreamer && 0 !== $currentStreamer->getArtUpdatedAt()) {
|
||||
return $this->router->named(
|
||||
route_name: 'api:stations:streamer:art',
|
||||
route_params: [
|
||||
routeName: 'api:stations:streamer:art',
|
||||
routeParams: [
|
||||
'station_id' => $station->getIdRequired(),
|
||||
'id' => $currentStreamer->getIdRequired() . '|' . $currentStreamer->getArtUpdatedAt(),
|
||||
],
|
||||
|
|
|
@ -21,6 +21,8 @@ final class Router implements RouterInterface
|
|||
|
||||
private ?UriInterface $baseUrl = null;
|
||||
|
||||
private ?RouteInterface $currentRoute = null;
|
||||
|
||||
public function __construct(
|
||||
private readonly Entity\Repository\SettingsRepository $settingsRepo,
|
||||
private readonly RouteParserInterface $routeParser
|
||||
|
@ -31,26 +33,27 @@ final class Router implements RouterInterface
|
|||
{
|
||||
$this->request = $request;
|
||||
$this->baseUrl = null;
|
||||
|
||||
$this->currentRoute = (null !== $request)
|
||||
? RouteContext::fromRequest($request)->getRoute()
|
||||
: null;
|
||||
}
|
||||
|
||||
public function getBaseUrl(?bool $useRequest = null): UriInterface
|
||||
public function getBaseUrl(): UriInterface
|
||||
{
|
||||
if (null === $useRequest) {
|
||||
if (null === $this->baseUrl) {
|
||||
$settings = $this->settingsRepo->readSettings();
|
||||
$this->baseUrl = $this->buildBaseUrl($settings->getPreferBrowserUrl());
|
||||
}
|
||||
|
||||
return $this->baseUrl;
|
||||
if (null === $this->baseUrl) {
|
||||
$this->baseUrl = $this->buildBaseUrl();
|
||||
}
|
||||
|
||||
return $this->buildBaseUrl($useRequest);
|
||||
return $this->baseUrl;
|
||||
}
|
||||
|
||||
private function buildBaseUrl(bool $useRequest = true): UriInterface
|
||||
public function buildBaseUrl(?bool $useRequest = null): UriInterface
|
||||
{
|
||||
$settings = $this->settingsRepo->readSettings();
|
||||
|
||||
$useRequest ??= $settings->getPreferBrowserUrl();
|
||||
|
||||
$baseUrl = $settings->getBaseUrlAsUri() ?? new Uri('');
|
||||
$useHttps = $settings->getAlwaysUseSsl();
|
||||
|
||||
|
@ -93,64 +96,58 @@ final class Router implements RouterInterface
|
|||
* @inheritDoc
|
||||
*/
|
||||
public function fromHereWithQuery(
|
||||
?string $route_name = null,
|
||||
array $route_params = [],
|
||||
array $query_params = [],
|
||||
?string $routeName = null,
|
||||
array $routeParams = [],
|
||||
array $queryParams = [],
|
||||
bool $absolute = false
|
||||
): UriInterface {
|
||||
if ($this->request instanceof ServerRequestInterface) {
|
||||
$query_params = array_merge($this->request->getQueryParams(), $query_params);
|
||||
$queryParams = array_merge($this->request->getQueryParams(), $queryParams);
|
||||
}
|
||||
|
||||
return $this->fromHere($route_name, $route_params, $query_params, $absolute);
|
||||
return $this->fromHere($routeName, $routeParams, $queryParams, $absolute);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function fromHere(
|
||||
?string $route_name = null,
|
||||
array $route_params = [],
|
||||
array $query_params = [],
|
||||
?string $routeName = null,
|
||||
array $routeParams = [],
|
||||
array $queryParams = [],
|
||||
bool $absolute = false
|
||||
): UriInterface {
|
||||
if ($this->request instanceof ServerRequestInterface) {
|
||||
$route = RouteContext::fromRequest($this->request)->getRoute();
|
||||
} else {
|
||||
$route = null;
|
||||
if (null !== $this->currentRoute) {
|
||||
if (null === $routeName) {
|
||||
$routeName = $this->currentRoute->getName();
|
||||
}
|
||||
|
||||
$routeParams = array_merge($this->currentRoute->getArguments(), $routeParams);
|
||||
}
|
||||
|
||||
if (null === $route_name && $route instanceof RouteInterface) {
|
||||
$route_name = $route->getName();
|
||||
}
|
||||
|
||||
if (null === $route_name) {
|
||||
if (null === $routeName) {
|
||||
throw new InvalidArgumentException(
|
||||
'Cannot specify a null route name if no existing route is configured.'
|
||||
);
|
||||
}
|
||||
|
||||
if ($route instanceof RouteInterface) {
|
||||
$route_params = array_merge($route->getArguments(), $route_params);
|
||||
}
|
||||
|
||||
return $this->named($route_name, $route_params, $query_params, $absolute);
|
||||
return $this->named($routeName, $routeParams, $queryParams, $absolute);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function named(
|
||||
string $route_name,
|
||||
array $route_params = [],
|
||||
array $query_params = [],
|
||||
string $routeName,
|
||||
array $routeParams = [],
|
||||
array $queryParams = [],
|
||||
bool $absolute = false
|
||||
): UriInterface {
|
||||
return self::resolveUri(
|
||||
$this->getBaseUrl(),
|
||||
$this->routeParser->relativeUrlFor($route_name, $route_params, $query_params),
|
||||
$absolute
|
||||
);
|
||||
$relativeUri = new Uri($this->routeParser->relativeUrlFor($routeName, $routeParams, $queryParams));
|
||||
|
||||
return ($absolute)
|
||||
? self::resolveUri($this->getBaseUrl(), $relativeUri, true)
|
||||
: $relativeUri;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,10 +174,10 @@ final class Router implements RouterInterface
|
|||
// URI has an authority solely because of its port.
|
||||
if ($rel->getAuthority() !== '' && $rel->getHost() === '' && $rel->getPort()) {
|
||||
// Strip the authority from the URI, then reapply the port after the merge.
|
||||
$original_port = $rel->getPort();
|
||||
$originalPort = $rel->getPort();
|
||||
|
||||
$new_uri = UriResolver::resolve($base, $rel->withScheme('')->withHost('')->withPort(null));
|
||||
return $new_uri->withPort($original_port);
|
||||
$newUri = UriResolver::resolve($base, $rel->withScheme('')->withHost('')->withPort(null));
|
||||
return $newUri->withPort($originalPort);
|
||||
}
|
||||
|
||||
return UriResolver::resolve($base, $rel);
|
||||
|
|
|
@ -13,50 +13,52 @@ interface RouterInterface
|
|||
|
||||
public function withRequest(?ServerRequestInterface $request): self;
|
||||
|
||||
public function getBaseUrl(?bool $useRequest = null): UriInterface;
|
||||
public function getBaseUrl(): UriInterface;
|
||||
|
||||
public function buildBaseUrl(?bool $useRequest = null): UriInterface;
|
||||
|
||||
/**
|
||||
* Simpler format for calling "named" routes with parameters.
|
||||
*
|
||||
* @param string $route_name
|
||||
* @param array $route_params
|
||||
* @param array $query_params
|
||||
* @param string $routeName
|
||||
* @param array $routeParams
|
||||
* @param array $queryParams
|
||||
* @param boolean $absolute Whether to include the full URL.
|
||||
*/
|
||||
public function named(
|
||||
string $route_name,
|
||||
array $route_params = [],
|
||||
array $query_params = [],
|
||||
string $routeName,
|
||||
array $routeParams = [],
|
||||
array $queryParams = [],
|
||||
bool $absolute = false
|
||||
): UriInterface;
|
||||
|
||||
/**
|
||||
* Return a named route based on the current page and its route arguments.
|
||||
*
|
||||
* @param string|null $route_name
|
||||
* @param array $route_params
|
||||
* @param array $query_params
|
||||
* @param string|null $routeName
|
||||
* @param array $routeParams
|
||||
* @param array $queryParams
|
||||
* @param bool $absolute
|
||||
*/
|
||||
public function fromHere(
|
||||
?string $route_name = null,
|
||||
array $route_params = [],
|
||||
array $query_params = [],
|
||||
?string $routeName = null,
|
||||
array $routeParams = [],
|
||||
array $queryParams = [],
|
||||
bool $absolute = false
|
||||
): UriInterface;
|
||||
|
||||
/**
|
||||
* Same as $this->fromHere(), but merging the current GET query parameters into the request as well.
|
||||
*
|
||||
* @param string|null $route_name
|
||||
* @param array $route_params
|
||||
* @param array $query_params
|
||||
* @param string|null $routeName
|
||||
* @param array $routeParams
|
||||
* @param array $queryParams
|
||||
* @param bool $absolute
|
||||
*/
|
||||
public function fromHereWithQuery(
|
||||
?string $route_name = null,
|
||||
array $route_params = [],
|
||||
array $query_params = [],
|
||||
?string $routeName = null,
|
||||
array $routeParams = [],
|
||||
array $queryParams = [],
|
||||
bool $absolute = false
|
||||
): UriInterface;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ use App\Entity\Repository\SettingsRepository;
|
|||
use App\Enums\GlobalPermissions;
|
||||
use App\Event\GetNotifications;
|
||||
use App\Session\Flash;
|
||||
use App\Utilities\Strings;
|
||||
|
||||
final class BaseUrlCheck
|
||||
{
|
||||
|
@ -36,8 +35,8 @@ final class BaseUrlCheck
|
|||
return;
|
||||
}
|
||||
|
||||
$baseUriWithRequest = $router->getBaseUrl(true);
|
||||
$baseUriWithoutRequest = $router->getBaseUrl(false);
|
||||
$baseUriWithRequest = $router->buildBaseUrl(true);
|
||||
$baseUriWithoutRequest = $router->buildBaseUrl(false);
|
||||
|
||||
if ((string)$baseUriWithoutRequest !== (string)$baseUriWithRequest) {
|
||||
// phpcs:disable Generic.Files.LineLength
|
||||
|
@ -54,8 +53,8 @@ final class BaseUrlCheck
|
|||
$notification = new Notification();
|
||||
$notification->title = sprintf(
|
||||
__('Your "Base URL" setting (%s) does not match the URL you are currently using (%s).'),
|
||||
Strings::truncateUrl((string)$baseUriWithoutRequest),
|
||||
Strings::truncateUrl((string)$baseUriWithRequest)
|
||||
(string)$baseUriWithoutRequest,
|
||||
(string)$baseUriWithRequest
|
||||
);
|
||||
$notification->body = implode(' ', $notificationBodyParts);
|
||||
$notification->type = Flash::WARNING;
|
||||
|
|
Loading…
Reference in New Issue