Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/gallery.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Paroz <github@oparoz.com>2015-01-07 23:25:55 +0300
committerOlivier Paroz <github@oparoz.com>2015-01-07 23:25:55 +0300
commitd7bb84d2b781ea69436db7f746be4222fc3b0609 (patch)
treeed8d1c7c720c11b34257ccfe43fc02955c46e720 /utility
parentcc47a986090a4ae1da5a70fe784f3dbde5026512 (diff)
Make SmarterLogger::normalize() easier to read...hopefully
Diffstat (limited to 'utility')
-rw-r--r--utility/smarterlogger.php64
1 files changed, 43 insertions, 21 deletions
diff --git a/utility/smarterlogger.php b/utility/smarterlogger.php
index 30d26911..261793ac 100644
--- a/utility/smarterlogger.php
+++ b/utility/smarterlogger.php
@@ -185,19 +185,7 @@ class SmarterLogger implements ILogger {
}
if (is_array($data) || $data instanceof \Traversable) {
- $normalized = array();
- $count = 1;
- foreach ($data as $key => $value) {
- if ($count >= 1000) {
- $normalized['...'] =
- 'Over 1000 items, aborting normalization';
- break;
- }
- $normalized[$key] = $this->normalize($value);
- }
-
- //return $normalized;
- return $this->toJson($normalized);
+ return $this->normalizeTraversable($data);
}
if (is_object($data)) {
@@ -205,13 +193,7 @@ class SmarterLogger implements ILogger {
return $this->normalizeException($data);
}
- $arrayObject = new \ArrayObject($data);
- $serializedObject = $arrayObject->getArrayCopy();
-
- return sprintf(
- "[object] (%s: %s)", get_class($data),
- $this->toJson($serializedObject)
- );
+ return $this->normalizeObject($data);
}
if (is_resource($data)) {
@@ -222,7 +204,47 @@ class SmarterLogger implements ILogger {
}
/**
- * Normalises exceptions
+ * Converts a traversable variable to String
+ *
+ * @param $data
+ *
+ * @return string
+ */
+ private function normalizeTraversable($data) {
+ $normalized = array();
+ $count = 1;
+ foreach ($data as $key => $value) {
+ if ($count >= 1000) {
+ $normalized['...'] =
+ 'Over 1000 items, aborting normalization';
+ break;
+ }
+ $normalized[$key] = $this->normalize($value);
+ }
+
+ //return $normalized;
+ return $this->toJson($normalized);
+ }
+
+ /**
+ * Converts an Object to String
+ *
+ * @param $data
+ *
+ * @return string
+ */
+ private function normalizeObject($data) {
+ $arrayObject = new \ArrayObject($data);
+ $serializedObject = $arrayObject->getArrayCopy();
+
+ return sprintf(
+ "[object] (%s: %s)", get_class($data),
+ $this->toJson($serializedObject)
+ );
+ }
+
+ /**
+ * Converts an Exception to String
*
* @param \Exception $exception
*