1 <?php
2
3 namespace Balance\Form\Element;
4
5 use NumberFormatter;
6 use Zend\Form\Element\Text;
7 use Zend\ServiceManager\ServiceLocatorAwareInterface;
8 use Zend\ServiceManager\ServiceLocatorAwareTrait;
9
10 11 12
13 class Currency extends Text implements ServiceLocatorAwareInterface
14 {
15 use ServiceLocatorAwareTrait;
16
17 18 19
20 public function getAttribute($key)
21 {
22
23 $value = parent::getAttribute($key);
24
25 if ($key === 'class') {
26
27 $classes = array_filter(array_map('trim', explode(' ', $value)));
28
29 array_unshift($classes, 'form-control-currency');
30
31 $classes = array_unique($classes);
32
33 $value = implode(' ', $classes);
34
35 $this->setAttribute($key, $value);
36 }
37
38 return $value;
39 }
40
41 42 43
44 public function getOption($option)
45 {
46
47 $value = parent::getOption($option);
48
49 if ($option === 'add-on-prepend' && ! $value) {
50
51 $value = (new NumberFormatter(null, NumberFormatter::CURRENCY))
52 ->getSymbol(NumberFormatter::CURRENCY_SYMBOL);
53
54 $this->setOption($option, $value);
55 }
56
57 return $value;
58 }
59 }
60