From ed34c6e254d694bcfc0fe3b9e7526b94b40da6ca Mon Sep 17 00:00:00 2001 From: Andrii Vasyliev Date: Thu, 23 Aug 2018 08:02:03 +0000 Subject: [PATCH] csfixed --- src/Helper.php | 86 +++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/src/Helper.php b/src/Helper.php index f96bc32..62e937e 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -51,41 +51,15 @@ public static function mergeConfig(): array return $res; } - /** - * Dumps closure object to string. - * Based on http://www.metashock.de/2013/05/dump-source-code-of-closure-in-php/. - * @param Closure $closure - * @return string - */ - public static function dumpClosure(Closure $closure): string + public static function exportDefines(array $defines): string { - $res = 'function ('; - $fun = new ReflectionFunction($closure); - $args = []; - foreach ($fun->getParameters() as $arg) { - $str = ''; - if ($arg->isArray()) { - $str .= 'array '; - } elseif ($arg->getClass()) { - $str .= $arg->getClass()->name . ' '; - } - if ($arg->isPassedByReference()) { - $str .= '&'; - } - $str .= '$' . $arg->name; - if ($arg->isOptional()) { - $str .= ' = ' . var_export($arg->getDefaultValue(), true); - } - $args[] = $str; - } - $res .= implode(', ', $args); - $res .= ') {' . PHP_EOL; - $lines = file($fun->getFileName()); - for ($i = $fun->getStartLine(); $i < $fun->getEndLine(); ++$i) { - $res .= $lines[$i]; + $res = ''; + foreach ($defines as $key => $value) { + $var = static::exportVar($value); + $res .= "defined('$key') or define('$key', $var);\n"; } - return rtrim($res, "\r\n ,"); + return $res; } /** @@ -109,17 +83,6 @@ public static function exportVar($value): string return $res; } - public static function exportDefines(array $defines): string - { - $res = ''; - foreach ($defines as $key => $value) { - $var = static::exportVar($value); - $res .= "defined('$key') or define('$key', $var);\n"; - } - - return $res; - } - /** * Collects closures from given input. * Substitutes closures with a tag. @@ -145,4 +108,41 @@ private static function collectClosures(&$input): array return $closures; } + + /** + * Dumps closure object to string. + * Based on http://www.metashock.de/2013/05/dump-source-code-of-closure-in-php/. + * @param Closure $closure + * @return string + */ + public static function dumpClosure(Closure $closure): string + { + $res = 'function ('; + $fun = new ReflectionFunction($closure); + $args = []; + foreach ($fun->getParameters() as $arg) { + $str = ''; + if ($arg->isArray()) { + $str .= 'array '; + } elseif ($arg->getClass()) { + $str .= $arg->getClass()->name . ' '; + } + if ($arg->isPassedByReference()) { + $str .= '&'; + } + $str .= '$' . $arg->name; + if ($arg->isOptional()) { + $str .= ' = ' . var_export($arg->getDefaultValue(), true); + } + $args[] = $str; + } + $res .= implode(', ', $args); + $res .= ') {' . PHP_EOL; + $lines = file($fun->getFileName()); + for ($i = $fun->getStartLine(); $i < $fun->getEndLine(); ++$i) { + $res .= $lines[$i]; + } + + return rtrim($res, "\r\n ,"); + } }