Passed
Push — develop ( 737e58...dbbcfc )
by nguereza
02:10
created

PDF::getFormat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Platine PDF
5
 *
6
 * Platine PDF is the lightweight for generating PDF documents
7
 *
8
 * This content is released under the MIT License (MIT)
9
 *
10
 * Copyright (c) 2020 Platine PDF
11
 *
12
 * Permission is hereby granted, free of charge, to any person obtaining a copy
13
 * of this software and associated documentation files (the "Software"), to deal
14
 * in the Software without restriction, including without limitation the rights
15
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
 * copies of the Software, and to permit persons to whom the Software is
17
 * furnished to do so, subject to the following conditions:
18
 *
19
 * The above copyright notice and this permission notice shall be included in all
20
 * copies or substantial portions of the Software.
21
 *
22
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
 * SOFTWARE.
29
 */
30
31
/**
32
 *  @file PDF.php
33
 *
34
 *  The PDF main class.
35
 *
36
 *  @package    Platine\PDF
37
 *  @author Platine Developers Team
38
 *  @copyright  Copyright (c) 2020
39
 *  @license    http://opensource.org/licenses/MIT  MIT License
40
 *  @link   http://www.iacademy.cf
41
 *  @version 1.0.0
42
 *  @filesource
43
 */
44
45
declare(strict_types=1);
46
47
namespace Platine\PDF;
48
49
/**
50
 * @class PDF
51
 * @package Platine\PDF
52
 */
53
class PDF
54
{
55
56
    /**
57
     * The generator instance to use
58
     * @var PDFGeneratorInterface
59
     */
60
    protected PDFGeneratorInterface $generator;
61
62
    /**
63
     * The content to use to generate PDF document
64
     * @var string
65
     */
66
    protected string $content = '';
67
68
    /**
69
     * The PDF generated filename
70
     * @var string
71
     */
72
    protected string $filename = 'output.pdf';
73
74
    /**
75
     * The PDF document paper type like 'A4', 'A5', 'letter', etc.
76
     * @var string
77
     */
78
    protected string $format = 'A4';
79
80
    /**
81
     * The PDF document orientation like 'portrait', 'landscape'
82
     * @var string
83
     */
84
    protected string $orientation = 'portrait';
85
86
    /**
87
     * Create new instance
88
     *
89
     * @param PDFGeneratorInterface $generator
90
     */
91
    public function __construct(PDFGeneratorInterface $generator)
92
    {
93
        $this->generator = $generator;
94
    }
95
96
    /**
97
     * Return the generator
98
     * @return PDFGeneratorInterface
99
     */
100
    public function getGenerator(): PDFGeneratorInterface
101
    {
102
        return $this->generator;
103
    }
104
105
    /**
106
     * Set the generator
107
     * @param PDFGeneratorInterface $generator
108
     * @return $this
109
     */
110
    public function setGenerator(PDFGeneratorInterface $generator): self
111
    {
112
        $this->generator = $generator;
113
        return $this;
114
    }
115
116
    /**
117
     * Return the content
118
     * @return string
119
     */
120
    public function getContent(): string
121
    {
122
        return $this->content;
123
    }
124
125
    /**
126
     * Return the filename
127
     * @return string
128
     */
129
    public function getFilename(): string
130
    {
131
        return $this->filename;
132
    }
133
134
    /**
135
     * Return the format
136
     * @return string
137
     */
138
    public function getFormat(): string
139
    {
140
        return $this->format;
141
    }
142
143
    /**
144
     * Return the orientation
145
     * @return string
146
     */
147
    public function getOrientation(): string
148
    {
149
        return $this->orientation;
150
    }
151
152
    /**
153
     * Set the content
154
     * @param string $content
155
     * @return $this
156
     */
157
    public function setContent(string $content): self
158
    {
159
        $this->content = $content;
160
        return $this;
161
    }
162
163
    /**
164
     * Set the filename
165
     * @param string $filename
166
     * @return $this
167
     */
168
    public function setFilename(string $filename): self
169
    {
170
        $this->filename = $filename;
171
        return $this;
172
    }
173
174
    /**
175
     * Set the format
176
     * @param string $format
177
     * @return $this
178
     */
179
    public function setFormat(string $format): self
180
    {
181
        $this->format = $format;
182
        return $this;
183
    }
184
185
    /**
186
     * Set the orientation
187
     * @param string $orientation
188
     * @return $this
189
     */
190
    public function setOrientation(string $orientation): self
191
    {
192
        $this->orientation = $orientation;
193
        return $this;
194
    }
195
196
    /**
197
     * Return the content of the generated PDF document as string
198
     * @return string
199
     */
200
    public function raw(): string
201
    {
202
        $this->generate();
203
204
        return $this->generator->raw();
205
    }
206
207
    /**
208
     * Download the generated PDF document
209
     * @return void
210
     */
211
    public function download(): void
212
    {
213
        $this->generate();
214
215
        $this->generator->download();
216
    }
217
218
    /**
219
     * Save the content of the generated PDF document on
220
     * the file system, etc.
221
     * @return void
222
     */
223
    public function save(): void
224
    {
225
        $this->generate();
226
227
        $this->generator->save();
228
    }
229
230
    /**
231
     * Generate the PDF document
232
     * @return $this
233
     */
234
    protected function generate(): self
235
    {
236
        $this->generator->generate(
237
            $this->content,
238
            $this->filename,
239
            $this->format,
240
            $this->orientation
241
        );
242
243
        return $this;
244
    }
245
}
246