mirror of
https://github.com/dg/dibi.git
synced 2025-08-08 15:16:58 +02:00
- DibiRow: added helper methods asDate() & asBool()
- DibiTranslator: added new modifier %in - integer or NULL
This commit is contained in:
@@ -40,6 +40,44 @@ class DibiRow extends ArrayObject
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Converts value to date-time format.
|
||||
* @param string key
|
||||
* @param string format
|
||||
* @return mixed
|
||||
*/
|
||||
public function asDate($key, $format = NULL)
|
||||
{
|
||||
$value = $this[$key];
|
||||
if ($value === NULL || $value === FALSE) {
|
||||
return $value;
|
||||
|
||||
} else {
|
||||
$value = is_numeric($value) ? (int) $value : strtotime($value);
|
||||
return $format === NULL ? $value : date($format, $value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Converts value to boolean.
|
||||
* @param string key
|
||||
* @return mixed
|
||||
*/
|
||||
public function asBool($key)
|
||||
{
|
||||
$value = $this[$key];
|
||||
if ($value === NULL || $value === FALSE) {
|
||||
return $value;
|
||||
|
||||
} else {
|
||||
return ((bool) $value) && $value !== 'f' && $value !== 'F';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* PHP < 5.3 workaround
|
||||
* @return void
|
||||
|
Reference in New Issue
Block a user