findOne() public method

Finds one object in collection
public findOne ( callable $cb, array $p = [] ) : void
$cb callable Callback called when response received
$p array Hash of properties (offset, opts, where, col, fields, sort, hint, explain, snapshot, orderby, parse_oplog)
return void
コード例 #1
0
ファイル: GeoIP.php プロジェクト: kakserpom/WakePHP
 /**
  * @param string $ip
  * @param callable $cb
  */
 public function query($ip, $cb)
 {
     if (is_string($ip)) {
         $ip = ip2long($ip);
     }
     $this->blocks->findOne(function ($blk) use($cb) {
         if (!$blk) {
             call_user_func($cb, false);
             return;
         }
         $this->locations->findOne(function ($loc) use($cb) {
             if ($loc) {
                 $loc['country'] = $this->countries[$loc['cc']];
                 $loc['text'] = $loc['country'];
                 if (isset($loc['r']) && !ctype_digit($loc['r'])) {
                     $loc['text'] = $loc['r'] . ', ' . $loc['text'];
                 }
                 if (isset($loc['c'])) {
                     $loc['text'] = $loc['c'] . ', ' . $loc['text'];
                 }
             }
             call_user_func($cb, $loc);
         }, ['where' => ['_id' => $blk['l']]]);
     }, ['where' => ['s' => ['$lte' => $ip]], 'sort' => ['s' => -1]]);
 }
コード例 #2
0
ファイル: Blocks.php プロジェクト: kakserpom/WakePHP
 /**
  * @param array $find
  * @param callable $cb
  */
 public function getBlock($find, $cb)
 {
     if (isset($find['_id']) && is_string($find['_id'])) {
         $find['_id'] = new \MongoId($find['_id']);
     }
     $this->blocks->findOne($cb, array('where' => $find));
 }
コード例 #3
0
ファイル: Browsers.php プロジェクト: kakserpom/WakePHP
 /**
  * @param $names
  * @param callable $cb
  */
 public function get($agent, $cb)
 {
     $this->browsers->findOne(function ($item) use($cb, $agent) {
         if ($item) {
             call_user_func($cb, $item);
             return;
         }
         $browser = \get_browser($agent, true);
         $browser['name'] = $browser['browser'];
         unset($browser['browser_name_regex'], $browser['browser']);
         $this->browsers->insert(['_id' => $agent] + $browser);
         call_user_func($cb, $browser);
     }, ['where' => ['_id' => $agent]]);
 }
コード例 #4
0
ファイル: Captcha.php プロジェクト: kakserpom/WakePHP
 /**
  * @param $names
  * @param callable $cb
  */
 public function check($token, $text, $invalidate = true, $cb)
 {
     $e = static::decodeToken($token);
     if ($e === false) {
         call_user_func($cb, 'badToken');
         return;
     }
     list($id, $rnd) = $e;
     $this->captcha->findOne(function ($t) use($cb, $id, $text, $invalidate) {
         if (!$t) {
             call_user_func($cb, 'expired');
             return;
         }
         Daemon::log(Debug::dump([$invalidate]));
         if (!$invalidate) {
             if (strtolower($t['text']) === strtolower($text)) {
                 call_user_func($cb, 'ok');
                 return;
             }
         }
         $this->captcha->remove(['_id' => new \MongoId($id)], function ($lastError) use($t, $text, $cb) {
             if ($lastError['n'] !== 1) {
                 call_user_func($cb, 'expired');
                 return;
             }
             if (strtolower($t['text']) !== strtolower($text)) {
                 call_user_func($cb, 'incorrect');
                 return;
             }
             call_user_func($cb, 'ok');
         });
     }, ['where' => ['_id' => $id, 'rnd' => $rnd, 'ctime' => ['$gt' => time() - 3600]]]);
 }
コード例 #5
0
 /**
  * @param string $hash
  * @param callable $cb
  */
 public function findByIntToken($str, $cb = null)
 {
     $this->externalAuthTokens->findOne($cb, ['where' => ['intToken' => $str]]);
 }
コード例 #6
0
 /**
  * @param array $credentials
  * @param callable $cb
  */
 public function getRequestByCredentials(array $credentials, $cb = null)
 {
     $this->externalSignupRequests->findOne($cb, ['credentials' => ['$elemMatch' => $credentials]]);
 }