-
-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make profile urls work with usernames only and not user IDs. Fixes #1356
- Loading branch information
1 parent
7794546
commit e7d2729
Showing
4 changed files
with
93 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?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\Search\Gambit; | ||
|
||
use Flarum\Search\AbstractRegexGambit; | ||
use Flarum\Search\AbstractSearch; | ||
use Flarum\User\Search\UserSearch; | ||
use Flarum\User\UserRepository; | ||
use LogicException; | ||
|
||
class UsernameGambit extends AbstractRegexGambit | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $pattern = 'username:(.+)'; | ||
|
||
/** | ||
* @var \Flarum\User\UserRepository | ||
*/ | ||
protected $users; | ||
|
||
/** | ||
* @param \Flarum\User\UserRepository $users | ||
*/ | ||
public function __construct(UserRepository $users) | ||
{ | ||
$this->users = $users; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function conditions(AbstractSearch $search, array $matches, $negate) | ||
{ | ||
if (! $search instanceof UserSearch) { | ||
throw new LogicException('This gambit can only be applied on a UserSearch'); | ||
} | ||
|
||
$username = trim($matches[1], '"'); | ||
|
||
$search->getQuery()->where('username', $negate ? '!=' : '=', $username); | ||
} | ||
} |