Exemple #1
0
 /**
  * @param $value
  * @param string $cast
  * @return mixed
  */
 protected function castGet($value, string $cast)
 {
     $originalCast = $cast;
     if ($cast[0] === '?') {
         if ($value === null) {
             return null;
         }
         $cast = substr($cast, 1);
     }
     switch ($cast) {
         case 'int':
         case 'integer':
             return (int) $value;
         case 'float':
             return (double) $value;
         case 'bool':
         case 'boolean':
             return (bool) $value;
         case 'string':
             return (string) $value;
         case 'date':
             return DateTime::createFromFormat($this->mapper->getDateFormat(), $value);
         case 'json':
             return json_decode($value);
         case 'json-assoc':
             return json_decode($value, true);
     }
     throw new RuntimeException("Invalid cast type '{$originalCast}'");
 }