kaloa/filesystem
最新稳定版本:v0.2.1
Composer 安装命令:
composer require kaloa/filesystem
包简介
Utility classes for tasks related to the filesystem.
README 文档
README
Install
Via Composer:
$ composer require kaloa/filesystem
Requirements
The following PHP versions are supported:
- PHP 5.3
- PHP 5.4
- PHP 5.5
- PHP 5.6
- PHP 7.0
- PHP 7.1
- HHVM
Documentation
CsvReader
Goals
- Provide an interface to read CSV data from streams into associative arrays.
Usage
Read all CSV rows from a stream into a numeric array. This is also a general usage example.
use Kaloa\Filesystem\CsvReader; $stream = fopen(__DIR__ . '/file.csv', 'rb'); $csvReader = new CsvReader($stream); $data = $csvReader->fetchAll(); fclose($stream);
Read all CSV rows from a stream into an associative array. The first row from the input will be used as keys.
$data = $csvReader->fetchAllAssoc();
If the file doesn't contain a row with keys, keys can be provided manually. The first row will be seen as regular data.
$data = $csvReader->fetchAllAssoc(array('id', 'title', 'date_added'));
There’s also a streaming mode available.
while ($row = $csvReader->fetch()) { // ... }
Streaming works with associative arrays, too. Here, the first call to fetchAssoc will transparently read the first two rows from the input to read both the keys and the first data row.
while ($row = $csvReader->fetchAssoc()) { // ... }
Respectively:
while ($row = $csvReader->fetchAssoc(array('id', 'title', 'date_added'))) { // ... }
The reader class is intended to always return UTF-8 data. Differing CSV input encodings will be converted automatically if the input encoding is specified in the constructor.
$csvReader = new CsvReader($iso88591Stream, 'ISO-8859-1');
There’s also support for non-standard delimiter, enclosure and escape characters.
$csvReader = new CsvReader($stream, 'UTF-8', ':', '|', '%');
Further notes
- The
fetchandfetchAllmethods accept rows with varying numbers of fields in the same stream. ThefetchAssocandfetchAllAssocmethods will throw an exception if the number of fields in a row differs from the number of keys. - It is not possible to change the names of the keys while iterating over input data with
fetchAssoc. The reader always uses the keys from the first call tofetchAssoc. - Calls to different
fetch*methods must not be mixed. Currently, the code doesn’t prevent this, but it’s very likely that such functionality will be added in a future release.
Recipes
For usage with the reader, PHP strings can be converted to streams using the data protocol.
$csvString = <<<'CSV' "Col a","Col b" "value 1a","value 1b" "value 2a","value 2b" CSV; $dataUri = 'data://text/plain;base64,' . base64_encode($csvString); $stream = fopen($dataUri, 'rb'); $reader = new CsvReader($stream);
PathHelper
Goals
- “
realpathfor non-existing files” is the general idea. - Resolve relative components (
.and..) of “virtual” filesystem paths which don’t point to existing files or directories. - Generate a normalized representation for such paths.
- The code has to be able to work with both absolute and relative paths on multiple systems.
- It has to be able to deal with absolute paths on Windows. (A path like
c:\foois to be considered absolute on Windows but relative on Linux.c:\foois a valid filename on Linux.)
Usage
use Kaloa\Filesystem\PathHelper; $pathHelper = new PathHelper(); $pathHelper->normalize('./dir1/dir2/dir3/dir4/../../../'); // "dir1"
Testing
(Tools are not included in this package.)
$ phpunit
Further quality assurance:
$ phpcs --standard=PSR2 ./src $ phpmd ./src text codesize,design,naming
Credits
License
The package is published under the MIT License. See LICENSE for full license info.
kaloa/filesystem 适用场景与选型建议
kaloa/filesystem 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 88 次下载、GitHub Stars 达 1, 最近一次更新时间为 2012 年 03 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「filesystem」 「iterator」 「csv」 「filter」 「normalization」 「paths」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kaloa/filesystem 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kaloa/filesystem 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kaloa/filesystem 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
collection php library
A SDK for working with B2 cloud storage.
A PHP class providing static methods for reading, writing, copying, moving, and deleting files and directories, MIME type detection, image size detection, and file permission management
PHP PDO Mysql select statement iterator implemented as multiple queries using LIMIT clauses
Iteration tools for PHP
Sequential way to run Symfony Processes in parallel
统计信息
- 总下载量: 88
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2012-03-12