mirror of
https://github.com/flarum/core.git
synced 2025-10-14 00:15:51 +02:00
Combine URL generator classes into one
This commit is contained in:
@@ -19,6 +19,7 @@ use Flarum\Event\ConfigureNotificationTypes;
|
||||
use Flarum\Foundation\AbstractServiceProvider;
|
||||
use Flarum\Http\RouteCollection;
|
||||
use Flarum\Http\RouteHandlerFactory;
|
||||
use Flarum\Http\UrlGenerator;
|
||||
use Tobscure\JsonApi\ErrorHandler;
|
||||
use Tobscure\JsonApi\Exception\Handler\FallbackExceptionHandler;
|
||||
use Tobscure\JsonApi\Exception\Handler\InvalidParameterExceptionHandler;
|
||||
@@ -30,8 +31,8 @@ class ApiServiceProvider extends AbstractServiceProvider
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton(UrlGenerator::class, function () {
|
||||
return new UrlGenerator($this->app, $this->app->make('flarum.api.routes'));
|
||||
$this->app->extend(UrlGenerator::class, function (UrlGenerator $url) {
|
||||
return $url->addCollection('api', $this->app->make('flarum.api.routes'), 'api');
|
||||
});
|
||||
|
||||
$this->app->singleton('flarum.api.routes', function () {
|
||||
|
@@ -11,8 +11,8 @@
|
||||
|
||||
namespace Flarum\Api\Controller;
|
||||
|
||||
use Flarum\Api\UrlGenerator;
|
||||
use Flarum\Discussion\Search\DiscussionSearcher;
|
||||
use Flarum\Http\UrlGenerator;
|
||||
use Flarum\Search\SearchCriteria;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Tobscure\JsonApi\Document;
|
||||
@@ -86,7 +86,7 @@ class ListDiscussionsController extends AbstractListController
|
||||
$results = $this->searcher->search($criteria, $limit, $offset, $load);
|
||||
|
||||
$document->addPaginationLinks(
|
||||
$this->url->toRoute('discussions.index'),
|
||||
$this->url->to('api')->route('discussions.index'),
|
||||
$request->getQueryParams(),
|
||||
$offset,
|
||||
$limit,
|
||||
|
@@ -11,7 +11,7 @@
|
||||
|
||||
namespace Flarum\Api\Controller;
|
||||
|
||||
use Flarum\Api\UrlGenerator;
|
||||
use Flarum\Http\UrlGenerator;
|
||||
use Flarum\Search\SearchCriteria;
|
||||
use Flarum\User\Exception\PermissionDeniedException;
|
||||
use Flarum\User\Search\UserSearcher;
|
||||
@@ -84,7 +84,7 @@ class ListUsersController extends AbstractListController
|
||||
$results = $this->searcher->search($criteria, $limit, $offset, $load);
|
||||
|
||||
$document->addPaginationLinks(
|
||||
$this->url->toRoute('users.index'),
|
||||
$this->url->to('api')->route('users.index'),
|
||||
$request->getQueryParams(),
|
||||
$offset,
|
||||
$limit,
|
||||
|
@@ -11,8 +11,8 @@
|
||||
|
||||
namespace Flarum\Api\Controller;
|
||||
|
||||
use Flarum\Forum\UrlGenerator;
|
||||
use Flarum\Http\Controller\ControllerInterface;
|
||||
use Flarum\Http\UrlGenerator;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Flarum\User\AssertPermissionTrait;
|
||||
use Flarum\User\EmailToken;
|
||||
@@ -80,7 +80,7 @@ class SendConfirmationEmailController implements ControllerInterface
|
||||
|
||||
$data = [
|
||||
'{username}' => $actor->username,
|
||||
'{url}' => $this->url->toRoute('confirmEmail', ['token' => $token->id]),
|
||||
'{url}' => $this->url->to('forum')->route('confirmEmail', ['token' => $token->id]),
|
||||
'{forum}' => $this->settings->get('forum_title')
|
||||
];
|
||||
|
||||
|
@@ -11,8 +11,8 @@
|
||||
|
||||
namespace Flarum\Api\Serializer;
|
||||
|
||||
use Flarum\Forum\UrlGenerator;
|
||||
use Flarum\Foundation\Application;
|
||||
use Flarum\Http\UrlGenerator;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
|
||||
class ForumSerializer extends AbstractSerializer
|
||||
@@ -107,7 +107,7 @@ class ForumSerializer extends AbstractSerializer
|
||||
{
|
||||
$logoPath = $this->settings->get('logo_path');
|
||||
|
||||
return $logoPath ? $this->url->toPath('assets/'.$logoPath) : null;
|
||||
return $logoPath ? $this->url->to('forum')->path('assets/'.$logoPath) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,6 +117,6 @@ class ForumSerializer extends AbstractSerializer
|
||||
{
|
||||
$faviconPath = $this->settings->get('favicon_path');
|
||||
|
||||
return $faviconPath ? $this->url->toPath('assets/'.$faviconPath) : null;
|
||||
return $faviconPath ? $this->url->to('forum')->path('assets/'.$faviconPath) : null;
|
||||
}
|
||||
}
|
||||
|
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Api;
|
||||
|
||||
use Flarum\Http\AbstractUrlGenerator;
|
||||
|
||||
class UrlGenerator extends AbstractUrlGenerator
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $path = 'api';
|
||||
}
|
Reference in New Issue
Block a user