Пример #1
0
 /**
  * Get type cast object
  * 
  * @return Jasny\TypeCast
  */
 protected function typeCast($value)
 {
     $typecast = TypeCast::value($value);
     $typecast->alias('self', get_class($this));
     $typecast->alias('static', get_class($this));
     return $typecast;
 }
Пример #2
0
 /**
  * Cast data to use in DB
  * 
  * @param array $data
  * @return array
  */
 protected static function castForDB($data)
 {
     foreach ($data as $key => &$value) {
         $prop = trim(strstr($key, '(', true)) ?: $key;
         // Remove filter directives
         $meta = static::meta()->{$prop};
         if (isset($meta['dbSkip'])) {
             unset($data[$key]);
         } elseif (isset($meta['dbFieldType'])) {
             $value = TypeCast::cast($value, $meta['dbFieldType']);
         }
     }
     return $data;
 }
Пример #3
0
 /**
  * Test type casting presenting multiple array types with no matching type
  * 
  * @expectedException         PHPUnit_Framework_Error_Notice
  * @expectedExceptionMessage  Unable to cast string "rock" to integer|boolean
  */
 public function testToMultipleTypedArrayNoMatch()
 {
     TypeCast::value([1, 'on', false, 'rock'])->toMultiple(['int[]', 'boolean[]']);
 }