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

LiteralStringObject::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
/**
13
 * Literal string object as defined by section 3.2.3
14
 */
15
class LiteralStringObject extends AbstractObject
16
{
17
    /**
18
     * @var string
19
     */
20
    private $value;
21
22
    /**
23
     * @param string $value
24
     */
25
    public function __construct($value)
26
    {
27
        $this->value = $value;
28
    }
29
30
    /**
31
     * @return string
32
     */
33
    public function getValue()
34
    {
35
        return $this->value;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function writeToStream(SplFileObject $fileObject, $encryptionKey)
42
    {
43
        $value = $this->value;
44
45
        if (null !== $encryptionKey) {
46
            (new HexadecimalStringObject($value))->writeToStream($fileObject, $encryptionKey);
47
            return;
48
        }
49
50
        $fileObject->fwrite('(');
51
        $fileObject->fwrite(chunk_split(strtr($value, [
52
            '(' => '\\(',
53
            ')' => '\\)',
54
            '\\' => '\\\\',
55
        ]), 255, "\\\n"));
56
        $fileObject->fwrite(')');
57
    }
58
}
59