mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-18 17:28:41 +00:00
Improve array parsing
This commit is contained in:
parent
e4531d3726
commit
051c123b77
|
|
@ -55,7 +55,7 @@ class EventManager
|
|||
* Attach new event
|
||||
*
|
||||
* @param string $group Name of the event (unique)
|
||||
* @param \Closure $callback Callback for the event
|
||||
* @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!
|
||||
*
|
||||
|
|
@ -63,7 +63,7 @@ class EventManager
|
|||
*
|
||||
* @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']) {
|
||||
|
|
|
|||
|
|
@ -30,12 +30,13 @@ class ArrayParser
|
|||
* Serializing array (recursively).
|
||||
*
|
||||
* @param array $arr Array to serialize
|
||||
* @param int $depth Array depth
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function serializeArray(array $arr) : string
|
||||
public static function serializeArray(array $arr, int $depth = 1) : string
|
||||
{
|
||||
$stringify = '[' . PHP_EOL;
|
||||
|
||||
|
|
@ -44,26 +45,27 @@ class ArrayParser
|
|||
$key = '"' . $key . '"';
|
||||
}
|
||||
|
||||
$stringify .= ' ' . $key . ' => ' . 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)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user