Skip to content

Commit 7013690

Browse files
committed
Support for enum and IdIndexedModel
1 parent e7eeda5 commit 7013690

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/AbstractExpression.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ protected function normalizeArgument(mixed $argument, string $defaultType = self
4646
return $this->buildNormalizedArgument($key, $value);
4747
}
4848

49-
throw new Exception\InvalidArgumentException(sprintf('$argument should be %s or %s or %s or %s or %s, "%s" given',
50-
'null', 'scalar', 'array', 'Sql\ExpressionInterface', 'Sql\Sql\SqlInterface',
49+
if ($argument instanceof \BackedEnum) {
50+
return $this->buildNormalizedArgument($argument->value, $defaultType);
51+
}
52+
53+
if ($argument instanceof \Swango\Model\IdIndexedModel) {
54+
return $this->buildNormalizedArgument($argument->getId(), $defaultType);
55+
}
56+
57+
throw new Exception\InvalidArgumentException(sprintf('$argument should be %s or %s or %s or %s or %s or %s or %s, "%s" given',
58+
'null', 'scalar', 'array', 'Sql\ExpressionInterface', 'Sql\Sql\SqlInterface', 'BackedEnum', 'Swango\Model\IdIndexedModel',
5159
is_object($argument) ? get_class($argument) : gettype($argument)));
5260
}
5361
/**

src/AbstractSql.php

+6
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,13 @@ protected function resolveColumnValue(mixed $column, PlatformInterface $platform
317317
if ($column === null) {
318318
return 'NULL';
319319
}
320+
if ($column instanceof \BackedEnum) {
321+
$column = $column->value;
322+
} elseif ($column instanceof \Swango\Model\IdIndexedModel) {
323+
$column = $column->getId();
324+
}
320325
$column = (string)$column;
326+
321327
return $isIdentifier ? $fromTable .
322328
$platform->quoteIdentifierInFragment($column) : $platform->quoteValue($column);
323329
}

0 commit comments

Comments
 (0)