diff options
author | Thomas Citharel <tcit@tcit.fr> | 2014-12-14 00:16:39 +0100 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2014-12-14 00:16:39 +0100 |
commit | 1256e4c645c86f4165d052bf8116b957b373b837 (patch) | |
tree | 3cc3bd960df403a6e0645afcd9e4f5bbb68bfc0e /inc/3rdparty/libraries/MOBIClass/FileElement.php | |
parent | 9c55ed0923273da886497cb62302a79622e34a74 (diff) | |
parent | dc69d3e8d895c87f9d26c2d1309e40d6090d4c8d (diff) | |
download | wallabag-1256e4c645c86f4165d052bf8116b957b373b837.tar.gz wallabag-1256e4c645c86f4165d052bf8116b957b373b837.tar.zst wallabag-1256e4c645c86f4165d052bf8116b957b373b837.zip |
Merge branch 'tcitworld-ebook' into dev
Diffstat (limited to 'inc/3rdparty/libraries/MOBIClass/FileElement.php')
-rw-r--r-- | inc/3rdparty/libraries/MOBIClass/FileElement.php | 89 |
1 files changed, 89 insertions, 0 deletions
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 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Description of FileElement | ||
5 | * | ||
6 | * @author Sander | ||
7 | */ | ||
8 | class FileElement { | ||
9 | /** | ||
10 | * @var FileObject | ||
11 | */ | ||
12 | public $elements; | ||
13 | |||
14 | /** | ||
15 | * Make a record to be stored in a file | ||
16 | * @param Record $record | ||
17 | */ | ||
18 | public function __construct($elements = array()){ | ||
19 | $this->elements = $elements; | ||
20 | } | ||
21 | |||
22 | public function getByteLength(){ | ||
23 | return $this->getLength(); | ||
24 | } | ||
25 | |||
26 | public function getLength(){ | ||
27 | $total = 0; | ||
28 | foreach($this->elements as $val){ | ||
29 | $total += $val->getByteLength(); | ||
30 | } | ||
31 | return $total; | ||
32 | } | ||
33 | |||
34 | public function offsetToEntry($name){ | ||
35 | $pos = 0; | ||
36 | foreach($this->elements as $key=>$value){ | ||
37 | if($name == $key){ | ||
38 | break; | ||
39 | } | ||
40 | $pos += $value->getByteLength(); | ||
41 | } | ||
42 | return $pos; | ||
43 | } | ||
44 | |||
45 | public function exists($key){ | ||
46 | return isset($this->elements[$key]); | ||
47 | } | ||
48 | /** | ||
49 | * @param string $key | ||
50 | * @return FileObject | ||
51 | */ | ||
52 | public function get($key){ | ||
53 | return $this->elements[$key]; | ||
54 | } | ||
55 | |||
56 | /** | ||
57 | * @param string $key | ||
58 | * @param FileObject $value | ||
59 | */ | ||
60 | public function set($key, $value){ | ||
61 | $this->elements[$key] = $value; | ||
62 | } | ||
63 | |||
64 | public function add($key, $value){ | ||
65 | $this->elements[$key] = $value; | ||
66 | } | ||
67 | |||
68 | public function serialize() { | ||
69 | $result = ""; | ||
70 | foreach($this->elements as $val){ | ||
71 | $result .= $val->serialize(); | ||
72 | } | ||
73 | return $result; | ||
74 | } | ||
75 | |||
76 | public function unserialize($data) { | ||
77 | //TODO: If reading is needed -> way more complex | ||
78 | } | ||
79 | |||
80 | public function __toString(){ | ||
81 | $output = "FileElement (".$this->getByteLength()." bytes): {\n"; | ||
82 | foreach($this->elements as $key=>$value){ | ||
83 | $output .= "\t".$key.": ".$value."\n"; | ||
84 | } | ||
85 | $output .= "}"; | ||
86 | return $output; | ||
87 | } | ||
88 | } | ||
89 | ?> | ||