Commit 88e121b9 authored by Tomas Lang's avatar Tomas Lang

Restriction: flag "alsoAsArray" (fix "int|array" notation)

parent 878b6095
......@@ -86,20 +86,36 @@ abstract class AbstractRestriction
$property = $this->properties[$key];
if ($property->isNullable() && $value == NULL) {
if ($value == NULL && $property->isNullable()) {
} elseif ($property->isBasicType()) {
switch ($property->getType()) {
case 'boolean':
$value = (bool) $value;
if (is_array($value) && $property->hasCustomFlag('alsoAsArray')) {
$value = array_map('boolval', (array) $value);
} else {
$value = (bool) $value;
}
break;
case 'integer':
$value = (int) $value;
if (is_array($value) && $property->hasCustomFlag('alsoAsArray')) {
$value = array_map('intval', (array) $value);
} else {
$value = (int) $value;
}
break;
case 'float':
$value = (float) $value;
if (is_array($value) && $property->hasCustomFlag('alsoAsArray')) {
$value = array_map('floatval', (array) $value);
} else {
$value = (float) $value;
}
break;
case 'string':
$value = (string) $value;
if (is_array($value) && $property->hasCustomFlag('alsoAsArray')) {
$value = array_map('strval', (array) $value);
} else {
$value = (string) $value;
}
break;
case 'array':
$value = (array) $value;
......
......@@ -4,7 +4,7 @@ namespace LeanMapperWorkflow;
/**
* @property array|int $id
* @property int $id m:alsoAsArray
* @property int $limit
* @property int $offset
*/
......
......@@ -104,3 +104,14 @@ Assert::same($restriction->int, 123); // $int je v ExtendedRestriction zdeden od
$restriction->extended = '123';
Assert::same($restriction->extended, '123'); // $extended je vlastni promenna ExtendedRestriction
// use flag "alsoAsArray"
$restriction = new \LeanMapperWorkflow\Restriction($mapper);
$restriction->id = '1';
Assert::same($restriction->id, 1);
$restriction->id = [1, '2'];
Assert::same($restriction->id, [1, 2]);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment