function _patterns_array_context in Patterns 7
Same name and namespace in other branches
- 6.2 patterns.module \_patterns_array_context()
- 6 patterns.module \_patterns_array_context()
- 7.2 includes/unused.inc \_patterns_array_context()
Helper function to create a context array based on the supplied object.
Supplying a parent object will set the parent for this context. @TODO Doc.
2 calls to _patterns_array_context()
- patterns_array_fetch in includes/
unused.inc - Finds parts of an array based on a semi-compatible Xpath syntax.
- patterns_config_data in includes/
unused.inc - Take a $data and $config object and adjust $data based on the supplied configuration
File
- includes/
unused.inc, line 645 - Functions that are unused at the moment.
Code
function _patterns_array_context(&$obj, &$current = NULL) {
// If a current context is set, use it's parent and key values
if (!($trace = $current['trace'])) {
$trace = array();
}
if (!($key = $current['key'])) {
$key = NULL;
}
if (!($parent =& $current['parent'])) {
$parent = NULL;
}
$context = array(
'trace' => $trace,
'key' => $key,
'item' => &$obj,
'parent' => &$parent,
);
$refs = array(
&$context,
);
while (!empty($refs)) {
$ref =& $refs[0];
$parent =& $ref['item'];
array_splice($refs, 0, 1);
if (is_array($parent) && !empty($parent)) {
$i = 0;
foreach ($parent as $index => &$child) {
// TODO possible optimizations can be done here (with the parent trace)
$ref[$i] = array(
'trace' => _patterns_array_trace($ref),
'key' => $index,
'item' => &$child,
'parent' => &$ref,
);
array_unshift($refs, '');
$refs[0] =& $ref[$i++];
}
}
}
return $context;
}