function hook_upgrade_file_alter in Coder 7
Same name and namespace in other branches
- 7.2 coder_upgrade/coder_upgrade.api.php \hook_upgrade_file_alter()
Alters a code file using the grammar parser.
This hook allows contributed modules to alter a code file object using the grammar parser. If a module defines a class, then the calls to its methods are not included in the calls to hook_upgrade_hook_HOOK_NAME_alter or hook_upgrade_hook_alter.
Parameters
PGPReader $reader: The object containing the grammar statements of the file to convert.
1 invocation of hook_upgrade_file_alter()
- coder_upgrade_apply_parser in coder_upgrade/
includes/ main.inc - Applies grammar parser conversion routines to a file.
File
- coder_upgrade/
coder_upgrade.api.php, line 276 - Documents hooks provided by this module.
Code
function hook_upgrade_file_alter(&$reader) {
/*
* Task: Modify calls to class methods.
*/
// Get list of function calls (including the calls to class methods).
$nodes =& $reader
->getFunctionCalls();
// Loop on list.
foreach ($nodes as &$node) {
// Get the function call object.
$item =& $node->data;
if (!isset($item) || !is_object($item) || !$item instanceof PGPFunctionCall || $item->type != T_FUNCTION_CALL) {
/*
* These checks are necessary as the reference (i.e. $item) could have
* been changed in another routine so that it no longer refers to a
* function call object.
*/
continue;
}
/*
* To be a call to a class method, the function name must be an expression
* like $this->foo() as opposed to a string or a single variable. This code
* checks the name is an expression (using is_a($item->name, 'PGPOperand'))
* and the value element of the name object is '$this'.
*
* Review the grammar structure object using $item->print_r().
*/
if ($item->name instanceof PGPOperand && $item->name
->findNode('value') == '$this') {
// Strip '$this->' from the name.
$name = substr($item->name
->toString(), 7);
// Modify the function call
my_module_convert_method($item, $reader, $name);
}
}
}