Passed
Push — master ( efcec5...2f5cc5 )
by Maxence
02:34
created

TemplateFile::getFilename()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 2
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
/**
3
 * CMS Pico - Integration of Pico within your files to create websites.
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2017
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\CMSPico\Model;
28
29
30
class TemplateFile {
31
32
	/** @var string */
33
	private $base;
34
35
	/** @var string */
36
	private $filename;
37
38
	/** @var string */
39
	private $content;
40
41
42
	/**
43
	 * TemplateFile constructor.
44
	 *
45
	 * @param string $base
46
	 * @param string $filename
47
	 */
48
	function __construct($base, $filename) {
49
		$this->base = $base;
50
		$this->filename = $filename;
51
		$this->content = file_get_contents($base . $filename);
52
	}
53
54
55
	/**
56
	 * @return string
57
	 */
58
	public function getFilename() {
59
		return $this->filename;
60
	}
61
62
63
	/**
64
	 * @param string $content
65
	 */
66
	public function setContent($content) {
67
		$this->content = $content;
68
	}
69
70
	/**
71
	 * @return string
72
	 */
73
	public function getContent() {
74
		return $this->content;
75
	}
76
77
78
	public function applyData($data) {
79
		$ak = array_keys($data);
80
		$temp = $this->getContent();
81
		foreach ($ak as $k) {
82
			$temp = str_replace('%%' . $k . '%%', $data[$k], $temp);
83
		}
84
85
		$this->setContent($temp);
86
	}
87
}