narrowspark/pretty-array

此包已被废弃,不再维护。作者建议使用 symfony/var-exporter 包代替。

返回用于保存或输出的美观数组。

2.0.2 2019-08-13 09:00 UTC

This package is auto-updated.

Last update: 2019-08-16 06:46:37 UTC


README

68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6172726f77737061726b2f7072657474792d61727261792e7376673f7374796c653d666c61742d737175617265 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545372e322e302d3838393242462e7376673f7374796c653d666c61742d737175617265 68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6e6172726f77737061726b2f7072657474792d61727261792f6d61737465722e7376673f7374796c653d666c61742d737175617265 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265

分支状态

Travis branch Codecov branch

安装

使用 Composer 安装此包

composer require narrowspark/pretty-array

使用方法

use Narrowspark\PrettyArray\PrettyArray;

$prettyArray = new PrettyArray();

如果你只传递一个数组,你会得到以下输出。

/**
 * This is the output.
 * 
 * [
 *     0 => 1,
 * ]
 */
$prettyArray->print([1]);

要使数组输出从4个空格开始,只需更改缩进级别。

/**
 * This is the output.
 * 
 *     [
 *         0 => 1,
 *     ]
 */
$prettyArray->print([1], 2);

你可以添加一个类型解析器来更改值输出。

所有支持的类型可以在 php.net 上找到

$prettyArray->setResolver('object', function($value) {
    return 'foo'
});

/**
 * This is the output.
 * 
 * [
 *    0 => 'foo',
 * ]
 */
$prettyArray->print(
    [
        0 => function() {
            return 'foo'; 
        },
    ],
);

测试

你需要运行

$ php vendor/bin/phpunit

贡献

如果你想要帮忙,请查看 问题列表 并检查我们的 贡献指南

注意:请注意,此项目以贡献者行为准则发布。通过参与此项目,你同意遵守其条款。

致谢

许可证

MIT 许可证(MIT)。请参阅 许可证文件 以获取更多信息。