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 Bacon\Pdf\Exception\OutOfBoundsException; |
13
|
|
|
use IteratorAggregate; |
14
|
|
|
use SplFileObject; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Array object as defined by section 3.2.5 |
18
|
|
|
*/ |
19
|
|
|
class ArrayObject extends AbstractObject implements IteratorAggregate |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var ObjectInterface[] |
23
|
|
|
*/ |
24
|
|
|
private $items; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param ObjectInterface[] $items |
28
|
|
|
*/ |
29
|
|
|
public function __construct(array $items = []) |
30
|
|
|
{ |
31
|
|
|
foreach ($items as $item) { |
32
|
|
|
$this->append($item); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param ObjectInterface $object |
38
|
|
|
*/ |
39
|
|
|
public function append(ObjectInterface $object) |
40
|
|
|
{ |
41
|
|
|
$this->items[] = $object; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param int $index |
46
|
|
|
* @return ObjectInterface |
47
|
|
|
*/ |
48
|
|
|
public function get($index) |
49
|
|
|
{ |
50
|
|
|
if (!array_key_exists($index, $this->items)) { |
51
|
|
|
throw new OutOfBoundsException(sprintf( |
52
|
|
|
'Could not find an item with index %d', |
53
|
|
|
$index |
54
|
|
|
)); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $this->items[$index]; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
|
|
public function writeToStream(SplFileObject $fileObject, $encryptionKey) |
64
|
|
|
{ |
65
|
|
|
$fileObject->fwrite('['); |
66
|
|
|
|
67
|
|
|
foreach ($this->items as $value) { |
68
|
|
|
$fileObject->fwrite(' '); |
69
|
|
|
$value->writeToStream($fileObject); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$fileObject->fwrite(']'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
|
|
public function getIterator() |
79
|
|
|
{ |
80
|
|
|
foreach ($this->items as $index => $item) { |
81
|
|
|
yield $index => $item; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
This check looks for function calls that miss required arguments.