for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @author Jared King <[email protected]>
*
* @see http://jaredtking.com
* @copyright 2015 Jared King
* @license MIT
*/
namespace Pulsar;
* Handles value type casting.
class Property
{
* Casts a value to a string.
* @param mixed $value
* @return string
public static function to_string($value)
return (string) $value;
}
* Casts a value to an integer.
* @return int
public static function to_integer($value)
return (int) $value;
* Casts a value to a float.
* @return float
public static function to_float($value)
return (float) $value;
* Casts a value to a number.
* @param $value
* @return number
public static function to_number($value)
return $value + 0;
* Casts a value to a boolean.
* @return bool
public static function to_boolean($value)
return filter_var($value, FILTER_VALIDATE_BOOLEAN);
* Casts a date value as a UNIX timestamp.
public static function to_date($value)
if (!is_numeric($value)) {
return strtotime($value);
} else {
* Casts a value to an array.
* @return array
public static function to_array($value)
// decode JSON strings into an array
if (is_string($value)) {
return json_decode($value, true);
return (array) $value;
* Casts a value to an object.
* @return object
public static function to_object($value)
// decode JSON strings into an object
return (object) json_decode($value);
return (object) $value;