*
* Note that this method will auto-load the task class file and test for the existence
* of the name with "-" replaced by "_" as in PEAR/Task/mycustom/task.php makes class
* PEAR_Task_mycustom_task
* @param string
* @return boolean
*/
function getTask($task)
{
$this->getTasksNs();
// transform all '-' to '/' and 'tasks:' to '' so tasks:replace becomes replace
$task = str_replace(array($this->_tasksNs . ':', '-'), array('', ' '), $task);
$taskfile = str_replace(' ', '/', ucwords($task));
$task = str_replace(array(' ', '/'), '_', ucwords($task));
if (class_exists("PEAR_Task_$task")) {
return "PEAR_Task_$task";
}
$fp = @fopen("PEAR/Task/$taskfile.php", 'r', true);
if ($fp) {
fclose($fp);
require_once "PEAR/Task/$taskfile.php";
return "PEAR_Task_$task";
}
return false;
}
/**
* Key-friendly array_splice
* @param tagname to splice a value in before
* @param mixed the value to splice in
* @param string the new tag name
*/
function _ksplice($array, $key, $value, $newkey)
{
$offset = array_search($key, array_keys($array));
$after = array_slice($array, $offset);
$before = array_slice($array, 0, $offset);
$before[$newkey] = $value;
return array_merge($before, $after);
}
/**
* @param array a list of possible keys, in the order they may occur
* @param mixed contents of the new package.xml tag
* @param string tag name
* @access private
*/
function _insertBefore($array, $keys, $contents, $newkey)
{
foreach ($keys as $key) {
if (isset($array[$key])) {
return $array = $this->_ksplice($array, $key, $contents, $newkey);
}
}
$array[$newkey] = $contents;
return $array;
}
/**
* @param subsection of {@link $_packageInfo}
* @param array|string tag contents
* @param array format:
*
* array(
* tagname => array(list of tag names that follow this one),
* childtagname => array(list of child tag names that follow this one),
* )
*
*
* This allows construction of nested tags
* @access private
*/
function _mergeTag($manip, $contents, $order)
{
if (count($order)) {
foreach ($order as $tag => $curorder) {
if (!isset($manip[$tag])) {
// ensure that the tag is set up
$manip = $this->_insertBefore($manip, $curorder, array(), $tag);
}
if (count($order) > 1) {
$manip[$tag] = $this->_mergeTag($manip[$tag], $contents, array_slice($order, 1));
return $manip;
}
}
} else {
return $manip;
}
if (is_array($manip[$tag]) && !empty($manip[$tag]) && isset($manip[$tag][0])) {
$manip[$tag][] = $contents;
} else {
if (is_array($manip[$tag]) && !count($manip[$tag])) {
$manip[$tag] = $contents;
} else {
$manip[$tag] = array($manip[$tag]);
$manip[$tag][] = $contents;
}
}
return $manip;
}
}
?>