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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -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')
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -9,7 +9,6 @@
|
||||
|
||||
namespace Flarum\Http;
|
||||
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class SlugManager
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
|
@@ -77,7 +77,7 @@ class ShowTest extends TestCase
|
||||
$this->request('GET', '/api/discussions/1-fdsafdsajfsakf', [
|
||||
'authenticatedAs' => 2,
|
||||
])->withQueryParams([
|
||||
"bySlug" => true
|
||||
'bySlug' => true
|
||||
])
|
||||
);
|
||||
|
||||
|
@@ -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' => [
|
||||
|
@@ -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
|
||||
])
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user