将请求的key(字母)转换为key并用于查询

@param string $prefix
@param string $reqKey
@return $this
174145
public function whereConstKey($prefix, $reqKey = null)
    {
        if (func_num_args() === 1) {
            $reqKey = $this->request->get($prefix);
        }

        $id = $this->getConstId($prefix, $reqKey);
        if ($id !== '') {
            list($column) = $this->parseReqColumn($prefix);
            $this->andWhere([$column => $id]);
        }

        // OR
//        if (wei()->isPresent($curStatus)) {
//            $jthPatients->andWhere(['status' => $curStatus]);
//        }

        return $this;
    }
1302421
public function set_prefix( $prefix ) {
		if ( ! Str::starts_with( $prefix, '/' ) || Str::ends_with( $prefix, '/' ) ) {
			throw new MalformedRouteException;
		}

		$this->prefix = $prefix;

		return $this;
	}
189225
public function setKey($key)
    {
        parent::setKey($key);

        foreach ($this->getHandlers() as $handler) {
            $handler->setKey($key);
        }

        return $this;
    }
918586
public function cache($key=true,$expire=null,$type=''){
        // 增加快捷调用方式 cache(10) 等同于 cache(true, 10)
        if(is_numeric($key) && is_null($expire)){
            $expire = $key;
            $key    = true;
        }
        if(false !== $key)
            $this->options['cache']  =  array('key'=>$key,'expire'=>$expire,'type'=>$type);
        return $this;
    }
1280241
private function setPrefixKey()
    {
        if (null !== $this->getContext()) {
            $this->_prefix_key = md5($this->getContext());
        }

        return $this;
    }
13602
function stripPrefix($prefix)
    {
        $key = (string) $this;

        if (substr($key, 0, strlen($prefix)) == $prefix)
            $key = substr($key, strlen($prefix));

        return new self($key);
    }
1085692
public static function validate(string $key, string $prefix): string
    {
        if (in_array($key, self::$keys)) {
            throw new InvalidArgumentException("The key [$key] is not unique.");
        }

        if (strpos($key, $prefix) === false) {
            throw new InvalidArgumentException("The key must be prefixed with [$prefix].");
        }

        return $key;
    }
444292
protected function setKey($key): self
    {
        assert(is_resource($key) === true);

        $this->closeKey();
        $this->key = $key;

        return $this;
    }
590121
public function get_file_cache($key,$prefix=''){
        $option = array(
            'type'=>'File',
            'prefix'=>$prefix,
            'path'=>CACHE_PATH,
        );
        $cache = \think\Cache::connect($option);
        return $cache->get($key,[]);
    }
1079328
function addCount($key, $expire = 86400, $incrby = 1)
    {
        $key = self::PREFIX.$key;
        //增加计数
        if ($this->redis->exists($key))
        {
            return $this->redis->incr($key, $incrby);
        }
        //不存在的Key，设置为1
        else
        {
            return $this->redis->set($key, $incrby, $expire);
        }
    }
963604
protected function initUserByWechatOAuth2Code(Request $req)
    {
        // 1. 获取OAuth请求的code
        $code = $this->getOAuthCode();
        if (!$code) {
            return false;
        }

        // 2. 通过OAuth2.0的code,获取用户OpenID
        // TODO 允许失败不告警,重试完仍然失败才告警
        $api = wei()->wechatAccount->getCurrentAccount()->createApiService();
        $ret = $api->getOAuth2AccessTokenByAuth(['code' => $req['code']]);

        // 3. 如果错误是invalid code,且还有重试次数,重新跳转获得新的code
        if ($ret['errcode'] == 40029 && $retries = $this->getRetries()) {
            $url = $this->getRedirectUrl(['wechatRetries' => $retries - 1]);

            return $this->response->redirect($url);
        }

        // 4. 重试后还是失败,返回提醒给用户
        if (!isset($ret['openid'])) {
            return $this->ret->err('很抱歉,微信授权失败,请返回再试');
        }

        // 5. 重试成功,做个日志记录
        if (isset($ret['openid']) && isset($req['wechatRetries'])) {
            $this->logger->warning('微信获取Code重试成功', [
                'leftWechatRetries' => $this->getRetries(),
            ]);
        }

        // 6. 获取OpenID成功,创建或获取用户,并设置登录态
        wei()->curUser->loginBy(['wechatOpenId' => $ret['openid']]);
        $this->session->set([
            'accessToken' => $ret['access_token'], // 用于微信地址
            'scope' => $ret['scope'],
            'code' => $req['code'],
            'state' => $req['state'],
        ]);
    }
496325
public function appendToEachKey($prefix): self
    {
        // init
        $result = [];

        foreach ($this->getGenerator() as $key => $item) {
            if ($item instanceof self) {
                $result[$prefix . $key] = $item->appendToEachKey($prefix);
            } elseif (\is_array($item)) {
                $result[$prefix . $key] = self::create($item, $this->iteratorClass, false)
                    ->appendToEachKey($prefix)
                    ->toArray();
            } else {
                $result[$prefix . $key] = $item;
            }
        }

        return self::create($result, $this->iteratorClass, false);
    }
645596
public function prefix($prefix) {
		// Reset values before matching.
		$this->prefix = $this->parentPrefix;
		$this->requestPathOffset = $this->parentRequestPathOffset;
		if ($this->parentPrefixMatched) {
			$this->prefixMatched = $this->parentPrefixMatched;
		}

		if (!$this->result->hasHandler() && $this->prefixMatched) {
			$this->prefixMatched = $this->matchPartial($prefix);
		}

		$this->prefix .= $prefix;

		return $this;
	}
798424
public function prefix($prefix, callable $cb)
    {
        $prefix = rtrim($prefix, '/');

        if (!preg_match('@^/@', $prefix)) {
            $prefix = '/' . $prefix;
        }

        if ($this->prefix !== null) {
            $this->prefix .= $prefix;
        } else {
            $this->prefix = $prefix;
        }

        call_user_func_array($cb, [$this]);

        $this->prefix = '';

        return $this;
    }
906756
public static function canonquery($query, $prefix = '')
    {
        parse_str(preg_replace('#^\?#', '', $query), $args);

        if (empty($args)) {
            return '';
        }

        ksort($args);
        return $prefix . http_build_query($args);
    }
463719
public function prefixKeys(array $arguments, $prefix)
    {
        $normalized = [];
        $skip = ['id', 'ID'];

        foreach ($arguments as $key => $value) {
            if (in_array($key, $skip)) {
                $normalized[$key] = $value;

                continue;
            }

            $normalized["{$prefix}{$key}"] = $value;
        }

        return $normalized;
    }
288667
public static function generate(string $key, string $prefix): string
    {
        $key = sprintf('%s_%s', $prefix, static::hash($key));

        static::validate($key, $prefix);

        static::$keys[] = $key;

        return $key;
    }