mirror of
https://github.com/flarum/framework.git
synced 2024-11-22 12:48:28 +08:00
Add user id slug driver (#2787)
This commit is contained in:
parent
1f2411e15e
commit
b62debf031
|
@ -13,6 +13,7 @@ use Flarum\Discussion\Discussion;
|
|||
use Flarum\Discussion\IdWithTransliteratedSlugDriver;
|
||||
use Flarum\Foundation\AbstractServiceProvider;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Flarum\User\IdSlugDriver;
|
||||
use Flarum\User\User;
|
||||
use Flarum\User\UsernameSlugDriver;
|
||||
use Illuminate\Support\Arr;
|
||||
|
@ -38,7 +39,8 @@ class HttpServiceProvider extends AbstractServiceProvider
|
|||
'default' => IdWithTransliteratedSlugDriver::class
|
||||
],
|
||||
User::class => [
|
||||
'default' => UsernameSlugDriver::class
|
||||
'default' => UsernameSlugDriver::class,
|
||||
'id' => IdSlugDriver::class
|
||||
],
|
||||
];
|
||||
});
|
||||
|
|
36
src/User/IdSlugDriver.php
Normal file
36
src/User/IdSlugDriver.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?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 IdSlugDriver implements SlugDriverInterface
|
||||
{
|
||||
/**
|
||||
* @var UserRepository
|
||||
*/
|
||||
protected $users;
|
||||
|
||||
public function __construct(UserRepository $users)
|
||||
{
|
||||
$this->users = $users;
|
||||
}
|
||||
|
||||
public function toSlug(AbstractModel $instance): string
|
||||
{
|
||||
return $instance->id;
|
||||
}
|
||||
|
||||
public function fromSlug(string $slug, User $actor): AbstractModel
|
||||
{
|
||||
return $this->users->findOrFail($slug, $actor);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user