'.php', 'json' => '.json', 'object'=> '.data', ]; /** * 写入配置 * @param string $filename 文件名 * @param mixed $data 数据 * @param string $type 数据类型 * @param bool $absolutePath 绝对路径 * @return bool|int */ public static function set(string $filename, $data, string $type = 'array', bool $absolutePath = false) { if (empty($filename)) { return false; } clearstatcache(); if ($absolutePath) { $dir = dirname($filename); is_dir($dir) or mkdir($dir, 0777, true); } $file_name = $absolutePath ? $filename : static::createFilePath($filename, $type); if (file_exists($file_name)) { chmod($file_name, 0777); } switch (strtolower($type)) { case 'object': $str = serialize($data); break; case 'json': $str = json_encode($data, JSON_UNESCAPED_UNICODE); break; case 'array': $str = '