Get encoding.

@param string|null $file
@param string $default
@return string
491745
public static function getEncoding($file = null, $default = 'utf-8') {
		if (!function_exists('finfo_open')) {
			return $default;
		}
		$finfo = finfo_open(FILEINFO_MIME_ENCODING);
		$encoding = finfo_file($finfo, $file);
		finfo_close($finfo);
		if ($encoding !== false) {
			return $encoding;
		}
		return $default;
	}
1338472
public function get($key, $default = null)
    {
        if (empty($key)) {
            return $default;
        }

        $parts = explode(".", $key);
        $file = array_shift($parts);

        if (!isset($this->registry[$file])) {
            $this->registry[$file] = $this->discover($file);
        }
        $res = $this->parse($key);

        return is_null($res) ? $default : $res;
    }
784127
public static function deserializeFromFile($file)
  {
    if (file_exists($file))
    {
      $serialized_data = file_get_contents($file);
      return unserialize($serialized_data);
    }
    else return null;
  }
730367
public function decode($key, $default = null)
    {
        $input = $this->get($key, $default);
        if ($input AND is_string($input)) {
            $input = json_decode($input, true);
        }

        return (array)$input;
    }
948471
public static function getStr(string $key, ?string $default = null): ?string
    {
        $value = ini_get($key);

        return $value === false || $value === '' ? $default : $value;
    }
836432
protected function getTypeByFile($file)
  {
    switch (strtolower(pathinfo($file, PATHINFO_EXTENSION))) {
      case 'jpg':
      case 'jpeg':
        $type = IMG_JPG;
        break;
      case 'png':
        $type = IMG_PNG;
        break;
      case 'gif':
        $type = IMG_GIF;
        break;
      default:
        $type = false;
    }

    return $type;
  }
858180
public function build($file = null)
    {
        $prepared = preg_replace_callback('/%.*%/U', function ($m) {
            if ($m[0] === '%phpdoc%') {
                $string = '/**';
                foreach ($this->components as $name => $classes) {
                    $string .= PHP_EOL . ' * @property ' . implode('|', $classes) . ' $' . $name;
                }
                $string .= PHP_EOL . ' */';
                return $string;
            }
            return $m[0];
        }, $this->template);
        if ($file === null) {
            return $prepared;
        }
        return (bool)file_put_contents($file, $prepared);
    }
1141110
public function detectMimeType($file = null) {
		// Attempts to retrieve file info from FINFO
		// If FINFO functions are not available then try to retrieve MIME type from pre-defined MIMEs
		// If MIME type doesn't exist, then try (as a last resort) to use the (deprecated) mime_content_type function
		// If all else fails, just return application/octet-stream
		if (!function_exists('finfo_open')) {
			if (function_exists('mime_content_type')) {
				$type = mime_content_type($file);
				if (!empty($type)) {
					return $type;
				}
			}
			$extension = $this->_getExtension($file);
			$mimeType = $this->getMimeTypeByAlias($extension);
			if ($mimeType) {
				return $mimeType;
			}
			return 'application/octet-stream';
		}
		return $this->_detectMimeType($file);
	}
422204
private function getFullPath(string $file = null): string
	{
		return $this->getBasePath() . $this->path . ($file !== null ? DIRECTORY_SEPARATOR . $file : '');
	}
284335
public function getMimeEncoding(): ?string
	{
		$info = finfo_open(FILEINFO_MIME_ENCODING);

		$encoding = finfo_file($info, $this->getPathname());

		finfo_close($info);

		return $encoding ?: null;
	}
1526
public static function setDefaultEncoding($encoding=null)
    {
        if(!is_null($encoding) && is_string($encoding) && !empty($encoding))
        {
            self::$defaultencoding = $encoding;
        }
        else
        {
            self::$defaultencoding = null;
        }
    }
547642
protected function prepareSeedClass($file)
    {
        $extension = $file->getExtension();
        if ($extension !== 'php') {
            return null;
        }
        return '\\' . str_replace('.' . $extension, '', $file->getFilename());
    }
247634
public static function get($key = null, $default = null)
    {
        // 无参数时获取所有
        if (empty($key)) {
            return self::$_content;
        }

        $key = strtolower($key);
        return Cml::doteToArr($key, self::$_content['normal'], $default);
    }
1324738
public function getMimeType($file = null)
	{
		if (is_file($file))
		{
			$extension = $this->_getExtension($file);

			// Attempts to retrieve file info from FINFO
			// If FINFO functions are not available then try to retrieve MIME type from pre-defined MIMEs
			// If MIME type doesn't exist, then try (as a last resort) to use the (deprecated) mime_content_type function
			// If all else fails, just return application/octet-stream
			if (!function_exists('finfo_open') || in_array($extension, array('docx', 'pptx', 'xlsx')))
			{
				if (array_key_exists($extension, $this->mimeTypes))
				{
					return $this->mimeTypes[$extension];
				}
				else
				{
					if (function_exists('mime_content_type'))
					{
						$type = mime_content_type($file);
						return !empty($type) ? $type : 'application/octet-stream';
					}
					else
					{
						return 'application/octet-stream';
					}
				}
			}
			else
			{
				$finfo = finfo_open(FILEINFO_MIME);
				$MIMEType = finfo_file($finfo, $file);
				finfo_close($finfo);
				return $MIMEType;
			}
		}
		else
		{
			$extension = $this->_getExtension($file);
			if (array_key_exists($extension, $this->mimeTypes))
			{
				return $this->mimeTypes[$extension];
			}
		}
		return '##INVALID_FILE##';
	}
1266607
protected function getMimeType($file)
    {
        $info = finfo_open(FILEINFO_MIME_TYPE);
        $mime = finfo_file($info, $file);
        finfo_close($info);

        return $mime;
    }
560959
public function save($file = null): Language
    {
        if (is_null($file) && is_null($this->file)) {
            throw LanguageException::forFileNotSet();
        }

        if (is_null($file)) {
            $file = $this->file;
        }

        $contents = "<?php //-->\nreturn " . var_export($this->data, true) . ";";
        file_put_contents($file, $contents);

        return $this;
    }
1225106
public function getAcceptableEncodings(?string $default = null): array
	{
		if(!isset($this->acceptableEncodings))
		{
			$this->acceptableEncodings = $this->parseAcceptHeader($this->get('accept-encoding'));
		}

		return $this->acceptableEncodings ?: (array) $default;
	}