Exemplo n.º 1
0
 /**
  * @param $key
  *
  * @return RedisItem
  * @throws NotFoundHttpException
  */
 public static function find($key)
 {
     $ex = Redisman::getInstance()->executeCommand('EXISTS', [$key]);
     if (!$ex) {
         throw new NotFoundHttpException(Redisman::t('redisman', 'key not found'));
     } else {
         list($type, $size, $ttl, $refcount, $idletype, $encoding) = Redisman::getInstance()->executeCommand('EVAL', [self::infoScript($key), 0]);
         $model = new static();
         $model->setAttributes(ArrayHelper::merge(['class' => 'insolita\\redisman\\models\\RedisItem', 'key' => $key, 'db' => Redisman::getInstance()->getCurrentDb(), 'storage' => Redisman::getInstance()->getCurrentConn()], compact('type', 'size', 'ttl', 'refcount', 'idletime', 'encoding')), false);
         $event = new Event();
         $event->data = $model->getAttributes();
         $model->onAfterFind($event);
         return $model;
     }
 }
Exemplo n.º 2
0
Arquivo: User.php Projeto: h11Nox/slug
 /**
  * @param \nodge\eauth\ServiceBase $service
  * @return User
  * @throws ErrorException
  */
 public static function findByEAuth($service)
 {
     if (!$service->getIsAuthenticated()) {
         throw new ErrorException('EAuth user should be authenticated before creating identity.');
     }
     $user = static::find()->where('service = :service AND service_id = :ID', [':service' => $service->getServiceName(), ':ID' => $service->getAttribute('id')])->one();
     if (!$user) {
         $photo = $service->getServiceName() === 'vkontakte' ? $service->getAttribute('photo_big') : "https://graph.facebook.com/{$service->getAttribute('id')}/picture?type=large";
         $user = new static(['username' => $service->getAttribute('name'), 'service' => $service->getServiceName(), 'service_id' => $service->getAttribute('id'), 'img' => $photo]);
         $user->save();
     }
     $id = $service->getServiceName() . '-' . $service->getId();
     $attributes = array_merge($user->getAttributes(['id', 'username', 'img', 'rating']), ['id' => $id, 'auth_key' => md5($id), 'cid' => $user->id]);
     Yii::$app->getSession()->set('user-' . $id, $attributes);
     return new self($attributes);
 }