Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
11 / 11 |
| ConvertKanaListener | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
11 / 11 |
| __construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
| getSubscribedEvents | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| onPreSubmit | |
100.00% |
1 / 1 |
3 | |
100.00% |
7 / 7 |
|||
| <?php | |
| namespace Eccube\EventListener; | |
| use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
| use Symfony\Component\Form\FormEvent; | |
| use Symfony\Component\Form\FormEvents; | |
| class ConvertKanaListener implements EventSubscriberInterface | |
| { | |
| public function __construct($option = 'a', $encoding = 'utf-8') | |
| { | |
| $this->option = $option; | |
| $this->encoding = $encoding; | |
| } | |
| public static function getSubscribedEvents() | |
| { | |
| return array( | |
| FormEvents::PRE_SUBMIT => 'onPreSubmit', | |
| ); | |
| } | |
| public function onPreSubmit(FormEvent $event) | |
| { | |
| $data = $event->getData(); | |
| if (is_array($data)) { | |
| foreach ($data as &$value) { | |
| $value = mb_convert_kana($value, $this->option, $this->encoding); | |
| } | |
| } else { | |
| $data = mb_convert_kana($data, $this->option, $this->encoding); | |
| } | |
| $event->setData($data); | |
| } | |
| } |