-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
…rces or PDO instances in the logged data
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,12 +55,53 @@ public function export() | |
$data[$id] = $panel->save(); | ||
} | ||
$data['summary'] = $summary; | ||
file_put_contents($dataFile, serialize($data)); | ||
file_put_contents($dataFile, serialize($this->replaceUnserializable($data))); | ||
|
||
$indexFile = "$path/index.data"; | ||
$this->updateIndexFile($indexFile, $summary); | ||
} | ||
|
||
/** | ||
* Replacing everything that is not serializable with its text representation | ||
* | ||
* @param mixed $value | ||
* @return mixed | ||
*/ | ||
private function replaceUnserializable($value) | ||
{ | ||
if (is_scalar($value) || $value === null) { | ||
return $value; | ||
} | ||
|
||
if (is_array($value)) { | ||
foreach ($value as &$row) { | ||
$row = $this->replaceUnserializable($row); | ||
} | ||
return $value; | ||
} | ||
|
||
if ($value instanceof \Closure) { | ||
return '\Closure'; | ||
} | ||
|
||
if (is_resource($value)) { | ||
return 'resource'; | ||
} | ||
|
||
if ($value instanceof \PDO) { | ||
return '\PDO'; | ||
} | ||
|
||
$properties = (new \ReflectionObject($value))->getProperties(); | ||
foreach ($properties as &$property) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
samdark
Author
Member
|
||
$property->setAccessible(true); | ||
$propertyValue = $property->getValue($value); | ||
$property->setValue($value, $this->replaceUnserializable($propertyValue)); | ||
} | ||
|
||
return $value; | ||
} | ||
|
||
/** | ||
* Updates index file with summary log data | ||
* | ||
|
This change is dangerous. If the object contains recursive object references (e.g parent refers to child, while child refers to parent), it will cause infinite loop. I suggest we only handle
Closure
,resource
and nothing else.