protected function get($property, array $filterArgs = [])
{
if ($property instanceof Property) {
$name = $property->getName();
} else {
$name = $property;
$property = $this->getCurrentReflection()->getEntityProperty($name);
if ($property === null) {
throw new MemberAccessException("Cannot access undefined property '{$name}' in entity " . get_called_class() . '.');
}
}
$pass = $property->getGetterPass();
if ($property->isBasicType()) {
$column = $property->getColumn();
try {
$value = $this->row->{$column};
} catch (LeanMapperException $e) {
if (!$property->isNullable()) {
throw new InvalidStateException("Cannot get value of property '{$property->getName()}' in entity " . get_called_class() . ' due to low-level failure: ' . $e->getMessage(), $e->getCode(), $e);
}
$value = null;
}
if ($pass !== null) {
$value = $this->{$pass}($value);
}
if ($value === null) {
if (!$property->isNullable()) {
throw new InvalidValueException("Property {$name} in entity " . get_called_class() . ' cannot be null.');
}
return $value;
}
if ($pass !== null) {
return $value;
}
settype($value, $property->getType());
if ($property->containsEnumeration() and !$property->isValueFromEnum($value)) {
throw new InvalidValueException("Given value is not from possible values enumeration in property '{$property->getName()}' in entity " . get_called_class() . '.');
}
return $value;
}
// property doesn't contain basic type
if ($property->hasRelationship()) {
if ($this->entityFactory) {
$implicitFilters = $this->createImplicitFilters($property->getType(), new Caller($this, $property));
$firstFilters = $property->getFilters(0) ?: [];
$relationship = $property->getRelationship();
if ($relationship instanceof Relationship\HasMany) {
$secondFilters = $this->mergeFilters($property->getFilters(1) ?: [], $implicitFilters->getFilters());
} else {
$firstFilters = $this->mergeFilters($firstFilters, $implicitFilters->getFilters());
}
if (!empty($firstFilters) or !empty($secondFilters)) {
if ($relationship instanceof Relationship\HasMany) {
$relationshipTableFiltering = !empty($firstFilters) ? new Filtering($firstFilters, $filterArgs, $this, $property, (array) $property->getFiltersTargetedArgs(0)) : null;
$targetTableFiltering = new Filtering($secondFilters, $filterArgs, $this, $property, array_merge($implicitFilters->getTargetedArgs(), (array) $property->getFiltersTargetedArgs(1)));
} else {
$targetTableFiltering = !empty($firstFilters) ? new Filtering($firstFilters, $filterArgs, $this, $property, array_merge($implicitFilters->getTargetedArgs(), (array) $property->getFiltersTargetedArgs(0))) : null;
}
}
}
try {
return $this->getValueByPropertyWithRelationship($property, isset($targetTableFiltering) ? $targetTableFiltering : null, isset($relationshipTableFiltering) ? $relationshipTableFiltering : null);
} catch (LeanMapperException $e) {
throw new InvalidStateException($e->getMessage(), $e->getCode(), $e);
}
}
// property doesn't contain basic type and doesn't contain relationship
$column = $property->getColumn();
try {
$value = $this->row->{$column};
} catch (LeanMapperException $e) {
throw new LeanMapperException("Cannot get value of property '{$property->getName()}' in entity " . get_called_class() . ' due to low-level failure: ' . $e->getMessage(), $e->getCode(), $e);
}
if ($pass !== null) {
$value = $this->{$pass}($value);
}
if ($value === null) {
if (!$property->isNullable()) {
throw new InvalidValueException("Property '{$name}' in entity " . get_called_class() . " cannot be null.");
}
return $value;
}
// property doesn't contain basic type, doesn't contain relationship and doesn't contain null
if (!$property->containsCollection()) {
$type = $property->getType();
if (!$value instanceof $type) {
throw new InvalidValueException("Property '{$name}' in entity " . get_called_class() . " is expected to contain an instance of {$type}, " . (is_object($value) ? 'instance of ' . get_class($value) : gettype($value)) . " given.");
}
return $value;
}
if (!is_array($value)) {
throw new InvalidValueException("Property '{$name}' in entity " . get_called_class() . " is expected to contain an array of {$property->getType()} instances.");
}
return $value;
}