1
0
mirror of https://github.com/flarum/core.git synced 2025-08-07 00:47:00 +02:00

Apply fixes from StyleCI

[ci skip] [skip ci]
This commit is contained in:
luceos
2020-11-17 03:46:35 +00:00
committed by Matthew Kilgore
parent 4574fa6290
commit a155e41432
10 changed files with 44 additions and 26 deletions

View File

@@ -1,16 +1,20 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Discussion;
use Flarum\Database\AbstractModel;
use Flarum\Http\SlugDriverInterface;
use Flarum\User\User;
class IdWithSlugDriver implements SlugDriverInterface
{
public function toSlug(AbstractModel $instance): string
{
return $instance->id.(trim($instance->slug) ? '-'.$instance->slug : '');
@@ -22,6 +26,7 @@ class IdWithSlugDriver implements SlugDriverInterface
$slug_array = explode('-', $slug);
$slug = $slug_array[0];
}
return Discussion::where('id', $slug)->whereVisibleTo($actor)->firstOrFail();
}
}

View File

@@ -10,7 +10,6 @@
namespace Flarum\Forum\Content;
use Flarum\Api\Client;
use Flarum\Discussion\Discussion as FlarumDiscussion;
use Flarum\Frontend\Document;
use Flarum\Http\Exception\RouteNotFoundException;
use Flarum\Http\UrlGenerator;

View File

@@ -33,7 +33,7 @@ class HttpServiceProvider extends AbstractServiceProvider
return new Middleware\CheckCsrfToken($app->make('flarum.http.csrfExemptPaths'));
});
$this->app->singleton('flarum.http.slugDrivers', function() {
$this->app->singleton('flarum.http.slugDrivers', function () {
return [
Discussion::class => [
'default' => IdWithSlugDriver::class
@@ -44,12 +44,12 @@ class HttpServiceProvider extends AbstractServiceProvider
];
});
$this->app->singleton('flarum.http.selectedSlugDrivers', function() {
$this->app->singleton('flarum.http.selectedSlugDrivers', function () {
$settings = $this->app->make(SettingsRepositoryInterface::class);
$compiledDrivers = [];
foreach($this->app->make('flarum.http.slugDrivers') as $resourceClass => $resourceDrivers) {
foreach ($this->app->make('flarum.http.slugDrivers') as $resourceClass => $resourceDrivers) {
$driverClass = $resourceDrivers[$settings->get("slug_driver_$resourceClass", 'default')];
$compiledDrivers[$resourceClass] = $this->app->make($driverClass);
}
@@ -57,36 +57,37 @@ class HttpServiceProvider extends AbstractServiceProvider
return $compiledDrivers;
});
$this->app->singleton('flarum.http.resourceUrlGenerators', function() {
$this->app->singleton('flarum.http.resourceUrlGenerators', function () {
$slugManager = $this->app->make(SlugManager::class);
return [
Discussion::class => function(UrlGenerator $urlGenerator, Discussion $discussion) use ($slugManager) {
Discussion::class => function (UrlGenerator $urlGenerator, Discussion $discussion) use ($slugManager) {
return $urlGenerator->to('forum')->route('discussion', [
'id' => $slugManager->toResource(Discussion::class)->toSlug($discussion)
]);
},
Post::class => function(UrlGenerator $urlGenerator, Post $post) use ($slugManager) {
Post::class => function (UrlGenerator $urlGenerator, Post $post) use ($slugManager) {
return $urlGenerator->to('forum')->route('user', [
'id' => $slugManager->toResource(Discussion::class)->toSlug($post->discussion),
'near' => $post->id,
]);
},
User::class => function(UrlGenerator $urlGenerator, User $user) use ($slugManager) {
User::class => function (UrlGenerator $urlGenerator, User $user) use ($slugManager) {
return $urlGenerator->to('forum')->route('user', [
'id' => $slugManager->toResource(User::class)->toSlug($user)
]);
},
];
});
$this->app->bind(SlugManager::class, function() {
$this->app->bind(SlugManager::class, function () {
return new SlugManager($this->app->make('flarum.http.selectedSlugDrivers'));
});
$this->app->bind(UrlGenerator::class, function() {
$this->app->bind(UrlGenerator::class, function () {
return new UrlGenerator(
$this->app->make(Application::class),
$this->app->make('flarum.http.resourceUrlGenerators'));
$this->app->make('flarum.http.resourceUrlGenerators')
);
});
}
}

View File

@@ -1,9 +1,14 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Http;
use Flarum\Database\AbstractModel;
use Flarum\User\User;

View File

@@ -9,7 +9,6 @@
namespace Flarum\Http;
use Illuminate\Support\Arr;
class SlugManager

View File

@@ -68,7 +68,7 @@ class UrlGenerator
}
/**
* Generate a URL to an instance of a resource
* Generate a URL to an instance of a resource.
*
* @param string $resourceClass
* @param AbstractModel $instance

View File

@@ -1,15 +1,19 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\User;
use Flarum\Database\AbstractModel;
use Flarum\Http\SlugDriverInterface;
class UsernameSlugDriver implements SlugDriverInterface
{
public function toSlug(AbstractModel $instance): string
{
return $instance->username;

View File

@@ -77,7 +77,7 @@ class ShowTest extends TestCase
$this->request('GET', '/api/discussions/1-fdsafdsajfsakf', [
'authenticatedAs' => 2,
])->withQueryParams([
"bySlug" => true
'bySlug' => true
])
);

View File

@@ -57,7 +57,7 @@ class CreateTest extends TestCase
$this->assertEquals(422, $response->getStatusCode());
// The response body should contain details about the failed validation
$body = (string)$response->getBody();
$body = (string) $response->getBody();
$this->assertJson($body);
$this->assertEquals([
'errors' => [

View File

@@ -1,9 +1,14 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Tests\integration\api\users;
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
use Flarum\Tests\integration\TestCase;
@@ -55,7 +60,7 @@ class ShowTest extends TestCase
$this->request('GET', '/api/users/normal', [
'authenticatedAs' => 1,
])->withQueryParams([
"bySlug" => true
'bySlug' => true
])
);
@@ -81,7 +86,7 @@ class ShowTest extends TestCase
{
$response = $this->send(
$this->request('GET', '/api/users/2')->withQueryParams([
"bySlug" => true
'bySlug' => true
])
);
@@ -111,7 +116,7 @@ class ShowTest extends TestCase
$this->request('GET', '/api/users/normal', [
'authenticatedAs' => 2,
])->withQueryParams([
"bySlug" => true
'bySlug' => true
])
);
@@ -141,7 +146,7 @@ class ShowTest extends TestCase
$this->request('GET', '/api/users/admin', [
'authenticatedAs' => 2,
])->withQueryParams([
"bySlug" => true
'bySlug' => true
])
);
@@ -173,7 +178,7 @@ class ShowTest extends TestCase
$this->request('GET', '/api/users/admin', [
'authenticatedAs' => 2,
])->withQueryParams([
"bySlug" => true
'bySlug' => true
])
);