diff options
author | Thomas Citharel <tcit@tcit.fr> | 2015-02-18 19:17:31 +0100 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2015-02-18 19:17:31 +0100 |
commit | 4b1fa4c2febc7abbc6da3d65e4e760949a55843c (patch) | |
tree | a93ec906dbb03ec70e9cdc5dc876392c6d758e97 /inc/3rdparty/libraries/MOBIClass/FileElement.php | |
parent | 364953ede585b75fb29dc94b1c5f853053eaed0b (diff) | |
parent | df89c6f71adebfdb754ec3eb2fd775d8efbdb280 (diff) | |
download | wallabag-4b1fa4c2febc7abbc6da3d65e4e760949a55843c.tar.gz wallabag-4b1fa4c2febc7abbc6da3d65e4e760949a55843c.tar.zst wallabag-4b1fa4c2febc7abbc6da3d65e4e760949a55843c.zip |
Merge pull request #1081 from wallabag/dev1.9
Version 1.9.0
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 | ?> | ||