Gets filters that should be used used every time when given entity is loaded from database
public getImplicitFilters ( string $entityClass, |
||
$entityClass | string | |
$caller | ||
return | array | |
/** * @return Fluent */ protected function createFluent() { $table = $this->getTable(); $statement = $this->connection->select('%n.*', $table)->from($table); $filters = $this->mapper->getImplicitFilters($this->mapper->getEntityClass($table), new Caller($this)); if (!empty($filters)) { $funcArgs = func_get_args(); if (!$filters instanceof ImplicitFilters) { $filters = new ImplicitFilters($filters); } $targetedArgs = $filters->getTargetedArgs(); foreach ($filters->getFilters() as $filter) { $args = [$filter]; if (is_string($filter) and array_key_exists($filter, $targetedArgs)) { $args = array_merge($args, $targetedArgs[$filter]); } if (!empty($funcArgs)) { $args = array_merge($args, $funcArgs); } call_user_func_array([$statement, 'applyFilter'], $args); } } return $statement; }
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); }
/** * @param string $entityClass * @param Caller $caller * @return ImplicitFilters */ protected function createImplicitFilters($entityClass, Caller $caller = null) { $implicitFilters = $this->mapper->getImplicitFilters($entityClass, $caller); return $implicitFilters instanceof ImplicitFilters ? $implicitFilters : new ImplicitFilters($implicitFilters); }