| 1 | <?php |
||
| 16 | class ArrayField extends Field |
||
| 17 | { |
||
| 18 | protected $glue; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Render field value |
||
| 22 | * |
||
| 23 | * @param mixed $value |
||
| 24 | * @return string |
||
| 25 | * @throws Exception |
||
| 26 | */ |
||
| 27 | 1 | public function render($value) |
|
| 28 | { |
||
| 29 | 1 | if (!is_array($value) && !($value instanceof Traversable)) { |
|
| 30 | throw new Exception('Value should be an array instead of '.gettype($value)); |
||
| 31 | } |
||
| 32 | 1 | if ($value instanceof Collection) { |
|
| 33 | 1 | $value = $value->toArray(); |
|
| 34 | } |
||
| 35 | |||
| 36 | 1 | return implode($this->glue, $value); |
|
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Configure options resolver. |
||
| 41 | * |
||
| 42 | * @param OptionsResolver $resolver |
||
| 43 | * |
||
| 44 | * @return mixed |
||
| 45 | */ |
||
| 46 | public function configureOptions(OptionsResolver $resolver) |
||
| 47 | { |
||
| 48 | $resolver->setDefaults([ |
||
| 49 | 'glue' => ', ', |
||
| 50 | ]); |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Set options values after options resolving. |
||
| 55 | * |
||
| 56 | * @param array $options |
||
| 57 | * |
||
| 58 | * @return mixed |
||
| 59 | */ |
||
| 60 | 1 | public function setOptions(array $options) |
|
| 64 | |||
| 65 | /** |
||
| 66 | * @return string |
||
| 67 | */ |
||
| 68 | public function getType() |
||
| 72 | } |
||
| 73 |