Forked from matheusgontijo/magento-2-debugging-tricks-setdata-dataobject-php-and-xdebug.php
Created
June 18, 2019 11:50
-
-
Save phaelfp/414292bb401cea34bb3ff3d7a5ff8ea6 to your computer and use it in GitHub Desktop.
Magento 2 Debugging Tricks - setData, DataObject.php & xDebug by Matheus Gontijo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Magento 2 Debugging Tricks - setData, DataObject.php & xDebug by Matheus Gontijo | |
Video: https://www.youtube.com/watch?v=eo8N7e9eEPI | |
----------------------------------------------- | |
What is "stripos"? | |
<?php | |
// https://www.php.net/stripos | |
// Find the position of the first occurrence of a case-insensitive substring in a string | |
// PHP could have a function called "contains" | |
stripos('hello world', 'o') // position 4 | |
stripos('hello world', 'wor') // position 6 | |
stripos('hello world', 'hel') // position 0 | |
stripos('hello world', 'aaa') // position "false" | |
// "Contains" concept | |
stripos('hello world 123 magento', 'world') !== false // position 6 | |
?> | |
----------------------------------------------- | |
1) Try to track directly into the concrete object | |
vendor/magento/module-catalog/Model/Category.php | |
->setName or ->setDescription | |
----------------------------------------------- | |
2) Try to track on the parent classes | |
->setData (parent classes) | |
- vendor/magento/framework/Model/AbstractModel.php | |
- vendor/magento/framework/DataObject.php | |
<?php | |
// first try : vendor/magento/framework/Model/AbstractModel.php | |
// second try: vendor/magento/framework/DataObject.php | |
if (is_scalar($key)) { | |
$breakpoint = null; // is_scalar($value) && stripos($value, 'montana') !== false | |
} else if (is_array($key)) { | |
foreach ($key as $k => $v) { | |
$breakpoint = null; // is_scalar($v) && stripos($v, 'montana') !== false | |
} | |
} | |
?> | |
----------------------------------------------- | |
Real World examples: | |
Example 01 | Who is setting filter "LumaTech"? | |
Example 02 | Who is setting product price "56.99"? | |
Example 03 | Who is setting product configurable option as "Yellow"? | |
Example 04 | Who is setting the "reviews"? | |
----------------------------------------------- | |
<?php | |
// first form: array | |
$object->setData([ | |
'entity_id' => 9999, | |
'name' => 'xdebug is awesome', | |
'title' => 'you should use it!', | |
]); | |
// second form: key + value | |
$object->setData('entity_id', 9999); | |
$object->setData('name', 'xdebug is awesome'); | |
$object->setData('title', 'you should use it!'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment