1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the adminbsb-material-design-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2018 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\AdminBSBBundle\Helper; |
13
|
|
|
|
14
|
|
|
use WBW\Library\Core\Exception\FileSystem\IOException; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* View helper. |
18
|
|
|
* |
19
|
|
|
* @author webeweb <https://github.com/webeweb/> |
20
|
|
|
* @package WBW\Bundle\AdminBSBBundle\Helper |
21
|
|
|
*/ |
22
|
|
|
class ViewHelper { |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Write a view. |
26
|
|
|
* |
27
|
|
|
* @param string $filename The filename. |
28
|
|
|
* @param string $content The content. |
29
|
|
|
* @param boolean $overwrite Overwrite ? |
30
|
|
|
* @return void |
31
|
|
|
* @throws IOException Throws an I/O exception an I/O error occurs. |
32
|
|
|
*/ |
33
|
|
|
public static function write($filename, $content, $overwrite = false) { |
34
|
|
|
|
35
|
|
|
// Check the filename. |
36
|
|
|
if (true === file_exists($filename) && false === $overwrite) { |
37
|
|
|
return; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
// Get and check the directory. |
41
|
|
|
$directory = dirname($filename); |
42
|
|
|
if (false === file_exists($directory)) { |
43
|
|
|
|
44
|
|
|
// Create the directories. |
45
|
|
|
mkdir($directory, 0755, true); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
// Open the filename. |
49
|
|
|
$stream = @fopen($filename, "w"); |
50
|
|
|
if (false === $stream) { |
51
|
|
|
throw new IOException(sprintf("Failed to open \"%s\"", $filename)); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// Write the content. |
55
|
|
|
if (false === @fwrite($stream, $content)) { |
56
|
|
|
throw new IOException(sprintf("Failed to write into \"%s\"", $filename)); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
// Close the filename. |
60
|
|
|
if (false === @fclose($stream)) { |
61
|
|
|
throw new IOException(sprintf("Failed to close \"%s\"", $filename)); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
} |
66
|
|
|
|