-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace MazenTouati\NoEmoji; | ||
|
||
use MazenTouati\Simple2wayConfig\S2WConfig; | ||
use MazenTouati\NoEmoji\Entities\File; | ||
|
||
/** | ||
* Uses the scrapped unicodes to generate a RegEx pattern | ||
* | ||
* @author Mazen Touati <[email protected]> | ||
*/ | ||
class Prettifier | ||
{ | ||
/** | ||
* The class instance | ||
* | ||
* @var Prettifier | ||
*/ | ||
private static $_instance = null; | ||
|
||
/** | ||
* File instance | ||
* @var File | ||
*/ | ||
private $_file; | ||
|
||
/** | ||
* The pretty content | ||
* @var string | ||
*/ | ||
private $_content; | ||
|
||
/** | ||
* Retrieves the singleton instance | ||
* | ||
* @return Prettifier | ||
*/ | ||
public static function getInstance() | ||
{ | ||
if (self::$_instance == null) { | ||
self::$_instance = new Prettifier(); | ||
} | ||
|
||
return self::$_instance; | ||
} | ||
|
||
/** | ||
* Initializes the Scrapper | ||
* | ||
* @param S2WConfig $c Configuration object | ||
* | ||
* @return Handler | ||
*/ | ||
public static function factory(S2WConfig $c) | ||
{ | ||
$instance = self::getInstance(); | ||
$instance->config = $c; | ||
|
||
$instance->_file = new File($c, 'storage.output.ranges'); | ||
|
||
return $instance; | ||
} | ||
|
||
/** | ||
* Starts prettifying | ||
* | ||
* @param string $type Prettifier class name | ||
* | ||
* @return Prettifier | ||
*/ | ||
public function run($type = 'ArrayPrettifier') | ||
{ | ||
$type = 'MazenTouati\NoEmoji\Prettifiers\\'.$type; | ||
$this->_content = $type::run($this->_file); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Exports the pretty output | ||
* | ||
* @return boolean|array Returns false on error or the result array | ||
*/ | ||
public function export() | ||
{ | ||
$base = $this->config->get('storage.base'); | ||
$fileTitle = $this->config->get('storage.output.prettyRangesFileTitle', 'Undefined Title'); | ||
$output = $this->config->get('storage.output.prettyRanges'); | ||
|
||
$export = File::toText($base . $output, $fileTitle, $this->_content); | ||
|
||
if (!is_array($export)) { | ||
return false; | ||
} | ||
|
||
return $export; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace MazenTouati\NoEmoji\Prettifiers; | ||
|
||
use MazenTouati\NotEmoji\Entities\File; | ||
|
||
/** | ||
* @author Mazen Touati <[email protected]> | ||
*/ | ||
class ArrayPrettifier | ||
{ | ||
/** | ||
* Prettify the input | ||
* | ||
* @param File $file The file instance | ||
* | ||
* @return string | ||
*/ | ||
public static function run($file) | ||
{ | ||
$content = trim($file->content, '\''); | ||
$ranges = explode('|', $content); | ||
|
||
$pretty = '[' . PHP_EOL; | ||
|
||
foreach ($ranges as $range) { | ||
$pretty .= "\t'". $range . "'," . PHP_EOL; | ||
} | ||
|
||
$pretty .= ']' . PHP_EOL; | ||
|
||
return $pretty; | ||
} | ||
} |