数据库连接参数解析
@access private
@param mixed $config
@return array
171988
private static function parseConfig($config)
    {
        if (empty($config)) {
            $config = Db::getConfig();
        } elseif (is_string($config) && false === strpos($config, '/')) {
            // 支持读取配置参数
            $config = Db::getConfig($config);
        }

        if (is_string($config)) {
            return self::parseDsnConfig($config);
        } else {
            return $config;
        }
    }
520126
static public function instance($config): CacheBase
    {
        //防止单词大小写错误
        $config = strtolower(trim($config));

        //多例句柄
        static $instances = [];

        //如果尚未实例化,则创建
        if (!isset($instances[$config])) {
            $instances[$config] = self::createInstance($config);
        }

        //返回实例
        return $instances[$config];
    }
1220424
public function getRequiredFiles($config)
    {
        $files = [];
        
        foreach ($config as $key => $name) {
            
            if (is_numeric($key) && is_string($name)) {
                
                $files[] = $name;
                
            } elseif (is_numeric($key) && is_array($name)) {
                
                foreach ($name as $module => $file) {
                    $files[] = sprintf('%s: %s', $module, $file);
                }
                
            } elseif (!is_numeric($key) && is_array($name)) {
                
                foreach ($name as $file) {
                    $files[] = sprintf('%s: %s', $key, $file);
                }
                
            }
            
        }
        
        return $files;
    }
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];
    }
441343
public function loadConfig($config = null)
    {
        $config =
            !is_null($config) || !file_exists($this->configFile)
                ? $this->setConfigFile($this->getConfigFile($config))
                : $this->configFile;

        return $this->loadToLaravelConfig($config);
    }
481238
private function file($config = array()) {
        $filePath = $config['filePath'];

        if (!file_exists($filePath)) {
            Filesystem::mkdir($filePath);
        }
        //初始化缓存路径
        CacheManager::setup(array(
            "path" => isset($filePath) ? $filePath : sys_get_temp_dir(), // or in windows "C:/tmp/"
        ));
        CacheManager::CachingMethod("phpfastcache");

        //初始化缓存
        $InstanceCache = CacheManager::Files();

        return $InstanceCache;
    }
948438
public function listReleased(array $config = [])
    {
        try {
            return $this->privateListReleased($config);
        } catch (\Exception $e) {
            if ($e instanceof RequestException) {
                /*
                 * ListReleased and List return 404 error if no results are found, even for successful API calls,
                 * So if result status is 404, transform to 200 with empty results.
                 */
                /** @var ResponseInterface $response */
                $response = $e->getResponse();
                if (strval($response->getStatusCode()) === '404') {
                    return [
                        'statusCode' => 200,
                        'list' => [
                            'meta' => [
                                'totalCount' => 0
                            ]
                        ],
                        'elements' => []
                    ];
                }
                throw $e;
            } else {
                throw $e;
            }
        }
    }
278917
public function dump(Config $config)
    {
        $ignored = [
            'commands',
        ];

        $ignored = array_fill_keys($ignored, true);

        $output = '';

        $a = [];
        foreach ($config as $key => $value) {
            if (isset($ignored[$key])) {
                continue;
            }

            if ('uses' === $key) {
                $value = array_keys($value);
                $key = 'extensions';
            }

            $a[$key] = $value;
        }

        ksort($a);

        foreach ($a as $key => $value) {
            if ('_' === $key{0}) {
                continue;
            }
            $output .= sprintf(
                'export %s="%s"%s',
                $this->formatEnvironmentVariableName($key),
                $this->formatEnvironmentVariableValue($value),
                PHP_EOL
            );
        }

        return $output;
    }
989202
public function getQueryData(array $config = []) : array
    {
        if (empty($config)) {
            return [];
        }

        $resultSet = [];

        if (!empty($config['info']['finder'])) {
            $table = $config['info']['model'];

            $finder = $config['info']['finder']['name'];
            $options = Hash::get($config, 'info.finder.options', []);

            $resultSet = TableRegistry::get($table)->find($finder, $options);
        }

        if (empty($config['info']['finder']) && !empty($config['info']['query'])) {
            $resultSet = ConnectionManager::get('default')
                ->execute($config['info']['query'])
                ->fetchAll('assoc');
        }

        $columns = explode(',', $config['info']['columns']);

        $result = [];
        foreach ($resultSet as $item) {
            $row = [];
            foreach ($item as $column => $value) {
                if (in_array($column, $columns)) {
                    $row[$column] = $value;
                }
            }
            array_push($result, $row);
        }

        return $result;
    }
499444
public function prepareMenuConfig($config): array
    {
        if (is_string($config)) {
            Configure::load($config);
            $config = Configure::read($this->_defaultConfig['configKey']);
        }

        foreach ($config as $mainItem => &$mainData) {
            if (isset($mainData['url']) && !$this->Auth->urlAllowed($mainData['url'])) {
                unset($config[$mainItem]);
                continue;
            }

            if (!empty($mainData['children']) && !$this->_hasAllowedChildren($mainData['children'])) {
                unset($config[$mainItem]);
                continue;
            }

            if (isset($mainData['shouldRender']) && !$mainData['shouldRender']()) {
                unset($config[$mainItem]);
                continue;
            }

            $this->_isItemActive($mainData);

            $visibleChildCount = 0;
            if (!empty($mainData['children'])) {
                $activeChildCount = 0;
                $visibleChildCount = count($mainData['children']);
                foreach ($mainData['children'] as $subItem => &$subData) {
                    if (isset($subData['shouldRender']) && !$subData['shouldRender']()) {
                        unset($mainData['children'][$subItem]);
                        $visibleChildCount--;
                        continue;
                    }

                    $allowed = (!isset($subData['url']) || (isset($subData['url']) && $this->Auth->urlAllowed($subData['url'])));

                    if ($allowed) {
                        if ($this->_isItemActive($subData)) {
                            $activeChildCount++;
                        }
                    } else {
                        $visibleChildCount--;
                    }
                }
                unset($subData);

                if ($activeChildCount > 1) {
                    foreach ($mainData['children'] as $subItem => &$subData) {
                        $subData['active'] = false;
                    }
                    unset($subData);
                }
            }

            // if the main item has no displayable children, remove it.
            if ($visibleChildCount === 0 && isset($config['children']) && count($config['children']) > 0) {
                unset($config[$mainItem]);
            }
        }
        unset($mainData, $subData);

        //set active status
        if (empty($this->_controllerActive)) {
            $this->_controllerActive = $this->_currentUrl['controller'];
        }
        foreach ($config as &$mainData) {
            $mainData['active'] = '';
            if (!empty($this->_actionActive) && !empty($mainData['url'])) {
                if ($mainData['url']['controller'] == $this->_controllerActive && $mainData['url']['action'] == $this->_actionActive) {
                    $mainData['active'] = true;
                }
            } elseif (!empty($mainData['url']) && $mainData['url']['controller'] == $this->_controllerActive) {
                $mainData['active'] = true;
            }
            if (!empty($mainData['children'])) {
                foreach ($mainData['children'] as &$subData) {
                    $subData['active'] = '';
                    if (!empty($this->_actionActive) && !empty($subData['url'])) {
                        if ($subData['url']['controller'] == $this->_controllerActive && $subData['url']['action'] == $this->_actionActive) {
                            $subData['active'] = true;
                            $mainData['active'] = true;
                        }
                    } elseif (!empty($subData['url']) && $subData['url']['controller'] == $this->_controllerActive) {
                        $mainData['active'] = true;
                    }
                }
            }
        }

        return $config;
    }
718396
public static function configure(array $config)
    {
        foreach ($config as $key => $value) {
            // 子类处理
            if (is_array($value)) {
                if (array_values($value) === $value) {
                    // 非关联数组
                    foreach ($value as $subNumberKey => $subValue) {
                        if (isset($subValue['ref'])) {
                            $config[$key][$subNumberKey] = self::configure($subValue);
                        }
                    }
                } else {
                    // 引用依赖
                    if (isset($value['ref'])) {
                        $config[$key] = self::configure($value);
                    }
                    //组件
                    if (isset($value['component'])) {
                        $name         = $value['component'];
                        $config[$key] = self::$app->$name;
                    }
                }
            } elseif ($key === 'ref') {
                // 实例化
                return \Mix\Core\Bean::newInstance($config['ref']);
            }
        }
        return $config;
    }
616307
public function load(Config $config)
    {
        $parsed = [];

        if ($this->isFile($this->getPath())) {
            $parsed = $this->parse($this->fetch($this->getPath()));
        }

        if (!is_array($parsed)) {
            $parsed = [];
        }

        $this->apply($parsed, $config);
    }
1179842
private function getConfigsForUriTemplates($config)
    {
        $configs = [$config];

        if ($config['additionalBindings']) {
            foreach ($config['additionalBindings'] as $additionalBinding) {
                $configs[] = $additionalBinding + $config;
            }
        }

        return $configs;
    }
1328135
public static function config($config = null) {
		$defaults = ['scope' => null];

		if (is_array($config)) {
			foreach ($config as $i => $item) {
				$config[$i] += $defaults;
			}
		}
		return parent::config($config);
	}
732005
public function listAll(array $config = [])
    {
        try {
            return $this->privateList($config);
        } catch (\Exception $e) {
            if ($e instanceof RequestException) {
                /*
                 * ListReleased and List return 404 error if no results are found, even for successful API calls,
                 * So if result status is 404, transform to 200 with empty results.
                 */
                /** @var ResponseInterface $response */
                $response = $e->getResponse();
                if (strval($response->getStatusCode()) === '404') {
                    return [
                        'statusCode' => 200,
                        'list' => [
                            'meta' => [
                                'totalCount' => 0
                            ]
                        ],
                        'elements' => []
                    ];
                }
                throw $e;
            } else {
                throw $e;
            }
        }
    }
486433
public function load(Config $config)
    {

        $phpExtraPhpunitOpts = [];
        $xdebugSoLocation    = $this->getXdebugService()->findXdebugSoPath();

        if (null !== $xdebugSoLocation) {
            $phpExtraPhpunitOpts[] = sprintf('-d zend_extension=%s', $xdebugSoLocation);
        }

        $config['phpunit_conf_dir']       = $this->getPhpunitService()->getPhpunitXmlDir([__DIR__.'/../Resources/phpunit']);
        $config['php_extra_phpunit_opts'] = join(' ', $phpExtraPhpunitOpts);

        $config->setDefaultItem('commands', '_test', "#test,execute all tests");
        $config->setDefaultItem('commands', '_test-unit', "#test-unit,execute unit tests");
        $config->setDefaultItem('commands', '_test-group', "#test-group");
        $config->setDefaultItem('commands', '_test-integ', "#test-integ");
        $config->setDefaultItem('commands', '_test-loop', "#test-loop");
        $config->setDefaultItem('commands', '_test-unit-loop', "#test-unit-loop");
        $config->setDefaultItem('commands', '_test-unit', "#test-unit");
        $config->setDefaultItem('commands', 'tu', "#test-unit");
        $config->setDefaultItem('commands', 'ti', "#test-integ");
        $config->setDefaultItem('commands', 'tg', "#test-group");
        $config->setDefaultItem('commands', 'tul', "#test-unit-loop");
    }
915688
private function extractGuzzleConfig($config)
    {
        foreach (ConfigUtils::$GUZZLE_CONFIG_KEYS as $guzzleOption) {
            if (array_key_exists($guzzleOption, $config)) {
                $this->guzzleConfig[$guzzleOption] = $config[$guzzleOption];
                unset($config[$guzzleOption]);
            }
        }

        return $config;
    }