function coder_exec_processors in Coder 7
Same name and namespace in other branches
- 5.2 scripts/coder_format/coder_format.inc \coder_exec_processors()
- 5 scripts/coder_format/coder_format.inc \coder_exec_processors()
- 6.2 scripts/coder_format/coder_format.inc \coder_exec_processors()
- 6 scripts/coder_format/coder_format.inc \coder_exec_processors()
- 7.2 scripts/coder_format/coder_format.inc \coder_exec_processors()
Execute special tasks on source code.
This function works similar to the Drupal hook and forms system. It searches for all defined functions with the given prefix and performs a preg_replace on the source code for each of these functions.
Processor functions are defined with a associative array containing the following keys with the corresponding values: #title A human readable text describing what the processor actually does. #search The regular expression to search for. #replace The replacement text for each match.
Optional definitions: #debug Set this to true to directly output the results of preg_match_all and exit script execution after this processor.
Parameters
string $code: The source code to process.
string $prefix: Prefix of the functions to execute.
Return value
The processed source code.
1 call to coder_exec_processors()
- coder_format_string_all in scripts/
coder_format/ coder_format.inc - Formats source code according to Drupal conventions, also using post and pre-processors.
File
- scripts/
coder_format/ coder_format.inc, line 1100 - Coder format helper functions.
Code
function coder_exec_processors($code, $prefix) {
if (empty($prefix)) {
return;
}
$tasks = get_defined_functions();
$tasks = $tasks['user'];
for ($c = 0, $cc = count($tasks); $c < $cc; ++$c) {
// If the defined function starts with the specified prefix, invoke it.
if (strpos($tasks[$c], $prefix) === 0) {
// Store the results using the function name as key in $tasks.
$tasks[$tasks[$c]] = call_user_func($tasks[$c]);
}
// Remove the (indexed) key for every checked function.
unset($tasks[$c]);
}
uasort($tasks, 'coder_order_processors');
foreach ($tasks as $func => $task) {
if (!isset($task['#search']) || !isset($task['#replace']) && !isset($task['#replace_callback'])) {
continue;
}
if (isset($task['#debug'])) {
// Output regular expression results if debugging is enabled.
preg_match_all($task['#search'], $code, $matches, PREG_SET_ORDER);
echo "<pre>";
var_dump($matches);
echo "</pre>\n";
// Exit immediately in debugging mode.
exit;
}
if (isset($task['#replace_callback'])) {
$code = preg_replace_callback($task['#search'], $task['#replace_callback'], $code);
}
else {
$code = preg_replace($task['#search'], $task['#replace'], $code);
}
}
return $code;
}