PHP Variable Hunter
is a PHP module that searches an array for a given string, returning every match in a concise list. Very complex array variables are easy to locate both on screen and in a returned array. The results can be used directly as a PHP variable or further analyzed using dpm() or Search Krumo.
Sandbox Location
https://drupal.org/sandbox/jeoware/2023153.
For Developers and Themers
It's called like this: $varlist = pvh($variables , 'block', FALSE); // Third parm specifies exact match; optional.
The results are pre-formatted as a PHP array variable, printed to the screen and returned in a variable array. This is an example of the returned data:
$variables['page']['sidebar_first']['search_form']['#contextual_links']['block']['0']; == admin/structure/block/manage
$variables['page']['sidebar_first']['system_navigation']['#theme_wrappers']['1']; == block
$variables['page']['sidebar_first']['system_navigation']['#contextual_links']['block']['0']; == admin/structure/block/manage
$variables['page']['footer']['system_powered-by']['#contextual_links']['block']['0']; == admin/structure/block/manage
$variables['page']['footer']['system_powered-by']['#theme_wrappers']['0']; == block
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | Variable_Hunter.png | 88.17 KB | jeoware |
Comments
Comment #1
PA robot commentedWe are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)
Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).
I'm a robot and this is an automated message from Project Applications Scraper.
Comment #2
ronfeathers commentedNot sure why this is in "needs review"
There are no files, and you're still on the master branch?
Maybe I'm missing something?
~R~
Comment #3
jeoware commentedProblem/Motivation
Corrected missing files - changed branch to 7.x-1.x-dev
Proposed resolution
Please review php_variable_hunter. This little module saves me so much time finding where a variable is located in the tree.
Remaining tasks
php_variable_hunter complements print_r and dpm. It is more specific, searching for a value (needle) in a very complex variable tree. It will go down to 15 levels (more if you change the code)
Original report by ronfeathers
Not sure why this is in "needs review"
There are no files, and you're still on the master branch?
Maybe I'm missing something?
Comment #4
ayesh commentedLooks like a neat and useful module (I can remember myself expanding a huge dpm tree and searching it with the browser).
- in your repo, there is a folder with 7.x-1.x-dev name. Put the files in the branch root and a folder name is not necessary.
- Devel module is a de facto to debug stuff, so there is a good chance that the users have Devel module installed. I'd rather prefer a Devel integration so I can debug the stuff well.
Devel module has permission-based debug info display, as well as using Drupal's message system. Printing stuff directly makes it very difficult to use your module to debug an Ajax request.
Devel module does a good job there by adding multiple display methods. dpm, kpr, etc.
- you can use format_plural() to display "1 match found" or "x matches found" text.
- let's also document how to return an array of matches to a variable(describe the internal call function) - this will be very useful to dpm().
- GPL license will be included as a text file when your module gets downloaded from Drupal.org, so including those information is not necessary I think
Comment #5
ayesh commentedI'm sorry if I was at the extreme side when mentioning Devel integration. IMO, it's not necessary to patch Devel module and put this nice module into the Devel - but we can definitely make use of Devels features.
For example,
dpm(phpvariable_hunter_internalcall($array, $needle, $exact_match));Above line will return the results array to dpm() function that we use everyday to see array contacts.
Better yet, if we can create a function like dpvh() that does the same job as above, it will be more convenient I think. But in order to use dpm(), we must make sure dpm() function is available.
To do so, we can check function_exists('dpm'), or add devel as a dependency in the .info file.
If we can alias the internal call function to something smaller (phvr() for example), we can document an easy to use way like dpm(phvr())
However, deciding them is completely up to you. I'm going to be a big fan of this module because I can remember myself clicking the Devel-output tree numerous times. If it can be any quick or requires fewer keystrokes, the better :)
Comment #6
PA robot commentedThere are some errors reported by automated review tools, did you already check them? See http://pareview.sh/pareview/httpgitdrupalorgsandboxjeoware2023153git
I'm a robot and this is an automated message from Project Applications Scraper.
Comment #7
jeoware commentedFixed formatting errors.
To test, call in Marinelli theme (or any) page.tpl - $varlist = pvh($variables , 'block');
Returns 20 matches, sample follows; results can be copied into code or examined further using dpm, print_r or other variable display engines.
$variables['page']['sidebar_first']['search_form']['#contextual_links']['block']['0']; == admin/structure/block/manage
$variables['page']['sidebar_first']['system_navigation']['#theme_wrappers']['1']; == block
$variables['page']['sidebar_first']['system_navigation']['#contextual_links']['block']['0']; == admin/structure/block/manage
$variables['page']['footer']['system_powered-by']['#contextual_links']['block']['0']; == admin/structure/block/manage
$variables['page']['footer']['system_powered-by']['#theme_wrappers']['0']; == block
Comment #7.0
jeoware commentedRewrite description
Comment #8
fuzzy76 commentedMy initial thought is that this should probably be done as a patch to devel. I see you have an issue over there already #2061317: Add phpvariable_hunter … Come to think of it, this module is also too small to warrant a full review.
Comment #9
jeoware commentedI know it's tiny, but it's so useful. As a PHP developer, I was able to find variables in a second, rather than stopping the compiler, drilling down through a list or pressing find.
Unfortunately, I haven't been able to contact anyone for the dev module except through the request, so it's probably not going to be noticed. It's as tough as nails to get anyone to use anything new.
Comment #10
sreynen commentedComment #11
sreynen commentedHi jeoware,
I agree this is too small to do a full review and grant full project access. We can, however, review this and promote this specific project if you want.
To that end, manual review:
* It's not clear to me why you're using $GLOBALS. It doesn't appear to be necessary, and global scope should only be used when necessary. Could you pass those variables into phpvariable_hunter_results() as parameters, or use drupal_static to make them available globally without putting them in the global scope?
* I think pvh() needs to be namespaced with your module name as a prefix. Yes, devel breaks this rule with dpm(), etc. I'm not sure how we're deciding which modules can get away with that, but in this case, I don't see any good reason for your module to use a prefix that doesn't match your module name. If having pvh() as a function name is important, any reason not to change the module machine name to pvh?
* Why is phpvariable_hunter() making print() calls? It looks like that will dump output wherever it happens to be called in a page render, which would be mostly at the very beginning of a page, before the opening HTML. That seems kind of messy. Could that be returned as part of the response? Or maybe output with drupal_set_message()?
Comment #12
sreynen commentedComment #13
jeoware commentedsreynen,
Thanks for your critique. I'll put the 3 changes in, setting up a new sandbox called pvh. I wrestled with the name change, because pvh() doesn't mean anything, but I'm lazy and don't want to type 'phpvariable_hunter()'. The vanilla PHP code can't have Drupal calls, but passing the values by parm sounds interesting.
I'm fairly new to the community, I've been programming for several decades, find PHP fascinatingly dynamic. My do-it-yourself personality has left me with few comrades who know PHP. I'll make the changes for Drupal, setup a review request for the new module and leave it there; it would be nice to have it in the devel module. I look forward to reviewing some projects in the upcoming weeks, will find it a great education. Thanks so much for your input, and I hope to make friends along the way.
Comment #14
ayesh commentedIf you had a look at some applications here, you will see there are many applications from experienced users like you but are delayed because of these "Drupal standards".
I started to use phv in some of my test sites and getting used to it.
Comment #15
jeoware commentedThey have great points about not using $globals, using drupal_set_message.
So, this is what I'm going to do:
- Apply the fixes mentioned above.
- Leave it called PHP Variable Hunter with shorthand pvh().
- Put in new review requests, including for the Devel module.
- Review some other modules.
Web Development & Windows Software
http://www.idxsoft.com
Comment #16
jeoware commentedNew release for PHP Variable Hunter - Finds a deeply nested variable in an array.
- Added the calling variable to the printed list.
- Corrected the code to use parameters instead of $GLOBALS.
- Please review, comments are appreciated.
- Please consider recommending promotion to the Devel module.
Comment #17
kscheirer$callerinfo = '';? We generally don't allow bare PHP, and I can't find where you are using that.I think it's fine to provide a pvh() shortcut.
I reopened and commented on https://drupal.org/node/2061317#comment-7790309 as well.
Setting to needs work for the first 2 issues, which are blocking.
Comment #18
kscheirerComment #19
jeoware commentedIssue #1 - Remove license - fixed.
Issue #2 - Remove variable assignment - this was test code, lost in the comments. - fixed.
Cleaned up the order of subroutine execution. All should be ready whenever you are.
Comment #20
jeoware commentedI've put on the higher priority TODO list:
- Integrate with Drush.
- Add block for output.
Thanks so much for your input!
Comment #21
kscheirerThanks for those updates! I can't find any blocking issues.
----
Top Shelf Modules - Crafted, Curated, Contributed.
Comment #22
kscheirerIt's been a month without any problems reported, so I'm promoting this myself as per https://drupal.org/node/1125818.
Thanks for your contribution, jeoware!
I updated your account to let you promote this to a full project and also create new projects as either a sandbox or a "full" project.
Here are some recommended readings to help with excellent maintainership:
You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and get involved!
Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.
Thanks to the dedicated reviewer(s) as well.
----
Top Shelf Modules - Crafted, Curated, Contributed.
Comment #23.0
(not verified) commentedRevise description.