private static function _dump($obj, $message = null, $logLevel = LOG_DEBUG, $outputFile = null) { if (is_array($obj)) { $collection = array_reduce_val($obj, function ($startValue, $val, $key) { return $startValue || $val instanceof Lib_Model; }, false); if ($collection) { $message .= ' [collection]'; array_each($obj, function ($value, $key) use($message, $logLevel, $outputFile) { self::_dump($value, $message . "[{$key}]", $logLevel, $outputFile); }); return; } } if ($obj instanceof Lib_Model) { $message .= sprintf(' %s->toArray()', get_class($obj)); /* @var Lib_Model $obj */ $obj = $obj->toArray(); } $dump = var_export($obj, true); if (null != $outputFile) { fwrite($outputFile, $message . ': ' . $dump); } else { logger_log($message . ': ' . $dump, $logLevel); } }
/** * @param $callable mixed function($item1Val,$item2Val,$item2Key) * @param mixed $startValue * @return callable */ function array_reduce_val_dg($callable, $startValue = null) { return function ($array) use($callable, $startValue) { return array_reduce_val($array, $callable, $startValue); }; }