Laravel dd功能限制 [英] Laravel dd function limitations

查看:133
本文介绍了Laravel dd功能限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由320个数组组成的数组,而常规的var_dump恰好向我显示了320个具有所有嵌套元素的元素,Laravel的dd帮助器在索引 147 和所有其他元素处截断了嵌套元素被截断且没有扩展选项,请参见下面的示例

I have an array of 320 arrays, while regular var_dump shows me exactly 320 elements with all nested elements, Laravel's dd helper truncates the nested element at index 147 and all the further elements are truncated with no option to expand them, see the example below

  146 => array:17 [▼
    "total_unconfirmed_subscribers" => 0
    "total_subscribers_subscribed_yesterday" => 0
    "unique_list_id" => "24324"
    "http_etag" => ""fbb6febfca8af5541541ea960aaedb""
    "web_form_split_tests_collection_link" => "https://api.com/1.0/"
    "subscribers_collection_link" => "https://api.com/1.0/"
    "total_subscribers_subscribed_today" => 0
    "id" => 23432
    "total_subscribed_subscribers" => 0
    "total_unsubscribed_subscribers" => 0
    "campaigns_collection_link" => "https://api.com/1.0/"
    "custom_fields_collection_link" => "https://api.com/1.0/accounts"
    "self_link" => "https://api.com/1.0/accounts"
    "total_subscribers" => 0
    "resource_type_link" => "https://api.com/1.0/#list"
    "web_forms_collection_link" => "https://api.com/"
    "name" => "dccode"
  ]
  147 => array:17 [▼
    "total_unconfirmed_subscribers" => 0
     …16
  ]
  148 => array:17 [ …17]
  149 => array:17 [ …17]

为什么限制为147条完整记录,以及如何增加该限制? 相关主题 Laravels的DD helper功能是否正常工作?没有?不能真正解释这些限制.

Why is it limited to 147 full records and how to increase the limit? The related topic Is Laravels' DD helper function working properly? doesn't actually explain the limits.

这是非常一致的行为,我已经在Laravel 5.2和php7上进行过测试

This is pretty consistent behavior, I've tested with Laravel 5.2 and php7 on

  • Linux(Laravel Forge,Droplet,Ubuntu)
  • Mac(Laravel Valet)
  • Windows(valet4windows)

每个地方都在第147号元素上进行了完全相同的切割.使用CLI php artisan tinker输出相同的剪切

Everywhere got exactly the same cut on element #147. Using CLI php artisan tinker outputs the same cut

...
"name" => "dccode"   ]   147 => array:17 [
"total_unconfirmed_subscribers" => 0
 16   ]   148 => array:17 [ 17]
...

推荐答案

在版本5.0之前,laravel的dd()函数如下所示:

Prior to version 5.0 laravel's dd() function looked as follows:

function dd()
{
    array_map(function($x) { var_dump($x); }, func_get_args()); die;
}

从5.0开始,它看起来像这样:

Since 5.0 it looks like this:

function dd()
{
    array_map(function ($x) {
        (new Dumper)->dump($x);
    }, func_get_args());

    die(1);
}

Dumper使用的是symfony的VarCloner,它扩展了AbstractCloner.此类的$maxItems属性设置为2500.请参见: https://github.com/symfony/var-dumper/blob/master/Cloner/AbstractCloner.php#L125

The Dumper is using symfony's VarCloner which is extending the AbstractCloner. This class has a $maxItems attribute set to 2500. See: https://github.com/symfony/var-dumper/blob/master/Cloner/AbstractCloner.php#L125

每个数组有17个项目.将它乘以147,得到2499.这就是为什么键147的数组在第一项之后被截断的原因.

You have 17 items per array. Multiply it by 147 and you get 2499. That's why your array at key 147 is truncated after it's first item.

如果您想增加,则需要覆盖laravel的Dumper类(

If you'd like to increase that you'd need to override laravel's Dumper class (https://github.com/laravel/framework/blob/5.2/src/Illuminate/Support/Debug/Dumper.php):

public function dump($value)
{
    if (class_exists(CliDumper::class)) {
        $dumper = 'cli' === PHP_SAPI ? new CliDumper : new HtmlDumper;

        $cloner = new VarCloner();
        $cloner->setMaxItems(5000);
        $dumper->dump($cloner->cloneVar($value));
    } else {
        var_dump($value);
    }
}

这篇关于Laravel dd功能限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆