Skip to content

Instantly share code, notes, and snippets.

@uppfinnarjohnny
Created December 5, 2009 23:42
Show Gist options
  • Save uppfinnarjohnny/249920 to your computer and use it in GitHub Desktop.
Save uppfinnarjohnny/249920 to your computer and use it in GitHub Desktop.
MobWrite
<?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