承接 kayalion/vardump 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kayalion/vardump

Composer 安装命令:

composer require kayalion/vardump

包简介

Helper library to print variables for debugging purposes

关键字:

README 文档

README

PHP Helper library to print variables for debugging purposes.

Usage

<?php

// dumps a variable
vd("any variable");

// or multiple variables, as many as your memory can handle
vd("any variable", "any other variable");

// dumps a variable and dies
vdd("any variable");

// or with multiple variables
vdd("any variable", "any other variable");

// dumps one variable with a specific configuration
// set any configuration parameter to null to use the global value
$maxRecursiveDepth = 10;
$maxStringLength = 100;
$includeMethods = true;
$theme = new SpidermanHtmlVarDumpTheme();

vdc("any variable", $maxRecursiveDepth, $maxStringLength, $includeMethods, $theme);

// dumps one variable with a specific configuration and dies
vdcd("any variable", $maxRecursiveDepth, $maxStringLength, $includeMethods, $theme);

// as called for the sample screenshots
vd([
    null,
    true,
    42,
    3.1415,
    "any string",
    new Exception(),
    fopen('php://stdout', 'w'),
]);

Screenshots

Output on a HTML page:

Screenshot HTML

Output in a CLI:

Screenshot CLI

Configuration

You can use the environment variable to configure the vardump.

<?php

// Flag to see if object methods should be included
$_ENV['VAR_DUMP_METHODS'] = true;

// Maximum depth for arrays and objects
$_ENV['VAR_DUMP_RECURSIVE_DEPTH'] = 10;

// Maximum length for the preview of a string
$_ENV['VAR_DUMP_STRING_LENGTH'] = 100;

// Name of the CLI theme class
$_ENV['VAR_DUMP_THEME_CLI'] = 'CliVarDumpTheme';

// Name of the HTML theme class, choose between:
// - HtmlVarDumpTheme
// - BatmanHtmlVarDumpTheme
// - HulkHtmlVarDumpTheme,
// - IronmanHtmlVarDumpTheme,
// - SpidermanHtmlVarDumpTheme,
// - SupermanHtmlVarDumpTheme,
$_ENV['VAR_DUMP_THEME_HTML'] = 'SpidermanHtmlVarDumpTheme';

Dump To File

When you are debugging a web application, output can break your layout or response, especially when developing a restful API.

You can easily pipe the vardump output to a file using the file theme.

<?php

// the file to dump to
$file = __DIR__ . '/vardump.log';

// create a theme to log to the file
$theme = new FileVarDumpTheme($file);

// you can also provide a truncate size in KB, defaults to 1MB
$theme = new FileVarDumpTheme($file, 4096); // 4MB

// set the theme for both environments
$_ENV['VAR_DUMP_THEME_CLI'] = $theme;
$_ENV['VAR_DUMP_THEME_HTML'] = $theme;

Once the log file is created, you can use the tail command to keep an eye on it:

tail -f vardump.log

Installation

You can use Composer to install this helper into your project.

composer require kayalion/vardump

For manual installation, copy the src/VarDump.php file to your project and include it like:

<?php 

include __DIR__ . '/src/VarDump.php';

统计信息

  • 总下载量: 1.1k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-11-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固