1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* BaconPdf |
4
|
|
|
* |
5
|
|
|
* @link http://github.com/Bacon/BaconPdf For the canonical source repository |
6
|
|
|
* @copyright 2015 Ben 'DASPRiD' Scholzen |
7
|
|
|
* @license http://opensource.org/licenses/BSD-2-Clause Simplified BSD License |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Bacon\Pdf\Object; |
11
|
|
|
|
12
|
|
|
use ArrayAccess; |
13
|
|
|
use Bacon\Pdf\Exception\InvalidArgumentException; |
14
|
|
|
use IteratorAggregate; |
15
|
|
|
use SplFileObject; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Dictionary object as defined by section 3.2.6 |
19
|
|
|
*/ |
20
|
|
|
class DictionaryObject extends AbstractObject implements ArrayAccess, IteratorAggregate |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var ObjectInterface[] |
24
|
|
|
*/ |
25
|
|
|
private $items; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
|
|
public function writeToStream(SplFileObject $fileObject, $encryptionKey) |
31
|
|
|
{ |
32
|
|
|
$fileObject->fwrite("<<\n"); |
33
|
|
|
|
34
|
|
|
foreach ($this->items as $key => $value) { |
35
|
|
|
(new NameObject($key))->writeToStream($fileObject); |
36
|
|
|
$fileObject->fwrite(' '); |
37
|
|
|
$value->writeToStream($fileObject); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$fileObject->fwrite('>>'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
|
|
public function offsetExists($offset) |
47
|
|
|
{ |
48
|
|
|
return isset($this->items[$offset]); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function offsetGet($offset) |
55
|
|
|
{ |
56
|
|
|
return isset($this->items[$offset]) ? $this->items[$offset] : null; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
|
|
public function offsetSet($offset, $value) |
63
|
|
|
{ |
64
|
|
|
if (!$value instanceof ObjectInterface) { |
65
|
|
|
throw new InvalidArgumentException(sprintf( |
66
|
|
|
'Value must be an instance of type ObjectInterface, %s given', |
67
|
|
|
is_object($value) ? get_class($value) : gettype($value) |
68
|
|
|
)); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$this->items[$offset] = $value; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
|
|
public function offsetUnset($offset) |
78
|
|
|
{ |
79
|
|
|
unset($this->items[$offset]); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritdoc} |
84
|
|
|
*/ |
85
|
|
|
public function getIterator() |
86
|
|
|
{ |
87
|
|
|
foreach ($this->items as $index => $item) { |
88
|
|
|
yield $index => $item; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
This check looks for function calls that miss required arguments.