欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHP全局使用Laravel辅助函数dd

程序员文章站 2023-11-27 23:45:28
dump() 方法 全局 composer.json "require": { "squizlabs/php_codesniffer": "*", "fxp/c...

dump() 方法

全局 composer.json

"require": {
  "squizlabs/php_codesniffer": "*",
  "fxp/composer-asset-plugin": "^1.4",
  "symfony/var-dumper": "3.3.16"
}

配置php.ini

auto_prepend_file = "c:usersmsappdataroamingcomposervendorautoload.php"

更新composer

composer global update

更新后重启apache就可以全局使用函数 dump()

dd() 方法

全局 composer.json

# 新增 autoload
"autoload": {
  "files": [
    "d:/web/php/debughelper.php"
  ]
}

新建 debughelper.php

# install symfony/var-dump to your project
# composer require symfony/var-dumper

// use namespace
use componentvardumperclonervarcloner;
use componentvardumperdumperclidumper;
use componentvardumperdumperhtmldumper as symfonyhtmldumper;

/**
 * class htmldumper
 */
class htmldumper extends symfonyhtmldumper
{
  /**
大专栏 php 全局使用 laravel 辅助函数 ddnt">   * colour definitions for output.
   *
   * @var array
   */
  protected $styles = [
    'default' => 'background-color:#fff; color:#222; line-height:1.2em; font-weight:normal; font:12px monaco, consolas, monospace; word-wrap: break-word; white-space: pre-wrap; position:relative; z-index:100000',
    'num' => 'color:#a71d5d',
    'const' => 'color:#795da3',
    'str' => 'color:#df5000',
    'cchr' => 'color:#222',
    'note' => 'color:#a71d5d',
    'ref' => 'color:#a0a0a0',
    'public' => 'color:#795da3',
    'protected' => 'color:#795da3',
    'private' => 'color:#795da3',
    'meta' => 'color:#b729d9',
    'key' => 'color:#df5000',
    'index' => 'color:#a71d5d',
  ];
}

/**
 * class dumper
 */
class dumper
{
  /**
   * dump a value with elegance.
   *
   * @param mixed $value
   * @return void
   */
  public function dump($value)
  {
    if (class_exists(clidumper::class)) {
      $dumper = 'cli' === php_sapi ? new clidumper : new htmldumper;
      $dumper->dump((new varcloner)->clonevar($value));
    } else {
      var_dump($value);
    }
  }
}

if (! function_exists('dd')) {
  /**
   * dump the passed variables and end the script.
   *
   * @param mixed
   * @return void
   */
  function dd(...$args)
  {
    foreach ($args as $x) {
      (new dumper)->dump($x);
    }
    die(1);
  }
}

if (! function_exists('dda')) {
  /**
   * dump the passed array variables and end the script.
   *
   * @param mixed
   * @return void
   */
  function dda(...$args)
  {
    foreach ($args as $x) {
      (new dumper)->dump($x->toarray());
    }
    die(1);
  }
}

更新composer自动加载

composer global dump-autoload

更新后就可以全局使用函数 dd()

以上就是本次介绍的全部相关知识点,感谢大家的学习和对的支持。