From fb9df0c269f36703909b8b259abbdbed29881ecd Mon Sep 17 00:00:00 2001 From: tcit Date: Thu, 24 Jul 2014 21:56:04 +0200 Subject: use directly MOBIClass --- inc/3rdparty/libraries/MOBIClass/FileElement.php | 89 ++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 inc/3rdparty/libraries/MOBIClass/FileElement.php (limited to 'inc/3rdparty/libraries/MOBIClass/FileElement.php') diff --git a/inc/3rdparty/libraries/MOBIClass/FileElement.php b/inc/3rdparty/libraries/MOBIClass/FileElement.php new file mode 100644 index 00000000..552d04a8 --- /dev/null +++ b/inc/3rdparty/libraries/MOBIClass/FileElement.php @@ -0,0 +1,89 @@ +elements = $elements; + } + + public function getByteLength(){ + return $this->getLength(); + } + + public function getLength(){ + $total = 0; + foreach($this->elements as $val){ + $total += $val->getByteLength(); + } + return $total; + } + + public function offsetToEntry($name){ + $pos = 0; + foreach($this->elements as $key=>$value){ + if($name == $key){ + break; + } + $pos += $value->getByteLength(); + } + return $pos; + } + + public function exists($key){ + return isset($this->elements[$key]); + } + /** + * @param string $key + * @return FileObject + */ + public function get($key){ + return $this->elements[$key]; + } + + /** + * @param string $key + * @param FileObject $value + */ + public function set($key, $value){ + $this->elements[$key] = $value; + } + + public function add($key, $value){ + $this->elements[$key] = $value; + } + + public function serialize() { + $result = ""; + foreach($this->elements as $val){ + $result .= $val->serialize(); + } + return $result; + } + + public function unserialize($data) { + //TODO: If reading is needed -> way more complex + } + + public function __toString(){ + $output = "FileElement (".$this->getByteLength()." bytes): {\n"; + foreach($this->elements as $key=>$value){ + $output .= "\t".$key.": ".$value."\n"; + } + $output .= "}"; + return $output; + } +} +?> -- cgit v1.2.3