1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace MazenTouati\NoEmoji; |
5
|
|
|
|
6
|
|
|
use MazenTouati\Simple2wayConfig\S2WConfig; |
7
|
|
|
use MazenTouati\NoEmoji\Entities\File; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Uses the scrapped unicodes to generate a RegEx pattern |
11
|
|
|
* |
12
|
|
|
* @author Mazen Touati <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class Prettifier |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* The class instance |
18
|
|
|
* |
19
|
|
|
* @var Prettifier |
20
|
|
|
*/ |
21
|
|
|
private static $_instance = null; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* File instance |
25
|
|
|
* @var File |
26
|
|
|
*/ |
27
|
|
|
private $_file; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The pretty content |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $_content; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Retrieves the singleton instance |
37
|
|
|
* |
38
|
|
|
* @return Prettifier |
39
|
|
|
*/ |
40
|
|
|
public static function getInstance() |
41
|
|
|
{ |
42
|
|
|
if (self::$_instance == null) { |
43
|
|
|
self::$_instance = new Prettifier(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return self::$_instance; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Initializes the Scrapper |
51
|
|
|
* |
52
|
|
|
* @param S2WConfig $c Configuration object |
53
|
|
|
* |
54
|
|
|
* @return Handler |
55
|
|
|
*/ |
56
|
|
|
public static function factory(S2WConfig $c) |
57
|
|
|
{ |
58
|
|
|
$instance = self::getInstance(); |
59
|
|
|
$instance->config = $c; |
|
|
|
|
60
|
|
|
|
61
|
|
|
$instance->_file = new File($c, 'storage.output.ranges'); |
62
|
|
|
|
63
|
|
|
return $instance; |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Starts prettifying |
68
|
|
|
* |
69
|
|
|
* @param string $type Prettifier class name |
70
|
|
|
* |
71
|
|
|
* @return Prettifier |
72
|
|
|
*/ |
73
|
|
|
public function run($type = 'ArrayPrettifier') |
74
|
|
|
{ |
75
|
|
|
$type = 'MazenTouati\NoEmoji\Prettifiers\\'.$type; |
76
|
|
|
$this->_content = $type::run($this->_file); |
77
|
|
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Exports the pretty output |
82
|
|
|
* |
83
|
|
|
* @return boolean|array Returns false on error or the result array |
84
|
|
|
*/ |
85
|
|
|
public function export() |
86
|
|
|
{ |
87
|
|
|
$base = $this->config->get('storage.base'); |
88
|
|
|
$fileTitle = $this->config->get('storage.output.prettyRangesFileTitle', 'Undefined Title'); |
89
|
|
|
$output = $this->config->get('storage.output.prettyRanges'); |
90
|
|
|
|
91
|
|
|
$export = File::toText($base . $output, $fileTitle, $this->_content); |
92
|
|
|
|
93
|
|
|
if (!is_array($export)) { |
94
|
|
|
return false; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $export; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|