private function getUserByIdentifier() { $mapper = $this->getMapper(); if (empty($this->constraints)) { $user = $mapper::findOne(Filter::set($this->getIdentifierField(), Filter::EQUAL, $this->getIdentifierValue())); } else { $user = $mapper::findOne(Group::set(Filter::set($this->getIdentifierField(), Filter::EQUAL, $this->getIdentifierValue()), Group::OPERATOR_AND, $this->constraints)); } return $user; }
public static function get($entityId) { if (false === $entityId instanceof \MongoId) { $entityId = new \MongoId((string) $entityId); } $criteria = Filter::set('_id', Filter::EQUAL, $entityId); try { $entity = self::findOne($criteria); } catch (\Exception $e) { throw new MapperException($e->getMessage(), $e->getCode(), $e->getPrevious()); } return $entity; }
<?php require '../../../vendor/autoload.php'; require '../Resources/User/Mapper/User.php'; use Xeeo\Services\Database\Mongo\Mapper as MongoMapper, Xeeo\Services\Authenticate\AuthenticateApi, Xeeo\Services\Database\Mongo\Filter; MongoMapper::addConnection(array('name' => 'connectionName', 'url' => 'mongodb://localhost:27017/databaseName')); $config = array('passwordField' => 'credentials.password', 'identifierField' => 'credentials.email', 'mapper' => 'UserMapper', 'hashSalt' => 'some random text', 'hashCost' => 10); /** * @var AuthenticateApi $authApi */ $authApi = AuthenticateApi::getInstance($config); try { $criteria = Filter::set('status', Filter::EQUAL, 'active'); $login = $authApi->setIdentifierValue('*****@*****.**')->setPasswordValue('password')->setConstraints($criteria)->authenticate(); var_dump($login); } catch (\Exception $e) { print_r($e->getMessage()); }