yohns/filewriter
最新稳定版本:0.1.1
Composer 安装命令:
composer require yohns/filewriter
包简介
File writing utility for PHP
README 文档
README
Overview
The FileWriter class provides a simple and robust utility for writing content to files with various operations like overwriting, appending, and prepending.
Installation
Install via Composer:
composer require yohns/filewriter
Requirements
- PHP 7.4+
- Ext-fileinfo recommended
Usage Examples
Basic File Writing
use Yohns\Util\FileWriter; // Create a new FileWriter instance $fileWriter = new FileWriter('path/to/your/file.txt'); // Overwrite file content $fileWriter->overwrite("Hello, world!\n"); // Append to file $fileWriter->append("Additional content\n"); // Prepend to file $fileWriter->prepend("Initial content\n");
Handling File Operations
$fileWriter = new FileWriter('logs/app.log'); // Safely write content, with error handling if (!$fileWriter->append("Log entry: " . date('Y-m-d H:i:s') . "\n")) { // Handle writing error error_log("Could not write to log file"); }
Features
- Automatic directory creation
- File creation if not exists
- Overwrite, append, and prepend operations
- File locking to prevent race conditions
Error Handling
Methods return boolean values:
true: Operation successfulfalse: Operation failed
License
MIT License
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-22