zoukankan      html  css  js  c++  java
  • php 全局使用laravel的dd和dump

    一.使用dump

    1.找到composer安装路径

     2.找到路径新建composer.json文件并加入以下代码

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

    }

    3.更新composer

    composer global update

    4.配置php.ini

    auto_prepend_file = "C:UsersChenAppDataRoamingComposervendorautoload.php"

    5.重启服务。

    二.使用dd

    1.全局composer.json中新加

    "autoload": {
    "files": [
    "D:/www/debugHelper.php"
    ]
    }
    2.按照路径新建
    debugHelper.php文件
    <?php
    # install symfony/var-dump to your project
    # composer require symfony/var-dumper
    
    // use namespace
    use SymfonyComponentVarDumperClonerVarCloner;
    use SymfonyComponentVarDumperDumperCliDumper;
    use SymfonyComponentVarDumperDumperHtmlDumper 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);
        }
    }
    
    

    3.更新composer自动加载

    
    
    composer global dump-autoload
     
  • 相关阅读:
    Android实现不同Active页面间的跳转
    Android Dialog的整个生命周期
    fragment的基本用法
    使用URLEncoder、URLDecoder进行URL参数的转码与解码
    Android 通过URL获取网络资源
    Dialog向Activity传递数据
    Android 自定义AlertDialog(退出提示框)
    javascript的继承实现
    UVA Graph Coloring
    poj3744高速功率矩阵+可能性DP
  • 原文地址:https://www.cnblogs.com/F4natasy/p/12611768.html
Copyright © 2011-2022 走看看