fishingboy / madump
Magento 数据对象导出工具
1.1.3
2022-03-23 06:02 UTC
Requires (Dev)
- phpunit/phpunit: ^4.0 || ^5.0 || ^6.0 || ^7.0
README
为什么需要 MaDump ?
因为 Magento 的对象如果直接使用 var_dump() 或 print_r(),都可能出现内存不足的错误,所以编写了一个导出工具,只导出对象的第一层,方便开发。
安装
composer require fishingboy/madump
使用方法
-
直接输出
use Fishingboy\MaDump\MaDump; MaDump::dump($product);
输出
<pre> Magento\Catalog\Model\Product\Interceptor ->addAttributeUpdate($code, $value, $store) ->addCustomOption($code, $value, $product) ->addData(array $arr) ->addImageToMediaGallery($file, $mediaAttribute, $move, $exclude) ->addOption(Magento\Catalog\Model\Product\Option $option) ->afterCommitCallback() ->afterDelete() ->afterDeleteCommit() ->formatUrlKey($str) ->fromArray(array $data) ->getAttributeDefaultValue($attributeCode) ->getAttributeSetId() : 16 (string) ->getAttributeText($attributeCode) ->getAttributes($groupId, $skipSuper) ->getAvailableInCategories() : array ->getCacheIdTags() : array ->getCacheTags() : array ->getCalculatedFinalPrice() : (NULL) ->getCategory() : (NULL) ->getCategoryCollection() : Magento\Catalog\Model\ResourceModel\Category\Collection\Interceptor ... </pre>
-
记录在日志中(将输出内容返回)
use Fishingboy\MaDump\MaDump; $product_dump = MaDump::dump($product, true); $this->_logger->info("product => " . $product_dump);
-
有时可能需要直接中断执行,请直接使用 exit
use Fishingboy\MaDump\MaDump; MaDump::dump($product); exit;
-
通常追踪代码的过程会是这样的
步骤.1
MaDump::dump($product);
步骤.2
MaDump::dump($product->getCustomAttributes());
步骤.3
MaDump::dump($product->getCustomAttributes()[0]);
自己在程序中一层层往下查找
输出说明
-
如果是对象
<pre> Magento\Catalog\Model\Product\Interceptor ->addAttributeUpdate($code, $value, $store) ->addCustomOption($code, $value, $product) ->addData(array $arr) ->addImageToMediaGallery($file, $mediaAttribute, $move, $exclude) ->addOption(Magento\Catalog\Model\Product\Option $option) ->afterCommitCallback() ->afterDelete() ->afterDeleteCommit() ->formatUrlKey($str) ->fromArray(array $data) ->getAttributeDefaultValue($attributeCode) ->getAttributeSetId() : 16 (string) ->getAttributeText($attributeCode) ->getAttributes($groupId, $skipSuper) ->getAvailableInCategories() : array ->getCacheIdTags() : array ->getCacheTags() : array ->getCalculatedFinalPrice() : (NULL) ->getCategory() : (NULL) ->getCategoryCollection() : Magento\Catalog\Model\ResourceModel\Category\Collection\Interceptor ... </pre>
如果是 getter 方法且不带参数的话,会直接显示调用后的值,像这样:
->getAttributeSetId() : 16 (string) ->getCategoryCollection() : Magento\Catalog\Model\ResourceModel\Category\Collection\Interceptor ->getCacheIdTags() : array
-
如果是数组
<pre> Array(52) => [0] => (Magento\Framework\Api\AttributeValue) [10] => (Magento\Framework\Api\AttributeValue) [11] => (Magento\Framework\Api\AttributeValue) [12] => (Magento\Framework\Api\AttributeValue) ... </pre>
或是这样
<pre> Array(2) => [0] => 101 [1] => 102 </pre>
-
如果是普通值
<pre>1 (integer)</pre>
<pre>true (boolean)</pre>
<pre>sku-123 (string)</pre>