/** * Get the value of an index * * @param Index $index * @return string */ public function getIndexValue(Index $index) { $values = []; foreach ($index->getColumns() as $column) { $values[] = (string) $this->getPropertyValue($column); } return implode(self::ID_DELIMITER, $values); }
/** * 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); $indices[] = $index; } return $indices; }
/** * Get the key for an standard index * * @param Index $index Index belonging to entity * @param string $key Index key * @return string */ public function getIndexKey(Index $index, $key) { // idx:article:slug:some-slug return static::INDEX_NAMESPACE . $this->delimiter . $index->getTableName() . $this->delimiter . $index->getName() . $this->delimiter . $key; }
/** * 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; }