非递归得到 层级树形结构的 多维数组
@param array $config [ treeData => array ,field => 'id ,pid ,name','limit' => '' ]
@param bool 是否保留数组 默认false不保留
@return bool 是否直接返回树形层级的数组 默认false
@throws Exception
510849
public static function get_tree_array($config = [] ,$keep_array = false ,$return_tree_array = false){
        $field = explode(',',$config['field']);

        if(!isset($field[1]))throw new Exception('缺少父级关系字段 比如:parentid');

        //如果有 数据直接传进来 则直接使用数据
        if(isset($config['treeData']) )
        {
            if(!count($config['treeData'])) return [];
            $arr = $config['treeData'];
        }
        else
        {
            $sql = 'show tables like \''.config('database.prefix').$config['table'].'\' ';
            $flag = Db::query($sql);
            //表不存在返回空数组
            if(!count($flag))return [];

            //表存在的情况下
            //db::name($config['table'])->value();
            if(!isset($config['field']) || strlen($config['field']) == 0) throw new \Exception('field 不能为空');

            $field = explode(',' ,$config['field']);

            $sql = 'select COUNT(*) as num from information_schema.columns WHERE table_name = "'.config('database.prefix').$config['table'].'" and column_name= "'.$field[1].'" ';
            $flag = Db::query($sql);

            //查看 关系字段是否存在，不存在 直接返回空 数组
            //解决 当生成方案 是normal 转 category 的时候，需要对自己的表新增层级关系的时候
            if($flag[0]['num'] == 0)return [];

            $arr = Db::name($config['table'])
                ->field($config['field'].',path,listorder')
                ->where(isset($config['where']) ? $config['where'] : '')
                ->limit( (isset($config['limit']) && $config['limit'] > 0) ?  $config['limit'] : '')
                ->select();
            if(!count($arr)) return [];

        }
        //创建初始化数组
        foreach($arr as $k => $v){
            //解析参数
            if(isset($v['params']) && strlen($v['params']) && strpos($v['params'] ,'=')){
                $arr = explode('&',$v['params']);
                $arg = [];
                foreach($arr as $sk => $sv){
                    $tem = explode('=',$sv);
                    $arg[trim($tem[0])] = trim($tem[1]);
                }
                $v['params'] = $arg;
            }
            $tree[ $v[ $field[0] ] ] = $v;
            $tree[ $v[ $field[0] ] ]['son'] = [];
        }
        //引用
        foreach($tree as $sk => $sv){
            //自动生成层级关系 //查找的数据 可能上级的元素不存在
            if($sv[ $field[1] ] != 0 && isset($tree[ $sv[$field[1]] ])){
                //传值引用
                $tree[ $sv[ $field[1] ] ]['son'][] = &$tree[$sk];
            }
        }


        $true_tree = [];
        //剔除多余元素
        foreach($tree as $k => $v){
            //存储上级不存在的数组
            if(!isset($tree[ $v[$field[1]] ])){
                $true_tree[$k] = $v;
            }
        }
        sort($true_tree);

        //对tree 进行排序，默认排序字段是 listorder
        $true_tree = self::tree_array_sort($true_tree);

        //如果要返回树形数组 则排序后直接返回
        if($return_tree_array == true)  return $true_tree;

        //树形数组 转换成 一维数组 用于 select, table
        $arr = self::tree_to_array($true_tree ,$config['field'] ,$keep_array);

        if($keep_array){ //name值保留数组的层级关系，下标从新从0开始

            $i = 0;$table_arr = [];
            foreach($arr as $k => $v){
                unset($v['son']); //删除无用的son元素
                $table_arr[$i] = $v;
                $i++;
            }

            return $table_arr;
        }else{
            return $arr;
        }


    }
544028
public function connect($config = array())
    {
        // TODO: Implement connect() method.
        if (isset($config['database']['cache'])) {
            $configCache = $config['database']['cache'];
            $this->conn = new \Memcache();
            if ($this->conn->connect($configCache['host'], $configCache['port'], $configCache['timeout'])) {
                $this->connected = true;
                return true;
            }
        }
        return false;
    }
794634
public static function setConfig($config = [])
    {
        if (!is_array($config)) {
            return false;
        }
        self::$config = array_merge(self::$config, $config);
        return true;
    }
191004
public function checkArrayOfType(array $config)
    {
        if (\count($config) === 1 && isset($config[0])) {
            $type = $this->createType($config[0]);
            return $this->createArrayOfType($type);
        }
        return null;
    }
1013204
protected function setup(array $config = [])
    {
        if (!isset($config['data_provider'])) {
            throw new Exception(translate('{data_provider} must be a DatapPovider objetc'), 500, Exception::BADARGUMENTS);
        } elseif (isset($config['data_provider']) && !($config['data_provider'] instanceof DataProviderInterface)) {
            throw new Exception(translate('{data_provider} must be a DatapPovider objetc'), 500, Exception::BADARGUMENTS);
        }

        if (!isset($config['columns'])) {
            throw new Exception(translate('{columns} must be an array type Column[]'), 500, Exception::BADARGUMENTS);
        }

        parent::setup($config);

        $this->setupColumns();
    }
1202924
public function addFieldsFromConfig(array $config)
    {
        $i = 1;
        foreach ($config as $name => $field) {
            if (is_numeric($name) && !isset($field[$name]['type'])) {
                $fields = [];
                foreach ($field as $n => $f) {
                    $fields[$n] = Fields::create($n, $f);
                }
                if ($i > 1) {
                    $this->fieldsets[$this->current]->createGroup();
                }
                $this->fieldsets[$this->current]->addFields($fields);
                $i++;
            } else {
                $this->addField(Fields::create($name, $field));
            }
        }
        return $this;
    }
1022632
public function check(array $config): bool
    {
        try {
            return $this->filesystem->isDirectory(public_path('storage'));
        } catch (\Exception $e) {
            return false;
        }
    }
469162
final public static function setConfigDefault(array $config = [])
    {
        $calledClass = get_called_class();

        if (!isset(self::$loadedConfigSet[$calledClass])) {
            static::$config = $config;
        } else {
            self::$loadedConfigSet[$calledClass] = array_merge(self::$configDefault, $config);
        }

        return true;
    }
971390
protected function _assignRole($config)
    {
        if (!is_array($config)) {
            return false;
        }
        if (!$name = ArrayHelper::getValue($config, 'name')) {
            return false;
        }
        if (!$child = ArrayHelper::getValue($config, 'child')) {
            return false;
        }
        if (!$role = \Yii::$app->authManager->getRole($name)) {
            return false;
        }
        if ($childRoles = ArrayHelper::getValue($child, 'roles')) {
            if ($childRoles) {
                foreach ($childRoles as $name) {
                    if ($roleChild = \Yii::$app->authManager->getRole($name)) {
                        try {
                            \Yii::$app->authManager->addChild($role, $roleChild);
                            $this->stdout("\t\tassign child role: " . $name . ' - success' . "\n", Console::FG_GREEN);
                        } catch (\Exception $e) {
                            //$this->stdout(' - already exist'. "\n");
                        }
                    }
                }
            }
        }
        if ($childPermissions = ArrayHelper::getValue($child, 'permissions')) {
            if ($childPermissions) {
                foreach ($childPermissions as $name) {
                    if ($permissionChild = \Yii::$app->authManager->getPermission($name)) {
                        try {
                            \Yii::$app->authManager->addChild($role, $permissionChild);
                            $this->stdout("\t\tassign child permission: " . $name . " - success" . "\n",
                                Console::FG_GREEN);
                        } catch (\Exception $e) {
                            //$this->stdout(' - already exist'. "\n");
                        }
                    }
                }
            }
        }
        return $role;
    }
208509
private function setHost(array $config)
    {
        if (!isset($config[self::CONFIG_HOST]) || trim($config[self::CONFIG_HOST]) === "") {
            throw new Exception("Invalid config - host missing.");
        }

        $this->host = trim($config[self::CONFIG_HOST]);
    }
229096
public function setConfig(array $config = [])
    {
        // 设置App Key
        $this->appKey = isset($config['appKey']) ? $config['appKey'] : '';

        // 设置App Secret
        $this->appSecret = isset($config['appSecret']) ? $config['appSecret'] : '';

        // 沙箱环境
        $this->sandbox = isset($config['sandbox']) ? (bool)$config['sandbox'] : false;

        // 使用HTTPS
        $this->secure = isset($config['secure']) ? (bool)$config['secure'] : false;

        return $this;
    }
1186484
public static function instance($config = [], $name = false)
    {
        if (false === $name) {
            $name = md5(serialize($config));
        }

        if (true === $name || !isset(self::$instance[$name])) {
            // 解析连接参数 支持数组和字符串
            $options = self::parseConfig($config);

            if (true === $name) {
                $name = md5(serialize($config));
            }
            self::$instance[$name] = new static($options);
        }

        return self::$instance[$name];
    }
1149307
public static function getInstance(array $config = []) {
        // If element has no name
        if (!isset($config['name'])){
            throw new \Exception("You have to set the name of the field", 1);
        }
        if(!isset($config['class'])){
            $config['class'] = Text::className();
        }
        return parent::getInstance($config);
	}
364569
public function setConfig(array $config)
    {
        $this->config = $config;
        $this->senderID = $this->config['default_sender'];

        // The user may have called setConfig() manually,
        // and the array may have missing arguments.
        // So, we're checking whether they are set, and filling them if not set
        // Critical ones will throw exceptions, non-critical ones will set default values
        if (!isset($this->config['auth'])) {
            throw new \Exception($this->lang['exceptions']['0']);
        } else {
            if (!isset($this->config['auth']['username']) || !isset($this->config['auth']['password'])) {
                throw new \Exception($this->lang['exceptions']['1']);
            }
        }
        if (!isset($this->config['default_sender'])) {
            throw new \Exception($this->lang['exceptions']['2']);
        }
        if (!isset($this->config['queue'])) {
            $this->config['queue'] = false;
        }
        if (!isset($this->config['charset'])) {
            $this->config['charset'] = 'default';
        }
        if (!isset($this->config['append_unsubscribe_link'])) {
            $this->config['append_unsubscribe_link'] = false;
        }
        return $this;
    }
254316
public function check(array $config): bool
    {
        $this->paths = Collection::make(Arr::get($config, 'directories', []));

        $this->paths = $this->paths->reject(function ($path) {
            return $this->filesystem->isWritable($path);
        });

        return $this->paths->isEmpty();
    }
530455
private function _belongsTo(array $config): Record
    {
        //配置信息
        $tableClass = $config['table'];
        $primaryKey = $config['primaryKey'];//父表主键
        $foreignKey = $config['foreignKey']; //本表外键

        //取本表外键的值
        $foreignValue = $this->$foreignKey;

        /**
         * 父对象表
         * @var $tableInstance Table
         */
        $tableInstance = $tableClass::instance();

        //在父对象表中查询关联记录
        $row = $tableInstance->row('*', [$primaryKey => $foreignValue]);

        //返回父表行记录对象
        $recordClass = 'R' . substr($tableClass, 1);
        return new $recordClass($row->toArray());
    }
1224131
protected function doSetup($config = array())
    {
        // Catch the configuration file path
        if (isset($config[self::CONFIG_KEY_FILE_PATH])) {
            $this->configFilePath = $config[self::CONFIG_KEY_FILE_PATH];
        } else {
            // Also consider throwing an exception here instead
            // of failing silently
            return $config;
        }

        // Catch the context
        if (isset($config[ConfigInterface::KEY_CONTEXT])) {
            $this->context = $config[ConfigInterface::KEY_CONTEXT];
        }

        return $this->readConfigurationFiles();
    }