Shanty_Mongo_Document::export PHP Method

export() public method

Export all data
public export ( $skipRequired = false ) : array
return array
    public function export($skipRequired = false)
    {
        $exportData = $this->_cleanData;
        foreach ($this->_data as $property => $value) {
            // If property has been deleted
            if (is_null($value)) {
                unset($exportData[$property]);
                continue;
            }
            // If property is a document
            if ($value instanceof Shanty_Mongo_Document) {
                // Make when exporting from a documentset look up the correct requirement index
                if ($this instanceof Shanty_Mongo_DocumentSet) {
                    $requirementIndex = Shanty_Mongo_DocumentSet::DYNAMIC_INDEX;
                } else {
                    $requirementIndex = $property;
                }
                // If document is supposed to be a reference
                if ($this->hasRequirement($requirementIndex, 'AsReference') || $this->isReference($value)) {
                    $exportData[$property] = $value->createReference();
                    continue;
                }
                $data = $value->export();
                if (!empty($data)) {
                    $exportData[$property] = $data;
                }
                continue;
            }
            $exportData[$property] = $value;
        }
        if (!$skipRequired) {
            // make sure required properties are not empty
            $requiredProperties = $this->getPropertiesWithRequirement('Required');
            foreach ($requiredProperties as $property) {
                if (!isset($exportData[$property]) || is_array($exportData[$property]) && empty($exportData[$property])) {
                    require_once 'Shanty/Mongo/Exception.php';
                    throw new Shanty_Mongo_Exception("Property '{$property}' must not be null.");
                }
            }
        }
        return $exportData;
    }

Usage Example

Esempio n. 1
0
 /**
  * Export all data
  * 
  * @return array
  */
 public function export()
 {
     // Since this is an array, fill in empty index's with null
     $exportData = parent::export();
     $maxKey = max(array_keys($exportData));
     for ($i = 0; $i < $maxKey; $i++) {
         if (array_key_exists($i, $exportData)) {
             continue;
         }
         $exportData[$i] = null;
     }
     ksort($exportData);
     return $exportData;
 }
All Usage Examples Of Shanty_Mongo_Document::export