| Total Complexity | 6 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | class Helper |
||
| 11 | { |
||
| 12 | public static function exportDefines(array $defines): string |
||
| 13 | { |
||
| 14 | $res = ''; |
||
| 15 | foreach ($defines as $key => $value) { |
||
| 16 | $var = static::exportVar($value); |
||
| 17 | $res .= "defined('$key') or define('$key', $var);\n"; |
||
| 18 | } |
||
| 19 | |||
| 20 | return $res; |
||
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Returns PHP-executable string representation of given value. |
||
| 25 | * Uses Riimu/Kit-PHPEncoder based `var_export` alternative. |
||
| 26 | * And Opis/Closure to dump closures as PHP code. |
||
| 27 | * @param mixed $value |
||
| 28 | * @return string |
||
| 29 | * @throws \ReflectionException |
||
| 30 | */ |
||
| 31 | public static function exportVar($value): string |
||
| 32 | { |
||
| 33 | return static::getEncoder()->encode($value); |
||
| 34 | } |
||
| 35 | |||
| 36 | private static $encoder; |
||
| 37 | |||
| 38 | private static function getEncoder() |
||
| 45 | } |
||
| 46 | |||
| 47 | private static function createEncoder() |
||
| 55 | } |
||
| 56 | } |
||
| 57 |