读取配置文件

@param string $name 名称
@param string $defaultPrefix 前缀(默认前缀: 'bao-loan')
@param string $fileName 文件名(默认: bao-loan.yml)
@return mixed
@throws ConfigException 文件不存和键不存在都会跑出异常
424930
public static function get($name, $defaultPrefix = 'bao-loan', $fileName = 'bao-loan.yml')
    {
        return self::getInstance()->getValue($name, $defaultPrefix, $fileName);
    }
1202850
function makeDefaultNamePair(config, obj, packageName) {
  const regex = /^default/;
  let nam = "";
  let result = [];

  for (let defaultName of Object.keys(config)) {
    if (regex.test(defaultName)) {
      nam = defaultName.substr(7, 1).toLowerCase() + defaultName.substr(8); //defaultを除いて先頭文字を小文字にする
      if (obj.hasOwnProperty(nam)) {
        result.push([nam, defaultName]);
      } else {
        throw new Error(`${packageName}: makeDefaultNamePair is failed. [${nam}, ${defaultName}]`);
      }
    }
  }
  return result;
}
524737
public static function get(string $name, $default = null)
    {
        $value = getenv($name);

        if ($value === false) {
            return static::value($default);
        }

        switch (strtolower($value)) {
            case 'true':
            case '(true)':
                return true;

            case 'false':
            case '(false)':
                return false;

            case 'null':
            case '(null)':
                return null;
        }

        return static::sanitise($value);
    }
993977
public function getField($name, $key, $default = null)
    {
        if (array_key_exists($name, $this->fields) && array_key_exists($key, $this->fields[$name])) {
            return $this->fields[$name][$key];
        }
        return $default;
    }
732926
public function getAttribute($name, $default = null)
	{
		if ($this->element instanceof SimpleXMLElement)
		{
			$attributes = $this->element->attributes();

			// Ensure that the attribute exists
			if (property_exists($attributes, $name))
			{
				$value = $attributes->$name;

				if ($value !== null)
				{
					return (string) $value;
				}
			}
		}

		return $default;
	}
261013
protected function getConfig( $name, $default = null )
	{
		$config = $this->getContext()->getConfig();

		switch( $name )
		{
			case 'domains':
				/** controller/jobs/product/export/sitemap/domains
				 * List of associated items from other domains that should be fetched for the sitemap
				 *
				 * Products consist not only of the base data but also of texts, media
				 * files, prices, attrbutes and other details. Those information is
				 * associated to the products via their lists. Using the "domains" option
				 * you can make more or less associated items available in the template.
				 *
				 * @param array List of domain names
				 * @since 2018.07
				 * @category Developer
				 * @category User
				 * @see controller/jobs/product/export/sitemap/container/options
				 * @see controller/jobs/product/export/sitemap/location
				 * @see controller/jobs/product/export/sitemap/max-items
				 * @see controller/jobs/product/export/sitemap/max-query
				 * @see controller/jobs/product/export/sitemap/changefreq
				 */
				return $config->get( 'controller/jobs/product/export/sitemap/domains', $default );

			case 'max-items':
				/** controller/jobs/product/export/sitemap/max-items
				 * Maximum number of products per site map
				 *
				 * Each site map file must not contain more than 50,000 links and it's
				 * size must be less than 10MB. If your product URLs are rather long
				 * and one of your site map files is bigger than 10MB, you should set
				 * the number of products per file to a smaller value until each file
				 * is less than 10MB.
				 *
				 * More details about site maps can be found at
				 * {@link http://www.sitemaps.org/protocol.html sitemaps.org}
				 *
				 * @param integer Number of products per file
				 * @since 2015.01
				 * @category Developer
				 * @category User
				 * @see controller/jobs/product/export/sitemap/container/options
				 * @see controller/jobs/product/export/sitemap/location
				 * @see controller/jobs/product/export/sitemap/max-query
				 * @see controller/jobs/product/export/sitemap/changefreq
				 * @see controller/jobs/product/export/sitemap/domains
				 */
				return $config->get( 'controller/jobs/product/export/sitemap/max-items', 50000 );

			case 'max-query':
				/** controller/jobs/product/export/sitemap/max-query
				 * Maximum number of products per query
				 *
				 * The products are fetched from the database in bunches for efficient
				 * retrieval. The higher the value, the lower the total time the database
				 * is busy finding the records. Higher values also means that record
				 * updates in the tables need to wait longer and the memory consumption
				 * of the PHP process is higher.
				 *
				 * Note: The value of max-query must be smaller than or equal to
				 * {@see controller/jobs/product/export/sitemap/max-items max-items}
				 *
				 * @param integer Number of products per query
				 * @since 2015.01
				 * @category Developer
				 * @see controller/jobs/product/export/sitemap/container/options
				 * @see controller/jobs/product/export/sitemap/location
				 * @see controller/jobs/product/export/sitemap/max-items
				 * @see controller/jobs/product/export/sitemap/changefreq
				 * @see controller/jobs/product/export/sitemap/domains
				 */
				return $config->get( 'controller/jobs/product/export/sitemap/max-query', 1000 );
		}

		return $default;
	}
623154
public function get($name, $default = null)
    {
        try {
            if ($setting = $this->model->where('name', '=', $name)->first()) {
                return $this->castSetting($name, $setting->value);
            }

            return $default;
        } catch (Exception $e) {
            throw new ReadException($e);
        }
    }
1347156
public static function resolveConfigHandler($fileName)
    {
        $configHandler = NULL;

        preg_match("/(\.)([a-z]{3,})/", $fileName, $matches);

        $fileExtension = $matches[2];

        if (!in_array($fileExtension, ConfigConsts::getExtensions())) {
            throw new ConfigException("Not correct config file extension.");
        }

        switch ($fileExtension) {
            case(ConfigConsts::INI):
                $configHandler = new ConfigIniHandler();
                break;
            default:
                throw new ConfigException("Config handler wasn't set.");
        }

        return $configHandler;
    }
714867
public static function getString($name, $default = null)
    {
        if (isset($_GET[$name]) && $_GET[$name] !== '') return self::parseInputToString($_GET[$name]);
        return $default;
    }
980861
public function defaultConfig($name)
    {
        $config = $this->config();
        $default = array_key_exists('default', $config) ? $config['default'] : array();
        if (!array_key_exists($name, $default)) {
            return array();
        }
        return $default[$name];
    }
35679
public function getWithDefault($name, $default)
    {
        $value = NestedArrayUtil::getNestedArrayValue(self::$config, explode('.', $name), $exists);
        if (!$exists) {
            return $default;
        }

        return $value;
    }
968766
private function getValue ($name, $default)
	{
		$parts = explode ('.', $name);
		$file = array_shift ($parts);

		$this->loadFile ($file);

		if (! isset ($this->files[$file])) {
			return $default;
		}
		else {
			$out = $this->files[$file];
			foreach ($parts as $part)
			{
				if (!isset ($out[$part]))
				{
					return $default;
				}
				else {
					$out = $out[$part];
				}
			}
		}

		return $out;
	}
567903
protected function openAppConfig(string $name)
    {
        if (JL::exists(FEnv::get("app.config.file", $name))) {
            return (JL::open(FEnv::get("app.config.file", $name)));
        } else {
            return (null);
        }
    }
567839
public static function bcfg($name, $default = false) {
        if ($name == null) {
            return false;
        } else {
            $val = App::cfg($name, $default);
            if (is_bool($val)) {
                return $val;
            }
            if (empty ($val) || $val == 'false' || $val == '0') {
                return false;
            }

            return true;
        }
    }
1177335
public function get($name = null, $default = null)
    {
        $source = $this->_context->_REQUEST;

        if ($name === null) {
            return $source;
        }

        if (isset($source[$name]) && $source[$name] !== '') {
            $value = $source[$name];

            if (is_array($value) && is_scalar($default)) {
                throw new InvalidValueException(['the value of `:name` name is not scalar', 'name' => $name]);
            }

            if ($default !== null) {
                $type = gettype($default);
                if ($type === 'string') {
                    return (string)$value;
                } elseif ($type === 'integer') {
                    return (int)$value;
                } elseif ($type === 'double') {
                    return (float)$value;
                } elseif ($type === 'boolean') {
                    return (bool)$value;
                } else {
                    return $value;
                }
            } else {
                return $value;
            }
        } else {
            if ($default === null) {
                throw new MissingRequiredFieldsException($name);
            }

            return $default;
        }
    }
735617
public static function get(&$object, $name, $default = null)
    {
        $names = explode('.', $name);
        $result = &$object;
        foreach ($names as $nameItem)
        {
            $type = gettype($result);
            if('array' === $type)
            {
                // 数组
                if (isset($result[$nameItem]))
                {
                    $result = &$result[$nameItem];
                }
                else
                {
                    return $default;
                }
            }
            else if('object' === $type)
            {
                // 对象
                if (isset($result->$nameItem))
                {
                    $result = &$result->$nameItem;
                }
                else
                {
                    return $default;
                }
            }
            else
            {
                return $default;
            }
        }
        if (isset($names[0]))
        {
            return $result;
        }
        else
        {
            return $default;
        }
    }
950080
public static function get($name = '@', $default = false)
	{
		$names = parseCfgName($name);
		if (isset($names[0]))
		{
			$first = array_shift($names);
			$obj = self::getInstance($first);
			if ($obj)
			{
				return $obj->get($names, $default);
			}
			else
			{
				return $default;
			}
		}
		else
		{
			return $default;
		}
	}