xethron/l4-to-string
Composer 安装命令:
composer require xethron/l4-to-string
包简介
Laravel 4 version of xethron/to-string, which adds query and queryLog to string functions.
README 文档
README
Logging variables can sometimes cause huge logs, especially if you want to email those logs to yourself.
On the other hand, logging exceptions with the default __toString can will most likely give you just enough information to confuse the hell out of you!
This class extends Xethron\ToString, and in addition, adds a few Laravel 4 specific functions for converting Query Logs to Strings.
Variable to String
This is a function that will display a variable similar to print_r, with the ability to specify the max_lines, max_depth (for arrays) and min_depth (for arrays).
This means that you will never get an email with an array 3000 lines long as you would with print_r.
Xethron\L4ToString::variable( $var, $max_lines, $max_depth, $min_depth )
I recommend adding a global function to one of your startup files for easier access:
function varToStr( $var, $max_lines = 10, $max_depth = 4, $min_depth = 2 ) { return Xethron\L4ToString::variable( $var, $max_lines, $max_depth, $min_depth ); }
Exception to String
This converts an Exception to string, much like PHP's __toString, however, it won't cut off those important pieces of information you require while debugging.
On top of that, it also uses the Variable to String to to include all the variables passed in the Stack Trace.
Two functions are available:
Xethron\L4ToString::exception( $e ); // This will print out the entire Exception
Xethron\L4ToString::trace( $e->getTrace() ); // This will only print out the stack trace
Query Log to String
This will convert the Laravel 4 Query Log to a neat Query String like:
#0 select * from `table` where `table`.`id` = 113 and `deleted` = 0 limit 1; {"bindings":[113,0],"time":1.08} #1 select * from `another_table` where `another_table`.`deleted_at` is null and `id` = '66' limit 1; {"bindings":["66"],"time":0.49} #2 select * from `country` where `country`.`deleted` = 0 and `country`.`name` in ('South Africa'); {"bindings":[0,"South Africa"],"time":0.51}
Two Functions are available:
Xethron\L4ToString::queryLog(); // gets the latest query log and prints it
Xethron\L4ToString::queryLog( \DB::getQueryLog() ); // Specify your own query log
Xethron\L4ToString::query( $qyery ); // Pass a single query from the query log to be converted to string
License
L4ToString is distributed under the terms of the GNU General Public License, version 3 or later.
xethron/l4-to-string 适用场景与选型建议
xethron/l4-to-string 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17.38k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2014 年 02 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「convert」 「string」 「print_r」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 xethron/l4-to-string 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 xethron/l4-to-string 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 xethron/l4-to-string 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
Provides a simple decimal/roman number converter
a cleaner, leaner mix of print_r() and var_dump()
A library that provides a simple infrastructure to create your own converters and to perform any conversion you want
nice output for debug functions for PHP 5.3
Hooks for using KRUMO from within Symfony 2 or Symfony 3 -- KRUMO - version 2.0 of print_r(); and var_dump();
统计信息
- 总下载量: 17.38k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL
- 更新时间: 2014-02-01