sentgine / file
文件系统操作的一个简单封装。
v1.1.1
2024-07-01 08:53 UTC
Requires
- php: ^8.1
README
File是一个PHP库,它提供了一个简单的文件系统操作封装。
功能
- 创建、读取、更新和删除文件。
- 如果不存在,则创建目录。
- 在源文件中替换占位符并将修改后的内容写入目标文件。
- 递归删除目录及其所有内容。
要求
- PHP 8.0 或更高版本。
安装
您可以通过运行以下命令使用Composer安装此包:
composer require sentgine/file:^1.0
Filesystem的示例用法
基本用法
use Sentgine\File\Filesystem; // Create a new instance of the Filesystem class $fileSystem = new Filesystem(); // Set source and destination files $fileSystem->setSourceFile('path/to/source/file.txt') ->setDestinationFile('path/to/destination/file.txt'); // Read content from the source file $content = $fileSystem->read(); // Update content in the destination file $fileSystem->update('New content'); // Delete the destination file $fileSystem->delete();
replaceContent的用法
use Sentgine\File\Filesystem; // Create a new instance of the Filesystem class $fileSystem = new Filesystem(); // Get the content of the file.text file $content = $filesystem->setSourceFile('/source/directory/file.text')->read(); // Create a new directory if it doesn't exist $filesystem->createDirectory('/source/new_directory'); // Write the content to the Controller file $filesystem->setDestinationFile('/source/new_directory/new_file.text')->create($content); // Replace the content of the destination file $filesystem->replaceContent( replacements: [ 'placeholder1' => 'replacement1', 'placeholder2' => 'replacement2', ] );
目标文件(path/to/source/file.txt)应包含格式为 {{ placeholder }} 的占位符,如下例所示
Hello {{ placeholder1 }},
This is a sample file with placeholders. Here is the value of placeholder2: {{ placeholder2 }}.
Thank you!
变更日志
有关更改详情,请参阅CHANGELOG文件。
安全
如果您发现任何与安全相关的问题,请通过sentgine@gmail.com 发送电子邮件,而不是使用问题跟踪器。
鸣谢
File 由Adrian Navaja开发和维护。
- 在YouTube上查看一些酷炫的教程和内容!
- 在Twitter(前身为X)上关注我的最新推文和更新!
- 在LinkedIn上以更专业的方式与我联系!
- 有关我的更多信息和工作,请访问我的网站:sentgine.com。
许可证
MIT许可证(MIT)。有关更多信息,请参阅LICENSE文件。