coen-hyde/Shanty-Mongo — Issue #66: getProperties on Shanty_Mongo_Document
Author: ZtF
Created: 2012-02-18 20:25:51+00:00
State: open

Perhaps it would be nice to include something like this to Shanty_Mongo_Document. Haven't tested it much and it's just quick and dirty solution but it's good enough for me though.

/*
* Get array of properties (recursive)
* @param Shanty_Mongo_Document $document
* @return array
*/
public function getProperties($document = null){
if(is_null($document))
$document = $this;
$keys = $document->getPropertyKeys();
foreach($keys as $key){
if($document->$key instanceof Shanty_Mongo_Document){
$rval[$key] = $document->getProperties($document->$key);
} else {
$rval[$key] = $document->$key;
}
}
return $rval;
}