From 051c123b77222d4c83d4cd6cddaf713d6625ad31 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 31 Mar 2018 21:58:13 +0200 Subject: [PATCH] Improve array parsing --- Event/EventManager.php | 11 ++++++----- Module/InstallerAbstract.php | 2 +- Utils/Parser/Php/ArrayParser.php | 14 ++++++++------ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Event/EventManager.php b/Event/EventManager.php index 350f428d1..c48d365ff 100644 --- a/Event/EventManager.php +++ b/Event/EventManager.php @@ -54,16 +54,16 @@ class EventManager /** * Attach new event * - * @param string $group Name of the event (unique) - * @param \Closure $callback Callback for the event - * @param bool $remove Remove event after triggering it? - * @param bool $reset Reset event after triggering it? Remove must be false! + * @param string $group Name of the event (unique) + * @param mixed $callback Callback or route for the event + * @param bool $remove Remove event after triggering it? + * @param bool $reset Reset event after triggering it? Remove must be false! * * @return bool * * @since 1.0.0 */ - public function attach(string $group, \Closure $callback, bool $remove = false, bool $reset = false) : bool + public function attach(string $group, $callback, bool $remove = false, bool $reset = false) : bool { if (isset($this->callbacks[$group])) { return false; @@ -96,6 +96,7 @@ class EventManager } if (!$this->hasOutstanding($group)) { + // todo if it is route then call dispatcher? $this->callbacks[$group]['func']($data); if ($this->callbacks[$group]['remove']) { diff --git a/Module/InstallerAbstract.php b/Module/InstallerAbstract.php index 96d072b00..2844a3c5e 100644 --- a/Module/InstallerAbstract.php +++ b/Module/InstallerAbstract.php @@ -188,7 +188,7 @@ class InstallerAbstract $appRoutes = array_merge_recursive($appRoutes, $moduleRoutes); if (is_writable($destRoutePath)) { - file_put_contents($destRoutePath, ' ' . self::parseVariable($val) . ',' . PHP_EOL; + $stringify .= str_repeat(' ', $depth * 4) . $key . ' => ' . self::parseVariable($val, $depth + 1) . ',' . PHP_EOL; } - return $stringify . ']'; + return $stringify . str_repeat(' ', ($depth - 1) * 4) . ']'; } /** * Serialize value. * * @param mixed $value Value to serialzie + * @param int $depth Array depth * * @return string * * @since 1.0.0 */ - public static function parseVariable($value) : string + public static function parseVariable($value, int $depth = 1) : string { if (is_array($value)) { - return ArrayParser::serializeArray($value) . PHP_EOL; + return ArrayParser::serializeArray($value, $depth); } elseif (is_string($value)) { return '"' . $value . '"'; } elseif (is_scalar($value)) {