public function testStringTypeCast() { $this->assertSame(0, StringHelper::typeCast("0")); $this->assertSame(1, StringHelper::typeCast('1')); $this->assertSame('string', StringHelper::typeCast('string')); $this->assertSame([1 => 'bar'], StringHelper::typeCast(['1' => 'bar'])); }
public function onAfterListFind($event) { $value = StringHelper::typeCast($event->sender->getAttribute($this->name)); foreach ($this->data as $item) { if ($item['value'] === $value) { $event->sender->setAttribute($this->name, $item['label']); } } }
public function onAfterListFind($event) { $value = $event->sender->getAttribute($this->name); if (!$this->i18n) { $value = $this->jsonDecode($value); } $value = StringHelper::typeCast($value); if (!empty($value)) { $results = []; foreach ($this->getItems()['items'] as $item) { foreach ($value as $k => $v) { if (isset($v['value']) && $item['value'] === $v['value']) { $results[] = $item['label']; } } } $event->sender->setAttribute($this->name, implode(", ", $results)); } }