mirror of
https://github.com/flarum/core.git
synced 2025-10-12 15:34:26 +02:00
- Support slug drivers for core's sluggable models, easily extends to other models - Add automated testing for affected single-model API routes - Fix nickname selection UI - Serialize slugs as `slug` attribute - Make min search length a constant
66 lines
2.0 KiB
PHP
66 lines
2.0 KiB
PHP
<?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\Discussion\Discussion;
|
|
use Flarum\Discussion\IdWithTransliteratedSlugDriver;
|
|
use Flarum\Foundation\AbstractServiceProvider;
|
|
use Flarum\Settings\SettingsRepositoryInterface;
|
|
use Flarum\User\User;
|
|
use Flarum\User\UsernameSlugDriver;
|
|
use Illuminate\Support\Arr;
|
|
|
|
class HttpServiceProvider extends AbstractServiceProvider
|
|
{
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function register()
|
|
{
|
|
$this->app->singleton('flarum.http.csrfExemptPaths', function () {
|
|
return ['token'];
|
|
});
|
|
|
|
$this->app->bind(Middleware\CheckCsrfToken::class, function ($app) {
|
|
return new Middleware\CheckCsrfToken($app->make('flarum.http.csrfExemptPaths'));
|
|
});
|
|
|
|
$this->app->singleton('flarum.http.slugDrivers', function () {
|
|
return [
|
|
Discussion::class => [
|
|
'default' => IdWithTransliteratedSlugDriver::class
|
|
],
|
|
User::class => [
|
|
'default' => UsernameSlugDriver::class
|
|
],
|
|
];
|
|
});
|
|
|
|
$this->app->singleton('flarum.http.selectedSlugDrivers', function () {
|
|
$settings = $this->app->make(SettingsRepositoryInterface::class);
|
|
|
|
$compiledDrivers = [];
|
|
|
|
foreach ($this->app->make('flarum.http.slugDrivers') as $resourceClass => $resourceDrivers) {
|
|
$driverKey = $settings->get("slug_driver_$resourceClass", 'default');
|
|
|
|
$driverClass = Arr::get($resourceDrivers, $driverKey, $resourceDrivers['default']);
|
|
|
|
$compiledDrivers[$resourceClass] = $this->app->make($driverClass);
|
|
}
|
|
|
|
return $compiledDrivers;
|
|
});
|
|
$this->app->bind(SlugManager::class, function () {
|
|
return new SlugManager($this->app->make('flarum.http.selectedSlugDrivers'));
|
|
});
|
|
}
|
|
}
|