Archive: Namaste PHP AMQP framework v1.0 (2017-2020)
952 days continuous production uptime, 40k+ tp/s single node. Original corpo Bitbucket history not included — clean archive commit.
This commit is contained in:
55
classes/deprecated/gacMongoDB.class.txt
Normal file
55
classes/deprecated/gacMongoDB.class.txt
Normal file
@@ -0,0 +1,55 @@
|
||||
|
||||
|
||||
/**
|
||||
* deBSON() -- private method
|
||||
*
|
||||
* MongoDB has a problem fetching data as it tends to BSON serialize all properties within a record for
|
||||
* non-packed record arrays. So, this method, which is recursive, takes the current data payload of N-records,
|
||||
* and traverses all the records looking for declared array fields (fieldTypes).
|
||||
*
|
||||
* When found, that field type is force-cast to type = array and, if the field itself is another array, such
|
||||
* as a sub-collection, the method will recursively call itself.
|
||||
*
|
||||
* As of this time, version 1.0.0, this method is only called from the _fetchRecords() method.
|
||||
*
|
||||
* @author mike@givingassistant.org
|
||||
* @version 1.0
|
||||
*
|
||||
* @param $_data
|
||||
*
|
||||
* HISTORY:
|
||||
* ========
|
||||
* 08-29-17 mks CORE-494: original coding
|
||||
* 11-26-18 mks DB-55: added error processing if a key is not a member of the current class
|
||||
*
|
||||
*/
|
||||
private function deBSON(&$_data)
|
||||
{
|
||||
if (is_array($_data) and array_key_exists(0, $_data)) {
|
||||
for ($index = 0, $limit = count($_data); $index < $limit; $index++) {
|
||||
foreach ($_data[$index] as $column => &$value) {
|
||||
if ($this->fieldTypes[$column] == DATA_TYPE_ARRAY) {
|
||||
if (!is_scalar($value)) {
|
||||
foreach ($value as &$rec) {
|
||||
if (!is_scalar($rec)) $rec = (array) $rec;
|
||||
}
|
||||
$this->deBSON($value);
|
||||
}
|
||||
$_data[$index][$column] = (array) $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif (is_array($_data)) {
|
||||
foreach ($_data as $key => $val) {
|
||||
if (array_key_exists($key, $this->fieldTypes) and $this->fieldTypes[$key] == DATA_TYPE_ARRAY) {
|
||||
if (is_array($val))
|
||||
$this->deBSON($val);
|
||||
$_data[$key] = (array) $val;
|
||||
} elseif (!array_key_exists($key, $this->fieldTypes)) {
|
||||
$msg = ERROR_DATA_FIELD_NOT_MEMBER . $key;
|
||||
$this->eventMessages[] = sprintf(STUB_LOC, basename(__FILE__),__METHOD__, __LINE__) . COLON . $msg;
|
||||
$this->logger->data($msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user