Created
January 2, 2016 00:02
-
-
Save irfan/d59af29477244078ccbc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <?php | |
| /** | |
| * user nick update | |
| */ | |
| namespace \User\Credential; | |
| class User extends BaseUser | |
| { | |
| /** | |
| * @User's current nick name | |
| * @type String | |
| */ | |
| private $currentUsername; | |
| /** | |
| * @type String | |
| */ | |
| private $newUsername; | |
| /** | |
| * @param $username String | |
| */ | |
| public function setCurrentUsername($username) | |
| { | |
| $this->currentUsername = $username; | |
| } | |
| /** | |
| * @param $username String | |
| */ | |
| public function setNewUsername($username) | |
| { | |
| $this->newUsername = $username; | |
| } | |
| /** | |
| * TODO: We need implementation of the function | |
| */ | |
| public function isUsernameExists() | |
| { | |
| return false; | |
| } | |
| /** | |
| * Checks the username whether valid | |
| */ | |
| public function isValid() | |
| { | |
| if (!$this->isUsernameExists()) { | |
| preg_match("^[a-z0-9_-]{3,15}$", $this->newUsername, $matches); | |
| return $matches; | |
| } | |
| } | |
| /** | |
| * Set new username | |
| */ | |
| public function saveUsername($users) | |
| { | |
| foreach ($users as $id => $user) { | |
| if ($user['nickname'] == $this->currentUsername) { | |
| $users[$id]['nickname'] = $this->newUsername; | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment