/** * Get all indices on the entity * * @return Index[] */ public function getIndices() { $indices = []; $annotation_indices = $this->getEntityAnnotation()->indices; $table_name = $this->getTableName(); /** @var IndexAnnotation $annotation_index */ foreach ($annotation_indices as $annotation_index) { $index = new Index($table_name, $annotation_index->name); $index->setColumns($annotation_index->columns ?: []); $index->setMethods($annotation_index->methods ?: []); $indices[] = $index; } return $indices; }
/** * 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; }