Created
December 5, 2009 23:42
-
-
Save uppfinnarjohnny/249920 to your computer and use it in GitHub Desktop.
MobWrite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MobWrite { | |
protected $user = 0; | |
protected $file = NULL; | |
protected $datastore; | |
protected $diffengine; | |
public function __construct($datastore, $diffengine) { | |
$this->datastore = $datastore; | |
$this->diffengine = $diffengine; | |
} | |
public function handle($data) { | |
foreach(explode("\n", $data) as $command) | |
$this->parse($command); | |
} | |
protected function parse($command) { | |
$parts = explode(':', $command); | |
} | |
protected function command_u($user_id) { | |
$this->user = $user_id; | |
} | |
protected function command_f($revision_id = NULL, $file_id) { | |
$this->file = $file_id; | |
} | |
protected function command_d($revision_id, $patch) { | |
$text = $this->datastore->get($this->file, $revision_id); | |
if($result = $this->diffengine->patch($text, $patch)) | |
$this->datastore->set($this->file, $result); | |
} | |
protected function command_r($file_id) { | |
return $this->datastore->get($file_id); | |
} | |
protected function command_n($file_id) { | |
$this->datastore->nullify($file_id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment