mirror of
				https://github.com/flarum/core.git
				synced 2025-10-27 13:40:24 +01: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
		
			
				
	
	
		
			37 lines
		
	
	
		
			757 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			757 B
		
	
	
	
		
			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\User;
 | |
| 
 | |
| use Flarum\Database\AbstractModel;
 | |
| use Flarum\Http\SlugDriverInterface;
 | |
| 
 | |
| class UsernameSlugDriver implements SlugDriverInterface
 | |
| {
 | |
|     /**
 | |
|      * @var UserRepository
 | |
|      */
 | |
|     protected $users;
 | |
| 
 | |
|     public function __construct(UserRepository $users)
 | |
|     {
 | |
|         $this->users = $users;
 | |
|     }
 | |
| 
 | |
|     public function toSlug(AbstractModel $instance): string
 | |
|     {
 | |
|         return $instance->username;
 | |
|     }
 | |
| 
 | |
|     public function fromSlug(string $slug, User $actor): AbstractModel
 | |
|     {
 | |
|         return $this->users->findOrFailByUsername($slug, $actor);
 | |
|     }
 | |
| }
 |