typeCast() public static method

Arrays will passed to to the {{luya\helpers\ArrayHelper::typeCast}} class.
public static typeCast ( mixed $string ) : mixed
$string mixed The input string to type cast. Arrays will be passted to {{luya\helpers\ArrayHelper::typeCast}}.
return mixed The new type casted value, if the input is an array the output is the typecasted array.
Esempio n. 1
0
 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']));
 }
Esempio n. 2
0
 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']);
         }
     }
 }
Esempio n. 3
0
 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));
     }
 }