| @@ 24-84 (lines=61) @@ | ||
| 21 | * @author Karel Osorio Ramírez <[email protected]> |
|
| 22 | * @author Ivannis Suárez Jerez <[email protected]> |
|
| 23 | */ |
|
| 24 | class ArrayListType extends CollectionType |
|
| 25 | { |
|
| 26 | /** |
|
| 27 | * @var string |
|
| 28 | */ |
|
| 29 | protected $innerType = ''; |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @return string |
|
| 33 | */ |
|
| 34 | protected function innerType() |
|
| 35 | { |
|
| 36 | return $this->innerType; |
|
| 37 | } |
|
| 38 | ||
| 39 | /** |
|
| 40 | * @param string $innerType |
|
| 41 | */ |
|
| 42 | public function setInnerType($innerType) |
|
| 43 | { |
|
| 44 | $this->innerType = $innerType; |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * {@inheritdoc} |
|
| 49 | */ |
|
| 50 | public function convertToDatabaseValue($value) |
|
| 51 | { |
|
| 52 | if ($value !== null && $value instanceof ArrayListInterface) { |
|
| 53 | $items = array(); |
|
| 54 | $type = Type::getType($this->innerType); |
|
| 55 | foreach ($value as $item) { |
|
| 56 | $items[] = $type->convertToDatabaseValue($item); |
|
| 57 | } |
|
| 58 | $value = $items; |
|
| 59 | } |
|
| 60 | ||
| 61 | return parent::convertToDatabaseValue($value); |
|
| 62 | } |
|
| 63 | ||
| 64 | /** |
|
| 65 | * {@inheritdoc} |
|
| 66 | */ |
|
| 67 | public function convertToPHPValue($value) |
|
| 68 | { |
|
| 69 | if ($value === null) { |
|
| 70 | return new ArrayList(); |
|
| 71 | } |
|
| 72 | if (is_array($value) || $value instanceof \Traversable) { |
|
| 73 | $items = array(); |
|
| 74 | $type = Type::getType($this->innerType); |
|
| 75 | foreach ($value as $item) { |
|
| 76 | $items[] = $type->convertToPHPValue($item); |
|
| 77 | } |
|
| 78 | ||
| 79 | return new ArrayList($items); |
|
| 80 | } |
|
| 81 | ||
| 82 | return parent::convertToPHPValue($value); |
|
| 83 | } |
|
| 84 | } |
|
| 85 | ||
| @@ 24-84 (lines=61) @@ | ||
| 21 | * @author Karel Osorio Ramírez <[email protected]> |
|
| 22 | * @author Ivannis Suárez Jerez <[email protected]> |
|
| 23 | */ |
|
| 24 | class ArraySetType extends CollectionType |
|
| 25 | { |
|
| 26 | /** |
|
| 27 | * @var string |
|
| 28 | */ |
|
| 29 | protected $innerType = ''; |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @return string |
|
| 33 | */ |
|
| 34 | protected function innerType() |
|
| 35 | { |
|
| 36 | return $this->innerType; |
|
| 37 | } |
|
| 38 | ||
| 39 | /** |
|
| 40 | * @param string $innerType |
|
| 41 | */ |
|
| 42 | public function setInnerType($innerType) |
|
| 43 | { |
|
| 44 | $this->innerType = $innerType; |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * {@inheritdoc} |
|
| 49 | */ |
|
| 50 | public function convertToDatabaseValue($value) |
|
| 51 | { |
|
| 52 | if ($value !== null && $value instanceof ArraySetInterface) { |
|
| 53 | $items = array(); |
|
| 54 | $type = Type::getType($this->innerType); |
|
| 55 | foreach ($value as $item) { |
|
| 56 | $items[] = $type->convertToDatabaseValue($item); |
|
| 57 | } |
|
| 58 | $value = $items; |
|
| 59 | } |
|
| 60 | ||
| 61 | return parent::convertToDatabaseValue($value); |
|
| 62 | } |
|
| 63 | ||
| 64 | /** |
|
| 65 | * {@inheritdoc} |
|
| 66 | */ |
|
| 67 | public function convertToPHPValue($value) |
|
| 68 | { |
|
| 69 | if ($value === null) { |
|
| 70 | return new ArraySet(); |
|
| 71 | } |
|
| 72 | if (is_array($value) || $value instanceof \Traversable) { |
|
| 73 | $items = array(); |
|
| 74 | $type = Type::getType($this->innerType); |
|
| 75 | foreach ($value as $item) { |
|
| 76 | $items[] = $type->convertToPHPValue($item); |
|
| 77 | } |
|
| 78 | ||
| 79 | return new ArraySet($items); |
|
| 80 | } |
|
| 81 | ||
| 82 | return parent::convertToPHPValue($value); |
|
| 83 | } |
|
| 84 | } |
|
| 85 | ||