Skip to content
Snippets Groups Projects
Commit 85a8e556 authored by Jim Berry's avatar Jim Berry
Browse files

coder_upgrade.api.php: update documentation to reflect the node being returned...

coder_upgrade.api.php: update documentation to reflect the node being returned by getFunctionCalls(); coder_upgrade.db.inc: improve sql parsing and conversion to DBTNG syntax.
parent b3cdefca
No related branches found
No related tags found
No related merge requests found
...@@ -2,8 +2,14 @@ ...@@ -2,8 +2,14 @@
coder_upgrade 7.x-1.x, 2009-xx-xx (development version) coder_upgrade 7.x-1.x, 2009-xx-xx (development version)
--------------------------------- ---------------------------------
- Changes (2010-07-12):
* coder_upgrade.api.php
* - update documentation to reflect the node being returned by getFunctionCalls()
* coder_upgrade.db.inc
* - improve sql parsing and conversion to DBTNG syntax
- Changes (2010-07-09): - Changes (2010-07-09):
* coder_upgrade.call.inc, coder_upgrade.main.inc * coder_upgrade.call.inc, coder_upgrade.db.inc, and coder_upgrade.main.inc
* - revise code to reflect change to PGPReader::getFunctionCalls() which now returns a list of nodes * - revise code to reflect change to PGPReader::getFunctionCalls() which now returns a list of nodes
* (NOTE: this change was made using an upgrade routine and this module) * (NOTE: this change was made using an upgrade routine and this module)
* coder_upgrade.call.inc * coder_upgrade.call.inc
......
...@@ -68,21 +68,26 @@ function hook_upgrade_info() { ...@@ -68,21 +68,26 @@ function hook_upgrade_info() {
* @endcode * @endcode
* *
* Coder Upgrade will call this alter hook for each function call in the file * Coder Upgrade will call this alter hook for each function call in the file
* that was parsed. Refer to the grammar parser documentation for details of the * that was parsed. However, the function name must be a string, not a variable
* function call object. * expression. To modify the latter, use hook_upgrade_file_alter(). Refer to the
* grammar parser documentation for details of the function call object.
* *
* @see hook_upgrade_file_alter
* @see PGPFunctionCall * @see PGPFunctionCall
* *
* @param PGPFunctionCall $item * @param PGPFunctionCall $node
* A function call object of the expression or statement. * A node object containing a function call object.
* @param PGPReader $reader * @param PGPReader $reader
* The object containing the grammar statements of the file to convert. * The object containing the grammar statements of the file to convert.
*/ */
function hook_upgrade_call_FUNCTION_NAME_alter(&$item, &$reader) { function hook_upgrade_call_FUNCTION_NAME_alter(&$node, &$reader) {
// Get the function call object.
$item = &$node->data;
// Change the function name. // Change the function name.
$item->name = 'new_name'; $item->name['value'] = 'new_name';
if ($item->parameters->count() > 0) { if ($item->parameterCount() > 0) {
// Delete the first parameter. // Delete the first parameter.
$item->deleteParameter(); $item->deleteParameter();
} }
...@@ -102,20 +107,25 @@ function hook_upgrade_call_FUNCTION_NAME_alter(&$item, &$reader) { ...@@ -102,20 +107,25 @@ function hook_upgrade_call_FUNCTION_NAME_alter(&$item, &$reader) {
* @endcode * @endcode
* *
* Coder Upgrade will call this alter hook for each function call in the file * Coder Upgrade will call this alter hook for each function call in the file
* that was parsed. Refer to the grammar parser documentation for details of the * that was parsed. However, the function name must be a string, not a variable
* function call object. * expression. To modify the latter, use hook_upgrade_file_alter(). Refer to the
* grammar parser documentation for details of the function call object.
* *
* @see hook_upgrade_file_alter
* @see PGPFunctionCall * @see PGPFunctionCall
* *
* @param PGPFunctionCall $item * @param PGPFunctionCall $node
* A function call object of the expression or statement. * A node object containing a function call object.
* @param PGPReader $reader * @param PGPReader $reader
* The object containing the grammar statements of the file to convert. * The object containing the grammar statements of the file to convert.
* @param $name * @param $name
* The name of the function. * The name of the function.
*/ */
function hook_upgrade_call_alter(&$item, &$reader, $name) { function hook_upgrade_call_alter(&$node, &$reader, $name) {
// Modify function call. // Get the function call object.
$item = &$node->data;
// Modify the function call.
switch ($name) { switch ($name) {
case 'foo': case 'foo':
$item->deleteParameter(); $item->deleteParameter();
...@@ -151,8 +161,7 @@ function hook_upgrade_call_alter(&$item, &$reader, $name) { ...@@ -151,8 +161,7 @@ function hook_upgrade_call_alter(&$item, &$reader, $name) {
* that was parsed. However, the function name must follow the naming convention * that was parsed. However, the function name must follow the naming convention
* for a hook, i.e, your_module_name_hook. If your module declares a hook for * for a hook, i.e, your_module_name_hook. If your module declares a hook for
* another module or otherwise digresses from the standard naming convention, * another module or otherwise digresses from the standard naming convention,
* then you will need to add a converion routine to the list to be able to alter * then use hook_upgrade_file_alter() to alter this function.
* this function.
* *
* Refer to the grammar parser documentation for details of the function object * Refer to the grammar parser documentation for details of the function object
* (i.e. PGPClass). * (i.e. PGPClass).
...@@ -176,7 +185,7 @@ function hook_upgrade_hook_HOOK_NAME_alter(&$node, &$reader) { ...@@ -176,7 +185,7 @@ function hook_upgrade_hook_HOOK_NAME_alter(&$node, &$reader) {
// Update the document comment. // Update the document comment.
$item->comment['value'] = preg_replace('@\* Implement\s+@', "* Implements ", $item->comment['value']); $item->comment['value'] = preg_replace('@\* Implement\s+@', "* Implements ", $item->comment['value']);
if ($item->parameters->count() > 1) { if ($item->parameterCount() > 1) {
// Switch the first two parameters. // Switch the first two parameters.
$p0 = $item->getParameter(0); $p0 = $item->getParameter(0);
$p1 = $item->getParameter(1); $p1 = $item->getParameter(1);
...@@ -210,8 +219,7 @@ function hook_upgrade_hook_HOOK_NAME_alter(&$node, &$reader) { ...@@ -210,8 +219,7 @@ function hook_upgrade_hook_HOOK_NAME_alter(&$node, &$reader) {
* that was parsed. However, the function name must follow the naming convention * that was parsed. However, the function name must follow the naming convention
* for a hook, i.e, your_module_name_hook. If your module declares a hook for * for a hook, i.e, your_module_name_hook. If your module declares a hook for
* another module or otherwise digresses from the standard naming convention, * another module or otherwise digresses from the standard naming convention,
* then you will need to add a conversion routine to the list to be able to alter * then use hook_upgrade_file_alter() to alter this function.
* this function.
* *
* Refer to the grammar parser documentation for details of the function object * Refer to the grammar parser documentation for details of the function object
* (i.e. PGPClass). * (i.e. PGPClass).
...@@ -240,7 +248,7 @@ function hook_upgrade_hook_alter(&$node, &$reader, &$hook) { ...@@ -240,7 +248,7 @@ function hook_upgrade_hook_alter(&$node, &$reader, &$hook) {
// Update the document comment. // Update the document comment.
$item->comment['value'] = preg_replace('@\* Implement\s+@', "* Implements ", $item->comment['value']); $item->comment['value'] = preg_replace('@\* Implement\s+@', "* Implements ", $item->comment['value']);
if ($item->parameters->count() > 1) { if ($item->parameterCount() > 1) {
// Switch the first two parameters. // Switch the first two parameters.
$p0 = $item->getParameter(0); $p0 = $item->getParameter(0);
$p1 = $item->getParameter(1); $p1 = $item->getParameter(1);
...@@ -271,9 +279,10 @@ function hook_upgrade_file_alter(&$reader) { ...@@ -271,9 +279,10 @@ function hook_upgrade_file_alter(&$reader) {
*/ */
// Get list of function calls (including the calls to class methods). // Get list of function calls (including the calls to class methods).
$items = &$reader->getFunctionCalls(); $nodes = &$reader->getFunctionCalls();
// Loop on list. // Loop on list.
foreach ($items as &$item) { foreach ($nodes as &$node) {
$item = &$node->data;
if (!isset($item) || !is_object($item) || !is_a($item, 'PGPFunctionCall') || $item->type != T_FUNCTION_CALL) { if (!isset($item) || !is_object($item) || !is_a($item, 'PGPFunctionCall') || $item->type != T_FUNCTION_CALL) {
/* /*
* These checks are necessary as the reference (i.e. $item) could have * These checks are necessary as the reference (i.e. $item) could have
...@@ -446,11 +455,14 @@ function your_module_name_upgrade_info() { ...@@ -446,11 +455,14 @@ function your_module_name_upgrade_info() {
/** /**
* Implements hook_upgrade_call_FUNCTION_NAME_alter(). * Implements hook_upgrade_call_FUNCTION_NAME_alter().
*/ */
function your_module_name_upgrade_call_function_name_alter(&$item, &$reader) { function your_module_name_upgrade_call_function_name_alter(&$node, &$reader) {
// Get the function call object.
$item = &$node->data;
// Change the function name. // Change the function name.
$item->name = 'new_name'; $item->name['value'] = 'new_name';
if ($item->parameters->count() > 0) { if ($item->parameterCount() > 0) {
// Delete the first parameter. // Delete the first parameter.
$item->deleteParameter(); $item->deleteParameter();
} }
...@@ -470,7 +482,7 @@ function your_module_name_upgrade_hook_hook_name_alter(&$node, &$reader) { ...@@ -470,7 +482,7 @@ function your_module_name_upgrade_hook_hook_name_alter(&$node, &$reader) {
// Update the document comment. // Update the document comment.
$item->comment['value'] = preg_replace('@\* Implement\s+@', "* Implements ", $item->comment['value']); $item->comment['value'] = preg_replace('@\* Implement\s+@', "* Implements ", $item->comment['value']);
if ($item->parameters->count() > 1) { if ($item->parameterCount() > 1) {
// Switch the first two parameters. // Switch the first two parameters.
$p0 = $item->getParameter(0); $p0 = $item->getParameter(0);
$p1 = $item->getParameter(1); $p1 = $item->getParameter(1);
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment