aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/3rdparty/libraries/MOBIClass/FileElement.php
blob: 552d04a8499619de24dbe0d4c37c30e915dfcfec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php

/**
 * Description of FileElement
 *
 * @author Sander
 */
class FileElement {
	/**
	 * @var FileObject
	 */
	public $elements;

	/**
	 * Make a record to be stored in a file
	 * @param Record $record
	 */
	public function __construct($elements = array()){
		$this->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;
	}
}
?>