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 ...@@ -86,20 +86,36 @@ abstract class AbstractRestriction
$property = $this->properties[$key]; $property = $this->properties[$key];
if ($property->isNullable() && $value == NULL) { if ($value == NULL && $property->isNullable()) {
} elseif ($property->isBasicType()) { } elseif ($property->isBasicType()) {
switch ($property->getType()) { switch ($property->getType()) {
case 'boolean': case 'boolean':
if (is_array($value) && $property->hasCustomFlag('alsoAsArray')) {
$value = array_map('boolval', (array) $value);
} else {
$value = (bool) $value; $value = (bool) $value;
}
break; break;
case 'integer': case 'integer':
if (is_array($value) && $property->hasCustomFlag('alsoAsArray')) {
$value = array_map('intval', (array) $value);
} else {
$value = (int) $value; $value = (int) $value;
}
break; break;
case 'float': case 'float':
if (is_array($value) && $property->hasCustomFlag('alsoAsArray')) {
$value = array_map('floatval', (array) $value);
} else {
$value = (float) $value; $value = (float) $value;
}
break; break;
case 'string': case 'string':
if (is_array($value) && $property->hasCustomFlag('alsoAsArray')) {
$value = array_map('strval', (array) $value);
} else {
$value = (string) $value; $value = (string) $value;
}
break; break;
case 'array': case 'array':
$value = (array) $value; $value = (array) $value;
......
...@@ -4,7 +4,7 @@ namespace LeanMapperWorkflow; ...@@ -4,7 +4,7 @@ namespace LeanMapperWorkflow;
/** /**
* @property array|int $id * @property int $id m:alsoAsArray
* @property int $limit * @property int $limit
* @property int $offset * @property int $offset
*/ */
......
...@@ -104,3 +104,14 @@ Assert::same($restriction->int, 123); // $int je v ExtendedRestriction zdeden od ...@@ -104,3 +104,14 @@ Assert::same($restriction->int, 123); // $int je v ExtendedRestriction zdeden od
$restriction->extended = '123'; $restriction->extended = '123';
Assert::same($restriction->extended, '123'); // $extended je vlastni promenna ExtendedRestriction 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