LazyRecord\BaseCollection::getSchema PHP Method

getSchema() public method

public getSchema ( )
    public function getSchema()
    {
        if ($this->_schema) {
            return $this->_schema;
        } elseif (@constant('static::SCHEMA_PROXY_CLASS')) {
            return $this->_schema = SchemaLoader::load(static::SCHEMA_PROXY_CLASS);
        }
        throw new RuntimeException('schema is not defined in ' . get_class($this));
    }

Usage Example

Example #1
0
 /**
  * @return DOMDocument
  */
 public function exportCollection(BaseCollection $collection)
 {
     $dom = new DOMDocument('1.0', 'utf-8');
     $root = $dom->createElement('export');
     $dom->appendChild($root);
     // $this->appendRecord($dom, $root, $record, NULL, true);
     $schema = $collection->getSchema();
     $relations = $schema->getRelations();
     // find foreign many-to-many schema
     foreach ($relations as $rel) {
         if ($rel['type'] === Relationship::MANY_TO_MANY) {
             $junctionRel = $relations[$rel['relation_junction']];
             $junctionSchema = $junctionRel->newForeignSchema();
             $foreignRel = $junctionSchema->getRelation($rel['relation_foreign']);
             $foreignCollection = $foreignRel->newForeignCollection();
             $foreignSchema = $foreignRel->newForeignSchema();
             $collectionRoot = $dom->createElement('collection');
             $collectionRoot->setAttribute('schema', get_class($foreignSchema));
             $collectionRoot->setAttribute('class', get_class($foreignCollection));
             $root->appendChild($collectionRoot);
             foreach ($foreignCollection as $record) {
                 $this->appendRecord($dom, $collectionRoot, $record, $foreignSchema, true);
             }
         }
     }
     $collectionRoot = $dom->createElement('collection');
     $collectionRoot->setAttribute('schema', get_class($schema));
     $collectionRoot->setAttribute('class', get_class($collection));
     $root->appendChild($collectionRoot);
     foreach ($collection as $record) {
         $this->appendRecord($dom, $collectionRoot, $record, $schema, true);
     }
     $dom->formatOutput = true;
     return $dom;
 }
All Usage Examples Of LazyRecord\BaseCollection::getSchema