getEntityClass() public method

Gets fully qualified entity class name from given table name
public getEntityClass ( string $table, Row $row = null ) : string
$table string
$row Row
return string
コード例 #1
0
ファイル: Schema.php プロジェクト: joseki/migration
 public function addRepository(\Joseki\LeanMapper\Repository $repository)
 {
     $class = get_class($repository);
     $table = $this->mapper->getTableByRepositoryClass($class);
     $entity = $this->mapper->getEntityClass($table);
     $this->entities[] = new $entity();
 }
コード例 #2
0
ファイル: Repository.php プロジェクト: tharos/leanmapper
 /**
  * Checks whether give entity is instance of required type
  *
  * @param Entity $entity
  * @throws InvalidArgumentException
  */
 protected function checkEntityType(Entity $entity)
 {
     $entityClass = $this->mapper->getEntityClass($this->getTable());
     if (!$entity instanceof $entityClass) {
         throw new InvalidArgumentException('Repository ' . get_called_class() . ' can only handle ' . $entityClass . ' entites. Use different repository to handle ' . get_class($entity) . '.');
     }
 }
コード例 #3
0
 /**
  * @param $table
  * @return Property
  * @throws \Exception
  */
 private function getRelationshipColumnProperty($table)
 {
     $class = $this->mapper->getEntityClass($table);
     if (!class_exists($class)) {
         throw new \Exception();
     }
     /** @var Entity $entity */
     $entity = new $class();
     $primaryKey = $this->mapper->getPrimaryKey($table);
     $primryKeyField = $this->mapper->getEntityField($table, $primaryKey);
     return $entity->getReflection($this->mapper)->getEntityProperty($primryKeyField);
 }
コード例 #4
0
ファイル: Entity.php プロジェクト: tharos/leanmapper
 /**
  * @param Property $property
  * @param Relationship\BelongsToMany $relationship micro-optimalization
  * @param Filtering|null $filtering
  * @return Entity[]
  */
 private function getBelongsToManyValue(Property $property, Relationship\BelongsToMany $relationship, Filtering $filtering = null)
 {
     $targetTable = $relationship->getTargetTable();
     $rows = $this->row->referencing($targetTable, $relationship->getColumnReferencingSourceTable(), $filtering, $relationship->getStrategy());
     $value = [];
     foreach ($rows as $row) {
         $entityClass = $this->mapper->getEntityClass($targetTable, $row);
         $entity = $this->entityFactory->createEntity($entityClass, $row);
         $this->checkConsistency($property, $entityClass, $entity);
         $entity->makeAlive($this->entityFactory);
         $value[] = $entity;
     }
     return $this->entityFactory->createCollection($value);
 }
コード例 #5
0
ファイル: Query.php プロジェクト: inlm/query-object
 private function traverseToRelatedEntity(&$currentTable, &$currentTableAlias, Property $property)
 {
     if (!$property->hasRelationship()) {
         $entityClass = $this->mapper->getEntityClass($currentTable);
         throw new InvalidRelationshipException("Property '{$property->getName()}' in entity '{$entityClass}' doesn't have any relationship.");
     }
     $implicitFilters = array();
     $propertyType = $property->getType();
     if (is_subclass_of($propertyType, 'LeanMapper\\Entity')) {
         $caller = new Caller($this, $property);
         $implicitFilters = $this->mapper->getImplicitFilters($property->getType(), $caller);
     }
     $relationship = $property->getRelationship();
     if ($relationship instanceof Relationship\HasOne) {
         $targetTable = $relationship->getTargetTable();
         $targetTablePrimaryKey = $this->mapper->getPrimaryKey($targetTable);
         $referencingColumn = $relationship->getColumnReferencingTargetTable();
         // Join table.
         $targetTableAlias = $this->joinRelatedTable($currentTableAlias, $referencingColumn, $targetTable, $targetTablePrimaryKey, $implicitFilters, FALSE);
     } elseif ($relationship instanceof Relationship\BelongsTo) {
         // BelongsToOne, BelongsToMany
         $targetTable = $relationship->getTargetTable();
         $sourceTablePrimaryKey = $this->mapper->getPrimaryKey($currentTable);
         $referencingColumn = $relationship->getColumnReferencingSourceTable();
         // Join table.
         $targetTableAlias = $this->joinRelatedTable($currentTableAlias, $sourceTablePrimaryKey, $targetTable, $referencingColumn, $implicitFilters);
     } elseif ($relationship instanceof Relationship\HasMany) {
         $sourceTablePrimaryKey = $this->mapper->getPrimaryKey($currentTable);
         $relationshipTable = $relationship->getRelationshipTable();
         $sourceReferencingColumn = $relationship->getColumnReferencingSourceTable();
         $targetReferencingColumn = $relationship->getColumnReferencingTargetTable();
         $targetTable = $relationship->getTargetTable();
         $targetTablePrimaryKey = $this->mapper->getPrimaryKey($targetTable);
         // Join tables.
         // Don't apply filters on relationship table.
         $relationshipTableAlias = $this->joinRelatedTable($currentTableAlias, $sourceTablePrimaryKey, $relationshipTable, $sourceReferencingColumn);
         $targetTableAlias = $this->joinRelatedTable($relationshipTableAlias, $targetReferencingColumn, $targetTable, $targetTablePrimaryKey, $implicitFilters, FALSE);
     } else {
         throw new InvalidRelationshipException('Unknown relationship type. ' . get_class($relationship) . ' given.');
     }
     $currentTable = $targetTable;
     $currentTableAlias = $targetTableAlias;
     return $this->getPropertiesByTable($targetTable);
 }