doghouse-agency/php-table-multiformat
Composer 安装命令:
composer require doghouse-agency/php-table-multiformat
包简介
Table output for PHP scripts (CLI, CSV, etc)
README 文档
README
- Nice table output of data rows
- Columns adjust to data size
- Data manipulators for fields, formats raw data to a nice display output
- Colors! When specifying a color, choose from these strings: blue, red, green, yellow, black, magenta, cyan, white, grey
- Support for multi-line values.
Installing via Composer
# Install Composer curl -sS https://getcomposer.org/installer | php
Next, run the Composer command to install the latest stable version:
composer.phar require tnelson-doghouse/php-table
After installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';
Using
See the tests folder for some examples, but basically here's how to use it:
use \PHPTable\Format\HumanOnly; // $data used below is an array of rows with fields. See tests/data.php for an example. $tablemaker = new \PHPTable\Factory(); $table = $tablemaker->make('human-only'); $table->setTableColor('blue'); $table->setHeaderColor('cyan'); $table->addField('First Name', 'firstName', false, 'white'); $table->addField('Last Name', 'lastName', false, 'white'); $table->addField('DOB', 'dobTime', new \PHPTable\Manipulator\Base('datelong')); $table->addField('Admin', 'isAdmin', new \PHPTable\Manipulator\Base('yesno'), 'yellow'); $table->addField('Last Seen', 'lastSeenTime', new \PHPTable\Manipulator\Base('nicetime'), 'red'); $table->addField('Expires', 'expires', new \PHPTable\Manipulator\Base('duetime'), 'green'); $table->injectData($data); $table->display();
Manipulators
These are the manipulators provided in the package:
- dollar: Formats 12300.23 to $12,300.23
- date: Formats unix timestamp 1372132121 to AU date 25-06-2013 (because I'm an Aussie mate)
- datelong: Formats unix timestamp 1372132121 to 25th June 2013
- time: Formats unix timestamp 1372132121 to 1:48 pm
- datetime: Formats unix timestamp 1372132121 to 25th June 2013, 1:48 pm
- nicetime: Formats unix timestamp 1372132121 to one of the following, depending if it falls on Today or Yesterday or earlier:
- Today, 1:48 pm
- Yesterday, 1:48 pm
- 25th June 2013, 1:48 pm
- duetime: Formats unix timestamp to x years x days x hours x minutes x seconds
- nicenumber: Formats 123456 to 123,456
- month: Formats unix timestamp 1372132121 to June
- year: Formats unix timestamp 1372132121 to 2013
- monthyear: Formats unix timestamp 1372132121 to June 2013
- percent: Formats 54 to 54%
- yesno: Formats a boolean value to Yes or No
- text: Strips HTML from the value before returning
If you want to create your own manipulators:
class MyManipulator extends \PHPTable\Manipulator\Base { public function chucknorris($value) { return 'Chuck norris said: ' . $value; } } $tablemaker = new \PHPTable\Factory(); $table = $tablemaker->make('human-only'); $table->setTableColor('blue'); $table->setHeaderColor('cyan'); $table->addField('First Name', 'firstName', false, 'white'); $table->addField('Last Name', 'lastName', false, 'white'); $table->addField('DOB', 'dobTime', new \PHPTable\Manipulator\Base('datelong')); $table->addField('Admin', 'isAdmin', new MyManipulator('chucknorris'), 'yellow'); $table->addField('Last Seen', 'lastSeenTime', new \PHPTable\Manipulator\Base('nicetime'), 'red'); $table->addField('Expires', 'expires', new \PHPTable\Manipulator\Base('duetime'), 'green'); $table->injectData($data); $table->display();
Manipulator\TextWidth
This manipulator allows for fixed-width columns; it can clip or wrap, as desired.
$wrapper = new \PHPTable\Manipulator\TextWidth( max_width: 30, wrapping: 'clip', );
Formats
Currently supported formats are:
- human-only (HumanOnly): Pretty, aesthetically pleasing, but not machine readable; uses ANSI Escape sequences for colour, etc
- half-human (HalfHuman): Like a Unix command; in a table, but should be somewhat machine readable (specifically, columns split on space should work). Not well done yet, but works in some cases
- csv (CSVTable): Outputs to a CSV file
The advantage of using the Factory is that the format can then be eg. a string passed on the command line, so that people can choose to have their report in eg. human-readable or CSV.
doghouse-agency/php-table-multiformat 适用场景与选型建议
doghouse-agency/php-table-multiformat 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 4, 最近一次更新时间为 2025 年 03 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cli」 「command」 「line」 「table」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 doghouse-agency/php-table-multiformat 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 doghouse-agency/php-table-multiformat 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 doghouse-agency/php-table-multiformat 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Wrapper for exec and it's results
Symfony bundle to monitor and execute commands
Shell command module for PHP.
Library with classes to help you do batch.
Command bus implementation: Commands and domain events
A PHP console tool to generate Markdown documentation from your docblocks and types hints using templates.
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-1-Clause
- 更新时间: 2025-03-12
