我在項目中使用PHP-FineDiff
作爲服務。然而,當我嘗試使用例如恢復差異來創建diff時,效果很好。 FineDiff::renderToTextFromOpcodes()
,沒有任何反應。在Symfony2服務中回調失敗
我在代碼中挖了一點,發現回調不起作用。註釋掉一些
if (!is_callable($callback)) {
return;
}
後,我遇到了錯誤:
Warning: call_user_func() expects parameter 1 to be a valid callback, class 'FineDiff' not found in /var/www/sopos-blog/src/Sopos/WikiBundle/Services/FineDiff.php line 321.
這些都是一些代碼相關線路:
public static function renderToTextFromOpcodes($from, $opcodes) {
ob_start();
FineDiff::renderFromOpcodes($from, $opcodes, array('FineDiff','renderToTextFromOpcode'));
return ob_get_clean();
}
// ...
public static function renderFromOpcodes($from, $opcodes, $callback) {
if (!is_callable($callback)) {
return;
}
$opcodes_len = strlen($opcodes);
$from_offset = $opcodes_offset = 0;
while ($opcodes_offset < $opcodes_len) {
$opcode = substr($opcodes, $opcodes_offset, 1);
$opcodes_offset++;
$n = intval(substr($opcodes, $opcodes_offset));
if ($n) {
$opcodes_offset += strlen(strval($n));
}
else {
$n = 1;
}
if ($opcode === 'c') { // copy n characters from source
call_user_func($callback, 'c', $from, $from_offset, $n, '');
$from_offset += $n;
}
// ...
謝謝@Florent,它現在可以工作! – Michael 2012-08-10 15:38:44