我有一種方法,從數據庫中提取修改過的預定義樹橫向樹,並過濾使用回調函數。例如:我應該如何PHPDoc回調?
/**
* Recursive function for building the Cas_Template_TreeNode.
*
* @static
* @param array $rows
* @param callback $filter A function to filter the tree by (return a value convertible to false to remove the item from the tree)
* @return array
*/
private static function MakeTreeGivenDbRows($rows, $filter = null)
{
if ($filter === null)
{
$filter = function($unused)
{
return true;
};
}
$result = array();
$childrenCount = 0;
for ($idx = 0; $idx < count($rows); $idx += $childrenCount + 1)
{
$current = $rows[$idx];
$childrenCount = self::ChildrenCountFromRow($current);
if (!$filter($current))
{
continue;
}
$childrenStartAt = $idx + 1;
$childRows = array_slice($rows, $childrenStartAt, $childrenCount);
$children = self::MakeTreeGivenDbRows($childRows, $filter);
$result[] = new Cas_Template_TreeNode(self::MakeNodeGivenDbRow($current), $children);
}
if (empty($result))
{
return null;
}
return $result;
}
我不知道該PHPDoc的應該是什麼樣的變量$filter
- 這是一個回調,這是我所指出的,但我不知道這是正確的。
而且,在此代碼的質量(或缺乏)任何其他意見,將不勝感激:)
很好的問題。 – zerkms 2011-02-07 07:32:48