Completed
Push — master ( 655053...db47c8 )
by Ben
02:17
created

StreamObject::writeToStream()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 16
rs 9.4286
cc 2
eloc 10
nc 2
nop 2
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\Utils\EncryptionUtils;
13
use SplFileObject;
14
15
/**
16
 * Stream object as defined by section 3.2.7
17
 */
18
class StreamObject extends DictionaryObject
19
{
20
    /**
21
     * @var string
22
     */
23
    private $data;
24
25
    /**
26
     * @param string $data
27
     */
28
    public function __construct($data)
29
    {
30
        $this->data = $data;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function writeToStream(SplFileObject $fileObject, $encryptionKey)
37
    {
38
        $this['Length'] = new NumericObject(strlen($this->data));
39
        parent::writeToStream($fileObject, $encryptionKey);
40
        unset($this['Length']);
41
42
        $fileObject->fwrite("\nstream\n");
43
        $data = $this->data;
44
45
        if (null !== $encryptionKey) {
46
            $data = EncryptionUtils::rc4($encryptionKey, $data);
47
        }
48
49
        $fileObject->fwrite($data);
50
        $fileObject->fwrite("\nendstream");
51
    }
52
}
53