连接缓存
@access public
@param  array $options  配置数组
@param  bool  $force 强制重新连接
@return Driver
541514
public function connect(array $options = [], bool $force = false): Driver
    {
        $name = md5(serialize($options));

        if ($force || !isset($this->instance[$name])) {
            $type = !empty($options['type']) ? $options['type'] : 'File';

            $this->instance[$name] = $this->factory($type, '\\think\\cache\\driver\\', $options);
        }

        return $this->instance[$name];
    }
458641
public static function createAdminRole($force = false)
    {
        if(!$force) {
            if(Permission::exists('global', 'admin')) {
                return false;
            }
        }

        return self::createRole(
            'Admin', true, [[
            'app' => 'global',
            'key' => 'admin'
            ]]
        );
    }
729792
public function initConfig($force = false) {
		$pluginName = $this->_getPluginName();
		$checkPath = $this->_getCheckPath();
		$configFile = $this->_getConfigFile();
		$language = (string)Configure::read('Config.language');
		if (!$force && !empty($checkPath) && Configure::check($checkPath)) {
			return;
		}

		// Local config without extra config file
		$conf = $this->getConfig();

		$cachePath = 'static_cfg_' . Inflector::underscore($pluginName) . '_' . $language;
		$cached = Cache::read($cachePath, CAKE_CONFIG_PLUGIN_CACHE_CFG);
		if ($cached !== false) {
			$conf = Hash::mergeDiff($conf, (array)$cached);
			Configure::write($pluginName, $conf);

			return;
		}
		Configure::config('phpcfg', new PhpReader($this->path));
		// Fallback to Plugin config which can be overwritten via local app config.
		Configure::load($pluginName . '.' . $configFile, 'phpcfg', false);
		$defaultConf = $this->getConfig();

		// Local app config
		if (file_exists($this->path . $configFile . '.php')) {
			Configure::load($configFile, 'phpcfg', false);
			$localConf = $this->getConfig();
			$conf = Hash::mergeDiff($conf, $localConf);
		}
		Configure::drop('phpcfg');
		// BC comp:
		$conf = Hash::mergeDiff($conf, $defaultConf);
		Cache::write($cachePath, $conf, CAKE_CONFIG_PLUGIN_CACHE_CFG);
		Configure::write($pluginName, $conf);
	}
34212
public static function destroy($data, $force = false)
    {
        // 包含软删除数据
        $query = self::withTrashed();

        if (is_array($data) && key($data) !== 0) {
            $query->where($data);
            $data = null;
        } elseif ($data instanceof \Closure) {
            call_user_func_array($data, [ & $query]);
            $data = null;
        } elseif (is_null($data)) {
            return false;
        }

        $resultSet = $query->select($data);

        if ($resultSet) {
            foreach ($resultSet as $data) {
                $data->force($force)->delete();
            }
        }

        return true;
    }
428292
public function with($option = null, $driver = null)
    {
        return $this->option($option)->driver($driver);
    }
1146287
public function select($options=array()) {
        $this->model  =   $options['model'];
        $this->parseBind(!empty($options['bind'])?$options['bind']:array());
        $sql    = $this->buildSelectSql($options);
        $result   = $this->query($sql,!empty($options['fetch_sql']) ? true : false);
        return $result;
    }
1356708
private function index($force = false)
    {
        if ($force || !$this->index)
        {
            $items = Eresus_CMS::getLegacyKernel()->db->
                select($this->table, '', '`position`', '`id`,`owner`');
            if ($items)
            {
                $this->index = array();
                foreach ($items as $item)
                {
                    $this->index[$item['owner']] []= $item['id'];
                }
            }
        }
    }
195068
public static function createAuthorRole($force = false)
    {
        if(!$force) {
            if(Permission::exists('global', 'author')) {
                return false;
            }
        }

        return self::createRole(
            'Author', true, [[
            'app' => 'global',
            'key' => 'author'
            ]]
        );
    }
1128950
public function updateUser($force = false)
    {
        $user = $this->user;
        if (!$user || $force) {
            $wechat = $this->wechat;
            $user = new MpUser();
            $this->populateRelation('user',$user);
            $data = $wechat->getSdk()->getUserInfo($this->open_id);
            if ($data) {
                $user->setAttributes([
                    'id' => $this->id,
                    'nickname' => $data['nickname'],
                    'sex' => $data['sex'],
                    'city' => $data['city'],
                    'country' => $data['country'],
                    'province' => $data['province'],
                    'language' => $data['language'],
                    'avatar' => $data['headimgurl'],
                    'subscribe_time' => $data['subscribe_time'],
                    'remark' => $data['remark'],
                    'union_id' => isset($data['unionid']) ? $data['unionid'] : '', // 测试号无此项
                    'group_id' => $data['groupid'],
                ]);
                return $user->save();
            }
            $user->addError('id', '用户资料更新失败!');
            return false;
        }
        return true;
    }
611340
public function execute(Query $query, array $options = [])
    {
        $result = $this->_executeQuery($query, $options);

        if ($this->getDriver() === null) {
            throw new \UnexpectedValueException(__('No driver has been defined'));
        }

        // Write to the logger when one has been defined
        if ($this->getDriver()->getLogger()) {
            $this->_logQuery($query, $this->getDriver()->getLogger());
        }

        return $result;
    }
765122
public function render($force = false) {

		if(empty($this->html) || $force) {

			$attr = [];
			foreach($this->attributes as $k => $v) {
				$attr[] = sprintf('%s="%s"', $k, $v);
			}

			$options = [];
			foreach($this->options as $o) {
				$options[] = $o->render();
			}

			$this->html = sprintf('<select name="%s" %s>%s</select>',
				$this->getName(),
				implode(' ', $attr),
				"\n" . implode("\n", $options) . "\n"
			);
		}

		return $this->html;
	}
15671
public function get($force = false)
    {
        // Check if current set
        if (is_null(self::$current) || $force) {
            // Get environment variable (if set and valid)
            $releaseStage = trim(getenv('RELEASE_STAGE'));
            $releaseStage = in_array($releaseStage, $this->getAll()) ? $releaseStage : null;

            // If environment variable not set/valid, try to detect environment by url or path
            $releaseStage = $releaseStage ?: $this->determineFromPath();

            $releaseStage = $releaseStage ?: $this->detectAppServer();

            // If environment variable still not set, assume we are in production!
            $releaseStage = $releaseStage ?: self::PRODUCTION;

            self::$current = $releaseStage;
        }

        return self::$current;
    }
121931
public function getLowFF(bool $force = false): int
    {
        if ($force || $this->isOver32()) {
            return 0xFFFFFFFF;
        }
        return $this->getLow32();
    }
692607
public function init($force = false)
    {
        $flockFactory = new Factory(new FlockStore());

        $lock = $flockFactory->createLock('propel-cache-generation');

        // Acquire a blocking cache generation lock
        $lock->acquire(true);

        try {
            if ($force) {
                (new Filesystem())->remove($this->getPropelCacheDir());
            }

            if (!file_exists($this->getTheliaDatabaseConfigFile())) {
                return false;
            }

            $this->buildPropelConfig();

            $this->buildPropelInitFile();
            require $this->getPropelInitFile();

            $theliaDatabaseConnection = Propel::getConnection('thelia');
            $this->schemaLocator->setTheliaDatabaseConnection($theliaDatabaseConnection);

            $this->buildPropelGlobalSchema();

            $this->buildPropelModels();
            $this->registerPropelModelLoader();

            $theliaDatabaseConnection->setAttribute(ConnectionWrapper::PROPEL_ATTR_CACHE_PREPARES, true);

            if ($this->debug) {
                // In debug mode, we have to initialize Tlog at this point, as this class uses Propel
                Tlog::getInstance()->setLevel(Tlog::DEBUG);

                Propel::getServiceContainer()->setLogger('defaultLogger', Tlog::getInstance());
                $theliaDatabaseConnection->useDebug(true);
            }
        } catch (\Throwable $th) {
            $fs = new Filesystem();
            $fs->remove(THELIA_CACHE_DIR . $this->environment);
            $fs->remove($this->getPropelModelDir());
            throw $th;
        } finally {
            // Release cache generation lock
            $lock->release();
        }

        return true;
    }
552344
public function getAdminUser($force = false) {

        if ($this->nb_admin_user === null || $force) {
            $this->nb_admin_user = null;
            if ($this->isValueNumeric('nb_server_admin_user_id')) {
                $nb_user = new CNabuUser($this->getAdminUserId());
                if ($nb_user->isFetched()) {
                    $this->nb_admin_user = $nb_user;
                }
            }
        }

        return $this->nb_admin_user;
    }
384627
public function read($force = false)
	{
		// initialize the session
		$this->data = array();
		$this->keys = array();
		$this->flash = array();
		$this->record = null;

		// get the session cookie
		$cookie = $this->_get_cookie();

		// if a cookie was present, find the session record
		if ($cookie and ! $force and isset($cookie[0]))
		{
			// read the session record
			$this->record = \DB::select()->where('session_id', '=', $cookie[0])->from($this->config['table'])->execute($this->config['database']);

			// record found?
			if ($this->record->count())
			{
				$payload = $this->_unserialize($this->record->get('payload'));
			}
			else
			{
				// try to find the session on previous id
				$this->record = \DB::select()->where('previous_id', '=', $cookie[0])->from($this->config['table'])->execute($this->config['database']);

				// record found?
				if ($this->record->count())
				{
					$payload = $this->_unserialize($this->record->get('payload'));
				}
				else
				{
					// cookie present, but session record missing. force creation of a new session
					logger('DEBUG', 'Error: Session cookie with ID "'.$cookie[0].'" present but corresponding record is missing');
					return $this->read(true);
				}
			}

			if ( ! isset($payload[0]) or ! is_array($payload[0]))
			{
				logger('DEBUG', 'Error: not a valid db session payload!');
			}
			elseif ($payload[0]['updated'] + $this->config['expiration_time'] <= $this->time->get_timestamp())
			{
				logger('DEBUG', 'Error: session id has expired!');
			}
			elseif ($this->config['match_ip'] and $payload[0]['ip_hash'] !== md5(\Input::ip().\Input::real_ip()))
			{
				logger('DEBUG', 'Error: IP address in the session doesn\'t match this requests source IP!');
			}
			elseif ($this->config['match_ua'] and $payload[0]['user_agent'] !== \Input::user_agent())
			{
				logger('DEBUG', 'Error: User agent in the session doesn\'t match the browsers user agent string!');
			}
			else
			{
				// session is valid, retrieve the payload
				if (isset($payload[0]) and is_array($payload[0])) $this->keys  = $payload[0];
				if (isset($payload[1]) and is_array($payload[1])) $this->data  = $payload[1];
				if (isset($payload[2]) and is_array($payload[2])) $this->flash = $payload[2];
			}
		}

		return parent::read();
	}
601507
public function isOffline( $force = FALSE ){
		if( $this->status === self::STATUS_UNKNOWN || $force )
			$this->check();
		return $this->status === self::STATUS_OFFLINE;
	}