创建一个有内容的文件
@param      $filePath
@param      $content
@param bool $overwrite
@author : evalor <master@evalor.cn>
@return bool
554755
static function createFile($filePath, $content, $overwrite = true)
    {
        if (static::touchFile($filePath, $overwrite)) {
            return (bool)file_put_contents($filePath, $content);
        } else {
            return false;
        }
    }
637109
static function copyDirectoryContents($dir, $target, $overwrite = true, $base = '')
	{
		$dir = rtrim($dir, "\\/ ").'/';
		$target = rtrim($target, "\\/ ").'/';
		$report = ['error'=>[],'copied'=>[]];

		if (!static::checkAndOrCreateDir($target, true, 0777)) {
			$report['error']['permission'] = $taget;
			return $report;
		}

		foreach (scandir($dir) as $file) {
			if ($file == '.' || $file == '..') {
				continue;
			}

			if (is_dir($dir.$file)) {
				if (!static::checkAndOrCreateDir($target.$file, true, 0777)) {
					$report['error']['permission'] = $taget.$file;
					return $report;
				} else {
					$copy = static::copyDirectoryContents($dir.$file, $target.$file, $overwrite, $base);
					$report = array_merge_recursive($report, $copy);
				}
			} elseif (is_file($dir.$file)) {
				if ($overwrite === false && file_exists($target.$file)) {
					$report['error']['overwrite'][] = str_replace($base.'/', '', $target.$file);
					continue;
				}
				if (!copy($dir.$file, $target.$file)) {
					$report['error']['permission'] = $target.$file;
					return $report;
				} else {
					$report['copied'][] = str_replace($base.'/', '', $target.$file);
				}
			}
		}
		return $report;
	}
311792
public static function putContents(string $filename, $data, bool $override = false)
    {
        $dirname = dirname($filename);
        if (!file_exists($dirname)) {
            mkdir($dirname, 0700, true);
        }
        if (!file_exists($filename) || $override) {
            $result = file_put_contents($filename, $data);
        } else {
            throw new \Exception("{$filename} is already exists");
        }
        return $result;
    }
655471
public function move($fsPath, string $filePerm, bool $overwrite = true) {
		$fsPath = FsPath::create($fsPath);
		
		foreach ($this->fileListeners as $fileListener) {
			$fileListener->onMove($this, $fsPath, $overwrite);
		}
		
		$this->fileSource->move($fsPath, $filePerm, $overwrite);
		
		if ($this->fileSource->isValid()) {
			$this->fileSource = FileFactory::createFromFs($fsPath, $this->originalName);
		}
	}
327288
static function copyDirectory($source, $target, $overwrite = true)
    {
        $scanResult = static::scanDirectory($source);
        if (!$scanResult) return false;
        if (!is_dir($target)) self::createDirectory($target);

        try {
            $sourceRealPath = realpath($source);
            foreach ($scanResult['files'] as $file) {
                $targetRealPath = realpath($target) . '/' . ltrim(substr($file, strlen($sourceRealPath)), '/');
                static::copyFile($file, $targetRealPath, $overwrite);
            }
            return true;
        } catch (\Throwable $throwable) {
            return false;
        }
    }
207327
public static function create(string $path, string $content = '', bool $overwrite = true): self
    {
        $path = normalize_path($path);

        if (is_file($path) && $overwrite) {
            self::unlink($path);
        }
        if (!is_file($path)) {
            if (is_writeable(dirname($path))) {
                if ($handle = fopen($path, 'w')) {
                    fwrite($handle, $content);
                    fclose($handle);

                    return new static($path);
                }
                throw new FileException('Creating file ('.$path.') failed');
            }
            throw new FileException('Cannot create file, because the directory ('.dirname($path).') is not accessible',
                FileException::NOT_WRITEABLE);
        }
        throw new FileException('Cannot create file, because the file path ('.$path.') already exist', FileException::ALREADY_EXIST);
    }
922336
static function append_file($file_path_and_name, $file_content, $overwrite = false)
    {
        echo ("Appending the file: ".$file_path_and_name.PHP_EOL);
        if ($overwrite) {
            file_put_contents($file_path_and_name, $file_content);
        } else {
            file_put_contents($file_path_and_name, $file_content, FILE_APPEND);
        }
    }
1107598
static function write($filename, $contents, $overwriteExisting = true) {
        if (file_exists($filename) && self::isWritable($filename)) {
            if ($overwriteExisting) unlink($filename);
        }

        file_put_contents($filename, $contents);
    }
738520
public function copy(string $newFilePath, bool $overwrite = true): self
    {
        $newFilePath = normalize_path($newFilePath);

        if ($overwrite || !is_file($newFilePath)) {
            if (copy($this->path, $newFilePath)) {
                return new self($newFilePath);
            }
            throw new FileException('Cannot copy file to the new file path ('.$newFilePath.') for unknown reasons');
        }
        throw new FileException('Cannot copy file, because the new file path ('.$newFilePath.') already exists', FileException::ALREADY_EXIST);
    }
938701
private function loadFromFile($filename, $overwrite = false)
    {
        try {
            $yamlDatas = Yaml::parse(file_get_contents($filename));

            if (is_array($yamlDatas)) {
                if (true === $this->debug) {
                    $this->debug_data[$filename] = $yamlDatas;
                }

                if (self::CONFIG_FILE.'.'.self::EXTENSION === basename($filename) ||
                    self::CONFIG_FILE.'.'.$this->environment.'.'.self::EXTENSION === basename($filename)) {
                    foreach ($yamlDatas as $component => $config) {
                        if (!is_array($config)) {
                            $this->container->get('logger')->error('Bad configuration, array expected, given : '.$config);
                        }
                        $this->setSection($component, $config, $overwrite);
                    }
                } else {
                    $this->setSection(basename($filename, '.'.self::EXTENSION), $yamlDatas, $overwrite);
                }
            }
        } catch (ParseException $e) {
            throw new InvalidConfigException($e->getMessage(), null, $e, $e->getParsedFile(), $e->getParsedLine());
        }
    }
39804
static function touchFile($filePath, $overwrite = true)
    {
        if (file_exists($filePath) && $overwrite == false) {
            return false;
        } elseif (file_exists($filePath) && $overwrite == true) {
            if (!unlink($filePath)) {
                return false;
            }
        }
        $aimDir = dirname($filePath);
        if (self::createDirectory($aimDir)) {
            try {
                return touch($filePath);
            } catch (\Throwable $throwable) {
                return false;
            }
        } else {
            return false;
        }
    }
1352383
public function encodeFile( $fileName, $overwrite = FALSE )
	{
		if( !file_exists( $fileName ) )
			return FALSE;
		if( $this->isEncoded( $fileName ) )
			return TRUE;
		$php		= FS_File_Reader::load( $fileName );
		$code		= $this->encode( $php );
		$dirname	= dirname( $fileName );
		$basename	= basename( $fileName );
		$target		= $dirname."/".$this->filePrefix.$basename.$this->fileSuffix;
		if( $fileName == $target && !$overwrite )
			throw new RuntimeException( 'File cannot be overwritten, use Parameter "overwrite".' );
//		copy( $fileName, "#".$fileName );
		return (bool) FS_File_Writer::save( $target, $code );
	}
486091
private function loadFromBaseDir($basedir, $overwrite = false)
    {
        foreach ($this->getYmlFiles($basedir) as $filename) {
            $this->loadFromFile($filename, $overwrite);
        }
    }
732051
private static function compareContents($filePath, $newContent)
    {
        if (file_exists($filePath)) {
            $currentContent = file_get_contents($filePath);
            return strcmp($currentContent, $newContent) === 0;
        }

        return false;
    }
963154
protected function saveLog($data, $fileName, $override = false)
    {
        file_put_contents($this->directory . DIRECTORY_SEPARATOR . $fileName,
            $data, $override ? 0 : FILE_APPEND);
    }
1097522
public static function writeFile($fileName, $content, $flags = 0)
    {
        if (Coroutine::isIn()) {
            return Coroutine::writeFile($fileName, $content, $flags);
        } else {
            return false !== file_put_contents($fileName, $content, $flags);
        }
    }
812460
public static boolean writeFile(String filePath, String fileContent,
			String encoding) {
		FileOutputStream fout = null;
		FileChannel fcout = null;
		File file = new File(filePath);
		if (file.exists()) {
			file.delete();
		}
		
		try {
			fout = new FileOutputStream(filePath);
			// 获取输出通道
			fcout = fout.getChannel();
			// 创建缓冲区
			// ByteBuffer buffer = ByteBuffer.allocate(1024);
			ByteBuffer buffer = ByteBuffer.wrap(fileContent.getBytes(encoding));
			fcout.write(buffer);
			fout.flush();
		} catch (FileNotFoundException e) {
			LogUtil.writeErrorLog("WriteFile fail", e);
			return false;
		} catch (IOException ex) {
			LogUtil.writeErrorLog("WriteFile fail", ex);
			return false;
		} finally {
			try {
				if (null != fout)
					fout.close();
				if (null != fcout)
					fcout.close();
			} catch (IOException ex) {
				LogUtil.writeErrorLog("Releases any system resources fail", ex);
				return false;
			}
		}
		return true;
	}