/** * Get the Entity metadata object * * @return Entity */ public function getEntityMetadata() { $entity = new Entity($this->reflection_obj->name, $this->getTableName()); $entity->setColumns($this->getColumns()); $entity->setRelationships($this->getRelationships()); $entity->setIndices($this->getIndices()); $entity->setSortables($this->getSortables()); return $entity; }
/** * Parse a map file, loading metadata from YAML * * @param string $fn * @return $this */ protected function loadMap($fn) { $map = $this->getParser()->parse(file_get_contents($fn)); foreach ($map as $class => $schema) { $table = $this->getNode($schema, Schema::TABLE_NAME); $entity = new Entity($class, $table); // Columns $columns = $this->getNode($schema, Schema::COLUMNS); foreach ($columns as $property => $column_schema) { if ($this->getNode($column_schema, Schema::REL_ASSOCIATION, false)) { $rel = $this->createRelationship($property, $column_schema); $rel->setSource($class); $entity->addRelationship($rel); } else { $entity->addColumn($this->createColumn($property, $column_schema)); } } // Table sortables $entity->setSortables($this->createSortables($schema)); // Table indices $indices = $this->getNode($schema, Schema::STD_INDICES, false, []); foreach ($indices as $name => $index_schema) { $index = new Index($table, $name); $index->setColumns($this->getNode($index_schema, Schema::INDEX_COLUMNS, false, [])); $index->setMethods($this->getNode($index_schema, Schema::INDEX_METHODS, false, [])); $entity->addIndex($index); } // Add to map $this->entities[$class] = $entity; } return $this; }