Created
August 21, 2014 23:59
-
-
Save atrauzzi/9fd30dc9c3d194d1ccc8 to your computer and use it in GitHub Desktop.
User Repository
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 namespace BikeShed\Domain\Repository { | |
use BikeShed\Domain\User as UserModel; | |
interface User { | |
/** | |
* Searches Users without passwords by username. | |
* | |
* @param string $usernameQuery | |
* @return null|\BikeShed\Domain\User[] | |
*/ | |
public function searchPasswordless($usernameQuery); | |
/** | |
* Adds a User representation to the UoW. | |
* | |
* @param \BikeShed\Domain\User $user | |
*/ | |
public function persist(UserModel $user); | |
/** | |
* Obtains a user by their unique username. | |
* | |
* @param string $username | |
* @return \BikeShed\Domain\User | |
*/ | |
public function findOneByUsername($username); | |
} | |
} | |
// --- | |
<?php namespace BikeShed\Domain\Repository\DoctrineMongo { | |
use Doctrine\ODM\MongoDB\DocumentRepository; | |
use BikeShed\Domain\Repository\User as UserRepository; | |
// | |
use BikeShed\Domain\User as UserModel; | |
use MongoRegex; | |
class User extends DocumentRepository implements UserRepository { | |
/** | |
* @param string $usernameQuery | |
* @return null|\BikeShed\Domain\User[] | |
*/ | |
public function searchPasswordless($usernameQuery) { | |
return $this->findBy([ | |
'username' => new MongoRegex(sprintf('/^%s.*$/i', $usernameQuery)), | |
'password' => null | |
]); | |
} | |
/** | |
* Adds a User representation to the UoW. | |
* | |
* @param \BikeShed\Domain\User $user | |
*/ | |
public function persist(UserModel $user) { | |
$this->dm->persist($user); | |
} | |
/** | |
* Obtains a user by their unique username. | |
* | |
* @param string $username | |
* @return \BikeShed\Domain\User | |
*/ | |
public function findOneByUsername($username) { | |
return $this->findOneBy([ | |
'username' => $username | |
]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment