1
0
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:
David Grudl
2009-06-03 13:42:02 +00:00
parent 9c435acd2e
commit bf15d60fd1
3 changed files with 46 additions and 1 deletions

View File

@@ -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