satooshi/file-client
Composer 安装命令:
composer require satooshi/file-client
包简介
File reader/writer
关键字:
README 文档
README
FileClient object can read from or write content to a file. And you can handle file read process for every line as you like by passing a callback or a closure to walk() method. This method is intended for database manipulation. For example, you can insert or update record from a read line.
Installation
To install FileClient with Composer just add the following to your composer.json file:
// composer.json { // ... require: { // ... "satooshi/file-client": "dev-master" } }
Then, you can install the new dependencies by running Composer’s update command from the directory where your composer.json file is located:
# install $ php composer.phar install # update $ php composer.phar update satooshi/file-client # or you can simply execute composer command if you set composer command to # your PATH environment variable $ composer install $ composer update satooshi/file-client
Packagist page for this library is https://packagist.org/packages/satooshi/file-client
Or you can use git clone
# HTTP $ git clone https://github.com/satooshi/FileClient.git # SSH $ git clone git@github.com:satooshi/FileClient.git
Usage
plain text file
construction
<?php use Contrib\Component\File\Client\Plain\FileReader; // construction $path = '/path/to/file'; $client = new FileReader($path);
<?php use Contrib\Component\File\Client\Plain\FileReader; // default options $options = array( 'newLine' => PHP_EOL, 'throwException' => true, // throw exception on runtime error 'autoDetectLineEnding' => true, // better line ending handling on Mac ); // construct with options $client = new FileReader($path, $options);
read
<?php use Contrib\Component\File\Client\Plain\FileReader; $path = '/path/to/file'; $client = new FileReader($path); // read $content = $client->read(); $lines = $client->readLines();
write
<?php use Contrib\Component\File\Client\Plain\FileWriter; $path = '/path/to/file'; $client = new FileWriter($path); // write $content = 'hello world!'; $client->write($content); $lines = array( 'line1', 'line2', ); $client->writeLines($lines);
append
<?php use Contrib\Component\File\Client\Plain\FileAppender; $path = '/path/to/file'; $client = new FileAppender($path); // append $content = 'hello world!'; $client->write($content); $lines = array( 'line1', 'line2', ); $client->writeLines($lines);
walk
FileReaderIterator object can walk through read file.
<?php use Contrib\Component\File\Client\Plain\FileReaderIterator; // construction $path = '/path/to/file'; $client = new FileReaderIterator($path);
<?php use Contrib\Component\File\Client\Plain\FileReaderIterator; // default options $options = array( 'newLine' => PHP_EOL, 'throwException' => true, // throw exception on runtime error 'autoDetectLineEnding' => true, // better line ending handling on Mac 'skipEmptyCount' => true, 'limit' => 0, 'offset' => 0, ); // construct with options $client = new FileReaderIterator($path, $options);
<?php use Contrib\Component\File\Client\Plain\FileReaderIterator; // construction $path = '/path/to/file'; $client = new FileReaderIterator($path); // walk $client->walk( funtion ($line, $numLine) { if ($numLine === 1) { // do something at line 1 } } );
File format
Currently support json, xml, ltsv file format. Object serialization is also supported by Symfony Serializer component.
construction
<?php use Contrib\Component\File\Client\Generic\GenericFileReader; // construction $path = '/path/to/file'; $client = new GenericFileReader($path);
<?php use Contrib\Component\File\Client\Generic\GenericFileReader; // default options $options = array( 'newLine' => PHP_EOL, 'throwException' => true, // throw exception on runtime error 'autoDetectLineEnding' => true, // better line ending handling on Mac ); // construct with options $client = new GenericFileReader($path, $options);
read
<?php use Contrib\Component\File\Client\Generic\GenericFileReader; $path = '/path/to/file'; $client = new GenericFileReader($path); // read as json $content = $client->readAs('json'); $lines = $client->readLinesAs('ltsv'); // read as json to object $content = $client->readAs('json', 'Entity'); $lines = $client->readLinesAs('ltsv', 'Entity');
write
<?php use Contrib\Component\File\Client\Generic\GenericFileWriter; $path = '/path/to/file'; $client = new GenericFileWriter($path); // write Entity $content = new Entity(); $client->writeAs($content); $lines = array( new Entity(), new Entity(), ); $client->writeLinesAs($lines);
append
<?php use Contrib\Component\File\Client\Generic\GenericFileAppender; $path = '/path/to/file'; $client = new GenericFileAppender($path); // append Entity $content = new Entity(); $client->writeAs($content); $lines = array( new Entity(), new Entity(), ); $client->writeLinesAs($lines);
walk
<?php use Contrib\Component\File\Client\Plain\GenericFileReaderIterator; // construction $path = '/path/to/file'; $client = new GenericFileReaderIterator($path);
<?php use Contrib\Component\File\Client\Plain\GenericFileReaderIterator; // default options $options = array( 'newLine' => PHP_EOL, 'throwException' => true, // throw exception on runtime error 'autoDetectLineEnding' => true, // better line ending handling on Mac 'skipEmptyCount' => true, 'limit' => 0, 'offset' => 0, ); // construct with options $client = new GenericFileReaderIterator($path, $options);
<?php use Contrib\Component\File\Client\Plain\GenericFileReaderIterator; // construction $path = '/path/to/file'; $client = new GenericFileReaderIterator($path); // walk as json $client->walkAs( funtion ($line, $numLine) { if ($numLine === 1) { // do something at line 1 } }, 'json' ); // walk as json to object $client->walkAs( funtion ($line, $numLine) { if ($numLine === 1) { // do something at line 1 } }, 'json', 'Entity' );
satooshi/file-client 适用场景与选型建议
satooshi/file-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 51 次下载、GitHub Stars 达 2, 最近一次更新时间为 2013 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「file」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 satooshi/file-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 satooshi/file-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 satooshi/file-client 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
Laravel Media Popup to upload/view the files
PMVC Plugin for File information
Mapper for accessing resources in KWCMS
Text file manipulation
KCFinder web file manager
统计信息
- 总下载量: 51
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-02-08