fishingboy / madump
Magento Data Object Dump Tool
1.1.3
2022-03-23 06:02 UTC
Requires (Dev)
- phpunit/phpunit: ^4.0 || ^5.0 || ^6.0 || ^7.0
README
English | 繁體中文
Why MaDump?
Calling var_dump() or print_r() on a Magento object causes an out-of-memory error because of deeply nested circular references. MaDump dumps only the first level of an object, giving you just enough information to navigate the code during development.
Installation
composer require fishingboy/madump
Usage
-
Print directly
use Fishingboy\MaDump\MaDump; MaDump::dump($product);
Output:
<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>
-
Capture as a string (for logging)
use Fishingboy\MaDump\MaDump; $product_dump = MaDump::dump($product, true); $this->_logger->info("product => " . $product_dump);
-
Stop execution after dumping
use Fishingboy\MaDump\MaDump; MaDump::dump($product); exit;
-
Typical trace workflow
Step 1 — dump the top-level object:
MaDump::dump($product);
Step 2 — drill into an attribute:
MaDump::dump($product->getCustomAttributes());
Step 3 — drill further:
MaDump::dump($product->getCustomAttributes()[0]);
Keep going level by level until you find what you need.
Output Format
-
Object
<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>
Zero-argument getter methods are called automatically and their return values are shown inline:
->getAttributeSetId() : 16 (string) ->getCategoryCollection() : Magento\Catalog\Model\ResourceModel\Category\Collection\Interceptor ->getCacheIdTags() : array
-
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>
Or for a simple array:
<pre> Array(2) => [0] => 101 [1] => 102 </pre>
-
Scalar value
<pre>1 (integer)</pre>
<pre>true (boolean)</pre>
<pre>sku-123 (string)</pre>
License
This project is licensed under the MIT License.